Diskprovider cleanup.

This commit is contained in:
kay.one 2013-09-11 23:52:37 -07:00
parent 345b20f55f
commit 601cd31a1f
5 changed files with 21 additions and 18 deletions

View file

@ -25,8 +25,8 @@ public interface IDiskProvider
string[] GetFiles(string path, SearchOption searchOption);
long GetFolderSize(string path);
long GetFileSize(string path);
String CreateFolder(string path);
void CopyFolder(string source, string target);
void CreateFolder(string path);
void CopyFolder(string source, string destination);
void MoveFolder(string source, string destination);
void DeleteFile(string path);
void MoveFile(string source, string destination);
@ -37,7 +37,7 @@ public interface IDiskProvider
void WriteAllText(string filename, string contents);
void FileSetLastWriteTimeUtc(string path, DateTime dateTime);
void FolderSetLastWriteTimeUtc(string path, DateTime dateTime);
bool IsFileLocked(FileInfo file);
bool IsFileLocked(string path);
string GetPathRoot(string path);
void SetPermissions(string filename, WellKnownSidType accountSid, FileSystemRights rights, AccessControlType controlType);
bool IsParent(string parentPath, string childPath);
@ -60,7 +60,7 @@ static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes);
private static readonly Logger Logger = NzbDroneLogger.GetLogger();
private static readonly Logger Logger = NzbDroneLogger.GetLogger();
public HashSet<string> SpecialFolders
{
@ -162,19 +162,18 @@ public long GetFileSize(string path)
return fi.Length;
}
public String CreateFolder(string path)
public void CreateFolder(string path)
{
Ensure.That(() => path).IsValidPath();
return Directory.CreateDirectory(path).FullName;
Directory.CreateDirectory(path);
}
public void CopyFolder(string source, string target)
public void CopyFolder(string source, string destination)
{
Ensure.That(() => source).IsValidPath();
Ensure.That(() => target).IsValidPath();
Ensure.That(() => destination).IsValidPath();
TransferFolder(source, target, TransferAction.Copy);
TransferFolder(source, destination, TransferAction.Copy);
}
public void MoveFolder(string source, string destination)
@ -367,13 +366,17 @@ public void FolderSetLastWriteTimeUtc(string path, DateTime dateTime)
Directory.SetLastWriteTimeUtc(path, dateTime);
}
public bool IsFileLocked(FileInfo file)
public bool IsFileLocked(string file)
{
//TOOD: Needs test
//TODO: move to using instead of trycatch
//TODO: prob should use OpenWrite to check for lock.
FileStream stream = null;
try
{
stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None);
stream = File.OpenRead(file);
}
catch (IOException)
{

View file

@ -75,7 +75,7 @@ public void should_skip_import_if_dropfolder_doesnt_exist()
[Test]
public void should_skip_if_file_is_in_use_by_another_process()
{
Mocker.GetMock<IDiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<FileInfo>()))
Mocker.GetMock<IDiskProvider>().Setup(c => c.IsFileLocked(It.IsAny<string>()))
.Returns(true);
Subject.Execute(new DownloadedEpisodesScanCommand());

View file

@ -58,7 +58,7 @@ public void should_not_check_for_file_in_use_if_child_of_series_folder()
Subject.IsSatisfiedBy(_localEpisode);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.IsFileLocked(It.IsAny<FileInfo>()), Times.Never());
.Verify(v => v.IsFileLocked(It.IsAny<string>()), Times.Never());
}
[Test]
@ -67,7 +67,7 @@ public void should_return_false_if_file_is_in_use()
GivenNewFile();
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.IsFileLocked(It.IsAny<FileInfo>()))
.Setup(s => s.IsFileLocked(It.IsAny<string>()))
.Returns(true);
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
@ -79,7 +79,7 @@ public void should_return_true_if_file_is_not_in_use()
GivenNewFile();
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.IsFileLocked(It.IsAny<FileInfo>()))
.Setup(s => s.IsFileLocked(It.IsAny<string>()))
.Returns(false);
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();

View file

@ -125,7 +125,7 @@ private void ProcessVideoFile(string videoFile)
return;
}
if (_diskProvider.IsFileLocked(new FileInfo(videoFile)))
if (_diskProvider.IsFileLocked(videoFile))
{
_logger.Debug("[{0}] is currently locked by another process, skipping", videoFile);
return;

View file

@ -26,7 +26,7 @@ public bool IsSatisfiedBy(LocalEpisode localEpisode)
return true;
}
if (_diskProvider.IsFileLocked(new FileInfo(localEpisode.Path)))
if (_diskProvider.IsFileLocked(localEpisode.Path))
{
_logger.Trace("{0} is in use");
return false;