updated build system
This commit is contained in:
@ -27,6 +27,21 @@
|
||||
#include "utils/path.hpp"
|
||||
|
||||
namespace repertory::utils::file {
|
||||
[[nodiscard]] inline auto
|
||||
directory_exists_in_path(std::string_view path,
|
||||
std::string_view sub_directory) -> bool;
|
||||
|
||||
[[nodiscard]] inline auto
|
||||
directory_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view sub_directory) -> bool;
|
||||
|
||||
[[nodiscard]] inline auto
|
||||
file_exists_in_path(std::string_view path, std::string_view file_name) -> bool;
|
||||
|
||||
[[nodiscard]] inline auto
|
||||
file_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view file_name) -> bool;
|
||||
|
||||
#if defined(PROJECT_ENABLE_LIBDSM)
|
||||
[[nodiscard]] auto
|
||||
smb_create_and_validate_relative_path(std::string_view smb_path,
|
||||
@ -61,6 +76,7 @@ smb_get_parent_path(std::string_view smb_path) -> std::string;
|
||||
|
||||
struct i_fs_item {
|
||||
using fs_item_t = std::unique_ptr<i_fs_item>;
|
||||
|
||||
enum class time_types {
|
||||
access,
|
||||
creation,
|
||||
@ -74,8 +90,7 @@ struct i_fs_item {
|
||||
|
||||
[[nodiscard]] virtual auto get_path() const -> std::string = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
get_time(time_types type) const -> std::uint64_t = 0;
|
||||
[[nodiscard]] virtual auto get_time(time_types type) const -> std::uint64_t;
|
||||
|
||||
[[nodiscard]] virtual auto is_directory_item() const -> bool = 0;
|
||||
|
||||
@ -136,7 +151,7 @@ struct i_file : public i_fs_item {
|
||||
|
||||
virtual auto set_read_buffer_size(std::uint32_t size) -> std::uint32_t = 0;
|
||||
|
||||
[[nodiscard]] virtual auto size() const -> std::uint64_t = 0;
|
||||
[[nodiscard]] virtual auto size() const -> std::optional<std::uint64_t> = 0;
|
||||
|
||||
[[nodiscard]] virtual auto truncate() -> bool { return truncate(0U); }
|
||||
|
||||
@ -268,7 +283,7 @@ public:
|
||||
return read_buffer_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto size() const -> std::uint64_t override;
|
||||
[[nodiscard]] auto size() const -> std::optional<std::uint64_t> override;
|
||||
|
||||
[[nodiscard]] auto truncate(std::size_t size) -> bool override;
|
||||
|
||||
@ -335,7 +350,9 @@ public:
|
||||
return file_->get_read_buffer_size();
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override;
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override {
|
||||
return file_->get_time(type);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_read_only() const -> bool override {
|
||||
return file_->is_read_only();
|
||||
@ -353,7 +370,7 @@ public:
|
||||
return file_->set_read_buffer_size(size);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto size() const -> std::uint64_t override;
|
||||
[[nodiscard]] auto size() const -> std::optional<std::uint64_t> override;
|
||||
|
||||
[[nodiscard]] auto truncate(std::size_t size) -> bool override;
|
||||
|
||||
@ -445,7 +462,9 @@ public:
|
||||
return file_->get_read_buffer_size();
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override;
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override {
|
||||
return file_->get_time(type);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_read_only() const -> bool override {
|
||||
return file_->is_read_only();
|
||||
@ -463,7 +482,7 @@ public:
|
||||
return file_->set_read_buffer_size(size);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto size() const -> std::uint64_t override;
|
||||
[[nodiscard]] auto size() const -> std::optional<std::uint64_t> override;
|
||||
|
||||
[[nodiscard]] auto truncate(std::size_t size) -> bool override;
|
||||
|
||||
@ -497,7 +516,7 @@ struct i_directory : public i_fs_item {
|
||||
count(bool recursive = false) const -> std::uint64_t = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
create_directory(std::string_view path) const -> fs_directory_t = 0;
|
||||
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;
|
||||
@ -559,7 +578,7 @@ public:
|
||||
count(bool recursive = false) const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
create_directory(std::string_view path) const -> fs_directory_t override;
|
||||
create_directory(std::string_view path = "") const -> fs_directory_t override;
|
||||
|
||||
[[nodiscard]] auto create_file(std::string_view file_name,
|
||||
bool read_only) const -> fs_file_t override;
|
||||
@ -581,8 +600,6 @@ public:
|
||||
|
||||
[[nodiscard]] auto get_path() const -> std::string override { return path_; }
|
||||
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto move_to(std::string_view new_path) -> bool override;
|
||||
|
||||
[[nodiscard]] auto remove() -> bool override;
|
||||
@ -609,52 +626,35 @@ class smb_file final : public i_file {
|
||||
public:
|
||||
smb_file() = default;
|
||||
|
||||
smb_file(std::uint64_t access_time, std::uint64_t creation_time,
|
||||
std::optional<smb_fd> fd, std::uint64_t modified_time,
|
||||
std::string path, smb_session_t session, std::string_view share_name,
|
||||
smb_tid tid, std::uint64_t size, std::uint64_t write_time)
|
||||
: access_time_(access_time),
|
||||
creation_time_(creation_time),
|
||||
fd_(std::move(fd)),
|
||||
modified_time_(modified_time),
|
||||
smb_file(std::optional<smb_fd> fd, std::string path, smb_session_t session,
|
||||
std::string_view share_name, smb_tid tid)
|
||||
: fd_(std::move(fd)),
|
||||
path_(std::move(path)),
|
||||
session_(std::move(session)),
|
||||
share_name_(share_name),
|
||||
size_(size),
|
||||
tid_(tid),
|
||||
write_time_(write_time) {}
|
||||
tid_(tid) {}
|
||||
|
||||
smb_file(const smb_file &) = delete;
|
||||
|
||||
smb_file(smb_file &&f) noexcept
|
||||
: access_time_(f.access_time_),
|
||||
creation_time_(f.creation_time_),
|
||||
fd_(std::move(f.fd_)),
|
||||
modified_time_(f.modified_time_),
|
||||
: fd_(std::move(f.fd_)),
|
||||
path_(std::move(f.path_)),
|
||||
read_buffer_size(f.get_read_buffer_size()),
|
||||
read_only_(f.read_only_),
|
||||
session_(std::move(f.session_)),
|
||||
share_name_(std::move(f.share_name_)),
|
||||
size_(f.size_),
|
||||
tid_(f.tid_),
|
||||
write_time_(f.write_time_) {}
|
||||
tid_(f.tid_) {}
|
||||
|
||||
~smb_file() override { close(); }
|
||||
|
||||
private:
|
||||
std::uint64_t access_time_;
|
||||
std::uint64_t creation_time_;
|
||||
std::optional<smb_fd> fd_;
|
||||
std::uint64_t modified_time_;
|
||||
std::string path_;
|
||||
std::atomic_uint32_t read_buffer_size{65536U};
|
||||
bool read_only_;
|
||||
smb_session_t session_;
|
||||
std::string share_name_;
|
||||
std::uint64_t size_;
|
||||
smb_tid tid_;
|
||||
std::uint64_t write_time_;
|
||||
|
||||
public:
|
||||
void close() override;
|
||||
@ -673,20 +673,12 @@ public:
|
||||
return read_buffer_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] static auto get_time(smb_session *session, smb_tid tid,
|
||||
std::string path,
|
||||
time_types type) -> std::uint64_t;
|
||||
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override {
|
||||
switch (type) {
|
||||
case time_types::access:
|
||||
return access_time_;
|
||||
|
||||
case time_types::creation:
|
||||
return creation_time_;
|
||||
|
||||
case time_types::modified:
|
||||
return modified_time_;
|
||||
|
||||
case time_types::write:
|
||||
return write_time_;
|
||||
}
|
||||
return get_time(session_.get(), tid_, path_, type);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_unc_path() const -> std::string {
|
||||
@ -722,7 +714,7 @@ public:
|
||||
return read_buffer_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto size() const -> std::uint64_t override { return size_; }
|
||||
[[nodiscard]] auto size() const -> std::optional<std::uint64_t> override;
|
||||
|
||||
[[nodiscard]] auto truncate(std::size_t size) -> bool override;
|
||||
|
||||
@ -735,18 +727,13 @@ public:
|
||||
|
||||
auto operator=(smb_file &&move_file) noexcept -> smb_file & {
|
||||
if (this != &move_file) {
|
||||
access_time_ = move_file.access_time_;
|
||||
creation_time_ = move_file.creation_time_;
|
||||
fd_ = std::move(move_file.fd_);
|
||||
modified_time_ = move_file.modified_time_;
|
||||
path_ = std::move(move_file.path_);
|
||||
read_buffer_size = move_file.get_read_buffer_size();
|
||||
read_only_ = move_file.read_only_;
|
||||
session_ = std::move(move_file.session_);
|
||||
share_name_ = std::move(move_file.share_name_);
|
||||
size_ = move_file.size_;
|
||||
tid_ = move_file.tid_;
|
||||
write_time_ = move_file.write_time_;
|
||||
}
|
||||
|
||||
return *this;
|
||||
@ -796,7 +783,7 @@ public:
|
||||
count(bool recursive = false) const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
create_directory(std::string_view path) const -> fs_directory_t override;
|
||||
create_directory(std::string_view path = "") const -> fs_directory_t override;
|
||||
|
||||
[[nodiscard]] auto create_file(std::string_view file_name,
|
||||
bool read_only) const -> fs_file_t override;
|
||||
@ -818,7 +805,9 @@ public:
|
||||
|
||||
[[nodiscard]] auto get_path() const -> std::string override { return path_; }
|
||||
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override;
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override {
|
||||
return smb_file::get_time(session_.get(), tid_, path_, type);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_unc_path() const -> std::string {
|
||||
return smb_get_unc_path(path_);
|
||||
@ -853,44 +842,6 @@ public:
|
||||
};
|
||||
#endif // defined(PROJECT_ENABLE_LIBDSM)
|
||||
|
||||
[[nodiscard]] auto create_directories(std::string_view path) -> bool;
|
||||
|
||||
[[nodiscard]] auto create_directories(std::wstring_view path) -> bool;
|
||||
|
||||
[[nodiscard]] auto
|
||||
directory_exists_in_path(std::string_view path,
|
||||
std::string_view sub_directory) -> bool;
|
||||
|
||||
[[nodiscard]] auto
|
||||
directory_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view sub_directory) -> bool;
|
||||
|
||||
[[nodiscard]] auto get_file_size(std::string_view path,
|
||||
std::uint64_t &file_size) -> bool;
|
||||
|
||||
[[nodiscard]] auto get_file_size(std::wstring_view path,
|
||||
std::uint64_t &file_size) -> bool;
|
||||
|
||||
[[nodiscard]] auto file_exists_in_path(std::string_view path,
|
||||
std::string_view file_name) -> bool;
|
||||
|
||||
[[nodiscard]] auto file_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view file_name) -> bool;
|
||||
|
||||
[[nodiscard]] auto is_directory(std::string_view path) -> bool;
|
||||
|
||||
[[nodiscard]] auto is_directory(std::wstring_view path) -> bool;
|
||||
|
||||
[[nodiscard]] auto is_file(std::string_view path) -> bool;
|
||||
|
||||
[[nodiscard]] auto is_file(std::wstring_view path) -> bool;
|
||||
|
||||
[[nodiscard]] auto remove_directory(std::string_view path,
|
||||
bool recursive = false) -> bool;
|
||||
|
||||
[[nodiscard]] auto remove_directory(std::wstring_view path,
|
||||
bool recursive = false) -> bool;
|
||||
|
||||
#if defined(PROJECT_ENABLE_JSON)
|
||||
#if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||
[[nodiscard]] auto
|
||||
@ -924,18 +875,38 @@ read_json_file(std::string_view path, nlohmann::json &data,
|
||||
#endif // defined(PROJECT_ENABLE_JSON)
|
||||
|
||||
template <typename string_t>
|
||||
inline auto directory_exists_in_path_t(
|
||||
[[nodiscard]] inline auto directory_exists_in_path_t(
|
||||
std::basic_string_view<typename string_t::value_type> path,
|
||||
std::basic_string_view<typename string_t::value_type> sub_directory)
|
||||
-> bool {
|
||||
return is_directory(utils::path::combine(path, {sub_directory}));
|
||||
return directory(utils::path::combine(path, {sub_directory})).exists();
|
||||
}
|
||||
|
||||
template <typename string_t>
|
||||
inline auto file_exists_in_path_t(
|
||||
[[nodiscard]] inline auto file_exists_in_path_t(
|
||||
std::basic_string_view<typename string_t::value_type> path,
|
||||
std::basic_string_view<typename string_t::value_type> file_name) -> bool {
|
||||
return is_file(utils::path::combine(path, {file_name}));
|
||||
return file(utils::path::combine(path, {file_name})).exists();
|
||||
}
|
||||
|
||||
inline auto directory_exists_in_path(std::string_view path,
|
||||
std::string_view sub_directory) -> bool {
|
||||
return directory_exists_in_path_t<std::string>(path, sub_directory);
|
||||
}
|
||||
|
||||
inline auto directory_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view sub_directory) -> bool {
|
||||
return directory_exists_in_path_t<std::wstring>(path, sub_directory);
|
||||
}
|
||||
|
||||
inline auto file_exists_in_path(std::string_view path,
|
||||
std::string_view file_name) -> bool {
|
||||
return file_exists_in_path_t<std::string>(path, file_name);
|
||||
}
|
||||
|
||||
inline auto file_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view file_name) -> bool {
|
||||
return file_exists_in_path_t<std::wstring>(path, file_name);
|
||||
}
|
||||
} // namespace repertory::utils::file
|
||||
|
||||
|
Reference in New Issue
Block a user