From 82e222bf23dee04e6fb825037fbb4d86a9571ce0 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Tue, 21 Apr 2026 17:22:18 +0200 Subject: filesystem.h surface error codes (#998) - Improvement: File copy, scan, clone, and move operations now report the underlying OS error in failure messages --- src/zenutil/filesystemutils.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/zenutil/filesystemutils.cpp') 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& 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)); } } } -- cgit v1.2.3