1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2024-12-26 09:48:37 +00:00

core: Migrate configurations from bug fixed in #11173. Fixes #11313 (#11347)

This commit is contained in:
NinjaLikesCheez 2021-03-30 19:47:16 +02:00 committed by GitHub
parent ff941cec43
commit f5688f289d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 27 deletions

View file

@ -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,51 +79,56 @@ 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(oldDirectory, "");
var destPath = GetAppDataFolder() + path;
var destFolder = Path.GetDirectoryName(destPath);
if (!Directory.Exists(destFolder))
{
var path = file.Replace(oldDir, "");
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 dir = Directory.CreateDirectory(destFolder);
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))
}
if (!File.Exists(destPath))
{
File.Copy(file, destPath);
// The old files were created when running as admin so make sure they are editable by normal users / services.
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{
File.Copy(file, destPath);
// The old files were created when running as admin so make sure they are editable by normal users / services.
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{
var fileInfo = new FileInfo(destFolder);
var fileSecurity = new FileSecurity(destPath, AccessControlSections.All);
fileSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow));
fileInfo.SetAccessControl(fileSecurity);
}
var fileInfo = new FileInfo(destFolder);
var fileSecurity = new FileSecurity(destPath, AccessControlSections.All);
fileSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow));
fileInfo.SetAccessControl(fileSecurity);
}
}
Directory.Delete(oldDir, true);
}
Directory.Delete(oldDirectory, true);
}
public T GetConfig<T>()

View file

@ -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);
}
}

View 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);
}
}
}
}