1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-22 07:43:01 +00:00

Recompare file size after import file if necessary

This commit is contained in:
Jared Ledvina 2024-10-07 18:25:52 -04:00 committed by GitHub
parent bc0fc623ee
commit 6660db22ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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"))