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.
|
// On Windows we need admin permissions to migrate as they were made with admin permissions.
|
||||||
if (ServerUtil.IsUserAdministrator())
|
if (ServerUtil.IsUserAdministrator())
|
||||||
{
|
{
|
||||||
PerformMigration();
|
PerformMigration(oldDir);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -79,51 +79,56 @@ namespace Jackett.Common.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
PerformMigration();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logger.Error($"ERROR could not migrate settings directory\n{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(oldDirectory))
|
||||||
if (Directory.Exists(oldDir))
|
|
||||||
{
|
{
|
||||||
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 dir = Directory.CreateDirectory(destFolder);
|
||||||
var destPath = GetAppDataFolder() + path;
|
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
|
||||||
var destFolder = Path.GetDirectoryName(destPath);
|
|
||||||
if (!Directory.Exists(destFolder))
|
|
||||||
{
|
{
|
||||||
var dir = Directory.CreateDirectory(destFolder);
|
|
||||||
var directorySecurity = new DirectorySecurity(destFolder, AccessControlSections.All);
|
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));
|
directorySecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow));
|
||||||
dir.SetAccessControl(directorySecurity);
|
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);
|
var fileInfo = new FileInfo(destFolder);
|
||||||
// The old files were created when running as admin so make sure they are editable by normal users / services.
|
var fileSecurity = new FileSecurity(destPath, AccessControlSections.All);
|
||||||
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
|
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>()
|
public T GetConfig<T>()
|
||||||
|
@@ -15,7 +15,7 @@ namespace Jackett.Common.Services.Interfaces
|
|||||||
string ApplicationFolder();
|
string ApplicationFolder();
|
||||||
List<string> GetCardigannDefinitionsFolders();
|
List<string> GetCardigannDefinitionsFolders();
|
||||||
void CreateOrMigrateSettings();
|
void CreateOrMigrateSettings();
|
||||||
void PerformMigration();
|
void PerformMigration(string oldDirectory);
|
||||||
ServerConfig BuildServerConfig(RuntimeSettings runtimeSettings);
|
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