updated build system

This commit is contained in:
2024-08-23 09:34:41 -05:00
parent bc85e34310
commit 4eff7aae64
19 changed files with 198 additions and 226 deletions

View File

@ -21,6 +21,7 @@
*/
#include "utils/common.hpp"
#include "utils/error.hpp"
#include "utils/string.hpp"
namespace repertory::utils {
@ -153,4 +154,27 @@ auto get_next_available_port(std::uint16_t first_port,
return not error_code;
}
#endif // defined(PROJECT_ENABLE_BOOST)
auto retry_action(retryable_action_t action, std::size_t retry_count,
std::chrono::milliseconds retry_wait) -> bool {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
try {
for (std::size_t idx = 0U; idx < retry_count; ++idx) {
if (action()) {
return true;
}
std::this_thread::sleep_for(retry_wait);
}
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
return false;
}
} // namespace repertory::utils

View File

@ -21,6 +21,7 @@
*/
#include "utils/file.hpp"
#include "utils/common.hpp"
#include "utils/error.hpp"
#include "utils/unix.hpp"
#include "utils/windows.hpp"
@ -329,19 +330,21 @@ auto directory::remove() -> bool {
static_cast<const char *>(__FUNCTION__),
};
try {
return utils::retry_action([this]() -> bool {
try {
#if defined(_WIN32)
return (not exists() || ::RemoveDirectoryA(path_.c_str()));
return (not exists() || ::RemoveDirectoryA(path_.c_str()));
#else // !defined(_WIN32)
return not exists() || (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);
} catch (...) {
utils::error::handle_exception(function_name);
}
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
return false;
return false;
});
}
auto directory::remove_recursively() -> bool {

View File

@ -21,6 +21,7 @@
*/
#include "utils/file.hpp"
#include "utils/common.hpp"
#include "utils/encryption.hpp"
#include "utils/error.hpp"
#include "utils/path.hpp"
@ -339,12 +340,14 @@ auto file::remove() -> bool {
return true;
}
return utils::retry_action([this]() -> bool {
#if defined(_WIN32)
return !!::DeleteFileA(path_.c_str());
return !!::DeleteFileA(path_.c_str());
#else // !defined(_WIN32)
std::error_code ec{};
return std::filesystem::remove(path_, ec);
std::error_code ec{};
return std::filesystem::remove(path_, ec);
#endif // defined(_WIN32)
});
}
auto file::truncate(std::size_t size) -> bool {

View File

@ -21,6 +21,7 @@
*/
#include "utils/file.hpp"
#include "utils/common.hpp"
#include "utils/error.hpp"
#if defined(PROJECT_ENABLE_LIBDSM)
@ -490,14 +491,24 @@ auto smb_directory::remove() -> bool {
throw std::runtime_error("session not found|" + path_);
}
auto res = smb_directory_rm(session_.get(), tid_,
smb_create_relative_path(path_).c_str());
if (res != DSM_SUCCESS) {
throw std::runtime_error("failed to remove directory|" + path_ + '|' +
std::to_string(res));
}
return utils::retry_action([this]() -> bool {
try {
auto res = smb_directory_rm(session_.get(), tid_,
smb_create_relative_path(path_).c_str());
if (res != DSM_SUCCESS) {
throw std::runtime_error("failed to remove directory|" + path_ + '|' +
std::to_string(res));
}
return true;
return true;
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
return false;
});
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {

View File

@ -21,6 +21,7 @@
*/
#include "utils/file.hpp"
#include "utils/common.hpp"
#include "utils/error.hpp"
#include "utils/string.hpp"
@ -270,32 +271,34 @@ auto smb_file::remove() -> bool {
static_cast<const char *>(__FUNCTION__),
};
try {
close();
return utils::retry_action([this]() -> bool {
try {
close();
auto res = smb_tree_connect(session_.get(), share_name_.c_str(), &tid_);
if (res != DSM_SUCCESS) {
throw std::runtime_error("failed to connect to share|" + share_name_ +
'|' + std::to_string(res));
auto res = smb_tree_connect(session_.get(), share_name_.c_str(), &tid_);
if (res != DSM_SUCCESS) {
throw std::runtime_error("failed to connect to share|" + share_name_ +
'|' + std::to_string(res));
}
auto rel_path = smb_create_relative_path(path_);
res = smb_file_rm(session_.get(), tid_, rel_path.c_str());
if (res != DSM_SUCCESS) {
throw std::runtime_error(
"failed to remove file|" + path_ + '|' + rel_path + '|' +
std::to_string(res) + '|' +
std::to_string(smb_session_get_nt_status(session_.get())));
}
return true;
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
auto rel_path = smb_create_relative_path(path_);
res = smb_file_rm(session_.get(), tid_, rel_path.c_str());
if (res != DSM_SUCCESS) {
throw std::runtime_error(
"failed to remove file|" + path_ + '|' + rel_path + '|' +
std::to_string(res) + '|' +
std::to_string(smb_session_get_nt_status(session_.get())));
}
return true;
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
return false;
return false;
});
}
auto smb_file::size() const -> std::optional<std::uint64_t> {