Diskprovider cleanup.
This commit is contained in:
parent
345b20f55f
commit
601cd31a1f
|
@ -25,8 +25,8 @@ namespace NzbDrone.Common
|
||||||
string[] GetFiles(string path, SearchOption searchOption);
|
string[] GetFiles(string path, SearchOption searchOption);
|
||||||
long GetFolderSize(string path);
|
long GetFolderSize(string path);
|
||||||
long GetFileSize(string path);
|
long GetFileSize(string path);
|
||||||
String CreateFolder(string path);
|
void CreateFolder(string path);
|
||||||
void CopyFolder(string source, string target);
|
void CopyFolder(string source, string destination);
|
||||||
void MoveFolder(string source, string destination);
|
void MoveFolder(string source, string destination);
|
||||||
void DeleteFile(string path);
|
void DeleteFile(string path);
|
||||||
void MoveFile(string source, string destination);
|
void MoveFile(string source, string destination);
|
||||||
|
@ -37,7 +37,7 @@ namespace NzbDrone.Common
|
||||||
void WriteAllText(string filename, string contents);
|
void WriteAllText(string filename, string contents);
|
||||||
void FileSetLastWriteTimeUtc(string path, DateTime dateTime);
|
void FileSetLastWriteTimeUtc(string path, DateTime dateTime);
|
||||||
void FolderSetLastWriteTimeUtc(string path, DateTime dateTime);
|
void FolderSetLastWriteTimeUtc(string path, DateTime dateTime);
|
||||||
bool IsFileLocked(FileInfo file);
|
bool IsFileLocked(string path);
|
||||||
string GetPathRoot(string path);
|
string GetPathRoot(string path);
|
||||||
void SetPermissions(string filename, WellKnownSidType accountSid, FileSystemRights rights, AccessControlType controlType);
|
void SetPermissions(string filename, WellKnownSidType accountSid, FileSystemRights rights, AccessControlType controlType);
|
||||||
bool IsParent(string parentPath, string childPath);
|
bool IsParent(string parentPath, string childPath);
|
||||||
|
@ -162,19 +162,18 @@ namespace NzbDrone.Common
|
||||||
return fi.Length;
|
return fi.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String CreateFolder(string path)
|
public void CreateFolder(string path)
|
||||||
{
|
{
|
||||||
Ensure.That(() => path).IsValidPath();
|
Ensure.That(() => path).IsValidPath();
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
return Directory.CreateDirectory(path).FullName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CopyFolder(string source, string target)
|
public void CopyFolder(string source, string destination)
|
||||||
{
|
{
|
||||||
Ensure.That(() => source).IsValidPath();
|
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)
|
public void MoveFolder(string source, string destination)
|
||||||
|
@ -367,13 +366,17 @@ namespace NzbDrone.Common
|
||||||
Directory.SetLastWriteTimeUtc(path, 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;
|
FileStream stream = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None);
|
stream = File.OpenRead(file);
|
||||||
}
|
}
|
||||||
catch (IOException)
|
catch (IOException)
|
||||||
{
|
{
|
||||||
|
|
|
@ -75,7 +75,7 @@ namespace NzbDrone.Core.Test.MediaFiles
|
||||||
[Test]
|
[Test]
|
||||||
public void should_skip_if_file_is_in_use_by_another_process()
|
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);
|
.Returns(true);
|
||||||
|
|
||||||
Subject.Execute(new DownloadedEpisodesScanCommand());
|
Subject.Execute(new DownloadedEpisodesScanCommand());
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||||
Subject.IsSatisfiedBy(_localEpisode);
|
Subject.IsSatisfiedBy(_localEpisode);
|
||||||
|
|
||||||
Mocker.GetMock<IDiskProvider>()
|
Mocker.GetMock<IDiskProvider>()
|
||||||
.Verify(v => v.IsFileLocked(It.IsAny<FileInfo>()), Times.Never());
|
.Verify(v => v.IsFileLocked(It.IsAny<string>()), Times.Never());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -67,7 +67,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||||
GivenNewFile();
|
GivenNewFile();
|
||||||
|
|
||||||
Mocker.GetMock<IDiskProvider>()
|
Mocker.GetMock<IDiskProvider>()
|
||||||
.Setup(s => s.IsFileLocked(It.IsAny<FileInfo>()))
|
.Setup(s => s.IsFileLocked(It.IsAny<string>()))
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
|
|
||||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
Subject.IsSatisfiedBy(_localEpisode).Should().BeFalse();
|
||||||
|
@ -79,7 +79,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
|
||||||
GivenNewFile();
|
GivenNewFile();
|
||||||
|
|
||||||
Mocker.GetMock<IDiskProvider>()
|
Mocker.GetMock<IDiskProvider>()
|
||||||
.Setup(s => s.IsFileLocked(It.IsAny<FileInfo>()))
|
.Setup(s => s.IsFileLocked(It.IsAny<string>()))
|
||||||
.Returns(false);
|
.Returns(false);
|
||||||
|
|
||||||
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
Subject.IsSatisfiedBy(_localEpisode).Should().BeTrue();
|
||||||
|
|
|
@ -125,7 +125,7 @@ namespace NzbDrone.Core.MediaFiles
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_diskProvider.IsFileLocked(new FileInfo(videoFile)))
|
if (_diskProvider.IsFileLocked(videoFile))
|
||||||
{
|
{
|
||||||
_logger.Debug("[{0}] is currently locked by another process, skipping", videoFile);
|
_logger.Debug("[{0}] is currently locked by another process, skipping", videoFile);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_diskProvider.IsFileLocked(new FileInfo(localEpisode.Path)))
|
if (_diskProvider.IsFileLocked(localEpisode.Path))
|
||||||
{
|
{
|
||||||
_logger.Trace("{0} is in use");
|
_logger.Trace("{0} is in use");
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue