mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
This commit is contained in:
@@ -63,7 +63,7 @@ namespace Jackett.Common.Services
|
||||
// On Windows we need admin permissions to migrate as they were made with admin permissions.
|
||||
if (ServerUtil.IsUserAdministrator())
|
||||
{
|
||||
PerformMigration();
|
||||
PerformMigration(oldDir);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -79,36 +79,42 @@ namespace Jackett.Common.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PerformMigration();
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error($"ERROR could not migrate settings directory\n{e}");
|
||||
}
|
||||
}
|
||||
|
||||
// Perform a migration in case of https://github.com/Jackett/Jackett/pull/11173#issuecomment-787520128
|
||||
if (Environment.OSVersion.Platform == PlatformID.Unix)
|
||||
{
|
||||
PerformMigration("Jackett");
|
||||
}
|
||||
}
|
||||
|
||||
public void PerformMigration()
|
||||
public void PerformMigration(string oldDirectory)
|
||||
{
|
||||
var oldDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Jackett");
|
||||
if (Directory.Exists(oldDir))
|
||||
if (!Directory.Exists(oldDirectory))
|
||||
{
|
||||
foreach (var file in Directory.GetFiles(oldDir, "*", SearchOption.AllDirectories))
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var file in Directory.GetFiles(oldDirectory, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
var path = file.Replace(oldDir, "");
|
||||
var path = file.Replace(oldDirectory, "");
|
||||
var destPath = GetAppDataFolder() + path;
|
||||
var destFolder = Path.GetDirectoryName(destPath);
|
||||
if (!Directory.Exists(destFolder))
|
||||
{
|
||||
var dir = Directory.CreateDirectory(destFolder);
|
||||
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
|
||||
{
|
||||
var directorySecurity = new DirectorySecurity(destFolder, AccessControlSections.All);
|
||||
directorySecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow));
|
||||
dir.SetAccessControl(directorySecurity);
|
||||
}
|
||||
}
|
||||
if (!File.Exists(destPath))
|
||||
{
|
||||
File.Copy(file, destPath);
|
||||
@@ -122,8 +128,7 @@ namespace Jackett.Common.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
Directory.Delete(oldDir, true);
|
||||
}
|
||||
Directory.Delete(oldDirectory, true);
|
||||
}
|
||||
|
||||
public T GetConfig<T>()
|
||||
|
@@ -15,7 +15,7 @@ namespace Jackett.Common.Services.Interfaces
|
||||
string ApplicationFolder();
|
||||
List<string> GetCardigannDefinitionsFolders();
|
||||
void CreateOrMigrateSettings();
|
||||
void PerformMigration();
|
||||
void PerformMigration(string oldDirectory);
|
||||
ServerConfig BuildServerConfig(RuntimeSettings runtimeSettings);
|
||||
}
|
||||
}
|
||||
|
29
src/Jackett.Test/Server/Services/RuntimeSettingsTests.cs
Normal file
29
src/Jackett.Test/Server/Services/RuntimeSettingsTests.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Jackett.Common.Models.Config;
|
||||
using Jackett.Test.TestHelpers;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Jackett.Test.Server.Services
|
||||
{
|
||||
[TestFixture]
|
||||
internal class RuntimeSettingsTests : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void Default_data_folder_is_correct()
|
||||
{
|
||||
var runtimeSettings = new RuntimeSettings();
|
||||
var dataFolder = runtimeSettings.DataFolder;
|
||||
|
||||
if (System.Environment.OSVersion.Platform == PlatformID.Unix)
|
||||
{
|
||||
var expectedUnixPath = Environment.GetEnvironmentVariable("HOME") + "/.config/Jackett";
|
||||
Assert.AreEqual(expectedUnixPath, dataFolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
var expectedWindowsPath = Environment.ExpandEnvironmentVariables("%ProgramData%") + "\\Jackett";
|
||||
Assert.AreEqual(expectedWindowsPath, dataFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user