Fixed: Ignore .nfs* files during copy actions since those files are special NFS files that should never be touched.

fixes #1552
This commit is contained in:
Taloth Saldono 2017-02-09 19:32:13 +01:00
parent 0782a15979
commit 2f6d9e191e
2 changed files with 88 additions and 0 deletions

View File

@ -16,6 +16,7 @@ namespace NzbDrone.Common.Test.DiskTests
private readonly string _targetPath = @"C:\target\my.video.mkv".AsOsAgnostic(); private readonly string _targetPath = @"C:\target\my.video.mkv".AsOsAgnostic();
private readonly string _backupPath = @"C:\source\my.video.mkv.backup~".AsOsAgnostic(); private readonly string _backupPath = @"C:\source\my.video.mkv.backup~".AsOsAgnostic();
private readonly string _tempTargetPath = @"C:\target\my.video.mkv.partial~".AsOsAgnostic(); private readonly string _tempTargetPath = @"C:\target\my.video.mkv.partial~".AsOsAgnostic();
private readonly string _nfsFile = ".nfs01231232";
[SetUp] [SetUp]
public void SetUp() public void SetUp()
@ -642,6 +643,21 @@ namespace NzbDrone.Common.Test.DiskTests
VerifyCopyFolder(source.FullName, destination.FullName); VerifyCopyFolder(source.FullName, destination.FullName);
} }
[Test]
public void CopyFolder_should_ignore_nfs_temp_file()
{
WithRealDiskProvider();
var source = GetFilledTempFolder();
File.WriteAllText(Path.Combine(source.FullName, _nfsFile), "SubFile1");
var destination = new DirectoryInfo(GetTempFilePath());
Subject.TransferFolder(source.FullName, destination.FullName, TransferMode.Copy);
File.Exists(Path.Combine(destination.FullName, _nfsFile)).Should().BeFalse();
}
[Test] [Test]
public void MoveFolder_should_move_folder() public void MoveFolder_should_move_folder()
@ -704,6 +720,26 @@ namespace NzbDrone.Common.Test.DiskTests
destination.GetFileSystemInfos().Should().BeEmpty(); destination.GetFileSystemInfos().Should().BeEmpty();
} }
[Test]
public void MirrorFolder_should_not_remove_nfs_files()
{
WithRealDiskProvider();
var original = GetFilledTempFolder();
var source = new DirectoryInfo(GetTempFilePath());
var destination = new DirectoryInfo(GetTempFilePath());
source.Create();
Subject.TransferFolder(original.FullName, destination.FullName, TransferMode.Copy);
File.WriteAllText(Path.Combine(destination.FullName, _nfsFile), "SubFile1");
var count = Subject.MirrorFolder(source.FullName, destination.FullName);
count.Should().Equals(0);
destination.GetFileSystemInfos().Should().HaveCount(1);
}
[Test] [Test]
public void MirrorFolder_should_add_new_files() public void MirrorFolder_should_add_new_files()
{ {
@ -721,6 +757,24 @@ namespace NzbDrone.Common.Test.DiskTests
VerifyCopyFolder(original.FullName, destination.FullName); VerifyCopyFolder(original.FullName, destination.FullName);
} }
[Test]
public void MirrorFolder_should_ignore_nfs_temp_file()
{
WithRealDiskProvider();
var source = GetFilledTempFolder();
File.WriteAllText(Path.Combine(source.FullName, _nfsFile), "SubFile1");
var destination = new DirectoryInfo(GetTempFilePath());
var count = Subject.MirrorFolder(source.FullName, destination.FullName);
count.Should().Equals(3);
File.Exists(Path.Combine(destination.FullName, _nfsFile)).Should().BeFalse();
}
[Test] [Test]
public void MirrorFolder_should_not_touch_equivalent_files() public void MirrorFolder_should_not_touch_equivalent_files()
{ {

View File

@ -64,11 +64,15 @@ namespace NzbDrone.Common.Disk
foreach (var subDir in _diskProvider.GetDirectoryInfos(sourcePath)) foreach (var subDir in _diskProvider.GetDirectoryInfos(sourcePath))
{ {
if (ShouldIgnore(subDir)) continue;
result &= TransferFolder(subDir.FullName, Path.Combine(targetPath, subDir.Name), mode, verificationMode); result &= TransferFolder(subDir.FullName, Path.Combine(targetPath, subDir.Name), mode, verificationMode);
} }
foreach (var sourceFile in _diskProvider.GetFileInfos(sourcePath)) foreach (var sourceFile in _diskProvider.GetFileInfos(sourcePath))
{ {
if (ShouldIgnore(sourceFile)) continue;
var destFile = Path.Combine(targetPath, sourceFile.Name); var destFile = Path.Combine(targetPath, sourceFile.Name);
result &= TransferFile(sourceFile.FullName, destFile, mode, true, verificationMode); result &= TransferFile(sourceFile.FullName, destFile, mode, true, verificationMode);
@ -101,11 +105,15 @@ namespace NzbDrone.Common.Disk
foreach (var subDir in targetFolders.Where(v => !sourceFolders.Any(d => d.Name == v.Name))) foreach (var subDir in targetFolders.Where(v => !sourceFolders.Any(d => d.Name == v.Name)))
{ {
if (ShouldIgnore(subDir)) continue;
_diskProvider.DeleteFolder(subDir.FullName, true); _diskProvider.DeleteFolder(subDir.FullName, true);
} }
foreach (var subDir in sourceFolders) foreach (var subDir in sourceFolders)
{ {
if (ShouldIgnore(subDir)) continue;
filesCopied += MirrorFolder(subDir.FullName, Path.Combine(targetPath, subDir.Name)); filesCopied += MirrorFolder(subDir.FullName, Path.Combine(targetPath, subDir.Name));
} }
@ -114,11 +122,15 @@ namespace NzbDrone.Common.Disk
foreach (var targetFile in targetFiles.Where(v => !sourceFiles.Any(d => d.Name == v.Name))) foreach (var targetFile in targetFiles.Where(v => !sourceFiles.Any(d => d.Name == v.Name)))
{ {
if (ShouldIgnore(targetFile)) continue;
_diskProvider.DeleteFile(targetFile.FullName); _diskProvider.DeleteFile(targetFile.FullName);
} }
foreach (var sourceFile in sourceFiles) foreach (var sourceFile in sourceFiles)
{ {
if (ShouldIgnore(sourceFile)) continue;
var targetFile = Path.Combine(targetPath, sourceFile.Name); var targetFile = Path.Combine(targetPath, sourceFile.Name);
if (CompareFiles(sourceFile.FullName, targetFile)) if (CompareFiles(sourceFile.FullName, targetFile))
@ -564,5 +576,27 @@ namespace NzbDrone.Common.Disk
throw; throw;
} }
} }
private bool ShouldIgnore(DirectoryInfo folder)
{
if (folder.Name.StartsWith(".nfs"))
{
_logger.Trace("Ignoring folder {0}", folder.FullName);
return true;
}
return false;
}
private bool ShouldIgnore(FileInfo file)
{
if (file.Name.StartsWith(".nfs"))
{
_logger.Trace("Ignoring file {0}", file.FullName);
return true;
}
return false;
}
} }
} }