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/zen/cmds/admin_cmd.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/zen/cmds/admin_cmd.cpp') diff --git a/src/zen/cmds/admin_cmd.cpp b/src/zen/cmds/admin_cmd.cpp index 12ffd49aa..2580517fa 100644 --- a/src/zen/cmds/admin_cmd.cpp +++ b/src/zen/cmds/admin_cmd.cpp @@ -489,9 +489,10 @@ LoggingCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) { throw std::runtime_error(fmt::format("Failed to retrieve {} log path", SourceName)); } - if (!CopyFile(SourcePath, TargetPath, {})) + if (std::error_code Ec = CopyFile(SourcePath, TargetPath, {}); Ec) { - throw std::runtime_error( + throw std::system_error( + Ec, fmt::format("Failed to copy {} log file {} to output file '{}'", SourceName, SourcePath, TargetPath)); } }; @@ -585,7 +586,10 @@ Copy(const std::filesystem::path& Source, const std::filesystem::path& Target) CreateDirectories(Target.parent_path()); CopyFileOptions Options; - CopyFile(Source, Target, Options); + if (std::error_code Ec = CopyFile(Source, Target, Options); Ec) + { + throw std::system_error(Ec, fmt::format("Failed to copy '{}' to '{}'", Source, Target)); + } } static bool @@ -599,7 +603,8 @@ TryCopy(const std::filesystem::path& Source, const std::filesystem::path& Target CreateDirectories(Target.parent_path()); CopyFileOptions Options; - return CopyFile(Source, Target, Options); + std::error_code Ec = CopyFile(Source, Target, Options); + return !Ec; } void -- cgit v1.2.3