updated build system

This commit is contained in:
2024-08-08 19:20:38 -05:00
parent e1ac9efaaa
commit 7977b4b304
16 changed files with 131 additions and 237 deletions

View File

@ -38,15 +38,6 @@ void change_to_process_directory();
[[nodiscard]] auto copy_file(std::string from_path,
std::string to_path) -> bool;
[[nodiscard]] auto create_full_directory_path(std::string path) -> bool;
[[nodiscard]] auto delete_directory(std::string path,
bool recursive = false) -> bool;
[[nodiscard]] auto delete_directory_recursively(std::string path) -> bool;
[[nodiscard]] auto delete_file(std::string path) -> bool;
[[nodiscard]] auto generate_sha256(const std::string &file_path) -> std::string;
[[nodiscard]] auto get_accessed_time(const std::string &path,

View File

@ -103,15 +103,15 @@ app_config::app_config(const provider_type &prov,
hc_.api_password = get_provider_api_password(prov_);
hc_.api_port = default_api_port(prov_);
if (not utils::file::create_full_directory_path(data_directory_)) {
if (not utils::file::create_directories(data_directory_)) {
throw startup_exception("unable to create: " + data_directory_);
}
if (not utils::file::create_full_directory_path(cache_directory_)) {
if (not utils::file::create_directories(cache_directory_)) {
throw startup_exception("unable to create: " + cache_directory_);
}
if (not utils::file::create_full_directory_path(log_directory_)) {
if (not utils::file::create_directories(log_directory_)) {
throw startup_exception("unable to create: " + log_directory_);
}
@ -715,7 +715,7 @@ void app_config::save() {
recur_mutex_lock lock(read_write_mutex_);
if (config_changed_ || not utils::file::is_file(file_path)) {
if (not utils::file::is_directory(data_directory_)) {
if (not utils::file::create_full_directory_path(data_directory_)) {
if (not utils::file::create_directories(data_directory_)) {
utils::error::raise_error(
function_name, "failed to create directory|sp|" + data_directory_ +
"|err|" +

View File

@ -464,7 +464,7 @@ auto file_manager::open_file::close() -> bool {
utils::get_last_error_code(), "failed to delete file");
}
auto parent = utils::path::remove_file_name(fsi_.source_path);
auto parent = utils::path::get_parent_directory(fsi_.source_path);
fsi_.source_path =
utils::path::combine(parent, {utils::create_uuid_string()});
const auto res = provider_.set_item_meta(fsi_.api_path, META_SOURCE,

View File

@ -64,7 +64,7 @@ file_manager::ring_buffer_open_file::ring_buffer_open_file(
ring_state_.set(0U, ring_state_.size(), true);
buffer_directory = utils::path::absolute(buffer_directory);
if (not utils::file::create_full_directory_path(buffer_directory)) {
if (not utils::file::create_directories(buffer_directory)) {
throw std::runtime_error("failed to create buffer directory|path|" +
buffer_directory + "|err|" +
std::to_string(utils::get_last_error_code()));

View File

@ -57,7 +57,7 @@ lock_data::~lock_data() {
auto lock_data::get_lock_data_file() -> std::string {
const auto dir = get_state_directory();
if (not utils::file::create_full_directory_path(dir)) {
if (not utils::file::create_directories(dir)) {
throw startup_exception("failed to create directory|sp|" + dir + "|err|" +
std::to_string(utils::get_last_error_code()));
}
@ -67,7 +67,7 @@ auto lock_data::get_lock_data_file() -> std::string {
auto lock_data::get_lock_file() -> std::string {
const auto dir = get_state_directory();
if (not utils::file::create_full_directory_path(dir)) {
if (not utils::file::create_directories(dir)) {
throw startup_exception("failed to create directory|sp|" + dir + "|err|" +
std::to_string(utils::get_last_error_code()));
}

View File

@ -485,7 +485,7 @@ void base_provider::remove_deleted_files() {
if (utils::file::is_file(item.source_path)) {
const auto orphaned_directory =
utils::path::combine(config_.get_data_directory(), {"orphaned"});
if (utils::file::create_full_directory_path(orphaned_directory)) {
if (utils::file::create_directories(orphaned_directory)) {
const auto parts = utils::string::split(item.api_path, '/', false);
const auto orphaned_file = utils::path::combine(
orphaned_directory,

View File

@ -117,7 +117,7 @@ auto copy_directory_recursively(std::string from_path,
std::string to_path) -> bool {
from_path = utils::path::absolute(from_path);
to_path = utils::path::absolute(to_path);
auto ret = create_full_directory_path(to_path);
auto ret = create_directories(to_path);
if (ret) {
#if defined(_WIN32)
WIN32_FIND_DATA fd{};
@ -167,108 +167,6 @@ auto copy_directory_recursively(std::string from_path,
return ret;
}
auto create_full_directory_path(std::string path) -> bool {
#if defined(_WIN32)
const auto unicode_path =
utils::string::from_utf8(utils::path::absolute(path));
return is_directory(path) ||
(::SHCreateDirectory(nullptr, unicode_path.c_str()) == ERROR_SUCCESS);
#else
auto ret = true;
const auto paths = utils::string::split(
utils::path::absolute(path), utils::path::directory_seperator[0U], false);
std::string current_path;
for (std::size_t i = 0U; ret && (i < paths.size()); i++) {
if (paths[i].empty()) { // Skip root
current_path = utils::path::directory_seperator;
} else {
current_path = utils::path::combine(current_path, {paths[i]});
const auto status = mkdir(current_path.c_str(), S_IRWXU);
ret = ((status == 0) || (errno == EEXIST));
}
}
return ret;
#endif
}
auto delete_directory(std::string path, bool recursive) -> bool {
if (recursive) {
return delete_directory_recursively(path);
}
path = utils::path::absolute(path);
#if defined(_WIN32)
return (not is_directory(path) || utils::retryable_action([&]() -> bool {
return !!::RemoveDirectoryA(path.c_str());
}));
#else
return not is_directory(path) || (rmdir(path.c_str()) == 0);
#endif
}
auto delete_directory_recursively(std::string path) -> bool {
path = utils::path::absolute(path);
#if defined(_WIN32)
WIN32_FIND_DATA fd{};
const auto search = utils::path::combine(path, {"*.*"});
auto find = ::FindFirstFile(search.c_str(), &fd);
if (find != INVALID_HANDLE_VALUE) {
auto res = true;
do {
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
if ((std::string(fd.cFileName) != ".") &&
(std::string(fd.cFileName) != "..")) {
res = delete_directory_recursively(
utils::path::combine(path, {fd.cFileName}));
}
} else {
res = retry_delete_file(utils::path::combine(path, {fd.cFileName}));
}
} while (res && (::FindNextFile(find, &fd) != 0));
::FindClose(find);
}
#else
auto *root = opendir(path.c_str());
if (root) {
auto res = true;
struct dirent *de{};
while (res && (de = readdir(root))) {
if (de->d_type == DT_DIR) {
if ((strcmp(de->d_name, ".") != 0) && (strcmp(de->d_name, "..") != 0)) {
res = delete_directory_recursively(
utils::path::combine(path, {de->d_name}));
}
} else {
res = retry_delete_file(utils::path::combine(path, {de->d_name}));
}
}
closedir(root);
}
#endif
return delete_directory(path, false);
}
auto delete_file(std::string path) -> bool {
path = utils::path::absolute(path);
#if defined(_WIN32)
return (not is_file(path) || utils::retryable_action([&]() -> bool {
const auto ret = !!::DeleteFileA(path.c_str());
if (not ret) {
std::cout << "delete failed:" << path << std::endl;
}
return ret;
}));
#else
return (not is_file(path) || (unlink(path.c_str()) == 0));
#endif
}
auto generate_sha256(const std::string &file_path) -> std::string {
crypto_hash_sha256_state state{};
auto res = crypto_hash_sha256_init(&state);
@ -506,8 +404,8 @@ auto move_file(std::string from, std::string to) -> bool {
from = utils::path::absolute(from);
to = utils::path::absolute(to);
const auto directory = utils::path::remove_file_name(to);
if (not create_full_directory_path(directory)) {
const auto directory = utils::path::get_parent_directory(to);
if (not create_directories(directory)) {
return false;
}
@ -563,7 +461,7 @@ auto reset_modified_time(const std::string &path) -> bool {
auto retry_delete_directory(const std::string &dir) -> bool {
auto deleted = false;
for (std::uint8_t i = 0U; not(deleted = delete_directory(dir)) && (i < 200U);
for (std::uint8_t i = 0U; not(deleted = remove_directory(dir)) && (i < 200U);
i++) {
std::this_thread::sleep_for(10ms);
}
@ -573,8 +471,8 @@ auto retry_delete_directory(const std::string &dir) -> bool {
auto retry_delete_file(const std::string &file) -> bool {
auto deleted = false;
for (std::uint8_t i = 0U; not(deleted = delete_file(file)) && (i < 200U);
i++) {
for (std::uint8_t i = 0U;
not(deleted = utils::file::file{file}.remove()) && (i < 200U); i++) {
std::this_thread::sleep_for(10ms);
}