2015-01-21 19:59:03 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Security.AccessControl;
|
|
|
|
|
using System.Security.Principal;
|
|
|
|
|
using NUnit.Framework;
|
2014-12-16 07:28:55 +00:00
|
|
|
|
using NzbDrone.Common.Test.DiskTests;
|
2016-08-12 03:30:18 +00:00
|
|
|
|
using NzbDrone.Windows.Disk;
|
2014-01-06 06:20:08 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Windows.Test.DiskProviderTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2014-05-04 14:33:25 +00:00
|
|
|
|
[Platform("Win")]
|
2014-01-06 06:20:08 +00:00
|
|
|
|
public class DiskProviderFixture : DiskProviderFixtureBase<DiskProvider>
|
|
|
|
|
{
|
|
|
|
|
public DiskProviderFixture()
|
|
|
|
|
{
|
|
|
|
|
WindowsOnly();
|
|
|
|
|
}
|
2015-01-21 19:59:03 +00:00
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
{
|
2019-10-28 21:30:08 +00:00
|
|
|
|
var directory = new DirectoryInfo(path);
|
|
|
|
|
var ds = directory.GetAccessControl();
|
2015-01-21 19:59:03 +00:00
|
|
|
|
ds.SetAccessRule(new FileSystemAccessRule(owner, FileSystemRights.Write, accessControlType));
|
2019-10-28 21:30:08 +00:00
|
|
|
|
directory.SetAccessControl(ds);
|
2015-01-21 19:59:03 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-10-28 21:30:08 +00:00
|
|
|
|
var file = new FileInfo(path);
|
|
|
|
|
var fs = file.GetAccessControl();
|
2015-01-21 19:59:03 +00:00
|
|
|
|
fs.SetAccessRule(new FileSystemAccessRule(owner, FileSystemRights.Write, accessControlType));
|
2019-10-28 21:30:08 +00:00
|
|
|
|
file.SetAccessControl(fs);
|
2015-01-21 19:59:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-06 06:20:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|