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 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<fs_directory_t> {
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);

View File

@ -397,18 +397,14 @@ auto file::sha256() -> std::optional<std::string> {
#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)
});
}