From a23adf6db69fb3129bd7ee394b31be36fe54e56f Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Thu, 17 Oct 2024 13:35:00 -0500 Subject: [PATCH] fixes --- support/src/utils/file_directory.cpp | 18 +++++++----------- support/src/utils/file_file.cpp | 8 ++------ 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/support/src/utils/file_directory.cpp b/support/src/utils/file_directory.cpp index 7041af67..f633e010 100644 --- a/support/src/utils/file_directory.cpp +++ b/support/src/utils/file_directory.cpp @@ -94,8 +94,8 @@ auto traverse_directory( } // namespace namespace repertory::utils::file { -auto directory::copy_to(std::string_view new_path, - bool overwrite) const -> bool { +auto directory::copy_to(std::string_view new_path, bool overwrite) const + -> bool { REPERTORY_USES_FUNCTION_NAME(); try { @@ -194,7 +194,7 @@ auto directory::exists() const -> bool { #if defined(_WIN32) return ::PathIsDirectoryA(path_.c_str()) != 0; #else // !defined(_WIN32) - struct stat64 st {}; + struct stat64 st{}; return (stat64(path_.c_str(), &st) == 0 && S_ISDIR(st.st_mode)); #endif // defined(_WIN32) @@ -247,8 +247,8 @@ auto directory::get_directories() const -> std::vector { return {}; } -auto directory::create_file(std::string_view file_name, - bool read_only) const -> fs_file_t { +auto directory::create_file(std::string_view file_name, bool read_only) const + -> fs_file_t { REPERTORY_USES_FUNCTION_NAME(); try { @@ -374,16 +374,12 @@ auto directory::move_to(std::string_view new_path) -> bool { auto directory::remove() -> bool { REPERTORY_USES_FUNCTION_NAME(); - if (not exists()) { - return true; - } - return utils::retry_action([this]() -> bool { try { #if defined(_WIN32) - return ::RemoveDirectoryA(path_.c_str()); + return not exists() || (::RemoveDirectoryA(path_.c_str()) != 0); #else // !defined(_WIN32) - return (rmdir(path_.c_str()) == 0); + return not exists() || (rmdir(path_.c_str()) == 0); #endif // defined(_WIN32) } catch (const std::exception &e) { utils::error::handle_exception(function_name, e); diff --git a/support/src/utils/file_file.cpp b/support/src/utils/file_file.cpp index 34673954..e4d747f2 100644 --- a/support/src/utils/file_file.cpp +++ b/support/src/utils/file_file.cpp @@ -397,18 +397,14 @@ auto file::sha256() -> std::optional { #endif // defined(PROJECT_ENABLE_LIBSODIUM) auto file::remove() -> bool { - if (not exists()) { - return true; - } - close(); return utils::retry_action([this]() -> bool { #if defined(_WIN32) - return ::DeleteFileA(path_.c_str()) != 0; + return not exists() || (::DeleteFileA(path_.c_str()) != 0); #else // !defined(_WIN32) std::error_code ec{}; - return std::filesystem::remove(path_, ec); + return not exists() || std::filesystem::remove(path_, ec); #endif // defined(_WIN32) }); }