|
|
|
@ -25,31 +25,106 @@
|
|
|
|
|
#include "utils/config.hpp"
|
|
|
|
|
|
|
|
|
|
#include "utils/path.hpp"
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
namespace repertory::utils::file {
|
|
|
|
|
struct i_file {
|
|
|
|
|
#if defined(PROJECT_ENABLE_LIBDSM)
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
smb_create_and_validate_relative_path(std::string_view smb_path,
|
|
|
|
|
std::string_view rel_path) -> std::string;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
smb_create_relative_path(std::string_view smb_path) -> std::string;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
smb_create_search_path(std::string_view smb_path) -> std::string;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
smb_create_smb_path(std::string_view smb_path,
|
|
|
|
|
std::string_view rel_path) -> std::string;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
smb_get_parent_path(std::string_view smb_path) -> std::string;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto smb_get_root_path(std::string_view smb_path) -> std::string;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto smb_get_unc_path(std::string_view smb_path) -> std::string;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto smb_get_uri_path(std::string_view smb_path) -> std::string;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto smb_get_uri_path(std::string_view smb_path,
|
|
|
|
|
std::string_view user,
|
|
|
|
|
std::string_view password) -> std::string;
|
|
|
|
|
|
|
|
|
|
[[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>;
|
|
|
|
|
enum class time_types {
|
|
|
|
|
access,
|
|
|
|
|
creation,
|
|
|
|
|
modified,
|
|
|
|
|
write,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
virtual ~i_fs_item() = default;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] virtual auto exists() const -> bool = 0;
|
|
|
|
|
|
|
|
|
|
[[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 is_directory_item() 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;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] virtual auto exists() const -> bool = 0;
|
|
|
|
|
|
|
|
|
|
virtual void flush() const = 0;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] virtual auto get_handle() const -> native_handle = 0;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] virtual auto get_path() const -> std::string = 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 move_to(std::string_view new_path) -> bool = 0;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] virtual auto
|
|
|
|
|
read(data_buffer &data, std::uint64_t offset,
|
|
|
|
|
std::size_t *total_read = nullptr) -> 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,
|
|
|
|
@ -57,64 +132,59 @@ struct i_file {
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] virtual auto
|
|
|
|
|
read_all(data_buffer &data, std::uint64_t offset,
|
|
|
|
|
std::size_t *total_read = nullptr) -> bool = 0;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] virtual auto remove() -> bool = 0;
|
|
|
|
|
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::uint64_t = 0;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] virtual auto truncate() -> bool = 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 = 0;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
[[nodiscard]] virtual operator bool() const = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
i_file() noexcept = default;
|
|
|
|
|
|
|
|
|
|
i_file(const i_file &) noexcept = delete;
|
|
|
|
|
i_file(const i_file &) noexcept = default;
|
|
|
|
|
|
|
|
|
|
i_file(i_file &&) noexcept = delete;
|
|
|
|
|
i_file(i_file &&) noexcept = default;
|
|
|
|
|
|
|
|
|
|
auto operator=(i_file &&) noexcept -> i_file & = delete;
|
|
|
|
|
auto operator=(i_file &&) noexcept -> i_file & = default;
|
|
|
|
|
|
|
|
|
|
auto operator=(const i_file &) noexcept -> i_file & = delete;
|
|
|
|
|
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) -> std::unique_ptr<i_file>;
|
|
|
|
|
// bool read_only = false) -> fs_file_t;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] static auto
|
|
|
|
|
open_file(std::string_view path,
|
|
|
|
|
bool read_only = false) -> std::unique_ptr<i_file>;
|
|
|
|
|
[[nodiscard]] static auto open_file(std::string_view path,
|
|
|
|
|
bool read_only = false) -> fs_file_t;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] static auto
|
|
|
|
|
open_file(std::wstring_view path,
|
|
|
|
|
bool read_only = false) -> std::unique_ptr<i_file> {
|
|
|
|
|
[[nodiscard]] static auto open_file(std::wstring_view path,
|
|
|
|
|
bool read_only = false) -> fs_file_t {
|
|
|
|
|
return open_file(utils::string::to_utf8(path), read_only);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] static auto
|
|
|
|
|
open_or_create_file(std::string_view path,
|
|
|
|
|
bool read_only = false) -> std::unique_ptr<i_file>;
|
|
|
|
|
bool read_only = false) -> fs_file_t;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] static auto
|
|
|
|
|
open_or_create_file(std::wstring_view path,
|
|
|
|
|
bool read_only = false) -> std::unique_ptr<i_file> {
|
|
|
|
|
bool read_only = false) -> fs_file_t {
|
|
|
|
|
return open_or_create_file(utils::string::to_utf8(path), read_only);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -179,23 +249,18 @@ public:
|
|
|
|
|
return read_buffer_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto is_read_only() const -> bool override {
|
|
|
|
|
return read_only_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto move_to(std::string_view new_path) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto read(data_buffer &data, std::uint64_t offset,
|
|
|
|
|
std::size_t *total_read = nullptr) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto read(unsigned char *data, std::size_t to_read,
|
|
|
|
|
std::uint64_t offset,
|
|
|
|
|
std::size_t *total_read = nullptr) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
read_all(data_buffer &data, std::uint64_t offset,
|
|
|
|
|
std::size_t *total_read = nullptr) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto remove() -> bool override;
|
|
|
|
|
|
|
|
|
|
auto set_read_buffer_size(std::uint32_t size) -> std::uint32_t override {
|
|
|
|
@ -205,14 +270,8 @@ public:
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto size() const -> std::uint64_t override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto truncate() -> bool override { return truncate(0U); }
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto truncate(std::size_t size) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
write(const data_buffer &data, std::uint64_t offset,
|
|
|
|
|
std::size_t *total_written = nullptr) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
write(const unsigned char *data, std::size_t to_write, std::size_t offset,
|
|
|
|
|
std::size_t *total_written = nullptr) -> bool override;
|
|
|
|
@ -240,25 +299,25 @@ class thread_file final : public i_file {
|
|
|
|
|
public:
|
|
|
|
|
// [[nodiscard]] static auto
|
|
|
|
|
// attach_file(native_handle handle,
|
|
|
|
|
// bool read_only = false) -> std::unique_ptr<i_file>;
|
|
|
|
|
// bool read_only = false) -> fs_file_t;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] static auto
|
|
|
|
|
open_file(std::string_view path,
|
|
|
|
|
bool read_only = false) -> std::unique_ptr<i_file>;
|
|
|
|
|
[[nodiscard]] static auto attach_file(fs_file_t file) -> fs_file_t;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] static auto
|
|
|
|
|
open_file(std::wstring_view path,
|
|
|
|
|
bool read_only = false) -> std::unique_ptr<i_file> {
|
|
|
|
|
[[nodiscard]] static auto open_file(std::string_view path,
|
|
|
|
|
bool read_only = false) -> fs_file_t;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] static auto open_file(std::wstring_view path,
|
|
|
|
|
bool read_only = false) -> fs_file_t {
|
|
|
|
|
return open_file(utils::string::to_utf8(path), read_only);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] static auto
|
|
|
|
|
open_or_create_file(std::string_view path,
|
|
|
|
|
bool read_only = false) -> std::unique_ptr<i_file>;
|
|
|
|
|
bool read_only = false) -> fs_file_t;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] static auto
|
|
|
|
|
open_or_create_file(std::wstring_view path,
|
|
|
|
|
bool read_only = false) -> std::unique_ptr<i_file> {
|
|
|
|
|
bool read_only = false) -> fs_file_t {
|
|
|
|
|
return open_or_create_file(utils::string::to_utf8(path), read_only);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -271,7 +330,7 @@ public:
|
|
|
|
|
: file_(new file(utils::string::to_utf8(path))) {}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
thread_file(std::unique_ptr<i_file> file);
|
|
|
|
|
thread_file(fs_file_t file);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
thread_file(const thread_file &) = delete;
|
|
|
|
@ -282,7 +341,7 @@ public:
|
|
|
|
|
~thread_file() override { close(); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::unique_ptr<i_file> file_;
|
|
|
|
|
fs_file_t file_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
void close() override;
|
|
|
|
@ -303,23 +362,18 @@ public:
|
|
|
|
|
return file_->get_read_buffer_size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto is_read_only() const -> bool override {
|
|
|
|
|
return file_->is_read_only();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto move_to(std::string_view new_path) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto read(data_buffer &data, std::uint64_t offset,
|
|
|
|
|
std::size_t *total_read = nullptr) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto read(unsigned char *data, std::size_t to_read,
|
|
|
|
|
std::uint64_t offset,
|
|
|
|
|
std::size_t *total_read = nullptr) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
read_all(data_buffer &data, std::uint64_t offset,
|
|
|
|
|
std::size_t *total_read = nullptr) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto remove() -> bool override;
|
|
|
|
|
|
|
|
|
|
auto set_read_buffer_size(std::uint32_t size) -> std::uint32_t override {
|
|
|
|
@ -328,14 +382,8 @@ public:
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto size() const -> std::uint64_t override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto truncate() -> bool override { return truncate(0U); }
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto truncate(std::size_t size) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
write(const data_buffer &data, std::uint64_t offset,
|
|
|
|
|
std::size_t *total_written = nullptr) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
write(const unsigned char *data, std::size_t to_write, std::size_t offset,
|
|
|
|
|
std::size_t *total_written = nullptr) -> bool override;
|
|
|
|
@ -356,6 +404,372 @@ 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>;
|
|
|
|
|
|
|
|
|
|
directory() noexcept = default;
|
|
|
|
|
|
|
|
|
|
directory(std::string_view path) : path_(utils::path::absolute(path)) {}
|
|
|
|
|
|
|
|
|
|
directory(std::wstring_view path)
|
|
|
|
|
: path_(utils::path::absolute(utils::string::to_utf8(path))) {}
|
|
|
|
|
|
|
|
|
|
directory(const directory &) noexcept = delete;
|
|
|
|
|
|
|
|
|
|
directory(directory &&move_dir) noexcept = default;
|
|
|
|
|
|
|
|
|
|
~directory() override = default;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::string path_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
count(bool recursive = false) const -> std::uint64_t override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto exists() const -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
get_directory(std::string_view path) const -> fs_directory_t override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
get_directories() const -> std::vector<fs_directory_t> override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
get_file(std::string_view path) const -> fs_file_t override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto get_files() const -> std::vector<fs_file_t> override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto get_items() const -> std::vector<fs_item_t> override;
|
|
|
|
|
|
|
|
|
|
[[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;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto remove_recursively() -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
size(bool recursive = false) const -> std::uint64_t override;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
auto operator=(const directory &) noexcept -> directory & = delete;
|
|
|
|
|
|
|
|
|
|
auto operator=(directory &&move_dir) noexcept -> directory & = default;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] operator bool() const override { return exists(); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#if defined(PROJECT_ENABLE_LIBDSM)
|
|
|
|
|
#define SMB_MOD_RW2 \
|
|
|
|
|
(SMB_MOD_READ | SMB_MOD_WRITE | SMB_MOD_READ_EXT | SMB_MOD_WRITE_EXT | \
|
|
|
|
|
SMB_MOD_READ_ATTR | SMB_MOD_WRITE_ATTR | SMB_MOD_READ_CTL)
|
|
|
|
|
|
|
|
|
|
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),
|
|
|
|
|
path_(std::move(path)),
|
|
|
|
|
session_(std::move(session)),
|
|
|
|
|
share_name_(share_name),
|
|
|
|
|
size_(size),
|
|
|
|
|
tid_(tid),
|
|
|
|
|
write_time_(write_time) {}
|
|
|
|
|
|
|
|
|
|
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_),
|
|
|
|
|
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_) {}
|
|
|
|
|
|
|
|
|
|
~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;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto exists() const -> bool override;
|
|
|
|
|
|
|
|
|
|
void flush() const override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto get_handle() const -> native_handle override {
|
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto get_path() const -> std::string override { return path_; }
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto get_read_buffer_size() const -> std::uint32_t override {
|
|
|
|
|
return read_buffer_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[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_;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto get_unc_path() const -> std::string {
|
|
|
|
|
return smb_get_unc_path(path_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto get_uri_path() const -> std::string {
|
|
|
|
|
return smb_get_uri_path(path_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
get_uri_path(std::string_view user,
|
|
|
|
|
std::string_view password) const -> std::string {
|
|
|
|
|
return smb_get_uri_path(path_, user, password);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto is_read_only() const -> bool override {
|
|
|
|
|
return read_only_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto move_to(std::string_view new_path) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto open(bool read_only) -> bool;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto read(unsigned char *data, std::size_t to_read,
|
|
|
|
|
std::uint64_t offset,
|
|
|
|
|
std::size_t *total_read = nullptr) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto remove() -> bool override;
|
|
|
|
|
|
|
|
|
|
auto set_read_buffer_size(std::uint32_t size) -> std::uint32_t override {
|
|
|
|
|
read_buffer_size = size;
|
|
|
|
|
return read_buffer_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto size() const -> std::uint64_t override { return size_; }
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto truncate(std::size_t size) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
write(const unsigned char *data, std::size_t to_write, std::size_t offset,
|
|
|
|
|
std::size_t *total_written = nullptr) -> bool override;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
auto operator=(const smb_file &) noexcept -> smb_file & = delete;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] operator bool() const override { return fd_.has_value(); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class smb_directory final : public i_directory {
|
|
|
|
|
public:
|
|
|
|
|
using smb_directory_t = std::unique_ptr<smb_directory>;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] static auto
|
|
|
|
|
open(std::string_view host, std::string_view user, std::string_view password,
|
|
|
|
|
std::string_view share_name) -> smb_directory_t;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] static auto
|
|
|
|
|
open(std::wstring_view host, std::wstring_view user,
|
|
|
|
|
std::wstring_view password,
|
|
|
|
|
std::wstring_view share_name) -> smb_directory_t;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
smb_directory() noexcept = default;
|
|
|
|
|
|
|
|
|
|
smb_directory(const smb_directory &) noexcept = delete;
|
|
|
|
|
|
|
|
|
|
smb_directory(smb_directory &&) noexcept = default;
|
|
|
|
|
|
|
|
|
|
~smb_directory() override = default;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
smb_directory(std::string path, smb_session_t session,
|
|
|
|
|
std::string_view share_name, smb_tid tid)
|
|
|
|
|
: path_(std::move(path)),
|
|
|
|
|
session_(std::move(session)),
|
|
|
|
|
share_name_(share_name),
|
|
|
|
|
tid_(tid) {}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::string path_{};
|
|
|
|
|
smb_session_t session_{};
|
|
|
|
|
std::string share_name_{};
|
|
|
|
|
smb_tid tid_{};
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
count(bool recursive = false) const -> std::uint64_t override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto exists() const -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
get_directory(std::string_view path) const -> fs_directory_t override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
get_directories() const -> std::vector<fs_directory_t> override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
get_file(std::string_view path) const -> fs_file_t override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto get_files() const -> std::vector<fs_file_t> override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto get_items() const -> std::vector<fs_item_t> override;
|
|
|
|
|
|
|
|
|
|
[[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_unc_path() const -> std::string {
|
|
|
|
|
return smb_get_unc_path(path_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto get_uri_path() const -> std::string {
|
|
|
|
|
return smb_get_uri_path(path_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
get_uri_path(std::string_view user,
|
|
|
|
|
std::string_view password) const -> std::string {
|
|
|
|
|
return smb_get_uri_path(path_, user, password);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto move_to(std::string_view new_path) -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto remove() -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto remove_recursively() -> bool override;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto
|
|
|
|
|
size(bool recursive = false) const -> std::uint64_t override;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
auto operator=(const smb_directory &) noexcept -> smb_directory & = delete;
|
|
|
|
|
|
|
|
|
|
auto
|
|
|
|
|
operator=(smb_directory &&move_dir) noexcept -> smb_directory & = default;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] operator bool() const override { return session_ != nullptr; }
|
|
|
|
|
};
|
|
|
|
|
#endif // defined(PROJECT_ENABLE_LIBDSM)
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto create_directories(std::string_view path) -> bool;
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] auto create_directories(std::wstring_view path) -> bool;
|
|
|
|
|