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 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Core.Test.MediaFiles
[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 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
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 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
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 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
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 @@ namespace NzbDrone.Core.MediaFiles
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 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
return true;
}
if (_diskProvider.IsFileLocked(new FileInfo(localEpisode.Path)))
if (_diskProvider.IsFileLocked(localEpisode.Path))
{
_logger.Trace("{0} is in use");
return false;