From 3c186dc20342d9e432d549b95d7eb8c8a25ae87a Mon Sep 17 00:00:00 2001 From: Francis Tsui Date: Mon, 6 Jan 2025 19:50:37 -0800 Subject: [PATCH] Log error message when file operations fail. PiperOrigin-RevId: 712736323 --- internal/base/BUILD | 1 + internal/base/files.cc | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/internal/base/BUILD b/internal/base/BUILD index 4913e996..f3f0d075 100644 --- a/internal/base/BUILD +++ b/internal/base/BUILD @@ -59,6 +59,7 @@ cc_library( srcs = ["files.cc"], hdrs = ["files.h"], visibility = ["//visibility:public"], + deps = ["//internal/platform:logging"], ) cc_test( diff --git a/internal/base/files.cc b/internal/base/files.cc index b0302848..70c64453 100644 --- a/internal/base/files.cc +++ b/internal/base/files.cc @@ -19,6 +19,8 @@ #include #include // NOLINT(build/c++11) +#include "internal/platform/logging.h" + namespace nearby::sharing { bool FileExists(const std::filesystem::path& path) { @@ -81,6 +83,7 @@ bool Rename(const std::filesystem::path& old_path, std::error_code error_code; std::filesystem::rename(old_path, new_path, error_code); if (error_code) { + VLOG(1) << "Failed to rename file: " << error_code.message(); return false; } return true; @@ -90,6 +93,7 @@ bool CreateDirectories(const std::filesystem::path& path) { std::error_code error_code; std::filesystem::create_directories(path, error_code); if (error_code) { + VLOG(1) << "Failed to create directories: " << error_code.message(); return false; } return true; @@ -100,6 +104,7 @@ bool CreateHardLink(const std::filesystem::path& target, std::error_code error_code; std::filesystem::create_hard_link(target, link_path, error_code); if (error_code) { + VLOG(1) << "Failed to create hard link: " << error_code.message(); return false; } return true; @@ -110,6 +115,7 @@ bool CopyFileSafely(const std::filesystem::path& old_path, std::error_code error_code; std::filesystem::copy(old_path, new_path, error_code); if (error_code) { + VLOG(1) << "Failed to copy file: " << error_code.message(); return false; } return true;