diff --git a/src/NzbDrone.Common/Disk/DiskTransferService.cs b/src/NzbDrone.Common/Disk/DiskTransferService.cs index fb7d93f48..2da930a78 100644 --- a/src/NzbDrone.Common/Disk/DiskTransferService.cs +++ b/src/NzbDrone.Common/Disk/DiskTransferService.cs @@ -474,12 +474,7 @@ namespace NzbDrone.Common.Disk try { _diskProvider.CopyFile(sourcePath, targetPath); - - var targetSize = _diskProvider.GetFileSize(targetPath); - if (targetSize != originalSize) - { - throw new IOException(string.Format("File copy incomplete. [{0}] was {1} bytes long instead of {2} bytes.", targetPath, targetSize, originalSize)); - } + VerifyFile(sourcePath, targetPath, originalSize, "copy"); } catch { @@ -493,12 +488,7 @@ namespace NzbDrone.Common.Disk try { _diskProvider.MoveFile(sourcePath, targetPath); - - var targetSize = _diskProvider.GetFileSize(targetPath); - if (targetSize != originalSize) - { - throw new IOException(string.Format("File move incomplete, data loss may have occurred. [{0}] was {1} bytes long instead of the expected {2}.", targetPath, targetSize, originalSize)); - } + VerifyFile(sourcePath, targetPath, originalSize, "move"); } catch (Exception ex) { @@ -511,6 +501,27 @@ namespace NzbDrone.Common.Disk } } + private void VerifyFile(string sourcePath, string targetPath, long originalSize, string action) + { + var targetSize = _diskProvider.GetFileSize(targetPath); + + if (targetSize == originalSize) + { + return; + } + + _logger.Debug("File {0} incomplete, waiting in case filesystem is not synchronized. [{1}] was {2} bytes long instead of the expected {3}.", action, targetPath, targetSize, originalSize); + WaitForIO(); + targetSize = _diskProvider.GetFileSize(targetPath); + + if (targetSize == originalSize) + { + return; + } + + throw new IOException(string.Format("File {0} incomplete, data loss may have occurred. [{1}] was {2} bytes long instead of the expected {3}.", action, targetPath, targetSize, originalSize)); + } + private bool ShouldIgnore(DirectoryInfo folder) { if (folder.Name.StartsWith(".nfs"))