From 958a863d8f62bd24714ab132f85c48f10251dcdb Mon Sep 17 00:00:00 2001 From: Jared Ledvina Date: Mon, 7 Oct 2024 18:25:52 -0400 Subject: [PATCH] Recompare file size after import file if necessary (cherry picked from commit 6660db22ecf53d7747e3abc400529669ea779fa1) --- .../Disk/DiskTransferService.cs | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) 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"))