This commit is contained in:
Scott E. Graves 2024-10-17 13:35:00 -05:00
parent da5752e971
commit a23adf6db6
2 changed files with 9 additions and 17 deletions

View File

@ -94,8 +94,8 @@ auto traverse_directory(
} // namespace } // namespace
namespace repertory::utils::file { namespace repertory::utils::file {
auto directory::copy_to(std::string_view new_path, auto directory::copy_to(std::string_view new_path, bool overwrite) const
bool overwrite) const -> bool { -> bool {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -247,8 +247,8 @@ auto directory::get_directories() const -> std::vector<fs_directory_t> {
return {}; return {};
} }
auto directory::create_file(std::string_view file_name, auto directory::create_file(std::string_view file_name, bool read_only) const
bool read_only) const -> fs_file_t { -> fs_file_t {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -374,16 +374,12 @@ auto directory::move_to(std::string_view new_path) -> bool {
auto directory::remove() -> bool { auto directory::remove() -> bool {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (not exists()) {
return true;
}
return utils::retry_action([this]() -> bool { return utils::retry_action([this]() -> bool {
try { try {
#if defined(_WIN32) #if defined(_WIN32)
return ::RemoveDirectoryA(path_.c_str()); return not exists() || (::RemoveDirectoryA(path_.c_str()) != 0);
#else // !defined(_WIN32) #else // !defined(_WIN32)
return (rmdir(path_.c_str()) == 0); return not exists() || (rmdir(path_.c_str()) == 0);
#endif // defined(_WIN32) #endif // defined(_WIN32)
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::handle_exception(function_name, e); utils::error::handle_exception(function_name, e);

View File

@ -397,18 +397,14 @@ auto file::sha256() -> std::optional<std::string> {
#endif // defined(PROJECT_ENABLE_LIBSODIUM) #endif // defined(PROJECT_ENABLE_LIBSODIUM)
auto file::remove() -> bool { auto file::remove() -> bool {
if (not exists()) {
return true;
}
close(); close();
return utils::retry_action([this]() -> bool { return utils::retry_action([this]() -> bool {
#if defined(_WIN32) #if defined(_WIN32)
return ::DeleteFileA(path_.c_str()) != 0; return not exists() || (::DeleteFileA(path_.c_str()) != 0);
#else // !defined(_WIN32) #else // !defined(_WIN32)
std::error_code ec{}; std::error_code ec{};
return std::filesystem::remove(path_, ec); return not exists() || std::filesystem::remove(path_, ec);
#endif // defined(_WIN32) #endif // defined(_WIN32)
}); });
} }