From fd71d5d452030efa8e9b7824c4cc696b47f40bfd Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 23 Aug 2024 19:24:10 -0500 Subject: [PATCH] updated build system --- support/src/utils/file_directory.cpp | 12 ++++++++++-- support/src/utils/file_file.cpp | 4 ++-- support/src/utils/file_smb_directory.cpp | 8 ++++++++ support/src/utils/file_smb_file.cpp | 4 ++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/support/src/utils/file_directory.cpp b/support/src/utils/file_directory.cpp index cf418063..f0e41850 100644 --- a/support/src/utils/file_directory.cpp +++ b/support/src/utils/file_directory.cpp @@ -330,12 +330,16 @@ auto directory::remove() -> bool { static_cast(__FUNCTION__), }; + if (not exists()) { + return true; + } + return utils::retry_action([this]() -> bool { try { #if defined(_WIN32) - return (not exists() || ::RemoveDirectoryA(path_.c_str())); + return (::RemoveDirectoryA(path_.c_str())); #else // !defined(_WIN32) - return not exists() || (rmdir(path_.c_str()) == 0); + return (rmdir(path_.c_str()) == 0); #endif // defined(_WIN32) } catch (const std::exception &e) { utils::error::handle_exception(function_name, e); @@ -353,6 +357,10 @@ auto directory::remove_recursively() -> bool { }; try { + if (not exists()) { + return true; + } + if (not traverse_directory( path_, [](auto dir_item) -> bool { return dir_item.remove_recursively(); }, diff --git a/support/src/utils/file_file.cpp b/support/src/utils/file_file.cpp index e4fc58c6..515d08f0 100644 --- a/support/src/utils/file_file.cpp +++ b/support/src/utils/file_file.cpp @@ -404,12 +404,12 @@ auto file::remove() -> bool { recur_mutex_lock lock{*mtx_}; #endif // defined(_WIN32) - close(); - if (not exists()) { return true; } + close(); + return utils::retry_action([this]() -> bool { #if defined(_WIN32) return !!::DeleteFileA(path_.c_str()); diff --git a/support/src/utils/file_smb_directory.cpp b/support/src/utils/file_smb_directory.cpp index d5b74966..1add16c9 100644 --- a/support/src/utils/file_smb_directory.cpp +++ b/support/src/utils/file_smb_directory.cpp @@ -491,6 +491,10 @@ auto smb_directory::remove() -> bool { throw std::runtime_error("session not found|" + path_); } + if (not exists()) { + return true; + } + return utils::retry_action([this]() -> bool { try { auto res = smb_directory_rm(session_.get(), tid_, @@ -528,6 +532,10 @@ auto smb_directory::remove_recursively() -> bool { throw std::runtime_error("session not found|" + path_); } + if (not exists()) { + return true; + } + throw std::runtime_error("failed to remove directory recursively|" + path_ + "|not implemented"); } catch (const std::exception &e) { diff --git a/support/src/utils/file_smb_file.cpp b/support/src/utils/file_smb_file.cpp index 659c8a92..54ac70d5 100644 --- a/support/src/utils/file_smb_file.cpp +++ b/support/src/utils/file_smb_file.cpp @@ -272,6 +272,10 @@ auto smb_file::remove() -> bool { }; try { + if (not exists()) { + return true; + } + close(); return utils::retry_action([this]() -> bool {