mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-25 01:02:05 +00:00
Set ProgramData folder permissions for everyone
This commit is contained in:
parent
c719b17ac0
commit
72fe0e74d7
2 changed files with 34 additions and 4 deletions
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security.AccessControl;
|
||||
using NLog;
|
||||
|
||||
namespace NzbDrone.Common.EnvironmentInfo
|
||||
{
|
||||
|
@ -24,12 +26,13 @@ public AppFolderInfo(IDiskProvider diskProvider)
|
|||
|
||||
if (!_diskProvider.FolderExists(AppDataFolder))
|
||||
{
|
||||
MigrateFromAppDate();
|
||||
MigrateFromAppData();
|
||||
}
|
||||
|
||||
SetPermissions();
|
||||
}
|
||||
|
||||
|
||||
private void MigrateFromAppDate()
|
||||
private void MigrateFromAppData()
|
||||
{
|
||||
var oldAppDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.DoNotVerify), "NzbDrone");
|
||||
|
||||
|
@ -43,6 +46,18 @@ private void MigrateFromAppDate()
|
|||
}
|
||||
}
|
||||
|
||||
private void SetPermissions()
|
||||
{
|
||||
try
|
||||
{
|
||||
_diskProvider.SetPermissions(AppDataFolder, "Everyone", FileSystemRights.FullControl, AccessControlType.Allow);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Todo: Add logging
|
||||
}
|
||||
}
|
||||
|
||||
public string AppDataFolder { get; private set; }
|
||||
|
||||
public string StartUpFolder { get; private set; }
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.AccessControl;
|
||||
using NLog;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
@ -33,6 +34,7 @@ public interface IDiskProvider
|
|||
void FolderSetLastWriteTimeUtc(string path, DateTime dateTime);
|
||||
bool IsFileLocked(FileInfo file);
|
||||
string GetPathRoot(string path);
|
||||
void SetPermissions(string filename, string account, FileSystemRights Rights, AccessControlType ControlType);
|
||||
}
|
||||
|
||||
public class DiskProvider : IDiskProvider
|
||||
|
@ -83,7 +85,6 @@ public virtual DateTime GetLastFileWrite(string path)
|
|||
return new FileInfo(path).LastWriteTimeUtc;
|
||||
}
|
||||
|
||||
|
||||
public virtual void EnsureFolder(string path)
|
||||
{
|
||||
if (!FolderExists(path))
|
||||
|
@ -366,5 +367,19 @@ public virtual string GetPathRoot(string path)
|
|||
|
||||
return Path.GetPathRoot(path);
|
||||
}
|
||||
|
||||
public void SetPermissions(string filename, string account, FileSystemRights rights, AccessControlType controlType)
|
||||
{
|
||||
var directoryInfo = new DirectoryInfo(filename);
|
||||
var directorySecurity = directoryInfo.GetAccessControl();
|
||||
|
||||
var accessRule = new FileSystemAccessRule(account, rights,
|
||||
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
|
||||
PropagationFlags.None, controlType);
|
||||
|
||||
|
||||
directorySecurity.AddAccessRule(accessRule);
|
||||
directoryInfo.SetAccessControl(directorySecurity);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue