diff options
Diffstat (limited to 'src/zenutil')
| -rw-r--r-- | src/zenutil/filesystemutils.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/zenutil/filesystemutils.cpp b/src/zenutil/filesystemutils.cpp index ccc42a838..f8f7bfb18 100644 --- a/src/zenutil/filesystemutils.cpp +++ b/src/zenutil/filesystemutils.cpp @@ -211,7 +211,9 @@ FastCopyFile(bool AllowFileClone, std::atomic<uint64_t>& CloneByteCount) { ZEN_TRACE_CPU("CopyFile"); - if (AllowFileClone && TryCloneFile(SourceFilePath, TargetFilePath)) + std::error_code CloneEc = + AllowFileClone ? TryCloneFile(SourceFilePath, TargetFilePath) : std::make_error_code(std::errc::operation_not_supported); + if (!CloneEc) { WriteCount += 1; WriteByteCount += RawSize; @@ -225,15 +227,16 @@ FastCopyFile(bool AllowFileClone, { PrepareFileForScatteredWrite(TargetFile.Handle(), RawSize); } - uint64_t Offset = 0; - if (!ScanFile(SourceFilePath, 512u * 1024u, [&](const void* Data, size_t Size) { - TargetFile.Write(Data, Size, Offset); - Offset += Size; - WriteCount++; - WriteByteCount += Size; - })) + uint64_t Offset = 0; + std::error_code ScanEc = ScanFile(SourceFilePath, 512u * 1024u, [&](const void* Data, size_t Size) { + TargetFile.Write(Data, Size, Offset); + Offset += Size; + WriteCount++; + WriteByteCount += Size; + }); + if (ScanEc) { - throw std::runtime_error(fmt::format("Failed to copy file '{}' to '{}'", SourceFilePath, TargetFilePath)); + throw std::system_error(ScanEc, fmt::format("Failed to copy file '{}' to '{}'", SourceFilePath, TargetFilePath)); } } } |