disk provider removes readonly flag before trying to delete files.

This commit is contained in:
kay.one
2013-09-12 21:59:29 -07:00
parent d64e902fa0
commit 0ebbe102c9
10 changed files with 119 additions and 46 deletions
@@ -23,6 +23,10 @@ namespace NzbDrone.Common.Test.DiskProviderTests
if (_binFolderCopy.Exists)
{
foreach (var file in _binFolderCopy.GetFiles("*", SearchOption.AllDirectories))
{
file.Attributes = FileAttributes.Normal;
}
_binFolderCopy.Delete(true);
}
@@ -83,11 +87,7 @@ namespace NzbDrone.Common.Test.DiskProviderTests
[Test]
public void CopyFolder_should_copy_folder()
{
Subject.CopyFolder(_binFolder.FullName, _binFolderCopy.FullName);
VerifyCopy();
}
@@ -127,6 +127,22 @@ namespace NzbDrone.Common.Test.DiskProviderTests
}
[Test]
public void move_read_only_file()
{
var source = GetTestFilePath();
var destination = GetTestFilePath();
Subject.WriteAllText(source, "SourceFile");
Subject.WriteAllText(destination, "DestinationFile");
File.SetAttributes(source, FileAttributes.ReadOnly);
File.SetAttributes(destination, FileAttributes.ReadOnly);
Subject.MoveFile(source, destination);
}
[Test]
@@ -139,7 +155,7 @@ namespace NzbDrone.Common.Test.DiskProviderTests
[Test]
public void folder_should_return_correct_value_for_last_write()
{
var testFile = Path.Combine(SandboxFolder, "newfile.txt");
var testFile = GetTestFilePath();
TestLogger.Info("Path is: {0}", testFile);
@@ -149,6 +165,39 @@ namespace NzbDrone.Common.Test.DiskProviderTests
Subject.GetLastFolderWrite(SandboxFolder).Should().BeBefore(DateTime.UtcNow);
}
[Test]
public void should_return_false_for_unlocked_file()
{
var testFile = GetTestFilePath();
Subject.WriteAllText(testFile, new Guid().ToString());
Subject.IsFileLocked(testFile).Should().BeFalse();
}
[Test]
public void should_return_false_for_unlocked_and_readonly_file()
{
var testFile = GetTestFilePath();
Subject.WriteAllText(testFile, new Guid().ToString());
File.SetAttributes(testFile, FileAttributes.ReadOnly);
Subject.IsFileLocked(testFile).Should().BeFalse();
}
[Test]
public void should_return_true_for_unlocked_file()
{
var testFile = GetTestFilePath();
Subject.WriteAllText(testFile, new Guid().ToString());
using (var file = File.OpenWrite(testFile))
{
Subject.IsFileLocked(testFile).Should().BeTrue();
}
}
[Test]
[Explicit]
public void check_last_write()