updated build system
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit

This commit is contained in:
2024-08-31 08:27:23 -05:00
parent 64f1083fb7
commit 82ead48fa8
8 changed files with 360 additions and 194 deletions

View File

@ -25,50 +25,28 @@
#include "utils/config.hpp"
#include "utils/path.hpp"
#include "utils/types/file/i_directory.hpp"
#include "utils/types/file/i_file.hpp"
#include "utils/types/file/i_fs_item.hpp"
namespace repertory::utils::file {
enum class time_type {
accessed,
created,
modified,
written,
};
struct file_times final {
std::uint64_t accessed{};
std::uint64_t created{};
std::uint64_t modified{};
std::uint64_t written{};
[[nodiscard]] auto get(time_type type) const -> std::uint64_t {
switch (type) {
case time_type::accessed:
return accessed;
case time_type::created:
return created;
case time_type::modified:
return modified;
case time_type::written:
return written;
}
throw std::runtime_error("type_type not supported");
}
};
[[nodiscard]] auto change_to_process_directory() -> bool;
// INFO: has test
[[nodiscard]] inline auto
directory_exists_in_path(std::string_view path,
std::string_view sub_directory) -> bool;
// INFO: has test
[[nodiscard]] inline auto
directory_exists_in_path(std::wstring_view path,
std::wstring_view sub_directory) -> bool;
// INFO: has test
[[nodiscard]] inline auto
file_exists_in_path(std::string_view path, std::string_view file_name) -> bool;
// INFO: has test
[[nodiscard]] inline auto
file_exists_in_path(std::wstring_view path,
std::wstring_view file_name) -> bool;
@ -102,12 +80,15 @@ get_total_drive_space(std::wstring_view path) -> std::optional<std::uint64_t>;
smb_create_and_validate_relative_path(std::string_view smb_path,
std::string_view rel_path) -> std::string;
// INFO: has test
[[nodiscard]] auto
smb_create_relative_path(std::string_view smb_path) -> std::string;
// INFO: has test
[[nodiscard]] auto
smb_create_search_path(std::string_view smb_path) -> std::string;
// INFO: has test
[[nodiscard]] auto
smb_create_smb_path(std::string_view smb_path,
std::string_view rel_path) -> std::string;
@ -125,129 +106,18 @@ smb_get_parent_path(std::string_view smb_path) -> std::string;
std::string_view user,
std::string_view password) -> std::string;
// INFO: has test
[[nodiscard]] auto smb_parent_is_same(std::string_view smb_path1,
std::string_view smb_path2) -> bool;
#endif // defined(PROJECT_ENABLE_LIBDSM)
struct i_fs_item {
using fs_item_t = std::unique_ptr<i_fs_item>;
virtual ~i_fs_item() = default;
[[nodiscard]] virtual auto copy_to(std::string_view to_path,
bool overwrite) const -> bool = 0;
[[nodiscard]] virtual auto copy_to(std::wstring_view new_path,
bool overwrite) -> bool {
return copy_to(utils::string::to_utf8(new_path), overwrite);
}
[[nodiscard]] virtual auto exists() const -> bool = 0;
[[nodiscard]] virtual auto get_path() const -> std::string = 0;
[[nodiscard]] virtual auto
get_time(time_type type) const -> std::optional<std::uint64_t>;
[[nodiscard]] virtual auto is_directory_item() const -> bool = 0;
[[nodiscard]] auto is_file_item() const -> bool {
return not is_directory_item();
}
[[nodiscard]] virtual auto is_symlink() const -> bool = 0;
[[nodiscard]] virtual auto move_to(std::string_view new_path) -> bool = 0;
[[nodiscard]] virtual auto move_to(std::wstring_view new_path) -> bool {
return move_to(utils::string::to_utf8(new_path));
}
[[nodiscard]] virtual auto remove() -> bool = 0;
public:
[[nodiscard]] virtual operator bool() const = 0;
protected:
i_fs_item() noexcept = default;
i_fs_item(const i_fs_item &) noexcept = default;
i_fs_item(i_fs_item &&) noexcept = default;
auto operator=(i_fs_item &&) noexcept -> i_fs_item & = default;
auto operator=(const i_fs_item &) noexcept -> i_fs_item & = default;
};
struct i_file : public i_fs_item {
using fs_file_t = std::unique_ptr<i_file>;
virtual ~i_file() = default;
virtual void close() = 0;
virtual void flush() const = 0;
[[nodiscard]] virtual auto get_handle() const -> native_handle = 0;
[[nodiscard]] virtual auto get_read_buffer_size() const -> std::uint32_t = 0;
[[nodiscard]] auto is_directory_item() const -> bool override {
return false;
}
[[nodiscard]] virtual auto is_read_only() const -> bool = 0;
[[nodiscard]] virtual auto read(data_buffer &data, std::uint64_t offset,
std::size_t *total_read = nullptr) -> bool {
return read(data.data(), data.size(), offset, total_read);
}
[[nodiscard]] virtual auto
read(unsigned char *data, std::size_t to_read, std::uint64_t offset,
std::size_t *total_read = nullptr) -> bool = 0;
[[nodiscard]] virtual auto
read_all(data_buffer &data, std::uint64_t offset,
std::size_t *total_read = nullptr) -> bool;
virtual auto set_read_buffer_size(std::uint32_t size) -> std::uint32_t = 0;
[[nodiscard]] virtual auto size() const -> std::optional<std::uint64_t> = 0;
[[nodiscard]] virtual auto truncate() -> bool { return truncate(0U); }
[[nodiscard]] virtual auto truncate(std::size_t size) -> bool = 0;
[[nodiscard]] virtual auto
write(const data_buffer &data, std::uint64_t offset,
std::size_t *total_written = nullptr) -> bool {
return write(data.data(), data.size(), offset, total_written);
}
[[nodiscard]] virtual auto
write(const unsigned char *data, std::size_t to_write, std::size_t offset,
std::size_t *total_written = nullptr) -> bool = 0;
protected:
i_file() noexcept = default;
i_file(const i_file &) noexcept = default;
i_file(i_file &&) noexcept = default;
auto operator=(i_file &&) noexcept -> i_file & = default;
auto operator=(const i_file &) noexcept -> i_file & = default;
};
class file final : public i_file {
public:
// [[nodiscard]] static auto
// attach_file(native_handle handle,
// bool read_only = false) -> fs_file_t;
// INFO: has test
[[nodiscard]] static auto open_file(std::string_view path,
bool read_only = false) -> fs_file_t;
@ -256,6 +126,7 @@ public:
return open_file(utils::string::to_utf8(path), read_only);
}
// INFO: has test
[[nodiscard]] static auto
open_or_create_file(std::string_view path,
bool read_only = false) -> fs_file_t;
@ -578,53 +449,6 @@ public:
}
};
struct i_directory : public i_fs_item {
using fs_directory_t = std::unique_ptr<i_directory>;
using fs_file_t = i_file::fs_file_t;
virtual ~i_directory() = default;
[[nodiscard]] virtual auto
count(bool recursive = false) const -> std::uint64_t = 0;
[[nodiscard]] virtual auto
create_directory(std::string_view path = "") const -> fs_directory_t = 0;
[[nodiscard]] virtual auto create_file(std::string_view file_name,
bool read_only) const -> fs_file_t = 0;
[[nodiscard]] auto is_directory_item() const -> bool override { return true; }
[[nodiscard]] virtual auto
get_directory(std::string_view path) const -> fs_directory_t = 0;
[[nodiscard]] virtual auto
get_directories() const -> std::vector<fs_directory_t> = 0;
[[nodiscard]] virtual auto
get_file(std::string_view path) const -> fs_file_t = 0;
[[nodiscard]] virtual auto get_files() const -> std::vector<fs_file_t> = 0;
[[nodiscard]] virtual auto get_items() const -> std::vector<fs_item_t> = 0;
[[nodiscard]] virtual auto remove_recursively() -> bool = 0;
[[nodiscard]] virtual auto
size(bool recursive = false) const -> std::uint64_t = 0;
protected:
i_directory() noexcept = default;
i_directory(const i_directory &) noexcept = default;
i_directory(i_directory &&) noexcept = default;
auto operator=(i_directory &&) noexcept -> i_directory & = default;
auto operator=(const i_directory &) noexcept -> i_directory & = default;
};
class directory final : public i_directory {
public:
using directory_t = std::unique_ptr<directory>;
@ -936,6 +760,7 @@ public:
read_json_file(std::string_view path, nlohmann::json &data,
std::optional<std::string_view> password = std::nullopt) -> bool;
// INFO: has test
[[nodiscard]] auto read_json_file(
std::wstring_view path, nlohmann::json &data,
std::optional<std::wstring_view> password = std::nullopt) -> bool;
@ -944,16 +769,19 @@ read_json_file(std::string_view path, nlohmann::json &data,
std::string_view path, const nlohmann::json &data,
std::optional<std::string_view> password = std::nullopt) -> bool;
// INFO: has test
[[nodiscard]] auto write_json_file(
std::wstring_view path, const nlohmann::json &data,
std::optional<std::wstring_view> password = std::nullopt) -> bool;
#else // !defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
// INFO: has test
[[nodiscard]] auto read_json_file(std::string_view path,
nlohmann::json &data) -> bool;
[[nodiscard]] auto read_json_file(std::wstring_view path,
nlohmann::json &data) -> bool;
// INFO: has test
[[nodiscard]] auto write_json_file(std::string_view path,
const nlohmann::json &data) -> bool;