mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-04-24 22:37:06 -04:00
Added FolderWritable to DiskProvider to centralize the check.
This commit is contained in:
parent
104d35299b
commit
11803afc39
10 changed files with 106 additions and 49 deletions
|
@ -1,4 +1,7 @@
|
|||
using NUnit.Framework;
|
||||
using System.IO;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Test.DiskTests;
|
||||
|
||||
namespace NzbDrone.Windows.Test.DiskProviderTests
|
||||
|
@ -11,5 +14,26 @@ namespace NzbDrone.Windows.Test.DiskProviderTests
|
|||
{
|
||||
WindowsOnly();
|
||||
}
|
||||
|
||||
protected override void SetWritePermissions(string path, bool writable)
|
||||
{
|
||||
// Remove Write permissions, we're owner and have Delete permissions, so we can still clean it up.
|
||||
|
||||
var owner = WindowsIdentity.GetCurrent().Owner;
|
||||
var accessControlType = writable ? AccessControlType.Allow : AccessControlType.Deny;
|
||||
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
var ds = Directory.GetAccessControl(path);
|
||||
ds.SetAccessRule(new FileSystemAccessRule(owner, FileSystemRights.Write, accessControlType));
|
||||
Directory.SetAccessControl(path, ds);
|
||||
}
|
||||
else
|
||||
{
|
||||
var fs = File.GetAccessControl(path);
|
||||
fs.SetAccessRule(new FileSystemAccessRule(owner, FileSystemRights.Write, accessControlType));
|
||||
File.SetAccessControl(path, fs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue