Recompare file size after import file if necessary

(cherry picked from commit 6660db22ecf53d7747e3abc400529669ea779fa1)
pull/10499/head
Jared Ledvina 1 month ago committed by Bogdan
parent 8b7884deb0
commit 958a863d8f

@ -474,12 +474,7 @@ namespace NzbDrone.Common.Disk
try try
{ {
_diskProvider.CopyFile(sourcePath, targetPath); _diskProvider.CopyFile(sourcePath, targetPath);
VerifyFile(sourcePath, targetPath, originalSize, "copy");
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));
}
} }
catch catch
{ {
@ -493,12 +488,7 @@ namespace NzbDrone.Common.Disk
try try
{ {
_diskProvider.MoveFile(sourcePath, targetPath); _diskProvider.MoveFile(sourcePath, targetPath);
VerifyFile(sourcePath, targetPath, originalSize, "move");
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));
}
} }
catch (Exception ex) 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) private bool ShouldIgnore(DirectoryInfo folder)
{ {
if (folder.Name.StartsWith(".nfs")) if (folder.Name.StartsWith(".nfs"))

Loading…
Cancel
Save