fixes
This commit is contained in:
parent
da5752e971
commit
a23adf6db6
@ -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 {
|
||||||
@ -194,7 +194,7 @@ auto directory::exists() const -> bool {
|
|||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
return ::PathIsDirectoryA(path_.c_str()) != 0;
|
return ::PathIsDirectoryA(path_.c_str()) != 0;
|
||||||
#else // !defined(_WIN32)
|
#else // !defined(_WIN32)
|
||||||
struct stat64 st {};
|
struct stat64 st{};
|
||||||
return (stat64(path_.c_str(), &st) == 0 && S_ISDIR(st.st_mode));
|
return (stat64(path_.c_str(), &st) == 0 && S_ISDIR(st.st_mode));
|
||||||
#endif // defined(_WIN32)
|
#endif // defined(_WIN32)
|
||||||
|
|
||||||
@ -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);
|
||||||
|
@ -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)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user