2.0.0-rc (#9)
Some checks failed
BlockStorage/repertory_osx/pipeline/head This commit looks good
BlockStorage/repertory_windows/pipeline/head This commit looks good
BlockStorage/repertory/pipeline/head There was a failure building this commit
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good
BlockStorage/repertory_osx_builds/pipeline/head There was a failure building this commit
Some checks failed
BlockStorage/repertory_osx/pipeline/head This commit looks good
BlockStorage/repertory_windows/pipeline/head This commit looks good
BlockStorage/repertory/pipeline/head There was a failure building this commit
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good
BlockStorage/repertory_osx_builds/pipeline/head There was a failure building this commit
### Issues * \#1 \[bug\] Unable to mount S3 due to 'item_not_found' exception * \#2 Require bucket name for S3 mounts * \#3 \[bug\] File size is not being updated in S3 mount * \#4 Upgrade to libfuse-3.x.x * \#5 Switch to renterd for Sia support * \#6 Switch to cpp-httplib to further reduce dependencies * \#7 Remove global_data and calculate used disk space per provider * \#8 Switch to libcurl for S3 mount support ### Changes from v1.x.x * Added read-only encrypt provider * Pass-through mount point that transparently encrypts source data using `XChaCha20-Poly1305` * Added S3 encryption support via `XChaCha20-Poly1305` * Added replay protection to remote mounts * Added support base64 writes in remote FUSE * Created static linked Linux binaries for `amd64` and `aarch64` using `musl-libc` * Removed legacy Sia renter support * Removed Skynet support * Fixed multiple remote mount WinFSP API issues on \*NIX servers * Implemented chunked read and write * Writes for non-cached files are performed in chunks of 8Mib * Removed `repertory-ui` support * Removed `FreeBSD` support * Switched to `libsodium` over `CryptoPP` * Switched to `XChaCha20-Poly1305` for remote mounts * Updated `GoogleTest` to v1.14.0 * Updated `JSON for Modern C++` to v3.11.2 * Updated `OpenSSL` to v1.1.1w * Updated `RocksDB` to v8.5.3 * Updated `WinFSP` to 2023 * Updated `boost` to v1.78.0 * Updated `cURL` to v8.3.0 * Updated `zlib` to v1.3 * Use `upload_manager` for all providers * Adds a delay to uploads to prevent excessive API calls * Supports re-upload after mount restart for incomplete uploads * NOTE: Uploads for all providers are full file (no resume support) * Multipart upload support is planned for S3 Reviewed-on: #9
This commit is contained in:
@ -1,53 +1,58 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_APP_CONFIG_HPP_
|
||||
#define INCLUDE_APP_CONFIG_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/skynet.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config final {
|
||||
public:
|
||||
static std::string default_agent_name(const provider_type &pt);
|
||||
[[nodiscard]] static auto default_agent_name(const provider_type &pt)
|
||||
-> std::string;
|
||||
|
||||
static std::uint16_t default_api_port(const provider_type &pt);
|
||||
[[nodiscard]] static auto default_api_port(const provider_type &pt)
|
||||
-> std::uint16_t;
|
||||
|
||||
static std::string default_data_directory(const provider_type &pt);
|
||||
[[nodiscard]] static auto default_data_directory(const provider_type &pt)
|
||||
-> std::string;
|
||||
|
||||
static std::uint16_t default_rpc_port(const provider_type &pt);
|
||||
[[nodiscard]] static auto default_rpc_port(const provider_type &pt)
|
||||
-> std::uint16_t;
|
||||
|
||||
static std::string get_provider_api_password(const provider_type &pt);
|
||||
[[nodiscard]] static auto get_provider_api_password(const provider_type &pt)
|
||||
-> std::string;
|
||||
|
||||
static std::string get_provider_display_name(const provider_type &pt);
|
||||
[[nodiscard]] static auto get_provider_display_name(const provider_type &pt)
|
||||
-> std::string;
|
||||
|
||||
static std::string get_provider_minimum_version(const provider_type &pt);
|
||||
|
||||
static std::string get_provider_name(const provider_type &pt);
|
||||
|
||||
static std::string get_provider_path_name(const provider_type &pt);
|
||||
[[nodiscard]] static auto get_provider_name(const provider_type &pt)
|
||||
-> std::string;
|
||||
|
||||
public:
|
||||
explicit app_config(const provider_type &pt, const std::string &data_directory = "");
|
||||
app_config(const provider_type &pt, const std::string &data_directory = "");
|
||||
|
||||
~app_config() { save(); }
|
||||
|
||||
@ -67,6 +72,7 @@ private:
|
||||
bool enable_mount_manager_;
|
||||
#endif
|
||||
bool enable_remote_mount_;
|
||||
encrypt_config encrypt_config_;
|
||||
event_level event_level_;
|
||||
std::uint32_t eviction_delay_mins_;
|
||||
bool eviction_uses_accessed_time_;
|
||||
@ -76,7 +82,6 @@ private:
|
||||
std::uint64_t max_cache_size_bytes_;
|
||||
std::uint8_t max_upload_count_;
|
||||
std::uint8_t min_download_timeout_secs_;
|
||||
double minimum_redundancy_;
|
||||
std::uint16_t online_check_retry_secs_;
|
||||
std::uint16_t orphaned_file_retention_days_;
|
||||
std::string preferred_download_type_;
|
||||
@ -90,22 +95,20 @@ private:
|
||||
std::string remote_token_;
|
||||
std::uint16_t retry_read_count_;
|
||||
std::uint16_t ring_buffer_file_size_;
|
||||
api_currency storage_byte_month_;
|
||||
std::uint64_t version_ = REPERTORY_CONFIG_VERSION;
|
||||
std::string cache_directory_;
|
||||
host_config hc_;
|
||||
s3_config s3_config_;
|
||||
skynet_config skynet_config_;
|
||||
std::uint64_t version_ = REPERTORY_CONFIG_VERSION;
|
||||
std::string log_directory_;
|
||||
std::recursive_mutex read_write_mutex_;
|
||||
std::recursive_mutex remote_mount_mutex_;
|
||||
|
||||
private:
|
||||
bool load();
|
||||
[[nodiscard]] auto load() -> bool;
|
||||
|
||||
template <typename dest>
|
||||
bool get_value(const json &json_document, const std::string &name, dest &dst,
|
||||
bool &success_flag) {
|
||||
auto get_value(const json &json_document, const std::string &name, dest &dst,
|
||||
bool &success_flag) -> bool {
|
||||
auto ret = false;
|
||||
try {
|
||||
if (json_document.find(name) != json_document.end()) {
|
||||
@ -115,7 +118,7 @@ private:
|
||||
success_flag = false;
|
||||
}
|
||||
} catch (const json::exception &ex) {
|
||||
event_system::instance().raise<repertory_exception>(__FUNCTION__, ex.what());
|
||||
utils::error::raise_error(__FUNCTION__, ex, "exception occurred");
|
||||
success_flag = false;
|
||||
ret = false;
|
||||
}
|
||||
@ -123,7 +126,8 @@ private:
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename dest, typename source> bool set_value(dest &dst, const source &src) {
|
||||
template <typename dest, typename source>
|
||||
auto set_value(dest &dst, const source &src) -> bool {
|
||||
auto ret = false;
|
||||
recur_mutex_lock l(read_write_mutex_);
|
||||
if (dst != src) {
|
||||
@ -131,205 +135,255 @@ private:
|
||||
config_changed_ = true;
|
||||
save();
|
||||
ret = true;
|
||||
|
||||
if (reinterpret_cast<void *>(&dst) == &skynet_config_.portal_list) {
|
||||
event_system::instance().raise<skynet_portal_list_changed>();
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public:
|
||||
std::string get_api_auth() const { return api_auth_; }
|
||||
[[nodiscard]] auto get_api_auth() const -> std::string { return api_auth_; }
|
||||
|
||||
std::uint16_t get_api_port() const { return api_port_; }
|
||||
[[nodiscard]] auto get_api_port() const -> std::uint16_t { return api_port_; }
|
||||
|
||||
std::string get_api_user() const { return api_user_; }
|
||||
[[nodiscard]] auto get_api_user() const -> std::string { return api_user_; }
|
||||
|
||||
std::string get_cache_directory() const { return cache_directory_; }
|
||||
[[nodiscard]] auto get_cache_directory() const -> std::string {
|
||||
return cache_directory_;
|
||||
}
|
||||
|
||||
std::uint8_t get_chunk_downloader_timeout_secs() const {
|
||||
[[nodiscard]] auto get_chunk_downloader_timeout_secs() const -> std::uint8_t {
|
||||
return std::max(min_download_timeout_secs_, download_timeout_secs_);
|
||||
}
|
||||
|
||||
std::string get_config_file_path() const;
|
||||
[[nodiscard]] auto get_config_file_path() const -> std::string;
|
||||
|
||||
std::string get_data_directory() const { return data_directory_; }
|
||||
[[nodiscard]] auto get_data_directory() const -> std::string {
|
||||
return data_directory_;
|
||||
}
|
||||
|
||||
bool get_enable_chunk_download_timeout() const { return enable_chunk_downloader_timeout_; }
|
||||
[[nodiscard]] auto get_enable_chunk_download_timeout() const -> bool {
|
||||
return enable_chunk_downloader_timeout_;
|
||||
}
|
||||
|
||||
bool get_enable_comm_duration_events() const { return enable_comm_duration_events_; }
|
||||
[[nodiscard]] auto get_enable_comm_duration_events() const -> bool {
|
||||
return enable_comm_duration_events_;
|
||||
}
|
||||
|
||||
bool get_enable_drive_events() const { return enable_drive_events_; }
|
||||
[[nodiscard]] auto get_enable_drive_events() const -> bool {
|
||||
return enable_drive_events_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_encrypt_config() const -> encrypt_config {
|
||||
return encrypt_config_;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
bool get_enable_mount_manager() const { return enable_mount_manager_; }
|
||||
[[nodiscard]] auto get_enable_mount_manager() const -> bool {
|
||||
return enable_mount_manager_;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool get_enable_max_cache_size() const { return enable_max_cache_size_; }
|
||||
|
||||
bool get_enable_remote_mount() const { return enable_remote_mount_; }
|
||||
|
||||
event_level get_event_level() const { return event_level_; }
|
||||
|
||||
std::uint32_t get_eviction_delay_mins() const { return eviction_delay_mins_; }
|
||||
|
||||
bool get_eviction_uses_accessed_time() const { return eviction_uses_accessed_time_; }
|
||||
|
||||
std::uint8_t get_high_frequency_interval_secs() const {
|
||||
return std::max((std::uint8_t)1, high_freq_interval_secs_);
|
||||
[[nodiscard]] auto get_enable_max_cache_size() const -> bool {
|
||||
return enable_max_cache_size_;
|
||||
}
|
||||
|
||||
host_config get_host_config() const { return hc_; }
|
||||
|
||||
bool get_is_remote_mount() const { return is_remote_mount_; }
|
||||
|
||||
json get_json() const;
|
||||
|
||||
std::string get_log_directory() const { return log_directory_; }
|
||||
|
||||
std::uint32_t get_low_frequency_interval_secs() const {
|
||||
return std::max((std::uint32_t)1, low_freq_interval_secs_);
|
||||
[[nodiscard]] auto get_enable_remote_mount() const -> bool {
|
||||
return enable_remote_mount_;
|
||||
}
|
||||
|
||||
std::uint64_t get_max_cache_size_bytes() const;
|
||||
|
||||
std::uint8_t get_max_upload_count() const {
|
||||
return std::max(std::uint8_t(1u), max_upload_count_);
|
||||
[[nodiscard]] auto get_event_level() const -> event_level {
|
||||
return event_level_;
|
||||
}
|
||||
|
||||
double get_minimum_redundancy() const { return std::max(1.5, minimum_redundancy_); }
|
||||
|
||||
std::uint16_t get_online_check_retry_secs() const {
|
||||
return std::max(std::uint16_t(15), online_check_retry_secs_);
|
||||
[[nodiscard]] auto get_eviction_delay_mins() const -> std::uint32_t {
|
||||
return eviction_delay_mins_;
|
||||
}
|
||||
|
||||
std::uint16_t get_orphaned_file_retention_days() const {
|
||||
return std::min((std::uint16_t)31, std::max((std::uint16_t)1, orphaned_file_retention_days_));
|
||||
[[nodiscard]] auto get_eviction_uses_accessed_time() const -> bool {
|
||||
return eviction_uses_accessed_time_;
|
||||
}
|
||||
|
||||
download_type get_preferred_download_type() const {
|
||||
return utils::download_type_from_string(preferred_download_type_, download_type::fallback);
|
||||
[[nodiscard]] auto get_high_frequency_interval_secs() const -> std::uint8_t {
|
||||
return std::max(static_cast<std::uint8_t>(1U), high_freq_interval_secs_);
|
||||
}
|
||||
|
||||
provider_type get_provider_type() const { return pt_; }
|
||||
[[nodiscard]] auto get_host_config() const -> host_config { return hc_; }
|
||||
|
||||
std::uint8_t get_read_ahead_count() const { return std::max((std::uint8_t)1, read_ahead_count_); }
|
||||
|
||||
std::uint8_t get_remote_client_pool_size() const {
|
||||
return std::max((std::uint8_t)5u, remote_client_pool_size_);
|
||||
[[nodiscard]] auto get_is_remote_mount() const -> bool {
|
||||
return is_remote_mount_;
|
||||
}
|
||||
|
||||
std::string get_remote_host_name_or_ip() const { return remote_host_name_or_ip_; }
|
||||
[[nodiscard]] auto get_json() const -> json;
|
||||
|
||||
std::uint8_t get_remote_max_connections() const {
|
||||
return std::max((std::uint8_t)1, remote_max_connections_);
|
||||
[[nodiscard]] auto get_log_directory() const -> std::string {
|
||||
return log_directory_;
|
||||
}
|
||||
|
||||
std::uint16_t get_remote_port() const { return remote_port_; }
|
||||
[[nodiscard]] auto get_low_frequency_interval_secs() const -> std::uint32_t {
|
||||
return std::max(1U, low_freq_interval_secs_);
|
||||
}
|
||||
|
||||
std::uint16_t get_remote_receive_timeout_secs() const { return remote_receive_timeout_secs_; }
|
||||
[[nodiscard]] auto get_max_cache_size_bytes() const -> std::uint64_t;
|
||||
|
||||
std::uint16_t get_remote_send_timeout_secs() const { return remote_send_timeout_secs_; }
|
||||
[[nodiscard]] auto get_max_upload_count() const -> std::uint8_t {
|
||||
return std::max(std::uint8_t(1U), max_upload_count_);
|
||||
}
|
||||
|
||||
std::string get_remote_token() const { return remote_token_; }
|
||||
[[nodiscard]] auto get_online_check_retry_secs() const -> std::uint16_t {
|
||||
return std::max(std::uint16_t(15U), online_check_retry_secs_);
|
||||
}
|
||||
|
||||
std::uint16_t get_retry_read_count() const {
|
||||
[[nodiscard]] auto get_orphaned_file_retention_days() const -> std::uint16_t {
|
||||
return std::min(static_cast<std::uint16_t>(31U),
|
||||
std::max(static_cast<std::uint16_t>(1U),
|
||||
orphaned_file_retention_days_));
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_preferred_download_type() const -> download_type {
|
||||
return utils::download_type_from_string(preferred_download_type_,
|
||||
download_type::fallback);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_provider_type() const -> provider_type { return pt_; }
|
||||
|
||||
[[nodiscard]] auto get_read_ahead_count() const -> std::uint8_t {
|
||||
return std::max(static_cast<std::uint8_t>(1U), read_ahead_count_);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_remote_client_pool_size() const -> std::uint8_t {
|
||||
return std::max(static_cast<std::uint8_t>(5U), remote_client_pool_size_);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_remote_host_name_or_ip() const -> std::string {
|
||||
return remote_host_name_or_ip_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_remote_max_connections() const -> std::uint8_t {
|
||||
return std::max(static_cast<std::uint8_t>(1U), remote_max_connections_);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_remote_port() const -> std::uint16_t {
|
||||
return remote_port_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_remote_receive_timeout_secs() const -> std::uint16_t {
|
||||
return remote_receive_timeout_secs_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_remote_send_timeout_secs() const -> std::uint16_t {
|
||||
return remote_send_timeout_secs_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_remote_token() const -> std::string {
|
||||
return remote_token_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_retry_read_count() const -> std::uint16_t {
|
||||
return std::max(std::uint16_t(2), retry_read_count_);
|
||||
}
|
||||
|
||||
std::uint16_t get_ring_buffer_file_size() const {
|
||||
return std::max((std::uint16_t)64, std::min((std::uint16_t)1024, ring_buffer_file_size_));
|
||||
[[nodiscard]] auto get_ring_buffer_file_size() const -> std::uint16_t {
|
||||
return std::max(
|
||||
static_cast<std::uint16_t>(64U),
|
||||
std::min(static_cast<std::uint16_t>(1024U), ring_buffer_file_size_));
|
||||
}
|
||||
|
||||
s3_config get_s3_config() const { return s3_config_; }
|
||||
[[nodiscard]] auto get_s3_config() const -> s3_config { return s3_config_; }
|
||||
|
||||
skynet_config get_skynet_config() const { return skynet_config_; }
|
||||
[[nodiscard]] auto get_value_by_name(const std::string &name) -> std::string;
|
||||
|
||||
api_currency get_storage_byte_month() const { return storage_byte_month_; }
|
||||
|
||||
std::string get_value_by_name(const std::string &name);
|
||||
|
||||
std::uint64_t get_version() const { return version_; }
|
||||
[[nodiscard]] auto get_version() const -> std::uint64_t { return version_; }
|
||||
|
||||
void save();
|
||||
|
||||
void set_api_auth(const std::string &api_auth) { set_value(api_auth_, api_auth); }
|
||||
void set_api_auth(const std::string &api_auth) {
|
||||
set_value(api_auth_, api_auth);
|
||||
}
|
||||
|
||||
void set_api_port(const std::uint16_t &api_port) { set_value(api_port_, api_port); }
|
||||
void set_api_port(std::uint16_t api_port) { set_value(api_port_, api_port); }
|
||||
|
||||
void set_api_user(const std::string &api_user) { set_value(api_user_, api_user); }
|
||||
void set_api_user(const std::string &api_user) {
|
||||
set_value(api_user_, api_user);
|
||||
}
|
||||
|
||||
void set_chunk_downloader_timeout_secs(const std::uint8_t &chunk_downloader_timeout_secs) {
|
||||
void set_chunk_downloader_timeout_secs(
|
||||
std::uint8_t chunk_downloader_timeout_secs) {
|
||||
set_value(download_timeout_secs_, chunk_downloader_timeout_secs);
|
||||
}
|
||||
|
||||
void set_enable_chunk_downloader_timeout(const bool &enable_chunk_downloader_timeout) {
|
||||
set_value(enable_chunk_downloader_timeout_, enable_chunk_downloader_timeout);
|
||||
void
|
||||
set_enable_chunk_downloader_timeout(bool enable_chunk_downloader_timeout) {
|
||||
set_value(enable_chunk_downloader_timeout_,
|
||||
enable_chunk_downloader_timeout);
|
||||
}
|
||||
|
||||
void set_enable_comm_duration_events(const bool &enable_comm_duration_events) {
|
||||
void set_enable_comm_duration_events(bool enable_comm_duration_events) {
|
||||
set_value(enable_comm_duration_events_, enable_comm_duration_events);
|
||||
}
|
||||
|
||||
void set_enable_drive_events(const bool &enable_drive_events) {
|
||||
void set_enable_drive_events(bool enable_drive_events) {
|
||||
set_value(enable_drive_events_, enable_drive_events);
|
||||
}
|
||||
|
||||
void set_enable_max_cache_size(const bool &enable_max_cache_size) {
|
||||
void set_enable_max_cache_size(bool enable_max_cache_size) {
|
||||
set_value(enable_max_cache_size_, enable_max_cache_size);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
void set_enable_mount_manager(const bool &enable_mount_manager) {
|
||||
void set_enable_mount_manager(bool enable_mount_manager) {
|
||||
set_value(enable_mount_manager_, enable_mount_manager);
|
||||
}
|
||||
#endif
|
||||
|
||||
void set_enable_remote_mount(const bool &enable_remote_mount);
|
||||
void set_enable_remote_mount(bool enable_remote_mount);
|
||||
|
||||
void set_event_level(const event_level &level) {
|
||||
if (set_value(event_level_, level)) {
|
||||
event_system::instance().raise<event_level_changed>(event_level_to_string(level));
|
||||
event_system::instance().raise<event_level_changed>(
|
||||
event_level_to_string(level));
|
||||
}
|
||||
}
|
||||
|
||||
void set_eviction_delay_mins(const std::uint32_t &eviction_delay_mins) {
|
||||
void set_eviction_delay_mins(std::uint32_t eviction_delay_mins) {
|
||||
set_value(eviction_delay_mins_, eviction_delay_mins);
|
||||
}
|
||||
|
||||
void set_eviction_uses_accessed_time(const bool &eviction_uses_accessed_time) {
|
||||
void set_eviction_uses_accessed_time(bool eviction_uses_accessed_time) {
|
||||
set_value(eviction_uses_accessed_time_, eviction_uses_accessed_time);
|
||||
}
|
||||
|
||||
void set_high_frequency_interval_secs(const std::uint8_t &high_frequency_interval_secs) {
|
||||
void
|
||||
set_high_frequency_interval_secs(std::uint8_t high_frequency_interval_secs) {
|
||||
set_value(high_freq_interval_secs_, high_frequency_interval_secs);
|
||||
}
|
||||
|
||||
void set_is_remote_mount(const bool &is_remote_mount);
|
||||
#ifdef REPERTORY_TESTING
|
||||
void set_host_config(host_config hc) { hc_ = std::move(hc); }
|
||||
|
||||
void set_low_frequency_interval_secs(const std::uint32_t &low_frequency_interval_secs) {
|
||||
void set_s3_config(s3_config s3) { s3_config_ = std::move(s3); }
|
||||
#endif
|
||||
|
||||
void set_is_remote_mount(bool is_remote_mount);
|
||||
|
||||
void
|
||||
set_low_frequency_interval_secs(std::uint32_t low_frequency_interval_secs) {
|
||||
set_value(low_freq_interval_secs_, low_frequency_interval_secs);
|
||||
}
|
||||
|
||||
void set_max_cache_size_bytes(const std::uint64_t &max_cache_size_bytes) {
|
||||
void set_max_cache_size_bytes(std::uint64_t max_cache_size_bytes) {
|
||||
set_value(max_cache_size_bytes_, max_cache_size_bytes);
|
||||
}
|
||||
|
||||
void set_max_upload_count(const std::uint8_t &max_upload_count) {
|
||||
void set_max_upload_count(std::uint8_t max_upload_count) {
|
||||
set_value(max_upload_count_, max_upload_count);
|
||||
}
|
||||
|
||||
void set_minimum_redundancy(const double &minimum_redundancy) {
|
||||
set_value(minimum_redundancy_, minimum_redundancy);
|
||||
}
|
||||
|
||||
void set_online_check_retry_secs(const std::uint16_t &online_check_retry_secs) {
|
||||
void set_online_check_retry_secs(std::uint16_t online_check_retry_secs) {
|
||||
set_value(online_check_retry_secs_, online_check_retry_secs);
|
||||
}
|
||||
|
||||
void set_orphaned_file_retention_days(const std::uint16_t &orphaned_file_retention_days) {
|
||||
void
|
||||
set_orphaned_file_retention_days(std::uint16_t orphaned_file_retention_days) {
|
||||
set_value(orphaned_file_retention_days_, orphaned_file_retention_days);
|
||||
}
|
||||
|
||||
@ -337,15 +391,15 @@ public:
|
||||
set_value(preferred_download_type_, utils::download_type_to_string(dt));
|
||||
}
|
||||
|
||||
void set_read_ahead_count(const std::uint8_t &read_ahead_count) {
|
||||
void set_read_ahead_count(std::uint8_t read_ahead_count) {
|
||||
set_value(read_ahead_count_, read_ahead_count);
|
||||
}
|
||||
|
||||
void set_remote_client_pool_size(const std::uint8_t &remote_client_pool_size) {
|
||||
void set_remote_client_pool_size(std::uint8_t remote_client_pool_size) {
|
||||
set_value(remote_client_pool_size_, remote_client_pool_size);
|
||||
}
|
||||
|
||||
void set_ring_buffer_file_size(const std::uint16_t &ring_buffer_file_size) {
|
||||
void set_ring_buffer_file_size(std::uint16_t ring_buffer_file_size) {
|
||||
set_value(ring_buffer_file_size_, ring_buffer_file_size);
|
||||
}
|
||||
|
||||
@ -353,29 +407,33 @@ public:
|
||||
set_value(remote_host_name_or_ip_, remote_host_name_or_ip);
|
||||
}
|
||||
|
||||
void set_remote_max_connections(const std::uint8_t &remote_max_connections) {
|
||||
void set_remote_max_connections(std::uint8_t remote_max_connections) {
|
||||
set_value(remote_max_connections_, remote_max_connections);
|
||||
}
|
||||
|
||||
void set_remote_port(const std::uint16_t &remote_port) { set_value(remote_port_, remote_port); }
|
||||
void set_remote_port(std::uint16_t remote_port) {
|
||||
set_value(remote_port_, remote_port);
|
||||
}
|
||||
|
||||
void set_remote_receive_timeout_secs(const std::uint16_t &remote_receive_timeout_secs) {
|
||||
void
|
||||
set_remote_receive_timeout_secs(std::uint16_t remote_receive_timeout_secs) {
|
||||
set_value(remote_receive_timeout_secs_, remote_receive_timeout_secs);
|
||||
}
|
||||
|
||||
void set_remote_send_timeout_secs(const std::uint16_t &remote_send_timeout_secs) {
|
||||
void set_remote_send_timeout_secs(std::uint16_t remote_send_timeout_secs) {
|
||||
set_value(remote_send_timeout_secs_, remote_send_timeout_secs);
|
||||
}
|
||||
|
||||
void set_remote_token(const std::string &remote_token) { set_value(remote_token_, remote_token); }
|
||||
void set_remote_token(const std::string &remote_token) {
|
||||
set_value(remote_token_, remote_token);
|
||||
}
|
||||
|
||||
void set_retry_read_count(const std::uint16_t &retry_read_count) {
|
||||
void set_retry_read_count(std::uint16_t retry_read_count) {
|
||||
set_value(retry_read_count_, retry_read_count);
|
||||
}
|
||||
|
||||
void set_storage_byte_month(const api_currency &storage_byte_month);
|
||||
|
||||
std::string set_value_by_name(const std::string &name, const std::string &value);
|
||||
[[nodiscard]] auto set_value_by_name(const std::string &name,
|
||||
const std::string &value) -> std::string;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -1,91 +1,95 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_ACTIONS_HPP_
|
||||
#define INCLUDE_CLI_ACTIONS_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "cli/check_version.hpp"
|
||||
#include "cli/create_directory.hpp"
|
||||
#include "cli/display_config.hpp"
|
||||
#include "cli/drive_information.hpp"
|
||||
#include "cli/export.hpp"
|
||||
#include "cli/export_all.hpp"
|
||||
#include "cli/get.hpp"
|
||||
#include "cli/get_directory_items.hpp"
|
||||
#include "cli/get_pinned_files.hpp"
|
||||
#include "cli/help.hpp"
|
||||
#include "cli/import.hpp"
|
||||
#include "cli/import_json.hpp"
|
||||
#include "cli/list_objects.hpp"
|
||||
#include "cli/mount.hpp"
|
||||
#include "cli/open_files.hpp"
|
||||
#include "cli/pin_file.hpp"
|
||||
#include "cli/pinned_status.hpp"
|
||||
#include "cli/set.hpp"
|
||||
#include "cli/status.hpp"
|
||||
#include "cli/test_skynet_auth.hpp"
|
||||
#include "cli/unmount.hpp"
|
||||
#include "cli/unpin_file.hpp"
|
||||
#include "cli/version.hpp"
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
typedef std::function<exit_code(const int &argc, char *argv[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &unique_id,
|
||||
std::string user, std::string password)>
|
||||
action;
|
||||
using action = std::function<exit_code(
|
||||
int, char **, const std::string &, const provider_type &,
|
||||
const std::string &, std::string, std::string)>;
|
||||
|
||||
struct option_hasher {
|
||||
std::size_t operator()(const utils::cli::option &opt) const {
|
||||
auto operator()(const utils::cli::option &opt) const -> std::size_t {
|
||||
return std::hash<std::string>()(opt[0u] + '|' + opt[1u]);
|
||||
}
|
||||
};
|
||||
|
||||
static const std::unordered_map<utils::cli::option, action, option_hasher> option_actions = {
|
||||
{utils::cli::options::check_version_option, cli::actions::check_version},
|
||||
{utils::cli::options::display_config_option, cli::actions::display_config},
|
||||
{utils::cli::options::drive_information_option, cli::actions::drive_information},
|
||||
{utils::cli::options::export_option, cli::actions::export_action},
|
||||
{utils::cli::options::export_all_option, cli::actions::export_all},
|
||||
{utils::cli::options::get_directory_items_option, cli::actions::get_directory_items},
|
||||
{utils::cli::options::get_option, cli::actions::get},
|
||||
{utils::cli::options::get_pinned_files_option, cli::actions::get_pinned_files},
|
||||
{utils::cli::options::import_option, cli::actions::import},
|
||||
{utils::cli::options::import_json_option, cli::actions::import_json},
|
||||
{utils::cli::options::open_files_option, cli::actions::open_files},
|
||||
{utils::cli::options::pin_file_option, cli::actions::pin_file},
|
||||
{utils::cli::options::pinned_status_option, cli::actions::pinned_status},
|
||||
{utils::cli::options::set_option, cli::actions::set},
|
||||
{utils::cli::options::status_option, cli::actions::status},
|
||||
#if defined(REPERTORY_ENABLE_SKYNET)
|
||||
{utils::cli::options::test_skynet_auth_option, cli::actions::test_skynet_auth},
|
||||
static const std::unordered_map<utils::cli::option, action, option_hasher>
|
||||
option_actions = {
|
||||
{utils::cli::options::check_version_option,
|
||||
cli::actions::check_version},
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
{utils::cli::options::create_directory_option,
|
||||
cli::actions::create_directory},
|
||||
{utils::cli::options::list_objects_option, cli::actions::list_objects},
|
||||
#endif
|
||||
{utils::cli::options::unmount_option, cli::actions::unmount},
|
||||
{utils::cli::options::unpin_file_option, cli::actions::unpin_file},
|
||||
{utils::cli::options::display_config_option,
|
||||
cli::actions::display_config},
|
||||
{utils::cli::options::drive_information_option,
|
||||
cli::actions::drive_information},
|
||||
{utils::cli::options::get_directory_items_option,
|
||||
cli::actions::get_directory_items},
|
||||
{utils::cli::options::get_option, cli::actions::get},
|
||||
{utils::cli::options::get_pinned_files_option,
|
||||
cli::actions::get_pinned_files},
|
||||
{utils::cli::options::open_files_option, cli::actions::open_files},
|
||||
{utils::cli::options::pin_file_option, cli::actions::pin_file},
|
||||
{utils::cli::options::pinned_status_option,
|
||||
cli::actions::pinned_status},
|
||||
{utils::cli::options::set_option, cli::actions::set},
|
||||
{utils::cli::options::status_option, cli::actions::status},
|
||||
{utils::cli::options::unmount_option, cli::actions::unmount},
|
||||
{utils::cli::options::unpin_file_option, cli::actions::unpin_file},
|
||||
};
|
||||
|
||||
static exit_code perform_action(const utils::cli::option &opt, const int &argc, char *argv[],
|
||||
const std::string &data_directory, const provider_type &pt,
|
||||
const std::string &unique_id, std::string user,
|
||||
std::string password) {
|
||||
[[nodiscard]] inline auto
|
||||
perform_action(const utils::cli::option &opt, int argc, char *argv[],
|
||||
const std::string &data_directory, const provider_type &pt,
|
||||
const std::string &unique_id, std::string user,
|
||||
std::string password) -> exit_code {
|
||||
if (utils::cli::has_option(argc, argv, opt)) {
|
||||
if (option_actions.find(opt) != option_actions.end()) {
|
||||
return option_actions.at(opt)(argc, argv, data_directory, pt, unique_id, std::move(user),
|
||||
std::move(password));
|
||||
return option_actions.at(opt)(argc, argv, data_directory, pt, unique_id,
|
||||
user, password);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,60 +1,69 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_CHECK_VERSION_HPP_
|
||||
#define INCLUDE_CLI_CHECK_VERSION_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "comm/curl/curl_comm.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code check_version(const int &, char *[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &, std::string,
|
||||
std::string) {
|
||||
[[nodiscard]] inline auto
|
||||
check_version(int, char *[], const std::string & /* data_directory */,
|
||||
const provider_type & /* pt */, const std::string &, std::string,
|
||||
std::string) -> exit_code {
|
||||
auto ret = exit_code::success;
|
||||
|
||||
if (not((pt == provider_type::remote) || (pt == provider_type::s3) ||
|
||||
(pt == provider_type::skynet))) {
|
||||
app_config config(pt, data_directory);
|
||||
curl_comm comm(config);
|
||||
json data, err;
|
||||
|
||||
if (comm.get("/daemon/version", data, err) == api_error::success) {
|
||||
const auto res = utils::compare_version_strings(data["version"].get<std::string>(),
|
||||
app_config::get_provider_minimum_version(pt));
|
||||
if (res < 0) {
|
||||
ret = exit_code::incompatible_version;
|
||||
std::cerr << "Failed!" << std::endl;
|
||||
std::cerr << " Actual: " << data["version"].get<std::string>() << std::endl;
|
||||
std::cerr << " Minimum: " << app_config::get_provider_minimum_version(pt) << std::endl;
|
||||
} else {
|
||||
std::cout << "Success!" << std::endl;
|
||||
std::cout << " Actual: " << data["version"].get<std::string>() << std::endl;
|
||||
std::cout << " Minimum: " << app_config::get_provider_minimum_version(pt) << std::endl;
|
||||
}
|
||||
} else {
|
||||
std::cerr << "Failed!" << std::endl;
|
||||
std::cerr << err.dump(2) << std::endl;
|
||||
ret = exit_code::communication_error;
|
||||
}
|
||||
}
|
||||
// TODO need to updated way to check version
|
||||
// if (not((pt == provider_type::remote) || (pt == provider_type::s3))) {
|
||||
// app_config config(pt, data_directory);
|
||||
// curl_comm comm(config);
|
||||
// json data, err;
|
||||
//
|
||||
// if (comm.get("/daemon/version", data, err) == api_error::success) {
|
||||
// const auto res = utils::compare_version_strings(
|
||||
// data["version"].get<std::string>(),
|
||||
// app_config::get_provider_minimum_version(pt));
|
||||
// if (res < 0) {
|
||||
// ret = exit_code::incompatible_version;
|
||||
// std::cerr << "Failed!" << std::endl;
|
||||
// std::cerr << " Actual: " << data["version"].get<std::string>()
|
||||
// << std::endl;
|
||||
// std::cerr << " Minimum: "
|
||||
// << app_config::get_provider_minimum_version(pt) <<
|
||||
// std::endl;
|
||||
// } else {
|
||||
// std::cout << "Success!" << std::endl;
|
||||
// std::cout << " Actual: " << data["version"].get<std::string>()
|
||||
// << std::endl;
|
||||
// std::cout << " Minimum: "
|
||||
// << app_config::get_provider_minimum_version(pt) <<
|
||||
// std::endl;
|
||||
// }
|
||||
// } else {
|
||||
// std::cerr << "Failed!" << std::endl;
|
||||
// std::cerr << err.dump(2) << std::endl;
|
||||
// ret = exit_code::communication_error;
|
||||
// }
|
||||
// }
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
80
include/cli/create_directory.hpp
Normal file
80
include/cli/create_directory.hpp
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_CREATE_DIRECTORY_HPP_
|
||||
#define INCLUDE_CLI_CREATE_DIRECTORY_HPP_
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "comm/s3/s3_comm.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "providers/provider.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
[[nodiscard]] inline auto
|
||||
create_directory(int argc, char *argv[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &unique_id,
|
||||
std::string /* user */, std::string /* password */)
|
||||
-> exit_code {
|
||||
auto ret = exit_code::invalid_provider_type;
|
||||
|
||||
if (pt == provider_type::s3) {
|
||||
std::string api_path;
|
||||
if ((ret = utils::cli::parse_string_option(
|
||||
argc, argv, utils::cli::options::create_directory_option,
|
||||
api_path)) == exit_code::success) {
|
||||
lock_data lock(pt, unique_id);
|
||||
const auto res = lock.grab_lock(1u);
|
||||
/* if (res == lock_result::locked) { */
|
||||
/* auto port = app_config::default_api_port(pt); */
|
||||
/* utils::cli::get_api_authentication_data(user, password, port, pt,
|
||||
* data_directory); */
|
||||
/* const auto response = */
|
||||
/* client({"localhost", password, port,
|
||||
* user}).create_directory(api_path); */
|
||||
/* std::cout << static_cast<int>(response.response_type) << std::endl; */
|
||||
/* std::cout << response.data.dump(2) << std::endl; */
|
||||
/* } else */
|
||||
if (res == lock_result::success) {
|
||||
std::cout << "creating directory: '" << api_path << "'" << std::endl;
|
||||
app_config config(pt, data_directory);
|
||||
s3_comm comm(config);
|
||||
const auto res = comm.create_directory(api_path);
|
||||
std::cout << api_error_to_string(res) << std::endl;
|
||||
ret = exit_code::success;
|
||||
} else {
|
||||
std::cout << "failed to grab lock: '" << static_cast<int>(res) << "'"
|
||||
<< std::endl;
|
||||
ret = exit_code::lock_failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
} // namespace repertory::cli::actions
|
||||
|
||||
#endif // REPERTORY_ENABLE_S3
|
||||
#endif // INCLUDE_CLI_CREATE_DIRECTORY_HPP_
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_DISPLAY_CONFIG_HPP_
|
||||
#define INCLUDE_CLI_DISPLAY_CONFIG_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
@ -28,9 +30,10 @@
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code display_config(const int &, char *[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &unique_id,
|
||||
std::string user, std::string password) {
|
||||
[[nodiscard]] inline auto
|
||||
display_config(int, char *[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &unique_id,
|
||||
std::string user, std::string password) -> exit_code {
|
||||
lock_data lock(pt, unique_id);
|
||||
const auto res = lock.grab_lock(1u);
|
||||
if (res == lock_result::success) {
|
||||
@ -40,8 +43,10 @@ static exit_code display_config(const int &, char *[], const std::string &data_d
|
||||
std::cout << cfg.dump(2) << std::endl;
|
||||
} else if (res == lock_result::locked) {
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
const auto response = client({"localhost", password, port, user}).get_config();
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
||||
data_directory);
|
||||
const auto response =
|
||||
client({"localhost", password, port, user}).get_config();
|
||||
std::cout << static_cast<int>(response.response_type) << std::endl;
|
||||
std::cout << response.data.dump(2) << std::endl;
|
||||
}
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_DRIVE_INFORMATION_HPP_
|
||||
#define INCLUDE_CLI_DRIVE_INFORMATION_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
@ -28,21 +30,25 @@
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code drive_information(const int &, char *[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &unique_id,
|
||||
std::string user, std::string password) {
|
||||
[[nodiscard]] inline auto
|
||||
drive_information(int, char *[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &unique_id,
|
||||
std::string user, std::string password) -> exit_code {
|
||||
auto ret = exit_code::success;
|
||||
|
||||
lock_data lock(pt, unique_id);
|
||||
const auto res = lock.grab_lock(1u);
|
||||
if (res == lock_result::locked) {
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
const auto response = client({"localhost", password, port, user}).get_drive_information();
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
||||
data_directory);
|
||||
const auto response =
|
||||
client({"localhost", password, port, user}).get_drive_information();
|
||||
std::cout << static_cast<int>(response.response_type) << std::endl;
|
||||
std::cout << response.data.dump(2) << std::endl;
|
||||
} else {
|
||||
std::cerr << app_config::get_provider_display_name(pt) << " is not mounted." << std::endl;
|
||||
std::cerr << app_config::get_provider_display_name(pt) << " is not mounted."
|
||||
<< std::endl;
|
||||
ret = exit_code::not_mounted;
|
||||
}
|
||||
|
||||
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_EXPORT_HPP_
|
||||
#define INCLUDE_CLI_EXPORT_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/rpc.hpp"
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code export_action(const int &argc, char *argv[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &, std::string user,
|
||||
std::string password) {
|
||||
std::string data;
|
||||
auto ret = utils::cli::parse_string_option(argc, argv,
|
||||
repertory::utils::cli::options::export_option, data);
|
||||
if (ret == exit_code::success) {
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
const auto response =
|
||||
client({"localhost", password, port, user}).export_list(utils::string::split(data, ','));
|
||||
if (response.response_type == rpc_response_type::success) {
|
||||
std::cout << response.data.dump(2) << std::endl;
|
||||
} else {
|
||||
std::cerr << response.data.dump(2) << std::endl;
|
||||
ret = exit_code::export_failed;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
} // namespace repertory::cli::actions
|
||||
|
||||
#endif // INCLUDE_CLI_EXPORT_HPP_
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_EXPORT_ALL_HPP_
|
||||
#define INCLUDE_CLI_EXPORT_ALL_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/rpc.hpp"
|
||||
#include "types/skynet.hpp"
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code export_all(const int &, char *[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &, std::string user,
|
||||
std::string password) {
|
||||
auto ret = exit_code::success;
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
const auto response = client({"localhost", password, port, user}).export_all();
|
||||
if (response.response_type == rpc_response_type::success) {
|
||||
std::cout << response.data.dump(2) << std::endl;
|
||||
} else {
|
||||
std::cerr << response.data.dump(2) << std::endl;
|
||||
ret = exit_code::export_failed;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
} // namespace repertory::cli::actions
|
||||
|
||||
#endif // INCLUDE_CLI_EXPORT_ALL_HPP_
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_GET_HPP_
|
||||
#define INCLUDE_CLI_GET_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
@ -28,26 +30,32 @@
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code get(const int &argc, char *argv[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &unique_id, std::string user,
|
||||
std::string password) {
|
||||
[[nodiscard]] inline auto get(int argc, char *argv[],
|
||||
const std::string &data_directory,
|
||||
const provider_type &pt,
|
||||
const std::string &unique_id, std::string user,
|
||||
std::string password) -> exit_code {
|
||||
std::string data;
|
||||
auto ret =
|
||||
utils::cli::parse_string_option(argc, argv, repertory::utils::cli::options::get_option, data);
|
||||
auto ret = utils::cli::parse_string_option(
|
||||
argc, argv, repertory::utils::cli::options::get_option, data);
|
||||
if (ret == exit_code::success) {
|
||||
lock_data lock(pt, unique_id);
|
||||
const auto res = lock.grab_lock(1);
|
||||
if (res == lock_result::success) {
|
||||
app_config config(pt, data_directory);
|
||||
const auto value = config.get_value_by_name(data);
|
||||
std::cout << (value.empty() ? static_cast<int>(rpc_response_type::config_value_not_found) : 0)
|
||||
std::cout << (value.empty()
|
||||
? static_cast<int>(
|
||||
rpc_response_type::config_value_not_found)
|
||||
: 0)
|
||||
<< std::endl;
|
||||
std::cout << json({{"value", value}}).dump(2) << std::endl;
|
||||
} else if (res == lock_result::locked) {
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
const auto response =
|
||||
client({"localhost", password, port, user}).get_config_value_by_name(data);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
||||
data_directory);
|
||||
const auto response = client({"localhost", password, port, user})
|
||||
.get_config_value_by_name(data);
|
||||
std::cout << static_cast<int>(response.response_type) << std::endl;
|
||||
std::cout << response.data.dump(2) << std::endl;
|
||||
}
|
||||
|
@ -1,43 +1,48 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_GET_DIRECTORY_ITEMS_HPP_
|
||||
#define INCLUDE_CLI_GET_DIRECTORY_ITEMS_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/rpc.hpp"
|
||||
#include "types/skynet.hpp"
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code get_directory_items(const int &argc, char *argv[],
|
||||
const std::string &data_directory, const provider_type &pt,
|
||||
const std::string &, std::string user, std::string password) {
|
||||
[[nodiscard]] inline auto
|
||||
get_directory_items(int argc, char *argv[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &,
|
||||
std::string user, std::string password) -> exit_code {
|
||||
std::string data;
|
||||
auto ret = utils::cli::parse_string_option(
|
||||
argc, argv, repertory::utils::cli::options::get_directory_items_option, data);
|
||||
argc, argv, repertory::utils::cli::options::get_directory_items_option,
|
||||
data);
|
||||
if (ret == exit_code::success) {
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
const auto response = client({"localhost", password, port, user}).get_directory_items(data);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
||||
data_directory);
|
||||
const auto response =
|
||||
client({"localhost", password, port, user}).get_directory_items(data);
|
||||
if (response.response_type == rpc_response_type::success) {
|
||||
std::cout << response.data.dump(2) << std::endl;
|
||||
} else {
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_GET_PINNED_FILES_HPP_
|
||||
#define INCLUDE_CLI_GET_PINNED_FILES_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
@ -27,13 +29,16 @@
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code get_pinned_files(const int &, char *[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &, std::string user,
|
||||
std::string password) {
|
||||
[[nodiscard]] inline auto
|
||||
get_pinned_files(int, char *[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &, std::string user,
|
||||
std::string password) -> exit_code {
|
||||
auto ret = exit_code::success;
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
const auto response = client({"localhost", password, port, user}).get_pinned_files();
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
||||
data_directory);
|
||||
const auto response =
|
||||
client({"localhost", password, port, user}).get_pinned_files();
|
||||
if (response.response_type == rpc_response_type::success) {
|
||||
std::cout << response.data.dump(2) << std::endl;
|
||||
} else {
|
||||
|
@ -1,105 +1,99 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_HELP_HPP_
|
||||
#define INCLUDE_CLI_HELP_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
template <typename drive> static void help(const int &argc, char *argv[]) {
|
||||
template <typename drive> inline void help(int argc, char *argv[]) {
|
||||
drive::display_options(argc, argv);
|
||||
std::cout << "Repertory options:" << std::endl;
|
||||
std::cout << " -cv,--check_version Check daemon version compatibility"
|
||||
std::cout << " -cv,--check_version Check daemon version "
|
||||
"compatibility"
|
||||
<< std::endl;
|
||||
std::cout << " -dc,--display_config Display configuration" << std::endl;
|
||||
std::cout << " -dd,--data_directory [directory] Override data directory" << std::endl;
|
||||
std::cout << " -di,--drive_information Display mounted drive information"
|
||||
std::cout << " -dc,--display_config Display configuration"
|
||||
<< std::endl;
|
||||
#if defined(REPERTORY_ENABLE_SKYNET)
|
||||
std::cout << " -ea,--export_all Export all Skynet skylinks" << std::endl;
|
||||
std::cout << " -ex,--export [path1,path2,...] Export one or more Skynet skylinks"
|
||||
std::cout << " -dd,--data_directory [directory] Override data directory"
|
||||
<< std::endl;
|
||||
std::cout << " -di,--drive_information Display mounted drive "
|
||||
"information"
|
||||
<< std::endl;
|
||||
#endif // defined(REPERTORY_ENABLE_SKYNET)
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
std::cout << " -s3,--s3 Enables S3 mode" << std::endl;
|
||||
std::cout << " -na,--name Unique name for S3 instance [Required]"
|
||||
std::cout << " -s3,--s3 Enables S3 mode"
|
||||
<< std::endl;
|
||||
std::cout << " -na,--name Unique name for S3 "
|
||||
"instance [Required]"
|
||||
<< std::endl;
|
||||
std::cout
|
||||
<< " -cd,--create_directory [API path] Create directory object in S3"
|
||||
<< std::endl;
|
||||
std::cout << " -lo,--list_objects List all S3 objects"
|
||||
<< std::endl;
|
||||
#endif // defined(REPERTORY_ENABLE_S3)
|
||||
std::cout << " -gc,--generate_config Generate initial configuration" << std::endl;
|
||||
std::cout << " -get,--get [name] Get configuration value" << std::endl;
|
||||
std::cout << " -gdi,--get_directory_items Get directory list in json format"
|
||||
std::cout
|
||||
<< " -gc,--generate_config Generate initial configuration"
|
||||
<< std::endl;
|
||||
std::cout << " -get,--get [name] Get configuration value"
|
||||
<< std::endl;
|
||||
std::cout << " -gdi,--get_directory_items Get directory list in "
|
||||
"json format"
|
||||
<< std::endl
|
||||
<< " [API path]" << std::endl;
|
||||
std::cout << " -gpf,--get_pinned_files Get a list of all pinned files" << std::endl;
|
||||
std::cout << " -gt,--generate_template Generate configuration template" << std::endl;
|
||||
#if defined(REPERTORY_ENABLE_SKYNET)
|
||||
std::cout << " -ij,--import_json [json_array] Import Skynet skylink(s)" << std::endl;
|
||||
std::cout << " [json_array] format:" << std::endl;
|
||||
std::cout << " [{" << std::endl;
|
||||
std::cout << R"( "directory": "/parent",)" << std::endl;
|
||||
std::cout << R"( "skylink": "AACeCiD6WQG6DzDcCdIu3cFPSxMUMoQPx46NYSyijNMKUA",)"
|
||||
std::cout
|
||||
<< " -gpf,--get_pinned_files Get a list of all pinned files"
|
||||
<< std::endl;
|
||||
std::cout
|
||||
<< " -nc Force disable console output"
|
||||
<< std::endl;
|
||||
std::cout
|
||||
<< " -of,--open_files List all open files and count"
|
||||
<< std::endl;
|
||||
std::cout << " -rm,--remote_mount [host/ip:port] Enables remote mount mode"
|
||||
<< std::endl;
|
||||
std::cout << R"( "token": "encryption password")" << std::endl;
|
||||
std::cout << " }]" << std::endl;
|
||||
std::cout << " NOTE: 'directory' and 'token' are optional" << std::endl;
|
||||
std::cout << " -im,--import [list] Import Skynet skylink(s)" << std::endl;
|
||||
std::cout << " [list] format:" << std::endl;
|
||||
std::cout << " directory=<directory>:skylink=<skylink>:token=<token>;..." << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << " NOTE: 'directory' and 'token' are optional" << std::endl;
|
||||
std::cout << " NOTE: Use '@sem@' to escape a ';'" << std::endl;
|
||||
std::cout << " Use '@comma@' to escape a ','" << std::endl;
|
||||
std::cout << " Use '@equal@' to escape an '='" << std::endl;
|
||||
std::cout << " Use '@dbl_quote@' to escape a '\"'" << std::endl;
|
||||
#endif // defined(REPERTORY_ENABLE_SKYNET)
|
||||
std::cout << " -nc Force disable console output" << std::endl;
|
||||
std::cout << " -of,--open_files List all open files and count" << std::endl;
|
||||
std::cout << " -rm,--remote_mount [host/ip:port] Enables remote mount mode" << std::endl;
|
||||
std::cout << " -pf,--pin_file [API path] Pin a file to cache to prevent eviction"
|
||||
std::cout << " -pf,--pin_file [API path] Pin a file to cache to "
|
||||
"prevent eviction"
|
||||
<< std::endl;
|
||||
std::cout << " -ps,--pinned_status [API path] Return pinned status for a file" << std::endl;
|
||||
std::cout << " -pw,--password Specify API password" << std::endl;
|
||||
#if defined(REPERTORY_ENABLE_SKYNET)
|
||||
std::cout << " -sk,--skynet [EXPERIMENTAL] Enables Skynet mode"
|
||||
std::cout
|
||||
<< " -ps,--pinned_status [API path] Return pinned status for a file"
|
||||
<< std::endl;
|
||||
std::cout << " -pw,--password Specify API password"
|
||||
<< std::endl;
|
||||
#endif // defined(REPERTORY_ENABLE_SKYNET)
|
||||
#ifndef _WIN32
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
std::cout << " -o s3 Enables S3 mode for 'fstab' mounts"
|
||||
std::cout << " -o s3 Enables S3 mode for "
|
||||
"'fstab' mounts"
|
||||
<< std::endl;
|
||||
#endif // defined(REPERTORY_ENABLE_S3)
|
||||
#if defined(REPERTORY_ENABLE_SKYNET)
|
||||
std::cout << " -o sk,-o skynet Enables Skynet mode for 'fstab' mounts"
|
||||
<< std::endl;
|
||||
#endif // defined(REPERTORY_ENABLE_SKYNET)
|
||||
#endif // _WIN32
|
||||
std::cout << " -set,--set [name] [value] Set configuration value" << std::endl;
|
||||
std::cout << " -status Display mount status" << std::endl;
|
||||
#if defined(REPERTORY_ENABLE_SKYNET)
|
||||
std::cout << " -tsa,--test_skynet_auth Test Skynet portal authentication"
|
||||
std::cout << " -set,--set [name] [value] Set configuration value"
|
||||
<< std::endl;
|
||||
std::cout << " [URL] [user] [password] [agent string] [API key]" << std::endl;
|
||||
#endif // defined(REPERTORY_ENABLE_SKYNET)
|
||||
std::cout << " -unmount,--unmount Unmount and shutdown" << std::endl;
|
||||
std::cout << " -uf,--unpin_file [API path] Unpin a file from cache to allow eviction"
|
||||
std::cout << " -status Display mount status"
|
||||
<< std::endl;
|
||||
std::cout << " -unmount,--unmount Unmount and shutdown"
|
||||
<< std::endl;
|
||||
std::cout << " -uf,--unpin_file [API path] Unpin a file from cache "
|
||||
"to allow eviction"
|
||||
<< std::endl;
|
||||
std::cout << " -us,--user Specify API user name"
|
||||
<< std::endl;
|
||||
std::cout << " -us,--user Specify API user name" << std::endl;
|
||||
}
|
||||
} // namespace repertory::cli::actions
|
||||
|
||||
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_IMPORT_HPP_
|
||||
#define INCLUDE_CLI_IMPORT_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/rpc.hpp"
|
||||
#include "types/skynet.hpp"
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code import(const int &argc, char *argv[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &, std::string user,
|
||||
std::string password) {
|
||||
std::string data;
|
||||
auto ret = utils::cli::parse_string_option(argc, argv,
|
||||
repertory::utils::cli::options::import_option, data);
|
||||
if (ret == exit_code::success) {
|
||||
utils::string::replace(data, "@dbl_quote@", "\"");
|
||||
const auto parts = utils::string::split(data, ';');
|
||||
skylink_import_list list;
|
||||
for (const auto &part : parts) {
|
||||
list.emplace_back(
|
||||
skylink_import::from_string(utils::string::replace_copy(part, "@sem@", ";")));
|
||||
}
|
||||
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
const auto response = client({"localhost", password, port, user}).import_skylink(list);
|
||||
std::cout << static_cast<int>(response.response_type) << std::endl;
|
||||
if (response.response_type == rpc_response_type::success) {
|
||||
std::cout << response.data.dump(2) << std::endl;
|
||||
} else {
|
||||
std::cerr << response.data.dump(2) << std::endl;
|
||||
ret = exit_code::import_failed;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
} // namespace repertory::cli::actions
|
||||
|
||||
#endif // INCLUDE_CLI_IMPORT_HPP_
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_IMPORT_JSON_HPP_
|
||||
#define INCLUDE_CLI_IMPORT_JSON_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/rpc.hpp"
|
||||
#include "types/skynet.hpp"
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code import_json(const int &argc, char *argv[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &, std::string user,
|
||||
std::string password) {
|
||||
std::string data;
|
||||
auto ret = utils::cli::parse_string_option(argc, argv, {"-ij", "--import_json"}, data);
|
||||
if (ret == exit_code::success) {
|
||||
utils::string::replace(data, "@dbl_quote@", "\"");
|
||||
|
||||
skylink_import_list list;
|
||||
try {
|
||||
const auto json_data = json::parse(data);
|
||||
for (const auto &j : json_data) {
|
||||
list.emplace_back(skylink_import::from_json(j));
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "Import JSON failed:" << std::endl << e.what() << std::endl;
|
||||
ret = exit_code::import_failed;
|
||||
}
|
||||
|
||||
if (not list.empty()) {
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
const auto response = client({"localhost", password, port, user}).import_skylink(list);
|
||||
std::cout << static_cast<int>(response.response_type) << std::endl;
|
||||
if (response.response_type == rpc_response_type::success) {
|
||||
std::cout << response.data.dump(2) << std::endl;
|
||||
} else {
|
||||
std::cerr << response.data.dump(2) << std::endl;
|
||||
ret = exit_code::import_failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
} // namespace repertory::cli::actions
|
||||
|
||||
#endif // INCLUDE_CLI_IMPORT_JSON_HPP_
|
81
include/cli/list_objects.hpp
Normal file
81
include/cli/list_objects.hpp
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_LIST_OBJECTS_HPP_
|
||||
#define INCLUDE_CLI_LIST_OBJECTS_HPP_
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "comm/s3/s3_comm.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "providers/provider.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
[[nodiscard]] inline auto
|
||||
list_objects(int /* argc */, char * /* argv */[],
|
||||
const std::string &data_directory, const provider_type &pt,
|
||||
const std::string &unique_id, std::string /* user */,
|
||||
std::string /* password */) -> exit_code {
|
||||
auto ret = exit_code::invalid_provider_type;
|
||||
|
||||
if (pt == provider_type::s3) {
|
||||
lock_data lock(pt, unique_id);
|
||||
const auto res = lock.grab_lock(1u);
|
||||
/* if (res == lock_result::locked) { */
|
||||
/* auto port = app_config::default_api_port(pt); */
|
||||
/* utils::cli::get_api_authentication_data(user, password, port, pt,
|
||||
* data_directory); */
|
||||
/* const auto response = */
|
||||
/* client({"localhost", password, port,
|
||||
* user}).create_directory(api_path); */
|
||||
/* std::cout << static_cast<int>(response.response_type) << std::endl; */
|
||||
/* std::cout << response.data.dump(2) << std::endl; */
|
||||
/* } else */
|
||||
if (res == lock_result::success) {
|
||||
app_config config(pt, data_directory);
|
||||
s3_comm comm(config);
|
||||
std::vector<directory_item> list{};
|
||||
const auto res = comm.get_object_list(list);
|
||||
if (res == api_error::success) {
|
||||
for (const auto &di : list) {
|
||||
std::cout << di.to_json().dump(2) << std::endl;
|
||||
}
|
||||
ret = exit_code::success;
|
||||
} else {
|
||||
std::cout << api_error_to_string(res) << std::endl;
|
||||
}
|
||||
} else {
|
||||
std::cout << "failed to grab lock: '" << static_cast<int>(res) << "'"
|
||||
<< std::endl;
|
||||
ret = exit_code::lock_failed;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
} // namespace repertory::cli::actions
|
||||
|
||||
#endif // REPERTORY_ENABLE_S3
|
||||
#endif // INCLUDE_CLI_LIST_OBJECTS_HPP_
|
@ -1,153 +1,173 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_MOUNT_HPP_
|
||||
#define INCLUDE_CLI_MOUNT_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "providers/provider.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/cli_utils.hpp"
|
||||
#include "utils/com_init_wrapper.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "drives/winfsp/remotewinfsp/remote_client.hpp"
|
||||
#include "drives/winfsp/remotewinfsp/remote_winfsp_drive.hpp"
|
||||
#include "drives/winfsp/winfsp_drive.hpp"
|
||||
|
||||
typedef repertory::winfsp_drive repertory_drive;
|
||||
typedef repertory::remote_winfsp::remote_client remote_client;
|
||||
typedef repertory::remote_winfsp::remote_winfsp_drive remote_drive;
|
||||
typedef repertory::remote_winfsp::i_remote_instance remote_instance;
|
||||
using repertory_drive = repertory::winfsp_drive;
|
||||
using remote_client = repertory::remote_winfsp::remote_client;
|
||||
using remote_drive = repertory::remote_winfsp::remote_winfsp_drive;
|
||||
using remote_instance = repertory::remote_winfsp::i_remote_instance;
|
||||
#else
|
||||
#include "drives/fuse/fuse_drive.hpp"
|
||||
#include "drives/fuse/remotefuse/remote_client.hpp"
|
||||
#include "drives/fuse/remotefuse/remote_fuse_drive.hpp"
|
||||
|
||||
typedef repertory::fuse_drive repertory_drive;
|
||||
typedef repertory::remote_fuse::remote_client remote_client;
|
||||
typedef repertory::remote_fuse::remote_fuse_drive remote_drive;
|
||||
typedef repertory::remote_fuse::i_remote_instance remote_instance;
|
||||
using repertory_drive = repertory::fuse_drive;
|
||||
using remote_client = repertory::remote_fuse::remote_client;
|
||||
using remote_drive = repertory::remote_fuse::remote_fuse_drive;
|
||||
using remote_instance = repertory::remote_fuse::i_remote_instance;
|
||||
#endif
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code mount(const int &argc, char *argv[], std::string data_directory, int &mount_result,
|
||||
provider_type pt, const std::string &remote_host,
|
||||
const std::uint16_t &remote_port, const std::string &unique_id) {
|
||||
[[nodiscard]] inline auto
|
||||
mount(int argc, char *argv[], std::string data_directory, int &mount_result,
|
||||
provider_type pt, const std::string &remote_host,
|
||||
std::uint16_t remote_port, const std::string &unique_id) -> exit_code {
|
||||
auto ret = exit_code::success;
|
||||
|
||||
lock_data lock(pt, unique_id);
|
||||
const auto res = lock.grab_lock();
|
||||
if (res == lock_result::locked) {
|
||||
ret = exit_code::mount_active;
|
||||
std::cerr << app_config::get_provider_display_name(pt) << " mount is already active"
|
||||
<< std::endl;
|
||||
std::cerr << app_config::get_provider_display_name(pt)
|
||||
<< " mount is already active" << std::endl;
|
||||
} else if (res == lock_result::success) {
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
{
|
||||
const auto generate_config =
|
||||
utils::cli::has_option(argc, argv, utils::cli::options::generate_config_option);
|
||||
if (generate_config) {
|
||||
app_config config(pt, data_directory);
|
||||
if (pt == provider_type::remote) {
|
||||
config.set_enable_remote_mount(false);
|
||||
config.set_is_remote_mount(true);
|
||||
const auto generate_config = utils::cli::has_option(
|
||||
argc, argv, utils::cli::options::generate_config_option);
|
||||
if (generate_config) {
|
||||
app_config config(pt, data_directory);
|
||||
if (pt == provider_type::remote) {
|
||||
config.set_enable_remote_mount(false);
|
||||
config.set_is_remote_mount(true);
|
||||
config.set_remote_host_name_or_ip(remote_host);
|
||||
config.set_remote_port(remote_port);
|
||||
config.save();
|
||||
}
|
||||
std::cout << "Generated " << app_config::get_provider_display_name(pt)
|
||||
<< " Configuration" << std::endl;
|
||||
std::cout << config.get_config_file_path() << std::endl;
|
||||
ret = utils::file::is_file(config.get_config_file_path())
|
||||
? exit_code::success
|
||||
: exit_code::file_creation_failed;
|
||||
} else {
|
||||
#ifdef _WIN32
|
||||
if (utils::cli::has_option(argc, argv,
|
||||
utils::cli::options::hidden_option)) {
|
||||
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
|
||||
}
|
||||
#endif
|
||||
const auto drive_args =
|
||||
utils::cli::parse_drive_options(argc, argv, pt, data_directory);
|
||||
app_config config(pt, data_directory);
|
||||
#ifdef _WIN32
|
||||
if (config.get_enable_mount_manager() &&
|
||||
not utils::is_process_elevated()) {
|
||||
com_init_wrapper cw;
|
||||
if (not lock.set_mount_state(true, "elevating", -1)) {
|
||||
std::cerr << "failed to set mount state" << std::endl;
|
||||
}
|
||||
lock.release();
|
||||
|
||||
mount_result = utils::run_process_elevated(argc, argv);
|
||||
lock_data lock2(pt, unique_id);
|
||||
if (lock2.grab_lock() == lock_result::success) {
|
||||
if (not lock2.set_mount_state(false, "", -1)) {
|
||||
std::cerr << "failed to set mount state" << std::endl;
|
||||
}
|
||||
lock2.release();
|
||||
}
|
||||
|
||||
return exit_code::mount_result;
|
||||
}
|
||||
#endif
|
||||
std::cout << "Initializing " << app_config::get_provider_display_name(pt)
|
||||
<< (unique_id.empty() ? ""
|
||||
: (pt == provider_type::s3)
|
||||
? " [" + unique_id + ']'
|
||||
: " [" + remote_host + ':' +
|
||||
std::to_string(remote_port) + ']')
|
||||
<< " Drive" << std::endl;
|
||||
if (pt == provider_type::remote) {
|
||||
std::uint16_t port = 0u;
|
||||
if (utils::get_next_available_port(config.get_api_port(), port)) {
|
||||
config.set_remote_host_name_or_ip(remote_host);
|
||||
config.set_remote_port(remote_port);
|
||||
}
|
||||
std::cout << "Generated " << app_config::get_provider_display_name(pt) << " Configuration"
|
||||
<< std::endl;
|
||||
std::cout << config.get_config_file_path() << std::endl;
|
||||
ret = utils::file::is_file(config.get_config_file_path()) ? exit_code::success
|
||||
: exit_code::file_creation_failed;
|
||||
} else {
|
||||
#ifdef _WIN32
|
||||
if (utils::cli::has_option(argc, argv, utils::cli::options::hidden_option)) {
|
||||
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
|
||||
}
|
||||
#endif
|
||||
const auto driveArgs = utils::cli::parse_drive_options(argc, argv, pt, data_directory);
|
||||
std::cout << "Initializing " << app_config::get_provider_display_name(pt)
|
||||
<< (unique_id.empty() ? ""
|
||||
: (pt == provider_type::s3)
|
||||
? " [" + unique_id + ']'
|
||||
: " [" + remote_host + ':' + std::to_string(remote_port) + ']')
|
||||
<< " Drive" << std::endl;
|
||||
app_config config(pt, data_directory);
|
||||
if (pt == provider_type::remote) {
|
||||
std::uint16_t port = 0u;
|
||||
if (utils::get_next_available_port(config.get_api_port(), port)) {
|
||||
config.set_remote_host_name_or_ip(remote_host);
|
||||
config.set_remote_port(remote_port);
|
||||
config.set_api_port(port);
|
||||
config.set_is_remote_mount(true);
|
||||
config.set_enable_remote_mount(false);
|
||||
config.save();
|
||||
try {
|
||||
remote_drive drive(config, lock, [&config]() -> std::unique_ptr<remote_instance> {
|
||||
return std::unique_ptr<remote_instance>(new remote_client(config));
|
||||
});
|
||||
lock.set_mount_state(true, "", -1);
|
||||
mount_result = drive.mount(driveArgs);
|
||||
ret = exit_code::mount_result;
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "FATAL: " << e.what() << std::endl;
|
||||
ret = exit_code::startup_exception;
|
||||
}
|
||||
} else {
|
||||
std::cerr << "FATAL: Unable to get available port" << std::endl;
|
||||
ret = exit_code::startup_exception;
|
||||
}
|
||||
} else {
|
||||
#ifdef _WIN32
|
||||
if (config.get_enable_mount_manager() && not utils::is_process_elevated()) {
|
||||
com_init_wrapper cw;
|
||||
lock.set_mount_state(true, "elevating", -1);
|
||||
lock.release();
|
||||
|
||||
mount_result = utils::run_process_elevated(argc, argv);
|
||||
lock_data lockData2(pt, unique_id);
|
||||
if (lockData2.grab_lock() == lock_result::success) {
|
||||
lockData2.set_mount_state(false, "", -1);
|
||||
lockData2.release();
|
||||
}
|
||||
|
||||
return exit_code::mount_result;
|
||||
}
|
||||
#endif
|
||||
config.set_is_remote_mount(false);
|
||||
|
||||
config.set_api_port(port);
|
||||
config.set_is_remote_mount(true);
|
||||
config.set_enable_remote_mount(false);
|
||||
config.save();
|
||||
try {
|
||||
auto provider = create_provider(pt, config);
|
||||
repertory_drive drive(config, lock, *provider);
|
||||
lock.set_mount_state(true, "", -1);
|
||||
mount_result = drive.mount(driveArgs);
|
||||
remote_drive drive(
|
||||
config,
|
||||
[&config]() -> std::unique_ptr<remote_instance> {
|
||||
return std::unique_ptr<remote_instance>(
|
||||
new remote_client(config));
|
||||
},
|
||||
lock);
|
||||
if (not lock.set_mount_state(true, "", -1)) {
|
||||
std::cerr << "failed to set mount state" << std::endl;
|
||||
}
|
||||
mount_result = drive.mount(drive_args);
|
||||
ret = exit_code::mount_result;
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "FATAL: " << e.what() << std::endl;
|
||||
ret = exit_code::startup_exception;
|
||||
}
|
||||
} else {
|
||||
std::cerr << "FATAL: Unable to get available port" << std::endl;
|
||||
ret = exit_code::startup_exception;
|
||||
}
|
||||
} else {
|
||||
config.set_is_remote_mount(false);
|
||||
|
||||
try {
|
||||
auto provider = create_provider(pt, config);
|
||||
repertory_drive drive(config, lock, *provider);
|
||||
if (not lock.set_mount_state(true, "", -1)) {
|
||||
std::cerr << "failed to set mount state" << std::endl;
|
||||
}
|
||||
mount_result = drive.mount(drive_args);
|
||||
ret = exit_code::mount_result;
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "FATAL: " << e.what() << std::endl;
|
||||
ret = exit_code::startup_exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
curl_global_cleanup();
|
||||
} else {
|
||||
ret = exit_code::lock_failed;
|
||||
}
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_OPEN_FILES_HPP_
|
||||
#define INCLUDE_CLI_OPEN_FILES_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
@ -28,20 +30,24 @@
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code open_files(const int &, char *[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &unique_id, std::string user,
|
||||
std::string password) {
|
||||
[[nodiscard]] inline auto
|
||||
open_files(int, char *[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &unique_id,
|
||||
std::string user, std::string password) -> exit_code {
|
||||
auto ret = exit_code::success;
|
||||
lock_data lock(pt, unique_id);
|
||||
const auto res = lock.grab_lock(1u);
|
||||
if (res == lock_result::locked) {
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
const auto response = client({"localhost", password, port, user}).get_open_files();
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
||||
data_directory);
|
||||
const auto response =
|
||||
client({"localhost", password, port, user}).get_open_files();
|
||||
std::cout << static_cast<int>(response.response_type) << std::endl;
|
||||
std::cout << response.data.dump(2) << std::endl;
|
||||
} else {
|
||||
std::cerr << app_config::get_provider_display_name(pt) << " is not mounted." << std::endl;
|
||||
std::cerr << app_config::get_provider_display_name(pt) << " is not mounted."
|
||||
<< std::endl;
|
||||
ret = exit_code::not_mounted;
|
||||
}
|
||||
|
||||
|
@ -1,43 +1,48 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_PIN_FILE_HPP_
|
||||
#define INCLUDE_CLI_PIN_FILE_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/rpc.hpp"
|
||||
#include "types/skynet.hpp"
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code pin_file(const int &argc, char *argv[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &, std::string user,
|
||||
std::string password) {
|
||||
[[nodiscard]] inline auto pin_file(int argc, char *argv[],
|
||||
const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &,
|
||||
std::string user, std::string password)
|
||||
-> exit_code {
|
||||
std::string data;
|
||||
auto ret = utils::cli::parse_string_option(argc, argv,
|
||||
repertory::utils::cli::options::pin_file_option, data);
|
||||
auto ret = utils::cli::parse_string_option(
|
||||
argc, argv, repertory::utils::cli::options::pin_file_option, data);
|
||||
if (ret == exit_code::success) {
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
const auto response = client({"localhost", password, port, user}).pin_file(data);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
||||
data_directory);
|
||||
const auto response =
|
||||
client({"localhost", password, port, user}).pin_file(data);
|
||||
if (response.response_type == rpc_response_type::success) {
|
||||
std::cout << response.data.dump(2) << std::endl;
|
||||
} else {
|
||||
|
@ -1,43 +1,48 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_PINNED_STATUS_HPP_
|
||||
#define INCLUDE_CLI_PINNED_STATUS_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/rpc.hpp"
|
||||
#include "types/skynet.hpp"
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code pinned_status(const int &argc, char *argv[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &, std::string user,
|
||||
std::string password) {
|
||||
[[nodiscard]] inline auto pinned_status(int argc, char *argv[],
|
||||
const std::string &data_directory,
|
||||
const provider_type &pt,
|
||||
const std::string &, std::string user,
|
||||
std::string password) -> exit_code {
|
||||
std::string data;
|
||||
auto ret = utils::cli::parse_string_option(
|
||||
argc, argv, repertory::utils::cli::options::pinned_status_option, data);
|
||||
if (ret == exit_code::success) {
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
const auto response = client({"localhost", password, port, user}).pinned_status(data);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
||||
data_directory);
|
||||
const auto response =
|
||||
client({"localhost", password, port, user}).pinned_status(data);
|
||||
if (response.response_type == rpc_response_type::success) {
|
||||
std::cout << response.data.dump(2) << std::endl;
|
||||
} else {
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_SET_HPP_
|
||||
#define INCLUDE_CLI_SET_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
@ -28,9 +30,11 @@
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code set(const int &argc, char *argv[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &unique_id, std::string user,
|
||||
std::string password) {
|
||||
[[nodiscard]] inline auto set(int argc, char *argv[],
|
||||
const std::string &data_directory,
|
||||
const provider_type &pt,
|
||||
const std::string &unique_id, std::string user,
|
||||
std::string password) -> exit_code {
|
||||
auto ret = exit_code::success;
|
||||
auto data = utils::cli::parse_option(argc, argv, "-set", 2u);
|
||||
if (data.empty()) {
|
||||
@ -48,20 +52,24 @@ static exit_code set(const int &argc, char *argv[], const std::string &data_dire
|
||||
const auto value = config.set_value_by_name(data[0u], data[1u]);
|
||||
const auto notFound = value.empty() && not data[1u].empty();
|
||||
ret = notFound ? exit_code::set_option_not_found : exit_code::success;
|
||||
std::cout << (notFound ? static_cast<int>(rpc_response_type::config_value_not_found) : 0)
|
||||
std::cout << (notFound ? static_cast<int>(
|
||||
rpc_response_type::config_value_not_found)
|
||||
: 0)
|
||||
<< std::endl;
|
||||
std::cout << json({{"value", value}}).dump(2) << std::endl;
|
||||
} else if (res == lock_result::locked) {
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
const auto response =
|
||||
client({"localhost", password, port, user}).set_config_value_by_name(data[0u], data[1u]);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
||||
data_directory);
|
||||
const auto response = client({"localhost", password, port, user})
|
||||
.set_config_value_by_name(data[0u], data[1u]);
|
||||
std::cout << static_cast<int>(response.response_type) << std::endl;
|
||||
std::cout << response.data.dump(2) << std::endl;
|
||||
ret = response.response_type == rpc_response_type::config_value_not_found
|
||||
? exit_code::set_option_not_found
|
||||
: response.response_type == rpc_response_type::success ? exit_code::success
|
||||
: exit_code::communication_error;
|
||||
: response.response_type == rpc_response_type::success
|
||||
? exit_code::success
|
||||
: exit_code::communication_error;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,34 +1,38 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_STATUS_HPP_
|
||||
#define INCLUDE_CLI_STATUS_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code status(const int &, char *[], const std::string &, const provider_type &pt,
|
||||
const std::string &unique_id, std::string, std::string) {
|
||||
[[nodiscard]] inline auto status(int, char *[], const std::string &,
|
||||
const provider_type &pt,
|
||||
const std::string &unique_id, std::string,
|
||||
std::string) -> exit_code {
|
||||
auto ret = exit_code::success;
|
||||
lock_data lock(pt, unique_id);
|
||||
lock.grab_lock(10u);
|
||||
[[maybe_unused]] auto status = lock.grab_lock(10u);
|
||||
json mount_state;
|
||||
if (lock.get_mount_state(mount_state)) {
|
||||
std::cout << mount_state.dump(2) << std::endl;
|
||||
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_TEST_SKYNET_AUTH_HPP_
|
||||
#define INCLUDE_CLI_TEST_SKYNET_AUTH_HPP_
|
||||
#ifdef REPERTORY_ENABLE_SKYNET
|
||||
|
||||
#include "common.hpp"
|
||||
#include "comm/curl/curl_comm.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "events/consumers/console_consumer.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/cli_utils.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/path_utils.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code test_skynet_auth(const int &argc, char *argv[], const std::string &,
|
||||
const provider_type &, const std::string &, std::string,
|
||||
std::string) {
|
||||
auto ret = exit_code::success;
|
||||
auto data = utils::cli::parse_option(argc, argv, "-tsa", 5u);
|
||||
if (data.empty()) {
|
||||
data = utils::cli::parse_option(argc, argv, "--test_skynet_auth", 5u);
|
||||
if (data.empty()) {
|
||||
ret = exit_code::invalid_syntax;
|
||||
std::cerr << "Invalid syntax for '-tsa'" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
const auto uuid = utils::create_uuid_string();
|
||||
const auto config_directory = utils::path::absolute(utils::path::combine("./", {uuid}));
|
||||
if (ret == exit_code::success) {
|
||||
utils::file::change_to_process_directory();
|
||||
{
|
||||
console_consumer c;
|
||||
event_system::instance().start();
|
||||
app_config config(provider_type::skynet, config_directory);
|
||||
|
||||
host_config hc{};
|
||||
hc.auth_url = data[0];
|
||||
hc.auth_user = data[1];
|
||||
hc.auth_password = data[2];
|
||||
hc.agent_string = data[3];
|
||||
hc.api_password = data[4];
|
||||
|
||||
curl_comm comm(config);
|
||||
std::string session;
|
||||
CURL *curl_handle = nullptr;
|
||||
ret = (comm.create_auth_session(curl_handle, config, hc, session))
|
||||
? exit_code::success
|
||||
: exit_code::communication_error;
|
||||
if (ret == exit_code::success) {
|
||||
curl_easy_cleanup(curl_handle);
|
||||
comm.release_auth_session(config, hc, session);
|
||||
}
|
||||
|
||||
event_system::instance().stop();
|
||||
}
|
||||
|
||||
if (ret == exit_code::success) {
|
||||
std::cout << std::endl << "Authentication Succeeded!" << std::endl;
|
||||
} else {
|
||||
std::cerr << std::endl << "Authentication Failed!" << std::endl;
|
||||
}
|
||||
}
|
||||
utils::file::delete_directory_recursively(config_directory);
|
||||
|
||||
return ret;
|
||||
}
|
||||
} // namespace repertory::cli::actions
|
||||
|
||||
#endif // REPERTORY_ENABLE_SKYNET
|
||||
#endif // INCLUDE_CLI_TEST_SKYNET_AUTH_HPP_
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_UNMOUNT_HPP_
|
||||
#define INCLUDE_CLI_UNMOUNT_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
@ -27,12 +29,15 @@
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code unmount(const int &, char *[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &, std::string user,
|
||||
std::string password) {
|
||||
[[nodiscard]] inline auto unmount(int, char *[],
|
||||
const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &,
|
||||
std::string user, std::string password)
|
||||
-> exit_code {
|
||||
auto ret = exit_code::success;
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
||||
data_directory);
|
||||
const auto response = client({"localhost", password, port, user}).unmount();
|
||||
std::cout << static_cast<int>(response.response_type) << std::endl;
|
||||
if (response.response_type == rpc_response_type::success) {
|
||||
|
@ -1,43 +1,48 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_UNPIN_FILE_HPP_
|
||||
#define INCLUDE_CLI_UNPIN_FILE_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "rpc/client/client.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/rpc.hpp"
|
||||
#include "types/skynet.hpp"
|
||||
#include "utils/cli_utils.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
static exit_code unpin_file(const int &argc, char *argv[], const std::string &data_directory,
|
||||
const provider_type &pt, const std::string &, std::string user,
|
||||
std::string password) {
|
||||
[[nodiscard]] inline auto unpin_file(int argc, char *argv[],
|
||||
const std::string &data_directory,
|
||||
const provider_type &pt,
|
||||
const std::string &, std::string user,
|
||||
std::string password) -> exit_code {
|
||||
std::string data;
|
||||
auto ret = utils::cli::parse_string_option(
|
||||
argc, argv, repertory::utils::cli::options::unpin_file_option, data);
|
||||
if (ret == exit_code::success) {
|
||||
auto port = app_config::default_api_port(pt);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt, data_directory);
|
||||
const auto response = client({"localhost", password, port, user}).unpin_file(data);
|
||||
utils::cli::get_api_authentication_data(user, password, port, pt,
|
||||
data_directory);
|
||||
const auto response =
|
||||
client({"localhost", password, port, user}).unpin_file(data);
|
||||
if (response.response_type == rpc_response_type::success) {
|
||||
std::cout << response.data.dump(2) << std::endl;
|
||||
} else {
|
||||
|
@ -1,30 +1,33 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_CLI_VERSION_HPP_
|
||||
#define INCLUDE_CLI_VERSION_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
namespace repertory::cli::actions {
|
||||
template <typename drive> static void version(const int &argc, char *argv[]) {
|
||||
std::cout << "Repertory core version: " << get_repertory_version() << std::endl;
|
||||
std::cout << "Repertory Git revision: " << get_repertory_git_revision() << std::endl;
|
||||
template <typename drive> inline void version(int argc, char *argv[]) {
|
||||
std::cout << "Repertory core version: " << get_repertory_version()
|
||||
<< std::endl;
|
||||
std::cout << "Repertory Git revision: " << get_repertory_git_revision()
|
||||
<< std::endl;
|
||||
drive::display_version_information(argc, argv);
|
||||
}
|
||||
} // namespace repertory::cli::actions
|
||||
|
@ -1,124 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_AWS_S3_AWS_S3_COMM_HPP_
|
||||
#define INCLUDE_COMM_AWS_S3_AWS_S3_COMM_HPP_
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
|
||||
#include "common.hpp"
|
||||
#include "comm/i_s3_comm.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
class aws_s3_comm final : public virtual i_s3_comm {
|
||||
public:
|
||||
explicit aws_s3_comm(const app_config &config);
|
||||
|
||||
~aws_s3_comm() override;
|
||||
|
||||
private:
|
||||
struct cache_entry final {
|
||||
std::chrono::system_clock::time_point expiration;
|
||||
directory_item_list items;
|
||||
|
||||
void reset_timeout(std::chrono::seconds timeout) {
|
||||
timeout = std::max(std::chrono::seconds(5u), timeout);
|
||||
expiration = std::chrono::system_clock::now() + timeout;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
const app_config &config_;
|
||||
s3_config s3_config_;
|
||||
Aws::SDKOptions sdk_options_;
|
||||
std::unique_ptr<Aws::S3::S3Client> s3_client_;
|
||||
mutable std::recursive_mutex cached_directories_mutex_;
|
||||
mutable std::unordered_map<std::string, cache_entry> cached_directories_;
|
||||
|
||||
private:
|
||||
void clear_expired_directories();
|
||||
|
||||
bool get_cached_directory_item_count(const std::string &api_path, std::size_t &count) const;
|
||||
|
||||
bool get_cached_directory_items(const std::string &api_path,
|
||||
const meta_provider_callback &meta_provider,
|
||||
directory_item_list &list) const;
|
||||
|
||||
bool get_cached_file_exists(const std::string &api_path, bool &exists) const;
|
||||
|
||||
api_error grab_directory_items(const std::string &api_path,
|
||||
const meta_provider_callback &meta_provider,
|
||||
directory_item_list &list) const;
|
||||
|
||||
api_error get_file_list(const std::string &bucket_name,
|
||||
const get_api_file_token_callback &get_api_file_token,
|
||||
const get_name_callback &get_name, api_file_list &list) const;
|
||||
|
||||
void remove_cached_directory(const std::string &api_path);
|
||||
|
||||
void set_cached_directory_items(const std::string &api_path, directory_item_list list) const;
|
||||
|
||||
public:
|
||||
api_error create_bucket(const std::string &api_path) override;
|
||||
|
||||
bool exists(const std::string &api_path, const get_key_callback &get_key) const override;
|
||||
|
||||
void get_bucket_name_and_object_name(const std::string &api_path, const get_key_callback &getKey,
|
||||
std::string &bucketName,
|
||||
std::string &objectName) const override;
|
||||
|
||||
std::size_t get_directory_item_count(const std::string &api_path,
|
||||
const meta_provider_callback &meta_provider) const override;
|
||||
|
||||
api_error get_directory_items(const std::string &api_path,
|
||||
const meta_provider_callback &meta_provider,
|
||||
directory_item_list &list) const override;
|
||||
|
||||
api_error get_file(const std::string &api_path, const get_key_callback &get_key,
|
||||
const get_name_callback &get_name, const get_token_callback &get_token,
|
||||
api_file &file) const override;
|
||||
|
||||
api_error get_file_list(const get_api_file_token_callback &get_api_file_token,
|
||||
const get_name_callback &get_name, api_file_list &list) const override;
|
||||
|
||||
s3_config get_s3_config() override { return s3_config_; }
|
||||
|
||||
s3_config get_s3_config() const override { return s3_config_; }
|
||||
|
||||
bool is_online() const override { return s3_client_->ListBuckets().IsSuccess(); }
|
||||
|
||||
api_error read_file_bytes(const std::string &api_path, const std::size_t &size,
|
||||
const std::uint64_t &offset, std::vector<char> &data,
|
||||
const get_key_callback &get_key, const get_size_callback &get_size,
|
||||
const get_token_callback &get_token,
|
||||
const bool &stop_requested) const override;
|
||||
|
||||
api_error remove_bucket(const std::string &api_path) override;
|
||||
|
||||
api_error remove_file(const std::string &api_path, const get_key_callback &get_key) override;
|
||||
|
||||
api_error rename_file(const std::string &api_path, const std::string &new_api_path) override;
|
||||
|
||||
api_error upload_file(const std::string &api_path, const std::string &source_path,
|
||||
const std::string &encryption_token, const get_key_callback &get_key,
|
||||
const set_key_callback &set_key, const bool &stop_requested) override;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_ENABLE_S3
|
||||
#endif // INCLUDE_COMM_AWS_S3_AWS_S3_COMM_HPP_
|
@ -1,269 +1,231 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_CURL_CURL_COMM_HPP_
|
||||
#define INCLUDE_COMM_CURL_CURL_COMM_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "comm/curl/multi_request.hpp"
|
||||
#include "comm/curl/session_manager.hpp"
|
||||
#include "comm/i_comm.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "comm/i_http_comm.hpp"
|
||||
#include "utils/encryption.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class curl_resolver;
|
||||
namespace utils::encryption {
|
||||
class encrypting_reader;
|
||||
}
|
||||
struct curl_setup;
|
||||
struct raw_write_data;
|
||||
|
||||
class curl_comm : public virtual i_comm {
|
||||
class curl_comm final : public i_http_comm {
|
||||
public:
|
||||
typedef size_t (*curl_read_callback)(char *, size_t, size_t, void *);
|
||||
typedef size_t (*curl_write_callback)(char *, size_t, size_t, void *);
|
||||
curl_comm() = delete;
|
||||
|
||||
static curl_read_callback read_data_callback_;
|
||||
static curl_write_callback write_data_callback_;
|
||||
static curl_write_callback write_header_callback_;
|
||||
static curl_write_callback write_null_callback_;
|
||||
static curl_write_callback write_string_callback_;
|
||||
explicit curl_comm(host_config hc);
|
||||
|
||||
public:
|
||||
explicit curl_comm(const app_config &config) : config_(config) {}
|
||||
|
||||
~curl_comm() override = default;
|
||||
explicit curl_comm(s3_config s3);
|
||||
|
||||
private:
|
||||
const app_config &config_;
|
||||
session_manager session_manager_;
|
||||
using write_callback = size_t (*)(char *, size_t, size_t, void *);
|
||||
|
||||
public:
|
||||
static std::string construct_url(CURL *curl_handle, const std::string &relative_path,
|
||||
const host_config &hc);
|
||||
struct read_write_info final {
|
||||
repertory::data_buffer data{};
|
||||
repertory::stop_type &stop_requested;
|
||||
};
|
||||
|
||||
static bool create_auth_session(CURL *&curl_handle, const app_config &config, host_config hc,
|
||||
std::string &session);
|
||||
|
||||
static std::string http_range_to_string(const http_range &range);
|
||||
|
||||
static void release_auth_session(const app_config &config, host_config hc,
|
||||
const std::string &session);
|
||||
|
||||
static void update_auth_session(CURL *curl_handle, const app_config &config,
|
||||
const std::string &session);
|
||||
static const write_callback write_data;
|
||||
static const write_callback write_headers;
|
||||
|
||||
private:
|
||||
CURL *common_curl_setup(const std::string &path, curl_setup &setup, std::string &url,
|
||||
std::string &fields);
|
||||
std::optional<host_config> host_config_;
|
||||
std::optional<s3_config> s3_config_;
|
||||
|
||||
CURL *common_curl_setup(CURL *curl_handle, const std::string &path, curl_setup &setup,
|
||||
std::string &url, std::string &fields);
|
||||
|
||||
template <typename begin, typename end>
|
||||
api_error execute_binary_operation(CURL *curl_handle, const std::string &url,
|
||||
std::vector<char> &data, json &error,
|
||||
const bool &stop_requested,
|
||||
const CURLcode &default_code = CURLE_OK) {
|
||||
auto curl_code = default_code;
|
||||
long http_code = 400;
|
||||
execute_operation<begin>(curl_handle, url, curl_code, http_code, stop_requested);
|
||||
|
||||
const auto ret = process_binary_response(url, curl_code, http_code, data, error);
|
||||
if (config_.get_event_level() >= end::level) {
|
||||
event_system::instance().raise<end>(url, curl_code, http_code,
|
||||
((ret == api_error::success) ? "" : error.dump(2)));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename begin, typename end>
|
||||
api_error execute_json_operation(CURL *curl_handle, const std::string &url,
|
||||
const std::string &result, json &data, json &error,
|
||||
const bool &stop_requested,
|
||||
const CURLcode &default_code = CURLE_OK) {
|
||||
auto curl_code = default_code;
|
||||
long http_code = 400;
|
||||
execute_operation<begin>(curl_handle, url, curl_code, http_code, stop_requested);
|
||||
|
||||
const auto ret = process_json_response(url, curl_code, http_code, result, data, error);
|
||||
if (config_.get_event_level() >= end::level) {
|
||||
event_system::instance().raise<end>(url, curl_code, http_code,
|
||||
((ret == api_error::success) ? "" : error.dump(2)));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename begin>
|
||||
void execute_operation(CURL *curl_handle, const std::string &url, CURLcode &curl_code,
|
||||
long &http_code, const bool &stop_requested) {
|
||||
if (config_.get_event_level() >= begin::level) {
|
||||
event_system::instance().raise<begin>(url);
|
||||
}
|
||||
|
||||
if (curl_code == CURLE_OK) {
|
||||
multi_request request(curl_handle, stop_requested);
|
||||
request.get_result(curl_code, http_code);
|
||||
}
|
||||
}
|
||||
|
||||
api_error get_or_post(const host_config &hc, const bool &post, const std::string &path,
|
||||
const http_parameters ¶meters, json &data, json &error,
|
||||
http_headers *headers = nullptr,
|
||||
std::function<void(CURL *curl_handle)> cb = nullptr);
|
||||
|
||||
api_error get_range(const host_config &hc, const std::string &path,
|
||||
const std::uint64_t &data_size, const http_parameters ¶meters,
|
||||
const std::string &encryption_token, std::vector<char> &data,
|
||||
const http_ranges &ranges, json &error, http_headers *headers,
|
||||
const bool &stop_requested);
|
||||
|
||||
api_error get_range_unencrypted(const host_config &hc, const std::string &path,
|
||||
const http_parameters ¶meters, std::vector<char> &data,
|
||||
const http_ranges &ranges, json &error, http_headers *headers,
|
||||
const bool &stop_requested);
|
||||
|
||||
api_error process_binary_response(const std::string &url, const CURLcode &res,
|
||||
const long &http_code, std::vector<char> data, json &error);
|
||||
|
||||
api_error process_json_response(const std::string &url, const CURLcode &res,
|
||||
const long &http_code, const std::string &result, json &data,
|
||||
json &error);
|
||||
|
||||
api_error process_response(const std::string &url, const CURLcode &res, const long &http_code,
|
||||
const std::size_t &data_size,
|
||||
const std::function<std::string()> &to_string_converter,
|
||||
const std::function<void()> &success_handler, json &error) const;
|
||||
|
||||
static std::string url_encode(CURL *curl_handle, const std::string &data,
|
||||
const bool &allow_slash = false);
|
||||
private:
|
||||
bool use_s3_path_style_{false};
|
||||
|
||||
public:
|
||||
api_error get(const std::string &path, json &data, json &error) override {
|
||||
return get_or_post(config_.get_host_config(), false, path, {}, data, error);
|
||||
[[nodiscard]] static auto construct_url(CURL *curl,
|
||||
const std::string &relative_path,
|
||||
const host_config &hc) -> std::string;
|
||||
|
||||
[[nodiscard]] static auto create_host_config(const s3_config &config,
|
||||
bool use_s3_path_style)
|
||||
-> host_config;
|
||||
|
||||
[[nodiscard]] static auto url_encode(CURL *curl, const std::string &data,
|
||||
bool allow_slash) -> std::string;
|
||||
|
||||
template <typename request_type>
|
||||
[[nodiscard]] static auto
|
||||
make_encrypted_request(const host_config &hc, const request_type &request,
|
||||
long &response_code, stop_type &stop_requested)
|
||||
-> bool {
|
||||
response_code = 0;
|
||||
|
||||
if (not request.decryption_token.has_value() ||
|
||||
request.decryption_token.value().empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (not request.range.has_value()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (not request.total_size.has_value()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
data_buffer data{};
|
||||
const auto key =
|
||||
utils::encryption::generate_key(request.decryption_token.value());
|
||||
const auto result = utils::encryption::read_encrypted_range(
|
||||
request.range.value(), key,
|
||||
[&](std::vector<char> &ct, std::uint64_t start_offset,
|
||||
std::uint64_t end_offset) -> api_error {
|
||||
auto encrypted_request = request;
|
||||
encrypted_request.decryption_token = std::nullopt;
|
||||
encrypted_request.range = {{start_offset, end_offset}};
|
||||
encrypted_request.response_handler = [&ct](const auto &encrypted_data,
|
||||
long /*response_code*/) {
|
||||
ct = encrypted_data;
|
||||
};
|
||||
encrypted_request.total_size = std::nullopt;
|
||||
|
||||
if (not make_request(hc, encrypted_request, response_code,
|
||||
stop_requested)) {
|
||||
return api_error::comm_error;
|
||||
}
|
||||
|
||||
if (response_code != 200) {
|
||||
return api_error::comm_error;
|
||||
}
|
||||
|
||||
return api_error::success;
|
||||
},
|
||||
request.total_size.value(), data);
|
||||
if (result != api_error::success) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (request.response_handler.has_value()) {
|
||||
request.response_handler.value()(data, response_code);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
api_error get(const host_config &hc, const std::string &path, json &data, json &error) override {
|
||||
return get_or_post(hc, false, path, {}, data, error);
|
||||
template <typename request_type>
|
||||
[[nodiscard]] static auto
|
||||
make_request(const host_config &hc, const request_type &request,
|
||||
long &response_code, stop_type &stop_requested) -> bool {
|
||||
if (request.decryption_token.has_value() &&
|
||||
not request.decryption_token.value().empty()) {
|
||||
return make_encrypted_request(hc, request, response_code, stop_requested);
|
||||
}
|
||||
|
||||
response_code = 0;
|
||||
|
||||
auto *curl = utils::create_curl();
|
||||
if (not request.set_method(curl, stop_requested)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (not hc.agent_string.empty()) {
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, hc.agent_string.c_str());
|
||||
}
|
||||
|
||||
if (request.allow_timeout && hc.timeout_ms) {
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, hc.timeout_ms);
|
||||
}
|
||||
|
||||
std::string range_list{};
|
||||
if (request.range.has_value()) {
|
||||
range_list = std::to_string(request.range.value().begin) + '-' +
|
||||
std::to_string(request.range.value().end);
|
||||
curl_easy_setopt(curl, CURLOPT_RANGE, range_list.c_str());
|
||||
}
|
||||
|
||||
if (request.response_headers.has_value()) {
|
||||
curl_easy_setopt(curl, CURLOPT_HEADERDATA,
|
||||
&request.response_headers.value());
|
||||
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_headers);
|
||||
}
|
||||
|
||||
read_write_info write_info{{}, stop_requested};
|
||||
if (request.response_handler.has_value()) {
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &write_info);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||
}
|
||||
|
||||
std::string parameters{};
|
||||
for (const auto &kv : request.query) {
|
||||
parameters += (parameters.empty() ? '?' : '&') + kv.first + '=' +
|
||||
url_encode(curl, kv.second, false);
|
||||
}
|
||||
|
||||
if (not hc.api_password.empty()) {
|
||||
curl_easy_setopt(curl, CURLOPT_USERNAME, hc.api_user.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_PASSWORD, hc.api_password.c_str());
|
||||
} else if (not hc.api_user.empty()) {
|
||||
curl_easy_setopt(curl, CURLOPT_USERNAME, hc.api_user.c_str());
|
||||
}
|
||||
|
||||
if (request.aws_service.has_value()) {
|
||||
curl_easy_setopt(curl, CURLOPT_AWS_SIGV4,
|
||||
request.aws_service.value().c_str());
|
||||
}
|
||||
|
||||
auto url = construct_url(curl, request.get_path(), hc) + parameters;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
|
||||
multi_request curl_request(curl, stop_requested);
|
||||
|
||||
CURLcode curl_code{};
|
||||
curl_request.get_result(curl_code, response_code);
|
||||
if (curl_code != CURLE_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (request.response_handler.has_value()) {
|
||||
request.response_handler.value()(write_info.data, response_code);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
api_error get(const std::string &path, const http_parameters ¶meters, json &data,
|
||||
json &error) override {
|
||||
return get_or_post(config_.get_host_config(), false, path, parameters, data, error);
|
||||
}
|
||||
public:
|
||||
void enable_s3_path_style(bool enable) override;
|
||||
|
||||
api_error get(const host_config &hc, const std::string &path, const http_parameters ¶meters,
|
||||
json &data, json &error) override {
|
||||
return get_or_post(hc, false, path, parameters, data, error);
|
||||
}
|
||||
[[nodiscard]] auto make_request(const curl::requests::http_delete &del,
|
||||
long &response_code,
|
||||
stop_type &stop_requested) const
|
||||
-> bool override;
|
||||
|
||||
api_error get_range(const std::string &path, const std::uint64_t &data_size,
|
||||
const http_parameters ¶meters, const std::string &encryption_token,
|
||||
std::vector<char> &data, const http_ranges &ranges, json &error,
|
||||
const bool &stop_requested) override {
|
||||
return get_range(config_.get_host_config(), path, data_size, parameters, encryption_token, data,
|
||||
ranges, error, nullptr, stop_requested);
|
||||
}
|
||||
[[nodiscard]] auto make_request(const curl::requests::http_get &get,
|
||||
long &response_code,
|
||||
stop_type &stop_requested) const
|
||||
-> bool override;
|
||||
|
||||
api_error get_range(const host_config &hc, const std::string &path,
|
||||
const std::uint64_t &data_size, const http_parameters ¶meters,
|
||||
const std::string &encryption_token, std::vector<char> &data,
|
||||
const http_ranges &ranges, json &error, const bool &stop_requested) override {
|
||||
return get_range(hc, path, data_size, parameters, encryption_token, data, ranges, error,
|
||||
nullptr, stop_requested);
|
||||
}
|
||||
[[nodiscard]] auto make_request(const curl::requests::http_head &head,
|
||||
long &response_code,
|
||||
stop_type &stop_requested) const
|
||||
-> bool override;
|
||||
|
||||
api_error get_range_and_headers(const std::string &path, const std::uint64_t &dataSize,
|
||||
const http_parameters ¶meters,
|
||||
const std::string &encryption_token, std::vector<char> &data,
|
||||
const http_ranges &ranges, json &error, http_headers &headers,
|
||||
const bool &stop_requested) override {
|
||||
return get_range(config_.get_host_config(), path, dataSize, parameters, encryption_token, data,
|
||||
ranges, error, &headers, stop_requested);
|
||||
}
|
||||
|
||||
api_error get_range_and_headers(const host_config &hc, const std::string &path,
|
||||
const std::uint64_t &dataSize, const http_parameters ¶meters,
|
||||
const std::string &encryption_token, std::vector<char> &data,
|
||||
const http_ranges &ranges, json &error, http_headers &headers,
|
||||
const bool &stop_requested) override {
|
||||
return get_range(hc, path, dataSize, parameters, encryption_token, data, ranges, error,
|
||||
&headers, stop_requested);
|
||||
}
|
||||
|
||||
api_error get_raw(const std::string &path, const http_parameters ¶meters,
|
||||
std::vector<char> &data, json &error, const bool &stop_requested) override {
|
||||
return get_raw(config_.get_host_config(), path, parameters, data, error, stop_requested);
|
||||
}
|
||||
|
||||
api_error get_raw(const host_config &hc, const std::string &path,
|
||||
const http_parameters ¶meters, std::vector<char> &data, json &error,
|
||||
const bool &stop_requested) override;
|
||||
|
||||
api_error post(const std::string &path, json &data, json &error) override {
|
||||
return get_or_post(config_.get_host_config(), true, path, {}, data, error);
|
||||
}
|
||||
|
||||
api_error post(const host_config &hc, const std::string &path, json &data, json &error) override {
|
||||
return get_or_post(hc, true, path, {}, data, error);
|
||||
}
|
||||
|
||||
api_error post(const std::string &path, const http_parameters ¶meters, json &data,
|
||||
json &error) override {
|
||||
return get_or_post(config_.get_host_config(), true, path, parameters, data, error);
|
||||
}
|
||||
|
||||
api_error post(const host_config &hc, const std::string &path, const http_parameters ¶meters,
|
||||
json &data, json &error) override {
|
||||
return get_or_post(hc, true, path, parameters, data, error);
|
||||
}
|
||||
|
||||
api_error post_file(const std::string &path, const std::string &source_path,
|
||||
const http_parameters ¶meters, json &data, json &error,
|
||||
const bool &stop_requested) override {
|
||||
return post_file(config_.get_host_config(), path, source_path, parameters, data, error,
|
||||
stop_requested);
|
||||
}
|
||||
|
||||
api_error post_file(const host_config &hc, const std::string &path,
|
||||
const std::string &source_path, const http_parameters ¶meters, json &data,
|
||||
json &error, const bool &stop_requested) override;
|
||||
|
||||
api_error post_multipart_file(const std::string &path, const std::string &file_name,
|
||||
const std::string &source_path, const std::string &encryption_token,
|
||||
json &data, json &error, const bool &stop_requested) override {
|
||||
return post_multipart_file(config_.get_host_config(), path, file_name, source_path,
|
||||
encryption_token, data, error, stop_requested);
|
||||
}
|
||||
|
||||
api_error post_multipart_file(const host_config &hc, const std::string &path,
|
||||
const std::string &file_name, const std::string &source_path,
|
||||
const std::string &encryption_token, json &data, json &error,
|
||||
const bool &stop_requested) override;
|
||||
|
||||
bool tus_upload(host_config hc, const std::string &source_path, const std::string &file_name,
|
||||
std::uint64_t file_size, const std::string &location, std::string &skylink,
|
||||
const bool &stop_requested, utils::encryption::encrypting_reader *reader);
|
||||
|
||||
bool tus_upload_create(host_config hc, const std::string &file_name,
|
||||
const std::uint64_t &file_size, std::string &location);
|
||||
[[nodiscard]] auto make_request(const curl::requests::http_put_file &put_file,
|
||||
long &response_code,
|
||||
stop_type &stop_requested) const
|
||||
-> bool override;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_CURL_CURL_RESOLVER_HPP_
|
||||
#define INCLUDE_COMM_CURL_CURL_RESOLVER_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class curl_resolver final {
|
||||
public:
|
||||
curl_resolver() = delete;
|
||||
curl_resolver(const curl_resolver &) noexcept = delete;
|
||||
curl_resolver(curl_resolver &&) noexcept = delete;
|
||||
curl_resolver &operator=(const curl_resolver &) noexcept = delete;
|
||||
curl_resolver &operator=(curl_resolver &&) noexcept = delete;
|
||||
|
||||
public:
|
||||
curl_resolver(CURL *handle, std::vector<std::string> items, const bool &ignore_root = false);
|
||||
|
||||
~curl_resolver();
|
||||
|
||||
private:
|
||||
std::vector<std::string> items_;
|
||||
|
||||
struct curl_slist *host_list_ = nullptr;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_COMM_CURL_CURL_RESOLVER_HPP_
|
@ -1,36 +1,39 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_CURL_MULTI_REQUEST_HPP_
|
||||
#define INCLUDE_COMM_CURL_MULTI_REQUEST_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class multi_request final {
|
||||
public:
|
||||
multi_request(CURL *curl_handle, const bool &stop_requested);
|
||||
multi_request(CURL *curl_handle, stop_type &stop_requested);
|
||||
|
||||
~multi_request();
|
||||
|
||||
private:
|
||||
CURL *curl_handle_;
|
||||
const bool &stop_requested_;
|
||||
stop_type &stop_requested_;
|
||||
CURLM *multi_handle_;
|
||||
|
||||
public:
|
||||
|
40
include/comm/curl/requests/http_delete.hpp
Normal file
40
include/comm/curl/requests/http_delete.hpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_DELETE_HPP_
|
||||
#define INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_DELETE_HPP_
|
||||
|
||||
#include "comm/curl/requests/http_request_base.hpp"
|
||||
|
||||
namespace repertory::curl::requests {
|
||||
struct http_delete final : http_request_base {
|
||||
~http_delete() override = default;
|
||||
|
||||
[[nodiscard]] auto set_method(CURL *curl,
|
||||
stop_type & /* stop_requested */) const
|
||||
-> bool override {
|
||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
} // namespace repertory::curl::requests
|
||||
|
||||
#endif // INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_DELETE_HPP_
|
40
include/comm/curl/requests/http_get.hpp
Normal file
40
include/comm/curl/requests/http_get.hpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_GET_HPP_
|
||||
#define INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_GET_HPP_
|
||||
|
||||
#include "comm/curl/requests/http_request_base.hpp"
|
||||
|
||||
namespace repertory::curl::requests {
|
||||
struct http_get final : http_request_base {
|
||||
~http_get() override = default;
|
||||
|
||||
[[nodiscard]] auto set_method(CURL *curl,
|
||||
stop_type & /*stop_requested*/) const
|
||||
-> bool override {
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
} // namespace repertory::curl::requests
|
||||
|
||||
#endif // INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_GET_HPP_
|
41
include/comm/curl/requests/http_head.hpp
Normal file
41
include/comm/curl/requests/http_head.hpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_HEAD_HPP_
|
||||
#define INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_HEAD_HPP_
|
||||
|
||||
#include "comm/curl/requests/http_request_base.hpp"
|
||||
|
||||
namespace repertory::curl::requests {
|
||||
struct http_head final : http_request_base {
|
||||
~http_head() override = default;
|
||||
|
||||
[[nodiscard]] auto set_method(CURL *curl,
|
||||
stop_type & /* stop_requested */) const
|
||||
-> bool override {
|
||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "HEAD");
|
||||
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
} // namespace repertory::curl::requests
|
||||
|
||||
#endif // INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_HEAD_HPP_
|
47
include/comm/curl/requests/http_put_file.hpp
Normal file
47
include/comm/curl/requests/http_put_file.hpp
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_PUT_FILE_HPP_
|
||||
#define INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_PUT_FILE_HPP_
|
||||
|
||||
#include "comm/curl/requests/http_request_base.hpp"
|
||||
#include "utils/encrypting_reader.hpp"
|
||||
|
||||
namespace repertory::curl::requests {
|
||||
struct http_put_file final : http_request_base {
|
||||
~http_put_file() override = default;
|
||||
|
||||
std::optional<std::string> encryption_token{};
|
||||
std::string file_name{};
|
||||
mutable std::shared_ptr<utils::encryption::encrypting_reader> reader{};
|
||||
std::string source_path{};
|
||||
|
||||
[[nodiscard]] auto get_path() const -> std::string override;
|
||||
|
||||
[[nodiscard]] auto set_method(CURL *curl, stop_type &stop_requested) const
|
||||
-> bool override;
|
||||
|
||||
private:
|
||||
mutable std::shared_ptr<read_file_info> read_info{};
|
||||
};
|
||||
} // namespace repertory::curl::requests
|
||||
|
||||
#endif // INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_PUT_FILE_HPP_
|
74
include/comm/curl/requests/http_request_base.hpp
Normal file
74
include/comm/curl/requests/http_request_base.hpp
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_REQUEST_BASE_HPP_
|
||||
#define INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_REQUEST_BASE_HPP_
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/native_file.hpp"
|
||||
|
||||
namespace repertory::curl::requests {
|
||||
using read_callback = size_t (*)(char *, size_t, size_t, void *);
|
||||
|
||||
using response_callback =
|
||||
std::function<void(const data_buffer &data, long response_code)>;
|
||||
|
||||
struct read_file_info final {
|
||||
stop_type &stop_requested;
|
||||
native_file::native_file_ptr nf{};
|
||||
std::uint64_t offset{};
|
||||
};
|
||||
|
||||
inline const auto read_file_data = static_cast<read_callback>(
|
||||
[](char *buffer, size_t size, size_t nitems, void *instream) -> size_t {
|
||||
auto *rd = reinterpret_cast<read_file_info *>(instream);
|
||||
std::size_t bytes_read{};
|
||||
auto ret =
|
||||
rd->nf->read_bytes(buffer, size * nitems, rd->offset, bytes_read);
|
||||
if (ret) {
|
||||
rd->offset += bytes_read;
|
||||
}
|
||||
return ret && not rd->stop_requested ? bytes_read : CURL_READFUNC_ABORT;
|
||||
});
|
||||
|
||||
struct http_request_base {
|
||||
virtual ~http_request_base() = default;
|
||||
|
||||
bool allow_timeout{};
|
||||
std::optional<std::string> aws_service;
|
||||
std::optional<std::string> decryption_token{};
|
||||
http_headers headers{};
|
||||
std::string path{};
|
||||
query_parameters query{};
|
||||
std::optional<http_range> range{};
|
||||
std::optional<response_callback> response_handler;
|
||||
std::optional<http_headers> response_headers;
|
||||
std::optional<std::uint64_t> total_size{};
|
||||
|
||||
[[nodiscard]] virtual auto get_path() const -> std::string { return path; }
|
||||
|
||||
[[nodiscard]] virtual auto set_method(CURL *curl,
|
||||
stop_type &stop_requested) const
|
||||
-> bool = 0;
|
||||
};
|
||||
} // namespace repertory::curl::requests
|
||||
|
||||
#endif // INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_REQUEST_BASE_HPP_
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_CURL_SESSION_MANAGER_HPP_
|
||||
#define INCLUDE_COMM_CURL_SESSION_MANAGER_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
class session_manager final {
|
||||
private:
|
||||
std::string session_;
|
||||
std::uint64_t session_count_ = 0u;
|
||||
std::mutex session_mutex_;
|
||||
|
||||
public:
|
||||
bool create_auth_session(CURL *&curl_handle, const app_config &config, host_config hc,
|
||||
std::string &session);
|
||||
|
||||
void release_auth_session(const app_config &config, host_config hc, const std::string &session);
|
||||
|
||||
void update_auth_session(CURL *curl_handle, const app_config &config, const host_config &hc);
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_COMM_CURL_SESSION_MANAGER_HPP_
|
@ -1,107 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_I_COMM_HPP_
|
||||
#define INCLUDE_COMM_I_COMM_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_comm {
|
||||
INTERFACE_SETUP(i_comm);
|
||||
|
||||
public:
|
||||
virtual api_error get(const std::string &path, json &data, json &error) = 0;
|
||||
|
||||
virtual api_error get(const host_config &hc, const std::string &path, json &data,
|
||||
json &error) = 0;
|
||||
|
||||
virtual api_error get(const std::string &path, const http_parameters ¶meters, json &data,
|
||||
json &error) = 0;
|
||||
|
||||
virtual api_error get(const host_config &hc, const std::string &path,
|
||||
const http_parameters ¶meters, json &data, json &error) = 0;
|
||||
|
||||
virtual api_error get_range(const std::string &path, const std::uint64_t &data_size,
|
||||
const http_parameters ¶meters,
|
||||
const std::string &encryption_token, std::vector<char> &data,
|
||||
const http_ranges &ranges, json &error,
|
||||
const bool &stop_requested) = 0;
|
||||
|
||||
virtual api_error get_range(const host_config &hc, const std::string &path,
|
||||
const std::uint64_t &data_size, const http_parameters ¶meters,
|
||||
const std::string &encryption_token, std::vector<char> &data,
|
||||
const http_ranges &ranges, json &error,
|
||||
const bool &stop_requested) = 0;
|
||||
|
||||
virtual api_error get_range_and_headers(const std::string &path, const std::uint64_t &data_size,
|
||||
const http_parameters ¶meters,
|
||||
const std::string &encryption_token,
|
||||
std::vector<char> &data, const http_ranges &ranges,
|
||||
json &error, http_headers &headers,
|
||||
const bool &stop_requested) = 0;
|
||||
|
||||
virtual api_error get_range_and_headers(const host_config &hc, const std::string &path,
|
||||
const std::uint64_t &data_size,
|
||||
const http_parameters ¶meters,
|
||||
const std::string &encryption_token,
|
||||
std::vector<char> &data, const http_ranges &ranges,
|
||||
json &error, http_headers &headers,
|
||||
const bool &stop_requested) = 0;
|
||||
|
||||
virtual api_error get_raw(const std::string &path, const http_parameters ¶meters,
|
||||
std::vector<char> &data, json &error, const bool &stop_requested) = 0;
|
||||
|
||||
virtual api_error get_raw(const host_config &hc, const std::string &path,
|
||||
const http_parameters ¶meters, std::vector<char> &data, json &error,
|
||||
const bool &stop_requested) = 0;
|
||||
|
||||
virtual api_error post(const std::string &path, json &data, json &error) = 0;
|
||||
|
||||
virtual api_error post(const host_config &hc, const std::string &path, json &data,
|
||||
json &error) = 0;
|
||||
|
||||
virtual api_error post(const std::string &path, const http_parameters ¶meters, json &data,
|
||||
json &error) = 0;
|
||||
|
||||
virtual api_error post(const host_config &hc, const std::string &path,
|
||||
const http_parameters ¶meters, json &data, json &error) = 0;
|
||||
|
||||
virtual api_error post_file(const std::string &path, const std::string &sourcePath,
|
||||
const http_parameters ¶meters, json &data, json &error,
|
||||
const bool &stop_requested) = 0;
|
||||
|
||||
virtual api_error post_file(const host_config &hc, const std::string &path,
|
||||
const std::string &sourcePath, const http_parameters ¶meters,
|
||||
json &data, json &error, const bool &stop_requested) = 0;
|
||||
|
||||
virtual api_error post_multipart_file(const std::string &path, const std::string &file_name,
|
||||
const std::string &source_path,
|
||||
const std::string &encryption_token, json &data,
|
||||
json &error, const bool &stop_requested) = 0;
|
||||
|
||||
virtual api_error post_multipart_file(const host_config &hc, const std::string &path,
|
||||
const std::string &file_name,
|
||||
const std::string &source_path,
|
||||
const std::string &encryption_token, json &data,
|
||||
json &error, const bool &stop_requested) = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_COMM_I_COMM_HPP_
|
59
include/comm/i_http_comm.hpp
Normal file
59
include/comm/i_http_comm.hpp
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_I_HTTP_COMM_HPP_
|
||||
#define INCLUDE_COMM_I_HTTP_COMM_HPP_
|
||||
|
||||
#include "comm/curl/requests/http_delete.hpp"
|
||||
#include "comm/curl/requests/http_get.hpp"
|
||||
#include "comm/curl/requests/http_head.hpp"
|
||||
#include "comm/curl/requests/http_put_file.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
struct i_http_comm {
|
||||
INTERFACE_SETUP(i_http_comm);
|
||||
|
||||
public:
|
||||
virtual void enable_s3_path_style(bool enable) = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
make_request(const curl::requests::http_delete &del, long &response_code,
|
||||
stop_type &stop_requested) const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto make_request(const curl::requests::http_get &get,
|
||||
long &response_code,
|
||||
stop_type &stop_requested) const
|
||||
-> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto make_request(const curl::requests::http_head &head,
|
||||
long &response_code,
|
||||
stop_type &stop_requested) const
|
||||
-> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
make_request(const curl::requests::http_put_file &put_file,
|
||||
long &response_code, stop_type &stop_requested) const
|
||||
-> bool = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_COMM_I_HTTP_COMM_HPP_
|
@ -1,90 +1,107 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_I_S3_COMM_HPP_
|
||||
#define INCLUDE_COMM_I_S3_COMM_HPP_
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/s3.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_provider;
|
||||
|
||||
class i_s3_comm {
|
||||
INTERFACE_SETUP(i_s3_comm);
|
||||
|
||||
public:
|
||||
typedef std::function<std::string(const std::string &api_path)> get_api_file_token_callback;
|
||||
typedef std::function<std::string()> get_key_callback;
|
||||
typedef std::function<std::string(const std::string &key, const std::string &object_name)>
|
||||
get_name_callback;
|
||||
typedef std::function<std::uint64_t()> get_size_callback;
|
||||
typedef std::function<std::string()> get_token_callback;
|
||||
typedef std::function<api_error(const std::string &key)> set_key_callback;
|
||||
[[nodiscard]] virtual auto create_directory(const std::string &api_path)
|
||||
-> api_error = 0;
|
||||
|
||||
public:
|
||||
virtual api_error create_bucket(const std::string &api_path) = 0;
|
||||
[[nodiscard]] virtual auto directory_exists(const std::string &api_path) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual bool exists(const std::string &api_path, const get_key_callback &get_key) const = 0;
|
||||
[[nodiscard]] virtual auto file_exists(const std::string &api_path,
|
||||
const get_key_callback &get_key) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual void get_bucket_name_and_object_name(const std::string &api_path,
|
||||
const get_key_callback &get_key,
|
||||
std::string &bucket_name,
|
||||
std::string &object_name) const = 0;
|
||||
|
||||
virtual std::size_t
|
||||
[[nodiscard]] virtual auto
|
||||
get_directory_item_count(const std::string &api_path,
|
||||
const meta_provider_callback &meta_provider) const = 0;
|
||||
meta_provider_callback meta_provider) const
|
||||
-> std::size_t = 0;
|
||||
|
||||
virtual api_error get_directory_items(const std::string &api_path,
|
||||
const meta_provider_callback &meta_provider,
|
||||
directory_item_list &list) const = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_directory_items(const std::string &api_path,
|
||||
meta_provider_callback meta_provider,
|
||||
directory_item_list &list) const -> api_error = 0;
|
||||
|
||||
virtual s3_config get_s3_config() = 0;
|
||||
[[nodiscard]] virtual auto get_directory_list(api_file_list &list) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual s3_config get_s3_config() const = 0;
|
||||
[[nodiscard]] virtual auto get_file(const std::string &api_path,
|
||||
const get_key_callback &get_key,
|
||||
const get_name_callback &get_name,
|
||||
const get_token_callback &get_token,
|
||||
api_file &file) const -> api_error = 0;
|
||||
|
||||
virtual api_error get_file(const std::string &api_path, const get_key_callback &get_key,
|
||||
const get_name_callback &get_name, const get_token_callback &get_token,
|
||||
api_file &file) const = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_file_list(const get_api_file_token_callback &get_api_file_token,
|
||||
const get_name_callback &get_name, api_file_list &list) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual api_error get_file_list(const get_api_file_token_callback &get_api_file_token,
|
||||
const get_name_callback &get_name, api_file_list &list) const = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_object_list(std::vector<directory_item> &list) const -> api_error = 0;
|
||||
|
||||
virtual bool is_online() const = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_object_name(const std::string &api_path,
|
||||
const get_key_callback &get_key) const -> std::string = 0;
|
||||
|
||||
virtual api_error read_file_bytes(const std::string &api_path, const std::size_t &size,
|
||||
const std::uint64_t &offset, std::vector<char> &data,
|
||||
const get_key_callback &get_key,
|
||||
const get_size_callback &get_size,
|
||||
const get_token_callback &get_token,
|
||||
const bool &stop_requested) const = 0;
|
||||
[[nodiscard]] virtual auto get_s3_config() -> s3_config = 0;
|
||||
|
||||
virtual api_error remove_file(const std::string &api_path, const get_key_callback &get_key) = 0;
|
||||
[[nodiscard]] virtual auto get_s3_config() const -> s3_config = 0;
|
||||
|
||||
virtual api_error remove_bucket(const std::string &api_path) = 0;
|
||||
[[nodiscard]] virtual auto is_online() const -> bool = 0;
|
||||
|
||||
virtual api_error rename_file(const std::string &api_path, const std::string &new_api_path) = 0;
|
||||
[[nodiscard]] virtual auto read_file_bytes(
|
||||
const std::string &api_path, std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data, const get_key_callback &get_key,
|
||||
const get_size_callback &get_size, const get_token_callback &get_token,
|
||||
stop_type &stop_requested) const -> api_error = 0;
|
||||
|
||||
virtual api_error upload_file(const std::string &api_path, const std::string &source_path,
|
||||
const std::string &encryption_token,
|
||||
const get_key_callback &get_key, const set_key_callback &set_key,
|
||||
const bool &stop_requested) = 0;
|
||||
[[nodiscard]] virtual auto remove_directory(const std::string &api_path)
|
||||
-> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto remove_file(const std::string &api_path,
|
||||
const get_key_callback &get_key)
|
||||
-> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto rename_file(const std::string &api_path,
|
||||
const std::string &new_api_path)
|
||||
-> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
upload_file(const std::string &api_path, const std::string &source_path,
|
||||
const std::string &encryption_token,
|
||||
const get_key_callback &get_key, const set_key_callback &set_key,
|
||||
stop_type &stop_requested) -> api_error = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -1,40 +1,45 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_PACKET_CLIENT_POOL_HPP_
|
||||
#define INCLUDE_COMM_PACKET_CLIENT_POOL_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "comm/packet/packet.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class client_pool final {
|
||||
public:
|
||||
typedef std::function<packet::error_type()> worker_callback;
|
||||
typedef std::function<void(const packet::error_type &result)> worker_complete_callback;
|
||||
using worker_callback = std::function<packet::error_type()>;
|
||||
using worker_complete_callback =
|
||||
std::function<void(const packet::error_type &)>;
|
||||
|
||||
private:
|
||||
class pool final {
|
||||
private:
|
||||
struct work_item final {
|
||||
work_item(const worker_callback &worker, const worker_complete_callback &worker_complete)
|
||||
: work(worker), work_complete(worker_complete) {}
|
||||
work_item(worker_callback worker,
|
||||
worker_complete_callback worker_complete)
|
||||
: work(std::move(worker)),
|
||||
work_complete(std::move(worker_complete)) {}
|
||||
|
||||
worker_callback work;
|
||||
worker_complete_callback work_complete;
|
||||
@ -47,7 +52,7 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
explicit pool(const std::uint8_t &pool_size);
|
||||
explicit pool(std::uint8_t pool_size);
|
||||
|
||||
~pool() { shutdown(); }
|
||||
|
||||
@ -58,14 +63,14 @@ private:
|
||||
std::atomic<std::uint8_t> thread_index_;
|
||||
|
||||
public:
|
||||
void execute(const std::uint64_t &thread_id, const worker_callback &worker,
|
||||
void execute(std::uint64_t thread_id, const worker_callback &worker,
|
||||
const worker_complete_callback &worker_complete);
|
||||
|
||||
void shutdown();
|
||||
};
|
||||
|
||||
public:
|
||||
explicit client_pool(const std::uint8_t &pool_size = 10u)
|
||||
explicit client_pool(std::uint8_t pool_size = 10u)
|
||||
: pool_size_(pool_size ? pool_size : 10u) {}
|
||||
|
||||
~client_pool() { shutdown(); }
|
||||
@ -77,8 +82,9 @@ private:
|
||||
bool shutdown_ = false;
|
||||
|
||||
public:
|
||||
void execute(const std::string &client_id, const std::uint64_t &thread_id,
|
||||
const worker_callback &worker, const worker_complete_callback &worker_complete);
|
||||
void execute(const std::string &client_id, std::uint64_t thread_id,
|
||||
const worker_callback &worker,
|
||||
const worker_complete_callback &worker_complete);
|
||||
|
||||
void remove_client(const std::string &client_id);
|
||||
|
||||
|
@ -1,110 +1,116 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_PACKET_PACKET_HPP_
|
||||
#define INCLUDE_COMM_PACKET_PACKET_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/remote.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
#define DECODE_OR_RETURN(p, value) \
|
||||
if ((ret = (p)->decode(value)) != 0) \
|
||||
#define DECODE_OR_RETURN(p, value) \
|
||||
if ((ret = (p)->decode(value)) != 0) \
|
||||
return ret
|
||||
#define DECODE_OR_IGNORE(p, value) \
|
||||
if (ret == 0) \
|
||||
#define DECODE_OR_IGNORE(p, value) \
|
||||
if (ret == 0) \
|
||||
ret = (p)->decode(value)
|
||||
|
||||
class packet final {
|
||||
public:
|
||||
typedef std::int32_t error_type;
|
||||
using error_type = std::int32_t;
|
||||
|
||||
public:
|
||||
packet() = default;
|
||||
|
||||
explicit packet(std::vector<char> buffer) : buffer_(std::move(buffer)) {}
|
||||
explicit packet(data_buffer buffer) : buffer_(std::move(buffer)) {}
|
||||
|
||||
explicit packet(std::vector<char> &&buffer) : buffer_(std::move(buffer)) {}
|
||||
explicit packet(data_buffer &&buffer) : buffer_(std::move(buffer)) {}
|
||||
|
||||
packet(const packet &p) noexcept : buffer_(p.buffer_), decode_offset_(p.decode_offset_) {}
|
||||
packet(const packet &p) noexcept = default;
|
||||
|
||||
packet(packet &&p) noexcept : buffer_(std::move(p.buffer_)), decode_offset_(p.decode_offset_) {}
|
||||
packet(packet &&p) noexcept
|
||||
: buffer_(std::move(p.buffer_)), decode_offset_(p.decode_offset_) {}
|
||||
|
||||
private:
|
||||
std::vector<char> buffer_;
|
||||
data_buffer buffer_;
|
||||
std::size_t decode_offset_ = 0u;
|
||||
|
||||
public:
|
||||
static int decode_json(packet &response, json &json_data);
|
||||
[[nodiscard]] static auto decode_json(packet &response, json &json_data)
|
||||
-> int;
|
||||
|
||||
public:
|
||||
void clear();
|
||||
|
||||
char *current_pointer() {
|
||||
return (decode_offset_ < buffer_.size()) ? &buffer_[decode_offset_] : nullptr;
|
||||
[[nodiscard]] auto current_pointer() -> char * {
|
||||
return (decode_offset_ < buffer_.size()) ? &buffer_[decode_offset_]
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
const char *current_pointer() const {
|
||||
return (decode_offset_ < buffer_.size()) ? &buffer_[decode_offset_] : nullptr;
|
||||
[[nodiscard]] auto current_pointer() const -> const char * {
|
||||
return (decode_offset_ < buffer_.size()) ? &buffer_[decode_offset_]
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
error_type decode(std::string &data);
|
||||
[[nodiscard]] auto decode(std::string &data) -> error_type;
|
||||
|
||||
error_type decode(std::wstring &data);
|
||||
[[nodiscard]] auto decode(std::wstring &data) -> error_type;
|
||||
|
||||
error_type decode(void *buffer, const size_t &size);
|
||||
[[nodiscard]] auto decode(void *buffer, std::size_t size) -> error_type;
|
||||
|
||||
error_type decode(void *&ptr);
|
||||
[[nodiscard]] auto decode(void *&ptr) -> error_type;
|
||||
|
||||
error_type decode(std::int8_t &i);
|
||||
[[nodiscard]] auto decode(std::int8_t &i) -> error_type;
|
||||
|
||||
error_type decode(std::uint8_t &i);
|
||||
[[nodiscard]] auto decode(std::uint8_t &i) -> error_type;
|
||||
|
||||
error_type decode(std::int16_t &i);
|
||||
[[nodiscard]] auto decode(std::int16_t &i) -> error_type;
|
||||
|
||||
error_type decode(std::uint16_t &i);
|
||||
[[nodiscard]] auto decode(std::uint16_t &i) -> error_type;
|
||||
|
||||
error_type decode(std::int32_t &i);
|
||||
[[nodiscard]] auto decode(std::int32_t &i) -> error_type;
|
||||
|
||||
error_type decode(std::uint32_t &i);
|
||||
[[nodiscard]] auto decode(std::uint32_t &i) -> error_type;
|
||||
|
||||
error_type decode(std::int64_t &i);
|
||||
[[nodiscard]] auto decode(std::int64_t &i) -> error_type;
|
||||
|
||||
error_type decode(std::uint64_t &i);
|
||||
[[nodiscard]] auto decode(std::uint64_t &i) -> error_type;
|
||||
|
||||
error_type decode(remote::open_flags &i) {
|
||||
[[nodiscard]] auto decode(remote::open_flags &i) -> error_type {
|
||||
return decode(reinterpret_cast<std::uint32_t &>(i));
|
||||
}
|
||||
|
||||
error_type decode(remote::setattr_x &i);
|
||||
[[nodiscard]] auto decode(remote::setattr_x &i) -> error_type;
|
||||
|
||||
error_type decode(remote::stat &i);
|
||||
[[nodiscard]] auto decode(remote::stat &i) -> error_type;
|
||||
|
||||
error_type decode(remote::statfs &i);
|
||||
[[nodiscard]] auto decode(remote::statfs &i) -> error_type;
|
||||
|
||||
error_type decode(remote::statfs_x &i);
|
||||
[[nodiscard]] auto decode(remote::statfs_x &i) -> error_type;
|
||||
|
||||
error_type decode(remote::file_info &i);
|
||||
[[nodiscard]] auto decode(remote::file_info &i) -> error_type;
|
||||
|
||||
error_type decrypt(const std::string &token);
|
||||
[[nodiscard]] auto decrypt(const std::string &token) -> error_type;
|
||||
|
||||
void encode(const void *buffer, const std::size_t &size, bool should_reserve = true);
|
||||
void encode(const void *buffer, std::size_t size, bool should_reserve = true);
|
||||
|
||||
void encode(char *str) { encode(std::string(str ? str : "")); }
|
||||
|
||||
@ -150,14 +156,16 @@ public:
|
||||
|
||||
void encode(remote::file_info i);
|
||||
|
||||
void encode_top(const void *buffer, const std::size_t &size, bool should_reserve = true);
|
||||
void encode_top(const void *buffer, std::size_t size,
|
||||
bool should_reserve = true);
|
||||
|
||||
void encode_top(const std::string &str);
|
||||
|
||||
void encode_top(const std::wstring &str);
|
||||
|
||||
void encode_top(void *ptr) {
|
||||
encode_top(static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(ptr)));
|
||||
encode_top(
|
||||
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(ptr)));
|
||||
}
|
||||
|
||||
void encode_top(std::int8_t i);
|
||||
@ -176,7 +184,9 @@ public:
|
||||
|
||||
void encode_top(std::uint64_t i);
|
||||
|
||||
void encode_top(remote::open_flags i) { encode_top(static_cast<std::uint32_t>(i)); }
|
||||
void encode_top(remote::open_flags i) {
|
||||
encode_top(static_cast<std::uint32_t>(i));
|
||||
}
|
||||
|
||||
void encode_top(remote::setattr_x i);
|
||||
|
||||
@ -190,24 +200,31 @@ public:
|
||||
|
||||
void encrypt(const std::string &token);
|
||||
|
||||
std::uint32_t get_size() const { return static_cast<std::uint32_t>(buffer_.size()); }
|
||||
[[nodiscard]] auto get_size() const -> std::uint32_t {
|
||||
return static_cast<std::uint32_t>(buffer_.size());
|
||||
}
|
||||
|
||||
void transfer_into(std::vector<char> &buffer);
|
||||
void transfer_into(data_buffer &buffer);
|
||||
|
||||
public:
|
||||
packet &operator=(const std::vector<char> &buffer) noexcept;
|
||||
auto operator=(const data_buffer &buffer) noexcept -> packet &;
|
||||
|
||||
packet &operator=(std::vector<char> &&buffer) noexcept;
|
||||
auto operator=(data_buffer &&buffer) noexcept -> packet &;
|
||||
|
||||
packet &operator=(const packet &p) noexcept;
|
||||
auto operator=(const packet &p) noexcept -> packet &;
|
||||
|
||||
packet &operator=(packet &&p) noexcept;
|
||||
auto operator=(packet &&p) noexcept -> packet &;
|
||||
|
||||
char &operator[](const size_t &index) { return buffer_[index]; }
|
||||
[[nodiscard]] auto operator[](std::size_t index) -> char & {
|
||||
return buffer_[index];
|
||||
}
|
||||
|
||||
const char &operator[](const size_t &index) const { return buffer_.at(index); }
|
||||
[[nodiscard]] auto operator[](std::size_t index) const -> const char & {
|
||||
return buffer_.at(index);
|
||||
}
|
||||
};
|
||||
typedef packet packet;
|
||||
|
||||
using packet = packet;
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_COMM_PACKET_PACKET_HPP_
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_PACKET_PACKET_CLIENT_HPP_
|
||||
#define INCLUDE_COMM_PACKET_PACKET_CLIENT_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "comm/packet/packet.hpp"
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
@ -27,17 +29,17 @@ using boost::asio::ip::tcp;
|
||||
namespace repertory {
|
||||
class packet_client final {
|
||||
private:
|
||||
struct client {
|
||||
client(boost::asio::io_context &ctx) : nonce(""), socket(ctx) {}
|
||||
struct client final {
|
||||
explicit client(boost::asio::io_context &ctx) : nonce(""), socket(ctx) {}
|
||||
|
||||
std::string nonce;
|
||||
tcp::socket socket;
|
||||
};
|
||||
|
||||
public:
|
||||
packet_client(std::string host_name_or_ip, const std::uint8_t &max_connections,
|
||||
const std::uint16_t &port, const std::uint16_t &receive_timeout,
|
||||
const std::uint16_t &send_timeout, std::string encryption_token);
|
||||
packet_client(std::string host_name_or_ip, std::uint8_t max_connections,
|
||||
std::uint16_t port, std::uint16_t receive_timeout,
|
||||
std::uint16_t send_timeout, std::string encryption_token);
|
||||
|
||||
~packet_client();
|
||||
|
||||
@ -52,7 +54,8 @@ private:
|
||||
std::string unique_id_;
|
||||
|
||||
bool allow_connections_ = true;
|
||||
boost::asio::ip::basic_resolver<boost::asio::ip::tcp>::results_type resolve_results_;
|
||||
boost::asio::ip::basic_resolver<boost::asio::ip::tcp>::results_type
|
||||
resolve_results_;
|
||||
std::mutex clients_mutex_;
|
||||
std::vector<std::shared_ptr<client>> clients_;
|
||||
|
||||
@ -61,23 +64,27 @@ private:
|
||||
|
||||
void close_all();
|
||||
|
||||
bool connect(client &c);
|
||||
void connect(client &c);
|
||||
|
||||
std::shared_ptr<client> get_client();
|
||||
[[nodiscard]] auto get_client() -> std::shared_ptr<client>;
|
||||
|
||||
void put_client(std::shared_ptr<client> &c);
|
||||
|
||||
packet::error_type read_packet(client &c, packet &response);
|
||||
[[nodiscard]] auto read_packet(client &c, packet &response)
|
||||
-> packet::error_type;
|
||||
|
||||
void resolve();
|
||||
|
||||
public:
|
||||
packet::error_type send(const std::string &method, std::uint32_t &service_flags);
|
||||
[[nodiscard]] auto send(const std::string &method,
|
||||
std::uint32_t &service_flags) -> packet::error_type;
|
||||
|
||||
packet::error_type send(const std::string &method, packet &request, std::uint32_t &service_flags);
|
||||
[[nodiscard]] auto send(const std::string &method, packet &request,
|
||||
std::uint32_t &service_flags) -> packet::error_type;
|
||||
|
||||
packet::error_type send(const std::string &method, packet &request, packet &response,
|
||||
std::uint32_t &service_flags);
|
||||
[[nodiscard]] auto send(const std::string &method, packet &request,
|
||||
packet &response, std::uint32_t &service_flags)
|
||||
-> packet::error_type;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -1,26 +1,29 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_PACKET_PACKET_SERVER_HPP_
|
||||
#define INCLUDE_COMM_PACKET_PACKET_SERVER_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "comm/packet/client_pool.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
using namespace boost::asio;
|
||||
@ -29,28 +32,27 @@ using boost::asio::ip::tcp;
|
||||
namespace repertory {
|
||||
class packet_server final {
|
||||
public:
|
||||
typedef std::function<void(const std::string &clientId)> closed_callback;
|
||||
typedef client_pool::worker_complete_callback message_complete_callback;
|
||||
typedef std::function<void(const std::uint32_t &service_flags, const std::string &client_id,
|
||||
const std::uint64_t &thread_id, const std::string &method,
|
||||
packet *request, packet &response,
|
||||
message_complete_callback message_complete)>
|
||||
message_handler_callback;
|
||||
using closed_callback = std::function<void(const std::string &)>;
|
||||
using message_complete_callback = client_pool::worker_complete_callback;
|
||||
using message_handler_callback = std::function<void(
|
||||
std::uint32_t, const std::string &, std::uint64_t, const std::string &,
|
||||
packet *, packet &, message_complete_callback)>;
|
||||
|
||||
public:
|
||||
packet_server(const std::uint16_t &port, std::string token, std::uint8_t pool_size,
|
||||
closed_callback closed, message_handler_callback message_handler);
|
||||
packet_server(std::uint16_t port, std::string token, std::uint8_t pool_size,
|
||||
closed_callback closed,
|
||||
message_handler_callback message_handler);
|
||||
|
||||
~packet_server();
|
||||
|
||||
private:
|
||||
struct connection {
|
||||
connection(boost::asio::io_service &io_service, tcp::acceptor &acceptor)
|
||||
: socket(io_service), acceptor(acceptor) {}
|
||||
connection(boost::asio::io_service &io_service, tcp::acceptor &acceptor_)
|
||||
: socket(io_service), acceptor(acceptor_) {}
|
||||
|
||||
tcp::socket socket;
|
||||
tcp::acceptor &acceptor;
|
||||
std::vector<char> buffer;
|
||||
data_buffer buffer;
|
||||
std::string client_id;
|
||||
std::string nonce;
|
||||
|
||||
@ -78,12 +80,12 @@ private:
|
||||
|
||||
void read_header(std::shared_ptr<connection> c);
|
||||
|
||||
void read_packet(std::shared_ptr<connection> c, const std::uint32_t &data_size);
|
||||
void read_packet(std::shared_ptr<connection> c, std::uint32_t data_size);
|
||||
|
||||
void remove_client(connection &c);
|
||||
|
||||
void send_response(std::shared_ptr<connection> c, const packet::error_type &result,
|
||||
packet &response);
|
||||
void send_response(std::shared_ptr<connection> c,
|
||||
const packet::error_type &result, packet &response);
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
177
include/comm/s3/s3_comm.hpp
Normal file
177
include/comm/s3/s3_comm.hpp
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_S3_S3_COMM_HPP_
|
||||
#define INCLUDE_COMM_S3_S3_COMM_HPP_
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
|
||||
#include "comm/i_http_comm.hpp"
|
||||
#include "comm/i_s3_comm.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
|
||||
class s3_comm final : public i_s3_comm {
|
||||
public:
|
||||
explicit s3_comm(const app_config &config);
|
||||
s3_comm(s3_comm &&comm);
|
||||
|
||||
~s3_comm() override;
|
||||
|
||||
private:
|
||||
struct cache_entry final {
|
||||
std::chrono::system_clock::time_point expiration;
|
||||
directory_item_list items;
|
||||
|
||||
void reset_timeout(std::chrono::seconds timeout) {
|
||||
timeout = std::max(std::chrono::seconds(5u), timeout);
|
||||
expiration = std::chrono::system_clock::now() + timeout;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
const app_config &config_;
|
||||
s3_config s3_config_;
|
||||
std::unique_ptr<i_http_comm> s3_client_;
|
||||
|
||||
private:
|
||||
mutable std::recursive_mutex cached_directories_mutex_;
|
||||
mutable std::unordered_map<std::string, cache_entry> cached_directories_;
|
||||
|
||||
protected:
|
||||
bool active_ = true;
|
||||
|
||||
private:
|
||||
void clear_expired_directories();
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_cached_directory_item_count(const std::string &api_path,
|
||||
std::size_t &count) const -> bool;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_cached_directory_items(const std::string &api_path,
|
||||
meta_provider_callback meta_provider,
|
||||
directory_item_list &list) const -> bool;
|
||||
|
||||
[[nodiscard]] auto get_cached_file_exists(const std::string &api_path) const
|
||||
-> bool;
|
||||
|
||||
[[nodiscard]] auto grab_directory_items(const std::string &api_path,
|
||||
meta_provider_callback meta_provider,
|
||||
directory_item_list &list) const
|
||||
-> api_error;
|
||||
|
||||
void raise_begin(const std::string &function_name,
|
||||
const std::string &api_path) const;
|
||||
|
||||
[[nodiscard]] auto raise_end(const std::string &function_name,
|
||||
const std::string &api_path,
|
||||
const api_error &error, long code) const
|
||||
-> api_error;
|
||||
|
||||
void remove_cached_directory(const std::string &api_path);
|
||||
|
||||
void set_cached_directory_items(const std::string &api_path,
|
||||
directory_item_list list) const;
|
||||
|
||||
public:
|
||||
[[nodiscard]] auto create_directory(const std::string &api_path)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto directory_exists(const std::string &api_path) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto file_exists(const std::string &api_path,
|
||||
const get_key_callback &get_key) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_directory_item_count(const std::string &api_path,
|
||||
meta_provider_callback meta_provider) const
|
||||
-> std::size_t override;
|
||||
|
||||
[[nodiscard]] auto get_directory_items(const std::string &api_path,
|
||||
meta_provider_callback meta_provider,
|
||||
directory_item_list &list) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_directory_list(api_file_list &list) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_file(const std::string &api_path,
|
||||
const get_key_callback &get_key,
|
||||
const get_name_callback &get_name,
|
||||
const get_token_callback &get_token,
|
||||
api_file &file) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_file_list(const get_api_file_token_callback &get_api_file_token,
|
||||
const get_name_callback &get_name, api_file_list &list) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_object_list(std::vector<directory_item> &list) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_object_name(const std::string &api_path,
|
||||
const get_key_callback &getKey) const
|
||||
-> std::string override;
|
||||
|
||||
[[nodiscard]] auto get_s3_config() -> s3_config override {
|
||||
return s3_config_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_s3_config() const -> s3_config override {
|
||||
return s3_config_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_online() const -> bool override {
|
||||
// TODO implement this
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto read_file_bytes(
|
||||
const std::string &api_path, std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data, const get_key_callback &get_key,
|
||||
const get_size_callback &get_size, const get_token_callback &get_token,
|
||||
stop_type &stop_requested) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto remove_directory(const std::string &api_path)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto remove_file(const std::string &api_path,
|
||||
const get_key_callback &get_key)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto rename_file(const std::string &api_path,
|
||||
const std::string &new_api_path)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
upload_file(const std::string &api_path, const std::string &source_path,
|
||||
const std::string &encryption_token,
|
||||
const get_key_callback &get_key, const set_key_callback &set_key,
|
||||
stop_type &stop_requested) -> api_error override;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_ENABLE_S3
|
||||
#endif // INCLUDE_COMM_S3_S3_COMM_HPP_
|
117
include/comm/s3/s3_requests.hpp
Normal file
117
include/comm/s3/s3_requests.hpp
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_S3_S3_REQUESTS_HPP_
|
||||
#define INCLUDE_COMM_S3_S3_REQUESTS_HPP_
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
|
||||
#include "comm/s3/s3_requests_curl.hpp"
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/s3.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
template <typename client_type>
|
||||
[[nodiscard]] inline auto
|
||||
create_directory_object_request(client_type &client, const s3_config &config,
|
||||
const std::string &object_name,
|
||||
long &response_code) -> bool {
|
||||
return create_directory_object_request_impl(client, config, object_name,
|
||||
response_code);
|
||||
}
|
||||
|
||||
template <typename client_type>
|
||||
[[nodiscard]] inline auto delete_object_request(client_type &client,
|
||||
const s3_config &config,
|
||||
const std::string &object_name,
|
||||
long &response_code) -> bool {
|
||||
return delete_object_request_impl(client, config, object_name, response_code);
|
||||
}
|
||||
|
||||
template <typename client_type>
|
||||
[[nodiscard]] inline auto
|
||||
head_object_request(client_type &client, const s3_config &config,
|
||||
const std::string &object_name, head_object_result &result,
|
||||
long &response_code) -> bool {
|
||||
return head_object_request_impl(client, config, object_name, result,
|
||||
response_code);
|
||||
}
|
||||
|
||||
template <typename client_type>
|
||||
[[nodiscard]] inline auto
|
||||
list_directories_request(client_type &client, const s3_config &config,
|
||||
list_directories_result &result, long &response_code)
|
||||
-> bool {
|
||||
return list_directories_request_impl(client, config, result, response_code);
|
||||
}
|
||||
|
||||
template <typename client_type>
|
||||
[[nodiscard]] inline auto
|
||||
list_files_request(client_type &client, const s3_config &config,
|
||||
const get_api_file_token_callback &get_api_file_token,
|
||||
const get_name_callback &get_name, list_files_result &result,
|
||||
long &response_code) -> bool {
|
||||
return list_files_request_impl(client, config, get_api_file_token, get_name,
|
||||
result, response_code);
|
||||
}
|
||||
|
||||
template <typename client_type>
|
||||
[[nodiscard]] inline auto list_objects_in_directory_request(
|
||||
client_type &client, const s3_config &config,
|
||||
const std::string &object_name, meta_provider_callback meta_provider,
|
||||
list_objects_result &result, long &response_code) -> bool {
|
||||
return list_objects_in_directory_request_impl(
|
||||
client, config, object_name, meta_provider, result, response_code);
|
||||
}
|
||||
|
||||
template <typename client_type>
|
||||
[[nodiscard]] inline auto
|
||||
list_objects_request(client_type &client, const s3_config &config,
|
||||
list_objects_result &result, long &response_code) -> bool {
|
||||
return list_objects_request_impl(client, config, result, response_code);
|
||||
}
|
||||
|
||||
template <typename client_type>
|
||||
[[nodiscard]] inline auto
|
||||
put_object_request(client_type &client, const s3_config &config,
|
||||
std::string object_name, const std::string &source_path,
|
||||
const std::string &encryption_token,
|
||||
get_key_callback get_key, set_key_callback set_key,
|
||||
long &response_code, stop_type &stop_requested) -> bool {
|
||||
return put_object_request_impl(client, config, object_name, source_path,
|
||||
encryption_token, get_key, set_key,
|
||||
response_code, stop_requested);
|
||||
}
|
||||
|
||||
template <typename client_type>
|
||||
[[nodiscard]] inline auto
|
||||
read_object_request(client_type &client, const s3_config &config,
|
||||
const std::string &object_name, std::size_t size,
|
||||
std::uint64_t offset, data_buffer &data,
|
||||
long &response_code, stop_type &stop_requested) -> bool {
|
||||
return read_object_request_impl(client, config, object_name, size, offset,
|
||||
data, response_code, stop_requested);
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
#endif
|
||||
#endif // INCLUDE_COMM_S3_S3_REQUESTS_HPP_
|
83
include/comm/s3/s3_requests_curl.hpp
Normal file
83
include/comm/s3/s3_requests_curl.hpp
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMM_S3_S3_REQUESTS_CURL_HPP_
|
||||
#define INCLUDE_COMM_S3_S3_REQUESTS_CURL_HPP_
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
|
||||
#include "comm/i_http_comm.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/s3.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
[[nodiscard]] auto create_directory_object_request_impl(
|
||||
i_http_comm &client, const s3_config &config,
|
||||
const std::string &object_name, long &response_code) -> bool;
|
||||
|
||||
[[nodiscard]] auto delete_object_request_impl(i_http_comm &client,
|
||||
const s3_config &config,
|
||||
const std::string &object_name,
|
||||
long &response_code) -> bool;
|
||||
|
||||
[[nodiscard]] auto head_object_request_impl(i_http_comm &client,
|
||||
const s3_config &config,
|
||||
const std::string &object_name,
|
||||
head_object_result &result,
|
||||
long &response_code) -> bool;
|
||||
|
||||
[[nodiscard]] auto
|
||||
list_directories_request_impl(i_http_comm &client, const s3_config &config,
|
||||
list_directories_result &result,
|
||||
long &response_code) -> bool;
|
||||
|
||||
[[nodiscard]] auto
|
||||
list_files_request_impl(i_http_comm &client, const s3_config &config,
|
||||
const get_api_file_token_callback &get_api_file_token,
|
||||
const get_name_callback &get_name,
|
||||
list_files_result &result, long &response_code) -> bool;
|
||||
|
||||
[[nodiscard]] auto list_objects_in_directory_request_impl(
|
||||
i_http_comm &client, const s3_config &config,
|
||||
const std::string &object_name, meta_provider_callback meta_provider,
|
||||
list_objects_result &result, long &response_code) -> bool;
|
||||
|
||||
[[nodiscard]] auto list_objects_request_impl(i_http_comm &client,
|
||||
const s3_config &config,
|
||||
list_objects_result &result,
|
||||
long &response_code) -> bool;
|
||||
|
||||
[[nodiscard]] auto
|
||||
put_object_request_impl(i_http_comm &client, const s3_config &config,
|
||||
std::string object_name, const std::string &source_path,
|
||||
const std::string &encryption_token,
|
||||
get_key_callback get_key, set_key_callback set_key,
|
||||
long &response_code, stop_type &stop_requested) -> bool;
|
||||
|
||||
[[nodiscard]] auto read_object_request_impl(
|
||||
i_http_comm &client, const s3_config &config,
|
||||
const std::string &object_name, std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data, long &response_code, stop_type &stop_requested) -> bool;
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_ENABLE_S3
|
||||
#endif // INCLUDE_COMM_S3_S3_REQUESTS_CURL_HPP_
|
@ -1,36 +1,39 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_COMMON_HPP_
|
||||
#define INCLUDE_COMMON_HPP_
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <WinSock2.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <Windows.h>
|
||||
#include <Shlwapi.h>
|
||||
#include <ShlObj.h>
|
||||
#include <windows.h>
|
||||
#include <shlwapi.h>
|
||||
#include <shlobj.h>
|
||||
#include <ciso646>
|
||||
#include <direct.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <time.h>
|
||||
#else
|
||||
#define FUSE_USE_VERSION 29
|
||||
#include <climits>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
@ -62,8 +65,31 @@
|
||||
#include <uuid/uuid.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <codecvt>
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <future>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/archive/text_iarchive.hpp>
|
||||
#include <boost/archive/text_oarchive.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
@ -71,111 +97,134 @@
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
#include <boost/dynamic_bitset/serialization.hpp>
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/serialization/vector.hpp>
|
||||
#include <chacha.h>
|
||||
#include <chachapoly.h>
|
||||
#include <chrono>
|
||||
#include <codecvt>
|
||||
#include <condition_variable>
|
||||
#include <curl/curl.h>
|
||||
#include <curl/multi.h>
|
||||
#include <deque>
|
||||
#include <fstream>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <jsonrp.hpp>
|
||||
#include <limits>
|
||||
#include <microhttpd.h>
|
||||
#include <httpserver.hpp>
|
||||
#include <mutex>
|
||||
|
||||
#if !IS_DEBIAN9_DISTRO && HAS_STD_OPTIONAL
|
||||
#include <optional>
|
||||
#else
|
||||
#include <utils/optional.h>
|
||||
#endif
|
||||
#include <files.h>
|
||||
#include <hex.h>
|
||||
#include <json.hpp>
|
||||
#include <osrng.h>
|
||||
#include <random>
|
||||
#include <regex>
|
||||
#include <rocksdb/db.h>
|
||||
#include <sha.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <ttmath.h>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <sddl.h>
|
||||
#include <winfsp/winfsp.hpp>
|
||||
#else
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
#include <fuse.h>
|
||||
#include <fuse_lowlevel.h>
|
||||
#else
|
||||
#include <fuse/fuse.h>
|
||||
#endif
|
||||
|
||||
#if defined(REPERTORY_ENABLE_S3)
|
||||
#include <aws/core/Aws.h>
|
||||
#include <aws/core/auth/AWSCredentials.h>
|
||||
#include <aws/core/utils/logging/AWSLogging.h>
|
||||
#include <aws/core/utils/logging/DefaultLogSystem.h>
|
||||
#include <aws/s3/S3Client.h>
|
||||
#include <aws/s3/model/CopyObjectRequest.h>
|
||||
#include <aws/s3/model/CreateBucketRequest.h>
|
||||
#include <aws/s3/model/DeleteBucketRequest.h>
|
||||
#include <aws/s3/model/DeleteObjectRequest.h>
|
||||
#include <aws/s3/model/GetObjectRequest.h>
|
||||
#include <aws/s3/model/HeadObjectRequest.h>
|
||||
#include <aws/s3/model/ListObjectsRequest.h>
|
||||
#include <aws/s3/model/Object.h>
|
||||
#include <aws/s3/model/PutObjectRequest.h>
|
||||
#endif
|
||||
|
||||
#include <pugixml.hpp>
|
||||
#include <sodium.h>
|
||||
|
||||
#define CPPHTTPLIB_TCP_NODELAY true
|
||||
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
#include <httplib.h>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using json = nlohmann::json;
|
||||
|
||||
const std::string &get_repertory_git_revision();
|
||||
const std::string &get_repertory_version();
|
||||
#define REPERTORY "repertory"
|
||||
#define REPERTORY_CONFIG_VERSION 0ull
|
||||
#define REPERTORY_DATA_NAME "repertory2"
|
||||
#define REPERTORY_MIN_REMOTE_VERSION "2.0.0"
|
||||
#define REPERTORY_W L"repertory"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define REPERTORY_INVALID_HANDLE INVALID_HANDLE_VALUE
|
||||
#define REPERTORY_API_INVALID_HANDLE static_cast<std::uint64_t>(-1)
|
||||
using native_handle = HANDLE;
|
||||
#else
|
||||
#define REPERTORY_INVALID_HANDLE -1
|
||||
#define REPERTORY_API_INVALID_HANDLE REPERTORY_INVALID_HANDLE
|
||||
using native_handle = int;
|
||||
#endif
|
||||
|
||||
#define NANOS_PER_SECOND 1000000000L
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef CreateDirectory
|
||||
#undef CreateDirectory
|
||||
#endif
|
||||
|
||||
#ifdef CreateFile
|
||||
#undef CreateFile
|
||||
#endif
|
||||
|
||||
#ifdef DeleteFile
|
||||
#undef DeleteFile
|
||||
#endif
|
||||
|
||||
#ifdef RemoveDirectory
|
||||
#undef RemoveDirectory
|
||||
#endif
|
||||
|
||||
#ifndef _SH_DENYRW
|
||||
#define _SH_DENYRW 0x10 // deny read/write mode
|
||||
#endif
|
||||
|
||||
#define MIN_REMOTE_VERSION "2.0.0"
|
||||
#define MIN_SIA_VERSION "1.4.1"
|
||||
#define MIN_SP_VERSION "1.4.1.2"
|
||||
#define REPERTORY_CONFIG_VERSION 0ull
|
||||
#define REPERTORY "repertory"
|
||||
#define REPERTORY_DATA_NAME "repertory2"
|
||||
#define REPERTORY_W L"repertory"
|
||||
|
||||
#define NANOS_PER_SECOND 1000000000L
|
||||
|
||||
#ifdef _WIN32
|
||||
#define REPERTORY_INVALID_HANDLE INVALID_HANDLE_VALUE
|
||||
#define REPERTORY_API_INVALID_HANDLE static_cast<std::uint64_t>(-1)
|
||||
#define OSHandle HANDLE
|
||||
#else
|
||||
#define REPERTORY_INVALID_HANDLE -1
|
||||
#define REPERTORY_API_INVALID_HANDLE REPERTORY_INVALID_HANDLE
|
||||
#define OSHandle int
|
||||
#ifndef _SH_DENYWR
|
||||
#define _SH_DENYWR 0x20 // deny write mode
|
||||
#endif
|
||||
|
||||
#ifndef _SH_DENYRD
|
||||
#define _SH_DENYRD 0x30 // deny read mode
|
||||
#endif
|
||||
|
||||
#ifndef _SH_DENYNO
|
||||
#define _SH_DENYNO 0x40 // deny none mode
|
||||
#endif
|
||||
|
||||
#ifndef _SH_SECURE
|
||||
#define _SH_SECURE 0x80 // secure mode
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ENETDOWN
|
||||
#define ENETDOWN 100
|
||||
#endif
|
||||
|
||||
#ifndef SETATTR_WANTS_MODE
|
||||
#define SETATTR_WANTS_MODE(attr) ((attr)->valid & (1 << 0))
|
||||
#endif // SETATTR_WANTS_MODE
|
||||
|
||||
#ifndef SETATTR_WANTS_UID
|
||||
#define SETATTR_WANTS_UID(attr) ((attr)->valid & (1 << 1))
|
||||
#endif // SETATTR_WANTS_UID
|
||||
|
||||
#ifndef SETATTR_WANTS_GID
|
||||
#define SETATTR_WANTS_GID(attr) ((attr)->valid & (1 << 2))
|
||||
#endif // SETATTR_WANTS_GID
|
||||
|
||||
#ifndef SETATTR_WANTS_SIZE
|
||||
#define SETATTR_WANTS_SIZE(attr) ((attr)->valid & (1 << 3))
|
||||
#endif // SETATTR_WANTS_SIZE
|
||||
|
||||
#ifndef SETATTR_WANTS_ACCTIME
|
||||
#define SETATTR_WANTS_ACCTIME(attr) ((attr)->valid & (1 << 4))
|
||||
#endif // SETATTR_WANTS_ACCTIME
|
||||
|
||||
#ifndef SETATTR_WANTS_MODTIME
|
||||
#define SETATTR_WANTS_MODTIME(attr) ((attr)->valid & (1 << 5))
|
||||
#endif // SETATTR_WANTS_MODTIME
|
||||
|
||||
#ifndef SETATTR_WANTS_CRTIME
|
||||
#define SETATTR_WANTS_CRTIME(attr) ((attr)->valid & (1 << 28))
|
||||
#endif // SETATTR_WANTS_CRTIME
|
||||
|
||||
#ifndef SETATTR_WANTS_CHGTIME
|
||||
#define SETATTR_WANTS_CHGTIME(attr) ((attr)->valid & (1 << 29))
|
||||
#endif // SETATTR_WANTS_CHGTIME
|
||||
|
||||
#ifndef SETATTR_WANTS_BKUPTIME
|
||||
#define SETATTR_WANTS_BKUPTIME(attr) ((attr)->valid & (1 << 30))
|
||||
#endif // SETATTR_WANTS_BKUPTIME
|
||||
|
||||
#ifndef SETATTR_WANTS_FLAGS
|
||||
#define SETATTR_WANTS_FLAGS(attr) ((attr)->valid & (1 << 31))
|
||||
#endif // SETATTR_WANTS_FLAGS
|
||||
|
||||
#ifndef _WIN32
|
||||
#ifdef __APPLE__
|
||||
#define G_PREFIX "org"
|
||||
@ -194,11 +243,26 @@ const std::string &get_repertory_version();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if __APPLE__
|
||||
#ifndef fstat64
|
||||
#define fstat64 fstat
|
||||
#endif
|
||||
|
||||
#ifndef pread64
|
||||
#define pread64 pread
|
||||
#endif
|
||||
|
||||
#ifndef pwrite64
|
||||
#define pwrite64 pwrite
|
||||
#endif
|
||||
|
||||
#ifndef stat64
|
||||
#define stat64 stat
|
||||
#endif
|
||||
|
||||
#ifndef statfs64
|
||||
#define statfs64 statfs
|
||||
#endif
|
||||
|
||||
#define WINFSP_ALLOCATION_UNIT UINT64(4096U)
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -206,18 +270,18 @@ const std::string &get_repertory_version();
|
||||
#define UTIME_OMIT ((1l << 30) - 2l)
|
||||
#define CONVERT_STATUS_NOT_IMPLEMENTED(e) e
|
||||
#else
|
||||
#define VOID void
|
||||
#define PVOID VOID *
|
||||
typedef PVOID HANDLE;
|
||||
#define WCHAR wchar_t
|
||||
#define PWSTR WCHAR *
|
||||
#define BOOLEAN std::uint8_t
|
||||
#define UINT16 std::uint16_t
|
||||
#define UINT32 std::uint32_t
|
||||
#define PUINT32 UINT32 *
|
||||
#define UINT64 std::uint64_t
|
||||
#define SIZE_T std::uint64_t
|
||||
#define DWORD std::uint32_t
|
||||
using BOOLEAN = std::uint8_t;
|
||||
using DWORD = std::uint32_t;
|
||||
using HANDLE = void *;
|
||||
using PUINT32 = std::uint32_t *;
|
||||
using PVOID = void *;
|
||||
using PWSTR = wchar_t *;
|
||||
using SIZE_T = std::uint64_t;
|
||||
using UINT16 = std::uint16_t;
|
||||
using UINT32 = std::uint32_t;
|
||||
using UINT64 = std::uint64_t;
|
||||
using VOID = void;
|
||||
using WCHAR = wchar_t;
|
||||
|
||||
#define FILE_ATTRIBUTE_READONLY 0x00000001
|
||||
#define FILE_ATTRIBUTE_HIDDEN 0x00000002
|
||||
@ -275,7 +339,7 @@ typedef PVOID HANDLE;
|
||||
#define STATUS_OBJECT_NAME_NOT_FOUND std::int32_t(0xC0000034L)
|
||||
#define STATUS_OBJECT_PATH_INVALID std::int32_t(0xC0000039L)
|
||||
#define STATUS_UNEXPECTED_IO_ERROR std::int32_t(0xC00000E9L)
|
||||
#define CONVERT_STATUS_NOT_IMPLEMENTED(e) \
|
||||
#define CONVERT_STATUS_NOT_IMPLEMENTED(e) \
|
||||
((std::int32_t(e) == STATUS_NOT_IMPLEMENTED) ? -ENOTSUP : e)
|
||||
|
||||
namespace Fsp::FileSystemBase {
|
||||
@ -302,23 +366,30 @@ struct FSP_FSCTL_FILE_INFO {
|
||||
UINT32 EaSize;
|
||||
};
|
||||
|
||||
typedef FSP_FSCTL_FILE_INFO FileInfo;
|
||||
using FileInfo = FSP_FSCTL_FILE_INFO;
|
||||
} // namespace Fsp::FileSystemBase
|
||||
#endif
|
||||
|
||||
using namespace Fsp;
|
||||
|
||||
#define INTERFACE_SETUP(name) \
|
||||
public: \
|
||||
name(const name &) noexcept = delete; \
|
||||
name(name &&) noexcept = delete; \
|
||||
name &operator=(const name &) noexcept = delete; \
|
||||
name &operator=(name &&) noexcept = delete; \
|
||||
\
|
||||
protected: \
|
||||
name() = default; \
|
||||
\
|
||||
public: \
|
||||
namespace repertory {
|
||||
auto get_repertory_git_revision() -> const std::string &;
|
||||
auto get_repertory_version() -> const std::string &;
|
||||
void repertory_init();
|
||||
void repertory_shutdown();
|
||||
} // namespace repertory
|
||||
|
||||
#define INTERFACE_SETUP(name) \
|
||||
public: \
|
||||
name(const name &) noexcept = delete; \
|
||||
name &operator=(const name &) noexcept = delete; \
|
||||
name &operator=(name &&) noexcept = delete; \
|
||||
\
|
||||
protected: \
|
||||
name() = default; \
|
||||
name(name &&) noexcept = default; \
|
||||
\
|
||||
public: \
|
||||
virtual ~name() = default
|
||||
|
||||
#endif // INCLUDE_COMMON_HPP_
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DB_DIRECTORY_DB_HPP_
|
||||
#define INCLUDE_DB_DIRECTORY_DB_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/rocksdb_utils.hpp"
|
||||
@ -29,22 +31,25 @@ class directory_db final {
|
||||
private:
|
||||
class directory_tree final {
|
||||
private:
|
||||
std::unordered_map<std::string, std::vector<std::string>> sub_directory_lookup_;
|
||||
std::unordered_map<std::string, std::vector<std::string>>
|
||||
sub_directory_lookup_;
|
||||
|
||||
public:
|
||||
void add_path(const std::string &api_path, const std::vector<std::string> &files,
|
||||
rocksdb::DB &db);
|
||||
void add_path(const std::string &api_path,
|
||||
const std::vector<std::string> &files, rocksdb::DB &db);
|
||||
|
||||
std::size_t get_count(const std::string &api_path) const;
|
||||
[[nodiscard]] auto get_count(const std::string &api_path) const
|
||||
-> std::size_t;
|
||||
|
||||
std::vector<std::string> get_directories() const;
|
||||
[[nodiscard]] auto get_directories() const -> std::vector<std::string>;
|
||||
|
||||
std::vector<std::string> get_sub_directories(const std::string &api_path) const;
|
||||
[[nodiscard]] auto get_sub_directories(const std::string &api_path) const
|
||||
-> std::vector<std::string>;
|
||||
|
||||
bool is_directory(const std::string &api_path) const;
|
||||
[[nodiscard]] auto is_directory(const std::string &api_path) const -> bool;
|
||||
|
||||
bool remove_directory(const std::string &api_path, rocksdb::DB &db,
|
||||
const bool &allow_remove_root = false);
|
||||
void remove_directory(const std::string &api_path, rocksdb::DB &db,
|
||||
bool allow_remove_root = false);
|
||||
};
|
||||
|
||||
public:
|
||||
@ -60,41 +65,52 @@ private:
|
||||
const std::string DIRDB_NAME = "directory_db";
|
||||
|
||||
private:
|
||||
json get_directory_data(const std::string &api_path) const;
|
||||
[[nodiscard]] auto get_directory_data(const std::string &api_path) const
|
||||
-> json;
|
||||
|
||||
public:
|
||||
api_error create_directory(const std::string &api_path, const bool &create_always = false);
|
||||
[[nodiscard]] auto create_directory(const std::string &api_path,
|
||||
bool create_always = false) -> api_error;
|
||||
|
||||
api_error create_file(const std::string &api_path);
|
||||
[[nodiscard]] auto create_file(const std::string &api_path) -> api_error;
|
||||
|
||||
std::uint64_t get_directory_item_count(const std::string &api_path) const;
|
||||
[[nodiscard]] auto get_directory_item_count(const std::string &api_path) const
|
||||
-> std::uint64_t;
|
||||
|
||||
api_error get_file(const std::string &api_path, api_file &file,
|
||||
api_file_provider_callback api_file_provider) const;
|
||||
[[nodiscard]] auto
|
||||
get_file(const std::string &api_path, api_file &file,
|
||||
api_file_provider_callback api_file_provider) const -> api_error;
|
||||
|
||||
api_error get_file_list(api_file_list &list, api_file_provider_callback api_file_provider) const;
|
||||
[[nodiscard]] auto
|
||||
get_file_list(api_file_list &list,
|
||||
api_file_provider_callback api_file_provider) const
|
||||
-> api_error;
|
||||
|
||||
std::size_t get_sub_directory_count(const std::string &api_path) const;
|
||||
[[nodiscard]] auto get_sub_directory_count(const std::string &api_path) const
|
||||
-> std::size_t;
|
||||
|
||||
std::uint64_t get_total_item_count() const;
|
||||
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t;
|
||||
|
||||
bool is_directory(const std::string &api_path) const;
|
||||
[[nodiscard]] auto is_directory(const std::string &api_path) const -> bool;
|
||||
|
||||
bool is_file(const std::string &api_path) const;
|
||||
[[nodiscard]] auto is_file(const std::string &api_path) const -> bool;
|
||||
|
||||
void populate_directory_files(const std::string &api_path,
|
||||
const meta_provider_callback &meta_provider,
|
||||
meta_provider_callback meta_provider,
|
||||
directory_item_list &list) const;
|
||||
|
||||
void populate_sub_directories(const std::string &api_path,
|
||||
const meta_provider_callback &meta_provider,
|
||||
meta_provider_callback meta_provider,
|
||||
directory_item_list &list) const;
|
||||
|
||||
api_error remove_directory(const std::string &api_path, const bool &allow_remove_root = false);
|
||||
[[nodiscard]] auto remove_directory(const std::string &api_path,
|
||||
bool allow_remove_root = false)
|
||||
-> api_error;
|
||||
|
||||
bool remove_file(const std::string &api_path);
|
||||
[[nodiscard]] auto remove_file(const std::string &api_path) -> bool;
|
||||
|
||||
api_error rename_file(const std::string &from_api_path, const std::string &to_api_path);
|
||||
[[nodiscard]] auto rename_file(const std::string &from_api_path,
|
||||
const std::string &to_api_path) -> api_error;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DB_META_DB_HPP_
|
||||
#define INCLUDE_DB_META_DB_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/rocksdb_utils.hpp"
|
||||
@ -34,47 +36,73 @@ public:
|
||||
|
||||
private:
|
||||
std::unique_ptr<rocksdb::DB> db_;
|
||||
std::unique_ptr<rocksdb::ColumnFamilyHandle> default_family_;
|
||||
std::unique_ptr<rocksdb::ColumnFamilyHandle> source_family_;
|
||||
std::unique_ptr<rocksdb::ColumnFamilyHandle> keys_family_;
|
||||
rocksdb::ColumnFamilyHandle *default_family_{};
|
||||
rocksdb::ColumnFamilyHandle *source_family_{};
|
||||
rocksdb::ColumnFamilyHandle *keys_family_{};
|
||||
const std::string METADB_NAME = "meta_db";
|
||||
|
||||
private:
|
||||
api_error get_item_meta_json(const std::string &api_path, json &json_data) const;
|
||||
[[nodiscard]] auto
|
||||
perform_action(const std::string &function_name,
|
||||
const std::function<rocksdb::Status()> &action) const
|
||||
-> api_error;
|
||||
|
||||
void release_resources();
|
||||
[[nodiscard]] auto get_item_meta_json(const std::string &api_path,
|
||||
json &json_data) const -> api_error;
|
||||
|
||||
[[nodiscard]] auto store_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
const std::string &value) -> api_error;
|
||||
|
||||
public:
|
||||
std::shared_ptr<rocksdb::Iterator> create_iterator(const bool &source_family);
|
||||
[[nodiscard]] auto create_iterator(bool source_family) const
|
||||
-> std::shared_ptr<rocksdb::Iterator>;
|
||||
|
||||
api_error get_api_path_from_key(const std::string &key, std::string &api_path) const;
|
||||
[[nodiscard]] auto get_api_path_from_key(const std::string &key,
|
||||
std::string &api_path) const
|
||||
-> api_error;
|
||||
|
||||
api_error get_api_path_from_source(const std::string &source_path, std::string &api_path) const;
|
||||
[[nodiscard]] auto get_api_path_from_source(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
-> api_error;
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, api_meta_map &meta) const;
|
||||
[[nodiscard]] auto get_item_meta(const std::string &api_path,
|
||||
api_meta_map &meta) const -> api_error;
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, const std::string &key,
|
||||
std::string &value) const;
|
||||
[[nodiscard]] auto get_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
std::string &value) const -> api_error;
|
||||
|
||||
bool get_item_meta_exists(const std::string &api_path) const;
|
||||
[[nodiscard]] auto get_item_meta_exists(const std::string &api_path) const
|
||||
-> bool;
|
||||
|
||||
std::vector<std::string> get_pinned_files() const;
|
||||
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t;
|
||||
|
||||
bool get_source_path_exists(const std::string &source_path) const;
|
||||
[[nodiscard]] auto get_pinned_files() const -> std::vector<std::string>;
|
||||
|
||||
void remove_item_meta(const std::string &api_path);
|
||||
[[nodiscard]] auto
|
||||
get_source_path_exists(const std::string &source_path) const -> bool;
|
||||
|
||||
api_error remove_item_meta(const std::string &api_path, const std::string &key);
|
||||
[[nodiscard]] auto remove_item_meta(const std::string &api_path) -> api_error;
|
||||
|
||||
api_error rename_item_meta(const std::string &source_path, const std::string &from_api_path,
|
||||
const std::string &to_api_path);
|
||||
[[nodiscard]] auto remove_item_meta(const std::string &api_path,
|
||||
const std::string &key) -> api_error;
|
||||
|
||||
api_error set_item_meta(const std::string &api_path, const std::string &key,
|
||||
const std::string &value);
|
||||
[[nodiscard]] auto rename_item_meta(const std::string &source_path,
|
||||
const std::string &from_api_path,
|
||||
const std::string &to_api_path)
|
||||
-> api_error;
|
||||
|
||||
api_error set_item_meta(const std::string &api_path, const api_meta_map &meta);
|
||||
[[nodiscard]] auto set_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
const std::string &value) -> api_error;
|
||||
|
||||
api_error set_source_path(const std::string &api_path, const std::string &source_path);
|
||||
[[nodiscard]] auto set_item_meta(const std::string &api_path,
|
||||
const api_meta_map &meta) -> api_error;
|
||||
|
||||
[[nodiscard]] auto set_source_path(const std::string &api_path,
|
||||
const std::string &source_path)
|
||||
-> api_error;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DB_RETRY_DB_HPP_
|
||||
#define INCLUDE_DB_RETRY_DB_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/path_utils.hpp"
|
||||
#include "utils/rocksdb_utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class retry_db final {
|
||||
public:
|
||||
typedef std::function<bool(const std::string &api_path)> process_callback;
|
||||
|
||||
public:
|
||||
explicit retry_db(const app_config &config);
|
||||
|
||||
~retry_db();
|
||||
|
||||
private:
|
||||
std::unique_ptr<rocksdb::DB> db_;
|
||||
bool paused_ = false;
|
||||
std::mutex processing_mutex_;
|
||||
const std::string ROCKS_DB_NAME = "retry_db";
|
||||
|
||||
public:
|
||||
bool exists(const std::string &api_path) const;
|
||||
|
||||
void pause();
|
||||
|
||||
bool process_all(const process_callback &process);
|
||||
|
||||
void remove(const std::string &api_path);
|
||||
|
||||
void rename(const std::string &from_api_path, const std::string &to_api_path);
|
||||
|
||||
void resume();
|
||||
|
||||
void set(const std::string &api_path);
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DB_RETRY_DB_HPP_
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DOWNLOAD_BUFFERED_READER_HPP_
|
||||
#define INCLUDE_DOWNLOAD_BUFFERED_READER_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
class buffered_reader final {
|
||||
public:
|
||||
buffered_reader(const app_config &config, const filesystem_item &fsi,
|
||||
const api_reader_callback &api_reader, const std::size_t &chunk_size,
|
||||
const std::size_t &total_chunks, const std::size_t &start_chunk);
|
||||
|
||||
~buffered_reader();
|
||||
|
||||
private:
|
||||
const filesystem_item &fsi_;
|
||||
const api_reader_callback &api_reader_;
|
||||
const std::size_t chunk_size_;
|
||||
const std::size_t total_chunks_;
|
||||
boost::dynamic_bitset<> ring_state_;
|
||||
|
||||
api_error error_ = api_error::success;
|
||||
std::unique_ptr<std::vector<char>> first_chunk_data_;
|
||||
std::unique_ptr<std::vector<char>> last_chunk_data_;
|
||||
std::size_t read_chunk_index_ = 0u;
|
||||
std::mutex read_mutex_;
|
||||
std::condition_variable read_notify_;
|
||||
std::size_t read_offset_ = 0u;
|
||||
bool reset_reader_ = false;
|
||||
std::vector<std::vector<char>> ring_data_;
|
||||
std::unique_ptr<std::thread> reader_thread_;
|
||||
bool stop_requested_ = false;
|
||||
std::mutex write_mutex_;
|
||||
std::size_t write_chunk_index_ = 0u;
|
||||
|
||||
private:
|
||||
bool is_active() const { return not stop_requested_ && (error_ == api_error::success); }
|
||||
|
||||
void reader_thread();
|
||||
|
||||
public:
|
||||
std::size_t get_chunk_size() const { return chunk_size_; }
|
||||
|
||||
void get_first_chunk(std::vector<char> *&data) { data = first_chunk_data_.get(); }
|
||||
|
||||
void get_last_chunk(std::vector<char> *&data) { data = last_chunk_data_.get(); }
|
||||
|
||||
bool has_first_chunk() const { return static_cast<bool>(first_chunk_data_); }
|
||||
|
||||
bool has_last_chunk() const { return static_cast<bool>(last_chunk_data_); }
|
||||
|
||||
void notify_stop_requested();
|
||||
|
||||
api_error read_chunk(const std::size_t &chunk_index, std::vector<char> &data);
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DOWNLOAD_BUFFERED_READER_HPP_
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DOWNLOAD_DIRECT_DOWNLOAD_HPP_
|
||||
#define INCLUDE_DOWNLOAD_DIRECT_DOWNLOAD_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "download/i_download.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class buffered_reader;
|
||||
class app_config;
|
||||
class direct_download final : public virtual i_download {
|
||||
public:
|
||||
direct_download(const app_config &config, filesystem_item fsi,
|
||||
const api_reader_callback &api_reader, const std::uint64_t &handle);
|
||||
|
||||
~direct_download() override;
|
||||
|
||||
private:
|
||||
const app_config &config_;
|
||||
const filesystem_item fsi_;
|
||||
const api_reader_callback &api_reader_;
|
||||
const std::uint64_t handle_;
|
||||
|
||||
api_error error_ = api_error::success;
|
||||
std::unique_ptr<buffered_reader> buffered_reader_;
|
||||
bool disable_download_end_ = false;
|
||||
bool download_end_notified_ = false;
|
||||
double progress_ = 0.0;
|
||||
std::mutex read_mutex_;
|
||||
bool stop_requested_ = false;
|
||||
|
||||
private:
|
||||
bool is_active() const { return not stop_requested_ && (error_ == api_error::success); }
|
||||
|
||||
void notify_download_end();
|
||||
|
||||
void set_api_error(const api_error &error);
|
||||
|
||||
public:
|
||||
api_error allocate(const std::uint64_t & /*handle*/, const std::uint64_t & /*size*/,
|
||||
const allocator_callback & /*allocator*/,
|
||||
const completer_callback & /*completer*/) override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
api_error download_all() override { return api_error::not_implemented; }
|
||||
|
||||
api_error get_result() const override { return error_; }
|
||||
|
||||
std::string get_source_path() const override { return ""; }
|
||||
|
||||
void get_state_information(filesystem_item &, std::size_t &, std::size_t &,
|
||||
boost::dynamic_bitset<> &, boost::dynamic_bitset<> &) override {}
|
||||
|
||||
bool get_write_supported() const override { return false; }
|
||||
|
||||
void notify_stop_requested() override;
|
||||
|
||||
bool pause() override { return false; }
|
||||
|
||||
api_error read_bytes(const std::uint64_t &, std::size_t read_size,
|
||||
const std::uint64_t &read_offset, std::vector<char> &data) override;
|
||||
|
||||
void reset_timeout(const bool &) override {}
|
||||
|
||||
void resume() override {}
|
||||
|
||||
void set_api_path(const std::string &) override {}
|
||||
|
||||
void set_disable_download_end(const bool &disable) override { disable_download_end_ = disable; }
|
||||
|
||||
api_error write_bytes(const std::uint64_t &, const std::uint64_t &, std::vector<char>,
|
||||
std::size_t &bytes_written,
|
||||
const completer_callback & /*completer*/) override {
|
||||
bytes_written = 0u;
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DOWNLOAD_DIRECT_DOWNLOAD_HPP_
|
@ -1,191 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DOWNLOAD_DOWNLOAD_HPP_
|
||||
#define INCLUDE_DOWNLOAD_DOWNLOAD_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "download/i_download.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/native_file.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_open_file_table;
|
||||
class download final : public virtual i_download {
|
||||
private:
|
||||
struct active_chunk {
|
||||
explicit active_chunk(std::thread worker) : worker(std::move(worker)) {}
|
||||
|
||||
std::thread worker;
|
||||
std::mutex mutex;
|
||||
std::condition_variable notify;
|
||||
};
|
||||
typedef std::shared_ptr<active_chunk> active_chunk_ptr;
|
||||
|
||||
struct read_data {
|
||||
read_data(std::vector<char> &data, const std::uint64_t &offset)
|
||||
: complete(false), data(data), offset(offset) {}
|
||||
|
||||
bool complete;
|
||||
std::vector<char> &data;
|
||||
const std::uint64_t offset;
|
||||
std::mutex mutex;
|
||||
std::condition_variable notify;
|
||||
};
|
||||
typedef std::shared_ptr<read_data> read_data_ptr;
|
||||
|
||||
struct write_data {
|
||||
write_data(const std::size_t &chunk, std::vector<char> data, const std::uint64_t &offset)
|
||||
: chunk_index(chunk), data(std::move(data)), offset(offset) {}
|
||||
write_data(const std::uint64_t &offset, std::vector<char> data)
|
||||
: chunk_index(0u), data(std::move(data)), offset(offset), from_read(false) {}
|
||||
|
||||
std::size_t chunk_index;
|
||||
std::vector<char> data;
|
||||
const std::uint64_t offset;
|
||||
bool from_read = true;
|
||||
bool complete = false;
|
||||
std::mutex mutex;
|
||||
std::condition_variable notify;
|
||||
std::size_t written = 0u;
|
||||
};
|
||||
typedef std::shared_ptr<write_data> write_data_ptr;
|
||||
|
||||
public:
|
||||
download(const app_config &config, filesystem_item &fsi, const api_reader_callback &api_reader,
|
||||
const std::size_t &chunk_size, i_open_file_table &oft);
|
||||
|
||||
download(const app_config &config, filesystem_item &fsi, const api_reader_callback &api_reader,
|
||||
const std::size_t &chunk_size, std::size_t &last_chunk_size,
|
||||
boost::dynamic_bitset<> &read_state, boost::dynamic_bitset<> &write_state,
|
||||
i_open_file_table &oft);
|
||||
|
||||
~download() override;
|
||||
|
||||
private:
|
||||
// Constructor initialization
|
||||
const app_config &config_;
|
||||
filesystem_item fsi_;
|
||||
const api_reader_callback &api_reader_;
|
||||
i_open_file_table &oft_;
|
||||
const std::size_t chunk_size_;
|
||||
boost::dynamic_bitset<> read_chunk_state_;
|
||||
std::size_t last_chunk_size_;
|
||||
boost::dynamic_bitset<> write_chunk_state_;
|
||||
|
||||
// Default initialization
|
||||
bool auto_close_ = false;
|
||||
std::unordered_map<std::size_t, active_chunk_ptr> active_chunks_;
|
||||
api_error error_ = api_error::success;
|
||||
std::vector<std::thread> background_workers_;
|
||||
std::size_t current_chunk_index_ = 0u;
|
||||
bool disable_download_end_ = false;
|
||||
std::unique_ptr<std::thread> io_thread_;
|
||||
std::uint64_t open_file_handle_ = REPERTORY_API_INVALID_HANDLE;
|
||||
bool paused_ = false;
|
||||
bool processed_ = false;
|
||||
std::condition_variable processed_notify_;
|
||||
double progress_ = 0.0;
|
||||
std::size_t read_offset_ = 0u;
|
||||
std::deque<read_data_ptr> read_queue_;
|
||||
native_file_ptr read_write_file_;
|
||||
std::mutex read_write_mutex_;
|
||||
std::condition_variable read_write_notify_;
|
||||
bool stop_requested_ = false;
|
||||
std::chrono::system_clock::time_point timeout_ =
|
||||
std::chrono::system_clock::now() +
|
||||
std::chrono::seconds(config_.get_chunk_downloader_timeout_secs());
|
||||
std::deque<write_data_ptr> write_queue_;
|
||||
|
||||
private:
|
||||
void create_active_chunk(std::size_t chunk_index);
|
||||
|
||||
void download_chunk(std::size_t chunk_index, bool inactive_only);
|
||||
|
||||
bool get_complete() const;
|
||||
|
||||
bool get_timeout_enabled() const;
|
||||
|
||||
void handle_active_chunk_complete(std::size_t chunk_index, unique_mutex_lock &lock);
|
||||
|
||||
void initialize_download(filesystem_item &fsi, const bool &delete_existing);
|
||||
|
||||
void io_data_worker();
|
||||
|
||||
void notify_progress();
|
||||
|
||||
void process_download_complete(unique_mutex_lock &lock);
|
||||
|
||||
void process_read_queue(unique_mutex_lock &lock);
|
||||
|
||||
void process_timeout(unique_mutex_lock &lock);
|
||||
|
||||
void process_write_queue(unique_mutex_lock &lock);
|
||||
|
||||
void read_ahead_worker();
|
||||
|
||||
void read_behind_worker();
|
||||
|
||||
void read_end_worker();
|
||||
|
||||
void shutdown(unique_mutex_lock &lock);
|
||||
|
||||
void wait_for_io(unique_mutex_lock &lock);
|
||||
|
||||
public:
|
||||
api_error allocate(const std::uint64_t &handle, const std::uint64_t &size,
|
||||
const allocator_callback &allocator,
|
||||
const completer_callback &completer) override;
|
||||
|
||||
api_error download_all() override;
|
||||
|
||||
api_error get_result() const override { return error_; }
|
||||
|
||||
std::string get_source_path() const override { return fsi_.source_path; }
|
||||
|
||||
void get_state_information(filesystem_item &fsi, std::size_t &chunk_size,
|
||||
std::size_t &last_chunk_size, boost::dynamic_bitset<> &read_state,
|
||||
boost::dynamic_bitset<> &write_state) override;
|
||||
|
||||
bool get_write_supported() const override { return true; }
|
||||
|
||||
bool is_active() const { return not read_chunk_state_.all(); }
|
||||
|
||||
void notify_stop_requested() override;
|
||||
|
||||
bool pause() override;
|
||||
|
||||
api_error read_bytes(const std::uint64_t &handle, std::size_t read_size,
|
||||
const std::uint64_t &read_offset, std::vector<char> &data) override;
|
||||
|
||||
void reset_timeout(const bool &) override;
|
||||
|
||||
void resume() override;
|
||||
|
||||
void set_api_path(const std::string &api_path) override;
|
||||
|
||||
void set_disable_download_end(const bool &disable) override { disable_download_end_ = disable; }
|
||||
|
||||
api_error write_bytes(const std::uint64_t &handle, const std::uint64_t &write_offset,
|
||||
std::vector<char> data, std::size_t &bytes_written,
|
||||
const completer_callback &completer) override;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DOWNLOAD_DOWNLOAD_HPP_
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DOWNLOAD_DOWNLOAD_MANAGER_HPP_
|
||||
#define INCLUDE_DOWNLOAD_DOWNLOAD_MANAGER_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "download/i_download.hpp"
|
||||
#include "download/i_download_manager.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
class download_end;
|
||||
class filesystem_item_handle_closed;
|
||||
class i_open_file_table;
|
||||
class download_manager final : public virtual i_download_manager {
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
download_manager(const app_config &config, api_reader_callback api_reader,
|
||||
const bool &force_download = false);
|
||||
|
||||
~download_manager() override;
|
||||
|
||||
private:
|
||||
const app_config &config_;
|
||||
const api_reader_callback api_reader_;
|
||||
bool force_download_;
|
||||
i_open_file_table *oft_ = nullptr;
|
||||
mutable std::recursive_mutex download_mutex_;
|
||||
std::unordered_map<std::string, std::unordered_map<std::uint64_t, download_ptr>> download_lookup_;
|
||||
std::recursive_mutex start_stop_mutex_;
|
||||
bool stop_requested_ = true;
|
||||
std::unique_ptr<rocksdb::DB> restore_db_;
|
||||
|
||||
private:
|
||||
bool contains_handle(const std::string &api_path, const std::uint64_t &handle) const;
|
||||
|
||||
download_ptr get_download(std::uint64_t handle, filesystem_item &fsi,
|
||||
const bool &write_Supported);
|
||||
|
||||
void handle_download_end(const download_end &de);
|
||||
|
||||
void on_handle_closed(const filesystem_item_handle_closed &handle_closed);
|
||||
|
||||
void reset_timeout(const std::string &api_path, const bool &file_closed);
|
||||
|
||||
void start_incomplete();
|
||||
|
||||
public:
|
||||
api_error allocate(const std::uint64_t &handle, filesystem_item &fsi, const std::uint64_t &size,
|
||||
const i_download::allocator_callback &allocator) override;
|
||||
|
||||
bool contains_restore(const std::string &api_path) const override;
|
||||
|
||||
api_error download_file(const std::uint64_t &handle, filesystem_item &fsi) override;
|
||||
|
||||
std::size_t get_download_count() const { return download_lookup_.size(); }
|
||||
|
||||
std::string get_source_path(const std::string &api_path) const;
|
||||
|
||||
bool is_processing(const std::string &api_path) const override;
|
||||
|
||||
bool pause_download(const std::string &api_path) override;
|
||||
|
||||
api_error read_bytes(const std::uint64_t &handle, filesystem_item &fsi, std::size_t read_size,
|
||||
const std::uint64_t &read_offset, std::vector<char> &data) override;
|
||||
|
||||
void rename_download(const std::string &from_api_path, const std::string &to_api_path) override;
|
||||
|
||||
api_error resize(const std::uint64_t &handle, filesystem_item &fsi,
|
||||
const std::uint64_t &size) override;
|
||||
|
||||
void resume_download(const std::string &api_path) override;
|
||||
|
||||
void start(i_open_file_table *oft);
|
||||
|
||||
void stop();
|
||||
|
||||
api_error write_bytes(const std::uint64_t &handle, filesystem_item &fsi,
|
||||
const std::uint64_t &write_offset, std::vector<char> data,
|
||||
std::size_t &bytes_written) override;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DOWNLOAD_DOWNLOAD_MANAGER_HPP_
|
@ -1,85 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DOWNLOAD_EVENTS_HPP_
|
||||
#define INCLUDE_DOWNLOAD_EVENTS_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
// clang-format off
|
||||
E_SIMPLE2(download_begin, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE4(download_end, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING,
|
||||
std::uint64_t, handle, handle, E_FROM_UINT64,
|
||||
api_error, result, result, E_FROM_API_FILE_ERROR
|
||||
);
|
||||
|
||||
E_SIMPLE2(download_paused, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(download_progress, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING,
|
||||
double, progress, prog, E_DOUBLE_PRECISE
|
||||
);
|
||||
|
||||
E_SIMPLE2(download_restored, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(download_restore_failed, error, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING,
|
||||
std::string, error, err, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE2(download_resumed, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE2(download_stored, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(download_store_failed, error, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING,
|
||||
std::string, error, err, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE2(download_timeout, warn, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING
|
||||
);
|
||||
// clang-format on
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DOWNLOAD_EVENTS_HPP_
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DOWNLOAD_I_DOWNLOAD_HPP_
|
||||
#define INCLUDE_DOWNLOAD_I_DOWNLOAD_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_download {
|
||||
INTERFACE_SETUP(i_download);
|
||||
|
||||
public:
|
||||
typedef std::function<api_error()> allocator_callback;
|
||||
|
||||
typedef std::function<void(std::uint64_t old_size, std::uint64_t new_size, bool changed)>
|
||||
completer_callback;
|
||||
|
||||
public:
|
||||
virtual api_error allocate(const std::uint64_t &handle, const std::uint64_t &size,
|
||||
const allocator_callback &allocator,
|
||||
const completer_callback &completer) = 0;
|
||||
|
||||
virtual api_error download_all() = 0;
|
||||
|
||||
virtual api_error get_result() const = 0;
|
||||
|
||||
virtual std::string get_source_path() const = 0;
|
||||
|
||||
virtual void get_state_information(filesystem_item &fsi, std::size_t &chunk_size,
|
||||
std::size_t &last_chunk_size,
|
||||
boost::dynamic_bitset<> &read_state,
|
||||
boost::dynamic_bitset<> &write_state) = 0;
|
||||
|
||||
virtual bool get_write_supported() const = 0;
|
||||
|
||||
virtual void notify_stop_requested() = 0;
|
||||
|
||||
virtual bool pause() = 0;
|
||||
|
||||
virtual api_error read_bytes(const std::uint64_t &handle, std::size_t read_size,
|
||||
const std::uint64_t &read_offset, std::vector<char> &data) = 0;
|
||||
|
||||
virtual void reset_timeout(const bool &file_closed) = 0;
|
||||
|
||||
virtual void resume() = 0;
|
||||
|
||||
virtual void set_api_path(const std::string &api_path) = 0;
|
||||
|
||||
virtual void set_disable_download_end(const bool &disable) = 0;
|
||||
|
||||
virtual api_error write_bytes(const std::uint64_t &handle, const std::uint64_t &write_offset,
|
||||
std::vector<char> data, std::size_t &bytes_written,
|
||||
const completer_callback &completer) = 0;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<i_download> download_ptr;
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DOWNLOAD_I_DOWNLOAD_HPP_
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DOWNLOAD_I_DOWNLOAD_MANAGER_HPP_
|
||||
#define INCLUDE_DOWNLOAD_I_DOWNLOAD_MANAGER_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "download/i_download.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_download_manager {
|
||||
INTERFACE_SETUP(i_download_manager);
|
||||
|
||||
public:
|
||||
virtual api_error allocate(const std::uint64_t &handle, filesystem_item &fsi,
|
||||
const std::uint64_t &size,
|
||||
const i_download::allocator_callback &allocator) = 0;
|
||||
|
||||
virtual bool contains_restore(const std::string &api_path) const = 0;
|
||||
|
||||
virtual api_error download_file(const std::uint64_t &handle, filesystem_item &fsi) = 0;
|
||||
|
||||
virtual bool is_processing(const std::string &api_path) const = 0;
|
||||
|
||||
virtual bool pause_download(const std::string &api_path) = 0;
|
||||
|
||||
virtual api_error read_bytes(const std::uint64_t &handle, filesystem_item &fsi,
|
||||
std::size_t read_size, const std::uint64_t &read_offset,
|
||||
std::vector<char> &data) = 0;
|
||||
|
||||
virtual void rename_download(const std::string &from_api_path,
|
||||
const std::string &to_api_path) = 0;
|
||||
|
||||
virtual api_error resize(const std::uint64_t &handle, filesystem_item &fsi,
|
||||
const std::uint64_t &size) = 0;
|
||||
|
||||
virtual void resume_download(const std::string &api_path) = 0;
|
||||
|
||||
virtual api_error write_bytes(const std::uint64_t &handle, filesystem_item &fsi,
|
||||
const std::uint64_t &write_offset, std::vector<char> data,
|
||||
std::size_t &bytes_written) = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DOWNLOAD_I_DOWNLOAD_MANAGER_HPP_
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DOWNLOAD_READER_POOL_HPP_
|
||||
#define INCLUDE_DOWNLOAD_READER_POOL_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class reader_pool final {
|
||||
public:
|
||||
typedef std::function<void(api_error error)> completed_callback;
|
||||
|
||||
private:
|
||||
struct pool_work_item {
|
||||
pool_work_item(std::string api_path, const std::size_t &read_size,
|
||||
const std::uint64_t &read_offset, std::vector<char> &data,
|
||||
completed_callback completed)
|
||||
: api_path(std::move(api_path)), read_size(read_size), read_offset(read_offset), data(data),
|
||||
completed(completed) {}
|
||||
|
||||
std::string api_path;
|
||||
std::size_t read_size;
|
||||
std::uint64_t read_offset;
|
||||
std::vector<char> &data;
|
||||
completed_callback completed;
|
||||
};
|
||||
|
||||
public:
|
||||
reader_pool(const std::size_t &pool_size, const api_reader_callback &api_reader)
|
||||
: pool_size_(pool_size), api_reader_(api_reader) {
|
||||
start();
|
||||
}
|
||||
|
||||
~reader_pool() { stop(); }
|
||||
|
||||
private:
|
||||
const std::size_t pool_size_;
|
||||
const api_reader_callback &api_reader_;
|
||||
bool paused_ = false;
|
||||
bool restart_active_ = false;
|
||||
bool stop_requested_ = false;
|
||||
std::mutex work_mutex_;
|
||||
std::condition_variable work_notify_;
|
||||
std::deque<std::shared_ptr<pool_work_item>> work_queue_;
|
||||
std::vector<std::thread> work_threads_;
|
||||
std::uint16_t active_count_ = 0u;
|
||||
|
||||
private:
|
||||
void process_work_item(pool_work_item &work);
|
||||
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
|
||||
void wait_for_resume(unique_mutex_lock &lock);
|
||||
|
||||
public:
|
||||
void pause();
|
||||
|
||||
void queue_read_bytes(const std::string &api_path, const std::size_t &read_size,
|
||||
const std::uint64_t &read_offset, std::vector<char> &data,
|
||||
completed_callback completed);
|
||||
|
||||
void restart();
|
||||
|
||||
void resume();
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DOWNLOAD_READER_POOL_HPP_
|
@ -1,136 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DOWNLOAD_RING_DOWNLOAD_HPP_
|
||||
#define INCLUDE_DOWNLOAD_RING_DOWNLOAD_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "download/i_download.hpp"
|
||||
#include "utils/native_file.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class buffered_reader;
|
||||
class app_config;
|
||||
class ring_download final : public virtual i_download {
|
||||
private:
|
||||
struct io_action {
|
||||
io_action(std::mutex &mtx, std::condition_variable &cv, std::function<void()> action)
|
||||
: mutex(mtx), notify(cv), action(action) {}
|
||||
|
||||
std::mutex &mutex;
|
||||
std::condition_variable ¬ify;
|
||||
std::function<void()> action;
|
||||
};
|
||||
|
||||
public:
|
||||
ring_download(const app_config &config, filesystem_item fsi,
|
||||
const api_reader_callback &api_reader, const std::uint64_t &handle,
|
||||
const std::size_t &chunk_size, const std::size_t &ring_buffer_size);
|
||||
|
||||
~ring_download() override;
|
||||
|
||||
private:
|
||||
const app_config &config_;
|
||||
const filesystem_item fsi_;
|
||||
const api_reader_callback &api_reader_;
|
||||
const std::uint64_t handle_;
|
||||
const std::size_t chunk_size_;
|
||||
boost::dynamic_bitset<> ring_state_;
|
||||
const std::size_t total_chunks_ = 0u;
|
||||
|
||||
api_error error_ = api_error::success;
|
||||
native_file_ptr buffer_file_;
|
||||
std::string buffer_file_path_;
|
||||
buffered_reader *buffered_reader_ = nullptr;
|
||||
bool disable_download_end_ = false;
|
||||
std::size_t head_chunk_index_ = 0ull;
|
||||
std::mutex io_mutex_;
|
||||
std::condition_variable io_notify_;
|
||||
std::deque<std::unique_ptr<io_action>> io_queue_;
|
||||
std::unique_ptr<std::thread> io_thread_;
|
||||
std::size_t read_chunk_ = 0ull;
|
||||
std::unique_ptr<std::thread> buffer_thread_;
|
||||
std::mutex read_mutex_;
|
||||
std::condition_variable read_notify_;
|
||||
bool stop_requested_ = false;
|
||||
std::size_t write_chunk_ = 0ull;
|
||||
std::mutex write_mutex_;
|
||||
|
||||
private:
|
||||
void buffer_thread(std::size_t start_chunk_index);
|
||||
|
||||
void io_thread();
|
||||
|
||||
bool is_active() const { return not stop_requested_ && (error_ == api_error::success); }
|
||||
|
||||
bool queue_io_item(std::mutex &m, std::condition_variable &cv, const bool &is_read,
|
||||
std::function<void()> action);
|
||||
|
||||
void read(std::size_t read_chunk_index, std::size_t read_size, std::size_t read_offset,
|
||||
std::vector<char> &data);
|
||||
|
||||
void set_api_error(const api_error &error);
|
||||
|
||||
void start(const std::size_t &start_chunk_index);
|
||||
|
||||
void stop();
|
||||
|
||||
public:
|
||||
api_error allocate(const std::uint64_t & /*handle*/, const std::uint64_t & /*size*/,
|
||||
const allocator_callback & /*allocator*/,
|
||||
const completer_callback & /*completer*/) override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
api_error download_all() override { return api_error::not_implemented; }
|
||||
|
||||
api_error get_result() const override { return error_; }
|
||||
|
||||
std::string get_source_path() const override { return buffer_file_path_; }
|
||||
|
||||
void get_state_information(filesystem_item &, std::size_t &, std::size_t &,
|
||||
boost::dynamic_bitset<> &, boost::dynamic_bitset<> &) override {}
|
||||
|
||||
bool get_write_supported() const override { return false; }
|
||||
|
||||
void notify_stop_requested() override;
|
||||
|
||||
bool pause() override { return false; }
|
||||
|
||||
api_error read_bytes(const std::uint64_t &, std::size_t read_size,
|
||||
const std::uint64_t &read_offset, std::vector<char> &data) override;
|
||||
|
||||
void reset_timeout(const bool &) override {}
|
||||
|
||||
void resume() override {}
|
||||
|
||||
void set_api_path(const std::string &) override {}
|
||||
|
||||
void set_disable_download_end(const bool &disable) override { disable_download_end_ = disable; }
|
||||
|
||||
api_error write_bytes(const std::uint64_t &, const std::uint64_t &, std::vector<char>,
|
||||
std::size_t &bytes_written,
|
||||
const completer_callback & /*completer*/) override {
|
||||
bytes_written = 0u;
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DOWNLOAD_RING_DOWNLOAD_HPP_
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DOWNLOAD_UTILS_HPP_
|
||||
#define INCLUDE_DOWNLOAD_UTILS_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
|
||||
namespace repertory::utils::download {
|
||||
template <typename event_type>
|
||||
void notify_progress(const app_config &config, const std::string &api_path,
|
||||
const std::string &source_path, const double ¤t, const double &total,
|
||||
double &progress) {
|
||||
if (config.get_event_level() >= event_type::level) {
|
||||
const double next_progress = (current / total) * 100.0;
|
||||
if ((next_progress == 0.0) || (next_progress >= (progress + 0.2)) ||
|
||||
((next_progress == 100.00) && (next_progress != progress))) {
|
||||
progress = next_progress;
|
||||
event_system::instance().raise<event_type>(api_path, source_path, progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace repertory::utils::download
|
||||
|
||||
#endif // INCLUDE_DOWNLOAD_UTILS_HPP_
|
@ -1,67 +1,66 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_DIRECTORY_CACHE_HPP_
|
||||
#define INCLUDE_DRIVES_DIRECTORY_CACHE_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "utils/single_thread_service_base.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class directory_iterator;
|
||||
|
||||
class directory_cache final {
|
||||
class directory_cache final : public single_thread_service_base {
|
||||
public:
|
||||
typedef std::function<void(directory_iterator &iterator)> execute_callback;
|
||||
using execute_callback = std::function<void(directory_iterator &)>;
|
||||
|
||||
private:
|
||||
struct open_directory {
|
||||
directory_iterator *iterator;
|
||||
std::chrono::system_clock::time_point last_update = std::chrono::system_clock::now();
|
||||
std::chrono::system_clock::time_point last_update =
|
||||
std::chrono::system_clock::now();
|
||||
};
|
||||
|
||||
public:
|
||||
directory_cache() = default;
|
||||
directory_cache() : single_thread_service_base("directory_cache") {}
|
||||
|
||||
~directory_cache() { stop(); }
|
||||
~directory_cache() override = default;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, open_directory> directory_lookup_;
|
||||
std::recursive_mutex directory_mutex_;
|
||||
bool is_shutdown_ = true;
|
||||
std::unique_ptr<std::thread> refresh_thread_;
|
||||
std::mutex shutdown_mutex_;
|
||||
std::condition_variable shutdown_notify_;
|
||||
|
||||
private:
|
||||
void refresh_thread();
|
||||
protected:
|
||||
void service_function() override;
|
||||
|
||||
public:
|
||||
bool execute_action(const std::string &api_path, const execute_callback &execute);
|
||||
void execute_action(const std::string &api_path,
|
||||
const execute_callback &execute);
|
||||
|
||||
directory_iterator *remove_directory(const std::string &api_path);
|
||||
[[nodiscard]] auto remove_directory(const std::string &api_path)
|
||||
-> directory_iterator *;
|
||||
|
||||
void remove_directory(directory_iterator *iterator);
|
||||
|
||||
void set_directory(const std::string &api_path, directory_iterator *iterator);
|
||||
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_DIRECTORY_ITERATOR_HPP_
|
||||
#define INCLUDE_DRIVES_DIRECTORY_ITERATOR_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/remote.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
@ -27,44 +29,52 @@ namespace repertory {
|
||||
class directory_iterator final {
|
||||
public:
|
||||
#ifndef _WIN32
|
||||
typedef std::function<void(const std::string &api_path, const std::uint64_t &file_size,
|
||||
const api_meta_map &meta, const bool &directory, struct stat *st)>
|
||||
populate_stat_callback;
|
||||
using populate_stat_callback =
|
||||
std::function<void(const std::string &, std::uint64_t,
|
||||
const api_meta_map &, bool, struct stat *)>;
|
||||
#endif
|
||||
public:
|
||||
explicit directory_iterator(directory_item_list list) : items_(std::move(list)) {}
|
||||
explicit directory_iterator(directory_item_list list)
|
||||
: items_(std::move(list)) {}
|
||||
|
||||
directory_iterator(const directory_iterator &iterator) noexcept : items_(iterator.items_) {}
|
||||
directory_iterator(const directory_iterator &iterator) noexcept = default;
|
||||
|
||||
directory_iterator(directory_iterator &&iterator) noexcept : items_(std::move(iterator.items_)) {}
|
||||
directory_iterator(directory_iterator &&iterator) noexcept
|
||||
: items_(std::move(iterator.items_)) {}
|
||||
|
||||
private:
|
||||
directory_item_list items_;
|
||||
|
||||
public:
|
||||
#ifndef _WIN32
|
||||
int fill_buffer(const remote::file_offset &offset, fuse_fill_dir_t filler_function, void *buffer,
|
||||
populate_stat_callback populate_stat);
|
||||
[[nodiscard]] auto fill_buffer(const remote::file_offset &offset,
|
||||
fuse_fill_dir_t filler_function, void *buffer,
|
||||
populate_stat_callback populate_stat) -> int;
|
||||
#endif
|
||||
|
||||
int get(const std::size_t &offset, std::string &item);
|
||||
[[nodiscard]] auto get(std::size_t offset, std::string &item) -> int;
|
||||
|
||||
std::size_t get_count() const { return items_.size(); }
|
||||
[[nodiscard]] auto get_count() const -> std::size_t { return items_.size(); }
|
||||
|
||||
api_error get_directory_item(const std::size_t &offset, directory_item &di);
|
||||
[[nodiscard]] auto get_directory_item(std::size_t offset, directory_item &di)
|
||||
-> api_error;
|
||||
|
||||
api_error get_directory_item(const std::string &api_path, directory_item &di);
|
||||
[[nodiscard]] auto get_directory_item(const std::string &api_path,
|
||||
directory_item &di) -> api_error;
|
||||
|
||||
int get_json(const std::size_t &offset, json &item);
|
||||
[[nodiscard]] auto get_json(std::size_t offset, json &item) -> int;
|
||||
|
||||
std::size_t get_next_directory_offset(const std::string &api_path) const;
|
||||
[[nodiscard]] auto
|
||||
get_next_directory_offset(const std::string &api_path) const -> std::size_t;
|
||||
|
||||
public:
|
||||
directory_iterator &operator=(const directory_iterator &iterator) noexcept;
|
||||
auto operator=(const directory_iterator &iterator) noexcept
|
||||
-> directory_iterator &;
|
||||
|
||||
directory_iterator &operator=(directory_iterator &&iterator) noexcept;
|
||||
auto operator=(directory_iterator &&iterator) noexcept
|
||||
-> directory_iterator &;
|
||||
|
||||
directory_iterator &operator=(directory_item_list list) noexcept;
|
||||
auto operator=(directory_item_list list) noexcept -> directory_iterator &;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -1,58 +1,57 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_EVICTION_HPP_
|
||||
#define INCLUDE_DRIVES_EVICTION_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "utils/single_thread_service_base.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
class i_open_file_table;
|
||||
class i_file_manager;
|
||||
class i_provider;
|
||||
class eviction final {
|
||||
public:
|
||||
eviction(i_provider &provider, const app_config &config, i_open_file_table &oft)
|
||||
: provider_(provider), config_(config), oft_(oft) {}
|
||||
|
||||
~eviction() = default;
|
||||
class eviction final : public single_thread_service_base {
|
||||
public:
|
||||
eviction(i_provider &provider, const app_config &config, i_file_manager &fm)
|
||||
: single_thread_service_base("eviction"),
|
||||
provider_(provider),
|
||||
config_(config),
|
||||
fm_(fm) {}
|
||||
|
||||
~eviction() override = default;
|
||||
|
||||
private:
|
||||
i_provider &provider_;
|
||||
const app_config &config_;
|
||||
i_open_file_table &oft_;
|
||||
bool stop_requested_ = false;
|
||||
std::mutex start_stop_mutex_;
|
||||
std::condition_variable stop_notify_;
|
||||
std::unique_ptr<std::thread> eviction_thread_;
|
||||
std::mutex eviction_mutex_;
|
||||
i_file_manager &fm_;
|
||||
|
||||
private:
|
||||
void check_items_thread();
|
||||
[[nodiscard]] auto check_minimum_requirements(const std::string &file_path)
|
||||
-> bool;
|
||||
|
||||
bool check_minimum_requirements(const std::string &file_path);
|
||||
[[nodiscard]] auto get_filtered_cached_files() -> std::deque<std::string>;
|
||||
|
||||
std::deque<std::string> get_filtered_cached_files();
|
||||
|
||||
public:
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
protected:
|
||||
void service_function() override;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_EVENTS_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_EVENTS_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
|
||||
namespace repertory {
|
||||
|
@ -1,39 +1,40 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_FUSE_BASE_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_FUSE_BASE_HPP_
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "drives/fuse/i_fuse_drive.hpp"
|
||||
#include "utils/path_utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
class i_provider;
|
||||
|
||||
class fuse_base : public i_fuse_drive {
|
||||
class fuse_base {
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
explicit fuse_base(app_config &config_);
|
||||
explicit fuse_base(app_config &config);
|
||||
|
||||
virtual ~fuse_base();
|
||||
|
||||
@ -51,454 +52,558 @@ protected:
|
||||
std::optional<mode_t> forced_umask_;
|
||||
|
||||
private:
|
||||
static fuse_base &instance();
|
||||
static auto instance() -> fuse_base &;
|
||||
|
||||
private:
|
||||
// clang-format off
|
||||
struct fuse_operations fuse_ops_ {
|
||||
.getattr = fuse_base::getattr_,
|
||||
.readlink = nullptr, // int (*readlink) (const char *, char *, size_t);
|
||||
.getdir = nullptr, // int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
|
||||
.mknod = nullptr, // int (*mknod) (const char *, mode_t, dev_t);
|
||||
.mkdir = fuse_base::mkdir_,
|
||||
.unlink = fuse_base::unlink_,
|
||||
.rmdir = fuse_base::rmdir_,
|
||||
.symlink = nullptr, // int (*symlink) (const char *, const char *);
|
||||
.rename = fuse_base::rename_,
|
||||
.link = nullptr, // int (*link) (const char *, const char *);
|
||||
.chmod = fuse_base::chmod_,
|
||||
.chown = fuse_base::chown_,
|
||||
.truncate = fuse_base::truncate_,
|
||||
.utime = nullptr, // int (*utime) (const char *, struct utimbuf *);
|
||||
.open = fuse_base::open_,
|
||||
.read = fuse_base::read_,
|
||||
.write = fuse_base::write_,
|
||||
#ifdef __APPLE__
|
||||
.statfs = nullptr,
|
||||
#else // __APPLE__
|
||||
.statfs = fuse_base::statfs_,
|
||||
#endif // __APPLE__
|
||||
.flush = nullptr, // int (*flush) (const char *, struct fuse_file_info *);
|
||||
.release = fuse_base::release_,
|
||||
.fsync = fuse_base::fsync_,
|
||||
#if HAS_SETXATTR
|
||||
.setxattr = fuse_base::setxattr_,
|
||||
.getxattr = fuse_base::getxattr_,
|
||||
.listxattr = fuse_base::listxattr_,
|
||||
.removexattr = fuse_base::removexattr_,
|
||||
#else // HAS_SETXATTR
|
||||
.setxattr = nullptr,
|
||||
.getxattr = nullptr,
|
||||
.listxattr = nullptr,
|
||||
.removexattr = nullptr,
|
||||
#endif // HAS_SETXATTR
|
||||
.opendir = fuse_base::opendir_,
|
||||
.readdir = fuse_base::readdir_,
|
||||
.releasedir = fuse_base::releasedir_,
|
||||
.fsyncdir = nullptr, // int (*fsyncdir) (const char *, int, struct fuse_file_info *);
|
||||
.init = fuse_base::init_,
|
||||
.destroy = fuse_base::destroy_,
|
||||
.access = fuse_base::access_,
|
||||
.create = fuse_base::create_,
|
||||
.ftruncate = fuse_base::ftruncate_,
|
||||
.fgetattr = fuse_base::fgetattr_,
|
||||
.lock = nullptr, // int (*lock) (const char *, struct fuse_file_info *, int cmd, struct flock *);
|
||||
.utimens = fuse_base::utimens_,
|
||||
.bmap = nullptr, // int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
|
||||
.flag_nullpath_ok = 0,
|
||||
.flag_nopath = 0,
|
||||
.flag_utime_omit_ok = 1,
|
||||
.flag_reserved = 0,
|
||||
.ioctl = nullptr, // int (*ioctl) (const char *, int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void *data);
|
||||
.poll = nullptr, // int (*poll) (const char *, struct fuse_file_info *, struct fuse_pollhandle *ph, unsigned *reventsp);
|
||||
.write_buf = nullptr, // int (*write_buf) (const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *);
|
||||
.read_buf = nullptr, // int (*read_buf) (const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *);
|
||||
.flock = nullptr, // int (*flock) (const char *, struct fuse_file_info *, int op);
|
||||
.fallocate = fuse_base::fallocate_
|
||||
};
|
||||
// clang-format on
|
||||
struct fuse_operations fuse_ops_ {};
|
||||
|
||||
private:
|
||||
int execute_callback(const std::string &function_name, const char *from, const char *to,
|
||||
const std::function<api_error(const std::string &, const std::string &)> &cb,
|
||||
const bool &disable_logging = false);
|
||||
[[nodiscard]] auto execute_callback(
|
||||
const std::string &function_name, const char *from, const char *to,
|
||||
const std::function<api_error(const std::string &, const std::string &)>
|
||||
&cb,
|
||||
bool disable_logging = false) -> int;
|
||||
|
||||
int execute_callback(const std::string &function_name, const char *path,
|
||||
const std::function<api_error(const std::string &)> &cb,
|
||||
const bool &disable_logging = false);
|
||||
[[nodiscard]] auto
|
||||
execute_callback(const std::string &function_name, const char *path,
|
||||
const std::function<api_error(const std::string &)> &cb,
|
||||
bool disable_logging = false) -> int;
|
||||
|
||||
static void execute_void_callback(const std::string &function_name,
|
||||
const std::function<void()> &cb);
|
||||
|
||||
static void *execute_void_pointer_callback(const std::string &function_name,
|
||||
const std::function<void *()> &cb);
|
||||
static auto execute_void_pointer_callback(const std::string &function_name,
|
||||
const std::function<void *()> &cb)
|
||||
-> void *;
|
||||
|
||||
void raise_fuse_event(std::string function_name, const std::string &api_file, const int &ret,
|
||||
const bool &disable_logging);
|
||||
void raise_fuse_event(std::string function_name, const std::string &api_file,
|
||||
int ret, bool disable_logging);
|
||||
|
||||
private:
|
||||
static int access_(const char *path, int mask);
|
||||
[[nodiscard]] static auto access_(const char *path, int mask) -> int;
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int chflags_(const char *path, uint32_t flags);
|
||||
[[nodiscard]] static auto chflags_(const char *path, uint32_t flags) -> int;
|
||||
#endif // __APPLE__
|
||||
|
||||
static int chmod_(const char *path, mode_t mode);
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] static auto chmod_(const char *path, mode_t mode,
|
||||
struct fuse_file_info *fi) -> int;
|
||||
#else
|
||||
[[nodiscard]] static auto chmod_(const char *path, mode_t mode) -> int;
|
||||
#endif
|
||||
|
||||
static int chown_(const char *path, uid_t uid, gid_t gid);
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] static auto chown_(const char *path, uid_t uid, gid_t gid,
|
||||
struct fuse_file_info *fi) -> int;
|
||||
#else
|
||||
[[nodiscard]] static auto chown_(const char *path, uid_t uid, gid_t gid)
|
||||
-> int;
|
||||
#endif
|
||||
|
||||
static int create_(const char *path, mode_t mode, struct fuse_file_info *fi);
|
||||
[[nodiscard]] static auto create_(const char *path, mode_t mode,
|
||||
struct fuse_file_info *fi) -> int;
|
||||
|
||||
static void destroy_(void *ptr);
|
||||
|
||||
static int fallocate_(const char *path, int mode, off_t offset, off_t length,
|
||||
struct fuse_file_info *fi);
|
||||
[[nodiscard]] static auto fallocate_(const char *path, int mode, off_t offset,
|
||||
off_t length, struct fuse_file_info *fi)
|
||||
-> int;
|
||||
|
||||
static int fgetattr_(const char *path, struct stat *st, struct fuse_file_info *fi);
|
||||
#if FUSE_USE_VERSION < 30
|
||||
[[nodiscard]] static auto fgetattr_(const char *path, struct stat *st,
|
||||
struct fuse_file_info *fi) -> int;
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int fsetattr_x_(const char *path, struct setattr_x *attr, struct fuse_file_info *fi);
|
||||
[[nodiscard]] static auto fsetattr_x_(const char *path,
|
||||
struct setattr_x *attr,
|
||||
struct fuse_file_info *fi) -> int;
|
||||
#endif // __APPLE__
|
||||
|
||||
static int fsync_(const char *path, int datasync, struct fuse_file_info *fi);
|
||||
[[nodiscard]] static auto fsync_(const char *path, int datasync,
|
||||
struct fuse_file_info *fi) -> int;
|
||||
|
||||
static int ftruncate_(const char *path, off_t size, struct fuse_file_info *fi);
|
||||
[[nodiscard]] static auto ftruncate_(const char *path, off_t size,
|
||||
struct fuse_file_info *fi) -> int;
|
||||
|
||||
static int getattr_(const char *path, struct stat *st);
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] static auto getattr_(const char *path, struct stat *st,
|
||||
struct fuse_file_info *fi) -> int;
|
||||
#else
|
||||
[[nodiscard]] static auto getattr_(const char *path, struct stat *st) -> int;
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int getxtimes_(const char *path, struct timespec *bkuptime, struct timespec *crtime);
|
||||
[[nodiscard]] static auto getxtimes_(const char *path,
|
||||
struct timespec *bkuptime,
|
||||
struct timespec *crtime) -> int;
|
||||
#endif // __APPLE__
|
||||
|
||||
static void *init_(struct fuse_conn_info *conn);
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] static auto init_(struct fuse_conn_info *conn,
|
||||
struct fuse_config *cfg) -> void *;
|
||||
#else
|
||||
[[nodiscard]] static auto init_(struct fuse_conn_info *conn) -> void *;
|
||||
#endif
|
||||
|
||||
static int mkdir_(const char *path, mode_t mode);
|
||||
[[nodiscard]] static auto mkdir_(const char *path, mode_t mode) -> int;
|
||||
|
||||
static int open_(const char *path, struct fuse_file_info *fi);
|
||||
[[nodiscard]] static auto open_(const char *path, struct fuse_file_info *fi)
|
||||
-> int;
|
||||
|
||||
static int opendir_(const char *path, struct fuse_file_info *fi);
|
||||
[[nodiscard]] static auto opendir_(const char *path,
|
||||
struct fuse_file_info *fi) -> int;
|
||||
|
||||
static int read_(const char *path, char *buffer, size_t read_size, off_t read_offset,
|
||||
struct fuse_file_info *fi);
|
||||
[[nodiscard]] static auto read_(const char *path, char *buffer,
|
||||
size_t read_size, off_t read_offset,
|
||||
struct fuse_file_info *fi) -> int;
|
||||
|
||||
static int readdir_(const char *path, void *buf, fuse_fill_dir_t fuse_fill_dir, off_t offset,
|
||||
struct fuse_file_info *fi);
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] static auto readdir_(const char *path, void *buf,
|
||||
fuse_fill_dir_t fuse_fill_dir,
|
||||
off_t offset, struct fuse_file_info *fi,
|
||||
fuse_readdir_flags flags) -> int;
|
||||
#else
|
||||
[[nodiscard]] static auto readdir_(const char *path, void *buf,
|
||||
fuse_fill_dir_t fuse_fill_dir,
|
||||
off_t offset, struct fuse_file_info *fi)
|
||||
-> int;
|
||||
#endif
|
||||
|
||||
static int release_(const char *path, struct fuse_file_info *fi);
|
||||
[[nodiscard]] static auto release_(const char *path,
|
||||
struct fuse_file_info *fi) -> int;
|
||||
|
||||
static int releasedir_(const char *path, struct fuse_file_info *fi);
|
||||
[[nodiscard]] static auto releasedir_(const char *path,
|
||||
struct fuse_file_info *fi) -> int;
|
||||
|
||||
static int rename_(const char *from, const char *to);
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] static auto rename_(const char *from, const char *to,
|
||||
unsigned int flags) -> int;
|
||||
#else
|
||||
[[nodiscard]] static auto rename_(const char *from, const char *to) -> int;
|
||||
#endif
|
||||
|
||||
static int rmdir_(const char *path);
|
||||
[[nodiscard]] static auto rmdir_(const char *path) -> int;
|
||||
|
||||
#ifdef HAS_SETXATTR
|
||||
#ifdef __APPLE__
|
||||
static int getxattr_(const char *path, const char *name, char *value, size_t size,
|
||||
uint32_t position);
|
||||
[[nodiscard]] static auto getxattr_(const char *path, const char *name,
|
||||
char *value, size_t size,
|
||||
uint32_t position) -> int;
|
||||
|
||||
#else // __APPLE__
|
||||
static int getxattr_(const char *path, const char *name, char *value, size_t size);
|
||||
[[nodiscard]] static auto getxattr_(const char *path, const char *name,
|
||||
char *value, size_t size) -> int;
|
||||
#endif // __APPLE__
|
||||
|
||||
static int listxattr_(const char *path, char *buffer, size_t size);
|
||||
[[nodiscard]] static auto listxattr_(const char *path, char *buffer,
|
||||
size_t size) -> int;
|
||||
|
||||
static int removexattr_(const char *path, const char *name);
|
||||
[[nodiscard]] static auto removexattr_(const char *path, const char *name)
|
||||
-> int;
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int setxattr_(const char *path, const char *name, const char *value, size_t size,
|
||||
int flags, uint32_t position);
|
||||
[[nodiscard]] static auto setxattr_(const char *path, const char *name,
|
||||
const char *value, size_t size, int flags,
|
||||
uint32_t position) -> int;
|
||||
|
||||
#else // __APPLE__
|
||||
static int setxattr_(const char *path, const char *name, const char *value, size_t size,
|
||||
int flags);
|
||||
[[nodiscard]] static auto setxattr_(const char *path, const char *name,
|
||||
const char *value, size_t size, int flags)
|
||||
-> int;
|
||||
#endif // __APPLE__
|
||||
#endif // HAS_SETXATTR
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int setattr_x_(const char *path, struct setattr_x *attr);
|
||||
[[nodiscard]] static auto setattr_x_(const char *path, struct setattr_x *attr)
|
||||
-> int;
|
||||
|
||||
static int setbkuptime_(const char *path, const struct timespec *bkuptime);
|
||||
[[nodiscard]] static auto setbkuptime_(const char *path,
|
||||
const struct timespec *bkuptime)
|
||||
-> int;
|
||||
|
||||
static int setchgtime_(const char *path, const struct timespec *chgtime);
|
||||
[[nodiscard]] static auto setchgtime_(const char *path,
|
||||
const struct timespec *chgtime) -> int;
|
||||
|
||||
static int setcrtime_(const char *path, const struct timespec *crtime);
|
||||
[[nodiscard]] static auto setcrtime_(const char *path,
|
||||
const struct timespec *crtime) -> int;
|
||||
|
||||
static int setvolname_(const char *volname);
|
||||
[[nodiscard]] static auto setvolname_(const char *volname) -> int;
|
||||
|
||||
static int statfs_x_(const char *path, struct statfs *stbuf);
|
||||
[[nodiscard]] static auto statfs_x_(const char *path, struct statfs *stbuf)
|
||||
-> int;
|
||||
|
||||
#else // __APPLE__
|
||||
static int statfs_(const char *path, struct statvfs *stbuf);
|
||||
[[nodiscard]] static auto statfs_(const char *path, struct statvfs *stbuf)
|
||||
-> int;
|
||||
#endif // __APPLE__
|
||||
|
||||
static int truncate_(const char *path, off_t size);
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] static auto truncate_(const char *path, off_t size,
|
||||
struct fuse_file_info *fi) -> int;
|
||||
#else
|
||||
[[nodiscard]] static auto truncate_(const char *path, off_t size) -> int;
|
||||
#endif
|
||||
|
||||
static int unlink_(const char *path);
|
||||
[[nodiscard]] static auto unlink_(const char *path) -> int;
|
||||
|
||||
static int utimens_(const char *path, const struct timespec tv[2]);
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] static auto utimens_(const char *path,
|
||||
const struct timespec tv[2],
|
||||
struct fuse_file_info *fi) -> int;
|
||||
#else
|
||||
[[nodiscard]] static auto utimens_(const char *path,
|
||||
const struct timespec tv[2]) -> int;
|
||||
#endif
|
||||
|
||||
static int write_(const char *path, const char *buffer, size_t write_size, off_t write_offset,
|
||||
struct fuse_file_info *fi);
|
||||
[[nodiscard]] static auto write_(const char *path, const char *buffer,
|
||||
size_t write_size, off_t write_offset,
|
||||
struct fuse_file_info *fi) -> int;
|
||||
|
||||
protected:
|
||||
api_error check_access(const std::string &api_path, int mask) const;
|
||||
|
||||
api_error check_and_perform(const std::string &api_path, int parent_mask,
|
||||
const std::function<api_error(api_meta_map &meta)> &action);
|
||||
|
||||
uid_t get_effective_uid() const;
|
||||
|
||||
gid_t get_effective_gid() const;
|
||||
|
||||
static api_error check_open_flags(const int &flags, const int &mask, const api_error &fail_error);
|
||||
|
||||
api_error check_owner(const api_meta_map &meta) const;
|
||||
|
||||
static api_error check_readable(const int &flags, const api_error &fail_error);
|
||||
|
||||
static api_error check_writeable(const int &flags, const api_error &fail_error);
|
||||
|
||||
#ifdef __APPLE__
|
||||
static __uint32_t get_flags_from_meta(const api_meta_map &meta);
|
||||
#endif // __APPLE__
|
||||
|
||||
static gid_t get_gid_from_meta(const api_meta_map &meta);
|
||||
|
||||
static mode_t get_mode_from_meta(const api_meta_map &meta);
|
||||
|
||||
static void get_timespec_from_meta(const api_meta_map &meta, const std::string &name,
|
||||
struct timespec &ts);
|
||||
|
||||
static uid_t get_uid_from_meta(const api_meta_map &meta);
|
||||
|
||||
static void populate_stat(const std::string &api_path, const std::uint64_t &size_or_count,
|
||||
const api_meta_map &meta, const bool &directory, i_provider &provider,
|
||||
struct stat *st);
|
||||
|
||||
static void set_timespec_from_meta(const api_meta_map &meta, const std::string &name,
|
||||
struct timespec &ts);
|
||||
|
||||
protected:
|
||||
virtual api_error access_impl(std::string api_path, int mask) {
|
||||
return check_access(api_path, mask);
|
||||
[[nodiscard]] virtual auto access_impl(std::string /*api_path*/, int /*mask*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
virtual api_error chflags_impl(std::string /*api_path*/, uint32_t /*flags*/) {
|
||||
[[nodiscard]] virtual auto chflags_impl(std::string /*api_path*/,
|
||||
uint32_t /*flags*/) -> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif // __APPLE__
|
||||
|
||||
virtual api_error chmod_impl(std::string /*api_path*/, mode_t /*mode*/) {
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] virtual auto chmod_impl(std::string /*api_path*/,
|
||||
mode_t /*mode*/,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error chown_impl(std::string /*api_path*/, uid_t /*uid*/, gid_t /*gid*/) {
|
||||
#else
|
||||
[[nodiscard]] virtual auto chmod_impl(std::string /*api_path*/,
|
||||
mode_t /*mode*/) -> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual api_error create_impl(std::string /*api_path*/, mode_t /*mode*/,
|
||||
struct fuse_file_info * /*fi*/) {
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] virtual auto chown_impl(std::string /*api_path*/, uid_t /*uid*/,
|
||||
gid_t /*gid*/,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#else
|
||||
[[nodiscard]] virtual auto chown_impl(std::string /*api_path*/, uid_t /*uid*/,
|
||||
gid_t /*gid*/) -> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif
|
||||
|
||||
[[nodiscard]] virtual auto create_impl(std::string /*api_path*/,
|
||||
mode_t /*mode*/,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual void destroy_impl(void * /*ptr*/) { return; }
|
||||
|
||||
virtual api_error fallocate_impl(std::string /*api_path*/, int /*mode*/, off_t /*offset*/,
|
||||
off_t /*length*/, struct fuse_file_info * /*fi*/) {
|
||||
[[nodiscard]] virtual auto
|
||||
fallocate_impl(std::string /*api_path*/, int /*mode*/, off_t /*offset*/,
|
||||
off_t /*length*/, struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error fgetattr_impl(std::string /*api_path*/, struct stat * /*st*/,
|
||||
struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error fsetattr_x_impl(std::string /*api_path*/, struct setattr_x * /*attr*/,
|
||||
struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error fsync_impl(std::string /*api_path*/, int /*datasync*/,
|
||||
struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error ftruncate_impl(std::string /*api_path*/, off_t /*size*/,
|
||||
struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error getattr_impl(std::string /*api_path*/, struct stat * /*st*/) {
|
||||
[[nodiscard]] virtual auto fgetattr_impl(std::string /*api_path*/,
|
||||
struct stat * /*st*/,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
virtual api_error getxtimes_impl(std::string /*api_path*/, struct timespec * /*bkuptime*/,
|
||||
struct timespec * /*crtime*/) {
|
||||
[[nodiscard]] virtual auto fsetattr_x_impl(std::string /*api_path*/,
|
||||
struct setattr_x * /*attr*/,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif // __APPLE__
|
||||
|
||||
virtual void *init_impl(struct fuse_conn_info *conn);
|
||||
|
||||
virtual api_error mkdir_impl(std::string /*api_path*/, mode_t /*mode*/) {
|
||||
[[nodiscard]] virtual auto fsync_impl(std::string /*api_path*/,
|
||||
int /*datasync*/,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error open_impl(std::string /*api_path*/, struct fuse_file_info * /*fi*/) {
|
||||
#if FUSE_USE_VERSION < 30
|
||||
[[nodiscard]] virtual auto ftruncate_impl(std::string /*api_path*/,
|
||||
off_t /*size*/,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] virtual auto getattr_impl(std::string /*api_path*/,
|
||||
struct stat * /*st*/,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#else
|
||||
[[nodiscard]] virtual auto getattr_impl(std::string /*api_path*/,
|
||||
struct stat * /*st*/) -> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
[[nodiscard]] virtual auto getxtimes_impl(std::string /*api_path*/,
|
||||
struct timespec * /*bkuptime*/,
|
||||
struct timespec * /*crtime*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif // __APPLE__
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
virtual auto init_impl(struct fuse_conn_info *conn, struct fuse_config *cfg)
|
||||
-> void *;
|
||||
#else
|
||||
virtual auto init_impl(struct fuse_conn_info *conn) -> void *;
|
||||
#endif
|
||||
|
||||
[[nodiscard]] virtual auto mkdir_impl(std::string /*api_path*/,
|
||||
mode_t /*mode*/) -> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error opendir_impl(std::string /*api_path*/, struct fuse_file_info * /*fi*/) {
|
||||
[[nodiscard]] virtual auto open_impl(std::string /*api_path*/,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error read_impl(std::string /*api_path*/, char * /*buffer*/, size_t /*read_size*/,
|
||||
off_t /*read_offset*/, struct fuse_file_info * /*fi*/,
|
||||
std::size_t & /*bytes_read*/) {
|
||||
[[nodiscard]] virtual auto opendir_impl(std::string /*api_path*/,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error readdir_impl(std::string /*api_path*/, void * /*buf*/,
|
||||
fuse_fill_dir_t /*fuse_fill_dir*/, off_t /*offset*/,
|
||||
struct fuse_file_info * /*fi*/) {
|
||||
[[nodiscard]] virtual auto
|
||||
read_impl(std::string /*api_path*/, char * /*buffer*/, size_t /*read_size*/,
|
||||
off_t /*read_offset*/, struct fuse_file_info * /*fi*/,
|
||||
std::size_t & /*bytes_read*/) -> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error release_impl(std::string /*api_path*/, struct fuse_file_info * /*fi*/) {
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] virtual auto
|
||||
readdir_impl(std::string /*api_path*/, void * /*buf*/,
|
||||
fuse_fill_dir_t /*fuse_fill_dir*/, off_t /*offset*/,
|
||||
struct fuse_file_info * /*fi*/, fuse_readdir_flags /*flags*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#else
|
||||
[[nodiscard]] virtual auto
|
||||
readdir_impl(std::string /*api_path*/, void * /*buf*/,
|
||||
fuse_fill_dir_t /*fuse_fill_dir*/, off_t /*offset*/,
|
||||
struct fuse_file_info * /*fi*/) -> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif
|
||||
|
||||
[[nodiscard]] virtual auto release_impl(std::string /*api_path*/,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error releasedir_impl(std::string /*api_path*/, struct fuse_file_info * /*fi*/) {
|
||||
[[nodiscard]] virtual auto releasedir_impl(std::string /*api_path*/,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error rename_impl(std::string /*from_api_path*/, std::string /*to_api_path*/) {
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] virtual auto rename_impl(std::string /*from_api_path*/,
|
||||
std::string /*to_api_path*/,
|
||||
unsigned int /*flags*/) -> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#else
|
||||
[[nodiscard]] virtual auto rename_impl(std::string /*from_api_path*/,
|
||||
std::string /*to_api_path*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual api_error rmdir_impl(std::string /*api_path*/) { return api_error::not_implemented; }
|
||||
[[nodiscard]] virtual auto rmdir_impl(std::string /*api_path*/) -> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
#ifdef HAS_SETXATTR
|
||||
#ifdef __APPLE__
|
||||
virtual api_error getxattr_impl(std::string /*api_path*/, const char * /*name*/, char * /*value*/,
|
||||
size_t /*size*/, uint32_t /*position*/,
|
||||
int & /*attribute_size*/) {
|
||||
[[nodiscard]] virtual auto
|
||||
getxattr_impl(std::string /*api_path*/, const char * /*name*/,
|
||||
char * /*value*/, size_t /*size*/, uint32_t /*position*/,
|
||||
int & /*attribute_size*/) -> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#else // __APPLE__
|
||||
virtual api_error getxattr_impl(std::string /*api_path*/, const char * /*name*/, char * /*value*/,
|
||||
size_t /*size*/, int & /*attribute_size*/) {
|
||||
[[nodiscard]] virtual auto
|
||||
getxattr_impl(std::string /*api_path*/, const char * /*name*/,
|
||||
char * /*value*/, size_t /*size*/, int & /*attribute_size*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif // __APPLE__
|
||||
|
||||
virtual api_error listxattr_impl(std::string /*api_path*/, char * /*buffer*/, size_t /*size*/,
|
||||
int & /*required_size*/, bool & /*return_size*/) {
|
||||
[[nodiscard]] virtual auto
|
||||
listxattr_impl(std::string /*api_path*/, char * /*buffer*/, size_t /*size*/,
|
||||
int & /*required_size*/, bool & /*return_size*/) -> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error removexattr_impl(std::string /*api_path*/, const char * /*name*/) {
|
||||
[[nodiscard]] virtual auto removexattr_impl(std::string /*api_path*/,
|
||||
const char * /*name*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
virtual api_error setxattr_impl(std::string /*api_path*/, const char * /*name*/,
|
||||
const char * /*value*/, size_t /*size*/, int /*flags*/,
|
||||
uint32_t /*position*/) {
|
||||
[[nodiscard]] virtual auto setxattr_impl(std::string /*api_path*/,
|
||||
const char * /*name*/,
|
||||
const char * /*value*/,
|
||||
size_t /*size*/, int /*flags*/,
|
||||
uint32_t /*position*/) -> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#else // __APPLE__
|
||||
virtual api_error setxattr_impl(std::string /*api_path*/, const char * /*name*/,
|
||||
const char * /*value*/, size_t /*size*/, int /*flags*/) {
|
||||
[[nodiscard]] virtual auto
|
||||
setxattr_impl(std::string /*api_path*/, const char * /*name*/,
|
||||
const char * /*value*/, size_t /*size*/, int /*flags*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif // __APPLE__
|
||||
#endif // HAS_SETXATTR
|
||||
|
||||
#ifdef __APPLE__
|
||||
virtual api_error setattr_x_impl(std::string /*api_path*/, struct setattr_x * /*attr*/) {
|
||||
[[nodiscard]] virtual auto setattr_x_impl(std::string /*api_path*/,
|
||||
struct setattr_x * /*attr*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error setbkuptime_impl(std::string /*api_path*/,
|
||||
const struct timespec * /*bkuptime*/) {
|
||||
[[nodiscard]] virtual auto
|
||||
setbkuptime_impl(std::string /*api_path*/,
|
||||
const struct timespec * /*bkuptime*/) -> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error setchgtime_impl(std::string /*api_path*/, const struct timespec * /*chgtime*/) {
|
||||
[[nodiscard]] virtual auto
|
||||
setchgtime_impl(std::string /*api_path*/, const struct timespec * /*chgtime*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error setcrtime_impl(std::string /*api_path*/, const struct timespec * /*crtime*/) {
|
||||
[[nodiscard]] virtual auto setcrtime_impl(std::string /*api_path*/,
|
||||
const struct timespec * /*crtime*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error setvolname_impl(const char * /*volname*/) { return api_error::not_implemented; }
|
||||
[[nodiscard]] virtual auto setvolname_impl(const char * /*volname*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error statfs_x_impl(std::string /*api_path*/, struct statfs * /*stbuf*/) {
|
||||
[[nodiscard]] virtual auto statfs_x_impl(std::string /*api_path*/,
|
||||
struct statfs * /*stbuf*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#else // __APPLE__
|
||||
virtual api_error statfs_impl(std::string /*api_path*/, struct statvfs * /*stbuf*/) {
|
||||
[[nodiscard]] virtual auto statfs_impl(std::string /*api_path*/,
|
||||
struct statvfs * /*stbuf*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif // __APPLE__
|
||||
|
||||
virtual api_error truncate_impl(std::string /*api_path*/, off_t /*size*/) {
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] virtual auto truncate_impl(std::string /*api_path*/,
|
||||
off_t /*size*/,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#else
|
||||
[[nodiscard]] virtual auto truncate_impl(std::string /*api_path*/,
|
||||
off_t /*size*/) -> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif
|
||||
|
||||
[[nodiscard]] virtual auto unlink_impl(std::string /*api_path*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error unlink_impl(std::string /*api_path*/) { return api_error::not_implemented; }
|
||||
|
||||
virtual api_error utimens_impl(std::string /*api_path*/, const struct timespec /*tv*/[2]) {
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] virtual auto utimens_impl(std::string /*api_path*/,
|
||||
const struct timespec /*tv*/[2],
|
||||
struct fuse_file_info * /*fi*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#else
|
||||
[[nodiscard]] virtual auto utimens_impl(std::string /*api_path*/,
|
||||
const struct timespec /*tv*/[2])
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual api_error write_impl(std::string /*api_path*/, const char * /*buffer*/,
|
||||
size_t /*write_size*/, off_t /*write_offset*/,
|
||||
struct fuse_file_info * /*fi*/, std::size_t & /*bytes_written*/) {
|
||||
[[nodiscard]] virtual auto
|
||||
write_impl(std::string /*api_path*/, const char * /*buffer*/,
|
||||
size_t /*write_size*/, off_t /*write_offset*/,
|
||||
struct fuse_file_info * /*fi*/, std::size_t & /*bytes_written*/)
|
||||
-> api_error {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void notify_fuse_args_parsed(const std::vector<std::string> & /*args*/) {}
|
||||
virtual void notify_fuse_args_parsed(const std::vector<std::string> &args);
|
||||
|
||||
virtual void notify_fuse_main_exit(int & /*ret*/) {}
|
||||
|
||||
virtual int parse_args(std::vector<std::string> &args);
|
||||
[[nodiscard]] virtual auto parse_args(std::vector<std::string> &args) -> int;
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error parse_xattr_parameters(const char *name, const uint32_t &position,
|
||||
std::string &attribute_name, const std::string &api_path);
|
||||
#else
|
||||
api_error parse_xattr_parameters(const char *name, std::string &attribute_name,
|
||||
const std::string &api_path);
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error parse_xattr_parameters(const char *name, const char *value, size_t size,
|
||||
const uint32_t &position, std::string &attribute_name,
|
||||
const std::string &api_path);
|
||||
#else
|
||||
api_error parse_xattr_parameters(const char *name, const char *value, size_t size,
|
||||
std::string &attribute_name, const std::string &api_path);
|
||||
#endif
|
||||
|
||||
virtual int shutdown();
|
||||
virtual void shutdown();
|
||||
|
||||
public:
|
||||
static void display_options(int argc, char *argv[]);
|
||||
|
||||
static void display_version_information(int argc, char *argv[]);
|
||||
|
||||
api_error check_parent_access(const std::string &api_path, int mask) const override;
|
||||
static auto unmount(const std::string &mount_location) -> int;
|
||||
|
||||
std::string get_mount_location() const { return mount_location_; }
|
||||
[[nodiscard]] auto get_mount_location() const -> std::string {
|
||||
return mount_location_;
|
||||
}
|
||||
|
||||
int mount(std::vector<std::string> args);
|
||||
[[nodiscard]] auto mount(std::vector<std::string> args) -> int;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -1,35 +1,36 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_FUSE_DRIVE_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_FUSE_DRIVE_HPP_
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "drives/fuse/fuse_base.hpp"
|
||||
#include "drives/open_file_table.hpp"
|
||||
#include "drives/fuse/fuse_drive_base.hpp"
|
||||
#include "file_manager/file_manager.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_provider;
|
||||
class app_config;
|
||||
class console_consumer;
|
||||
class directory_cache;
|
||||
class download_manager;
|
||||
class eviction;
|
||||
class full_server;
|
||||
class lock_data;
|
||||
@ -38,7 +39,7 @@ namespace remote_fuse {
|
||||
class remote_server;
|
||||
}
|
||||
|
||||
class fuse_drive final : public fuse_base {
|
||||
class fuse_drive final : public fuse_drive_base {
|
||||
public:
|
||||
fuse_drive(app_config &config, lock_data &lock_data, i_provider &provider);
|
||||
|
||||
@ -50,166 +51,276 @@ private:
|
||||
|
||||
std::shared_ptr<console_consumer> console_consumer_;
|
||||
std::shared_ptr<directory_cache> directory_cache_;
|
||||
std::shared_ptr<download_manager> download_manager_;
|
||||
std::shared_ptr<eviction> eviction_;
|
||||
std::shared_ptr<file_manager> fm_;
|
||||
std::shared_ptr<logging_consumer> logging_consumer_;
|
||||
std::shared_ptr<open_file_table<open_file_data>> oft_;
|
||||
std::shared_ptr<remote_fuse::remote_server> remote_server_;
|
||||
std::shared_ptr<full_server> server_;
|
||||
bool was_mounted_ = false;
|
||||
|
||||
private:
|
||||
void update_accessed_time(const std::string &api_path);
|
||||
|
||||
protected:
|
||||
#ifdef __APPLE__
|
||||
api_error chflags_impl(std::string api_path, uint32_t flags) override;
|
||||
[[nodiscard]] auto chflags_impl(std::string api_path, uint32_t flags)
|
||||
-> api_error override;
|
||||
#endif // __APPLE__
|
||||
|
||||
api_error chmod_impl(std::string api_path, mode_t mode) override;
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] auto chmod_impl(std::string api_path, mode_t mode,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#else
|
||||
[[nodiscard]] auto chmod_impl(std::string api_path, mode_t mode)
|
||||
-> api_error override;
|
||||
#endif
|
||||
|
||||
api_error chown_impl(std::string api_path, uid_t uid, gid_t gid) override;
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] auto chown_impl(std::string api_path, uid_t uid, gid_t gid,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#else
|
||||
[[nodiscard]] auto chown_impl(std::string api_path, uid_t uid, gid_t gid)
|
||||
-> api_error override;
|
||||
#endif
|
||||
|
||||
api_error create_impl(std::string api_path, mode_t mode, struct fuse_file_info *fi) override;
|
||||
[[nodiscard]] auto create_impl(std::string api_path, mode_t mode,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
|
||||
void destroy_impl(void *ptr) override;
|
||||
|
||||
api_error fallocate_impl(std::string api_path, int mode, off_t offset, off_t length,
|
||||
struct fuse_file_info *fi) override;
|
||||
[[nodiscard]] auto fallocate_impl(std::string api_path, int mode,
|
||||
off_t offset, off_t length,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
|
||||
api_error fgetattr_impl(std::string api_path, struct stat *st,
|
||||
struct fuse_file_info *fi) override;
|
||||
[[nodiscard]] auto fgetattr_impl(std::string api_path, struct stat *st,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error fsetattr_x_impl(std::string api_path, struct setattr_x *attr,
|
||||
struct fuse_file_info *fi) override;
|
||||
[[nodiscard]] auto fsetattr_x_impl(std::string api_path,
|
||||
struct setattr_x *attr,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#endif // __APPLE__
|
||||
|
||||
api_error fsync_impl(std::string api_path, int datasync, struct fuse_file_info *fi) override;
|
||||
[[nodiscard]] auto fsync_impl(std::string api_path, int datasync,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
|
||||
api_error ftruncate_impl(std::string api_path, off_t size, struct fuse_file_info *fi) override;
|
||||
#if FUSE_USE_VERSION < 30
|
||||
[[nodiscard]] auto ftruncate_impl(std::string api_path, off_t size,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#endif
|
||||
|
||||
api_error getattr_impl(std::string api_path, struct stat *st) override;
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] auto getattr_impl(std::string api_path, struct stat *st,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#else
|
||||
[[nodiscard]] auto getattr_impl(std::string api_path, struct stat *st)
|
||||
-> api_error override;
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error getxtimes_impl(std::string api_path, struct timespec *bkuptime,
|
||||
struct timespec *crtime) override;
|
||||
[[nodiscard]] auto getxtimes_impl(std::string api_path,
|
||||
struct timespec *bkuptime,
|
||||
struct timespec *crtime)
|
||||
-> api_error override;
|
||||
#endif // __APPLE__
|
||||
|
||||
void *init_impl(struct fuse_conn_info *conn) override;
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto init_impl(struct fuse_conn_info *conn, struct fuse_config *cfg)
|
||||
-> void * override;
|
||||
#else
|
||||
auto init_impl(struct fuse_conn_info *conn) -> void * override;
|
||||
#endif
|
||||
|
||||
api_error mkdir_impl(std::string api_path, mode_t mode) override;
|
||||
[[nodiscard]] auto mkdir_impl(std::string api_path, mode_t mode)
|
||||
-> api_error override;
|
||||
|
||||
api_error open_impl(std::string api_path, struct fuse_file_info *fi) override;
|
||||
void notify_fuse_main_exit(int &ret) override;
|
||||
|
||||
api_error opendir_impl(std::string api_path, struct fuse_file_info *fi) override;
|
||||
[[nodiscard]] auto open_impl(std::string api_path, struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
|
||||
api_error read_impl(std::string api_path, char *buffer, size_t read_size, off_t read_offset,
|
||||
struct fuse_file_info *fi, std::size_t &bytes_read) override;
|
||||
[[nodiscard]] auto opendir_impl(std::string api_path,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
|
||||
api_error readdir_impl(std::string api_path, void *buf, fuse_fill_dir_t fuse_fill_dir,
|
||||
off_t offset, struct fuse_file_info *fi) override;
|
||||
[[nodiscard]] auto read_impl(std::string api_path, char *buffer,
|
||||
size_t read_size, off_t read_offset,
|
||||
struct fuse_file_info *fi,
|
||||
std::size_t &bytes_read) -> api_error override;
|
||||
|
||||
api_error release_impl(std::string api_path, struct fuse_file_info *fi) override;
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] auto readdir_impl(std::string api_path, void *buf,
|
||||
fuse_fill_dir_t fuse_fill_dir, off_t offset,
|
||||
struct fuse_file_info *fi,
|
||||
fuse_readdir_flags flags)
|
||||
-> api_error override;
|
||||
#else
|
||||
[[nodiscard]] auto readdir_impl(std::string api_path, void *buf,
|
||||
fuse_fill_dir_t fuse_fill_dir, off_t offset,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#endif
|
||||
|
||||
api_error releasedir_impl(std::string api_path, struct fuse_file_info *fi) override;
|
||||
[[nodiscard]] auto release_impl(std::string api_path,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
|
||||
api_error rename_impl(std::string from_api_path, std::string to_api_path) override;
|
||||
[[nodiscard]] auto releasedir_impl(std::string api_path,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
|
||||
api_error rmdir_impl(std::string api_path) override;
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] auto rename_impl(std::string from_api_path,
|
||||
std::string to_api_path, unsigned int flags)
|
||||
-> api_error override;
|
||||
#else
|
||||
[[nodiscard]] auto rename_impl(std::string from_api_path,
|
||||
std::string to_api_path) -> api_error override;
|
||||
#endif
|
||||
|
||||
[[nodiscard]] auto rmdir_impl(std::string api_path) -> api_error override;
|
||||
|
||||
#ifdef HAS_SETXATTR
|
||||
api_error getxattr_common(std::string api_path, const char *name, char *value, size_t size,
|
||||
int &attribute_size, uint32_t *position);
|
||||
[[nodiscard]] auto getxattr_common(std::string api_path, const char *name,
|
||||
char *value, size_t size,
|
||||
int &attribute_size, uint32_t *position)
|
||||
-> api_error;
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error getxattr_impl(std::string api_path, const char *name, char *value, size_t size,
|
||||
uint32_t position, int &attribute_size) override;
|
||||
[[nodiscard]] auto getxattr_impl(std::string api_path, const char *name,
|
||||
char *value, size_t size,
|
||||
[[nodiscard]] uint32_t position,
|
||||
int &attribute_size) -> api_error override;
|
||||
#else // __APPLE__
|
||||
api_error getxattr_impl(std::string api_path, const char *name, char *value, size_t size,
|
||||
int &attribute_size) override;
|
||||
[[nodiscard]] auto getxattr_impl(std::string api_path, const char *name,
|
||||
char *value, size_t size,
|
||||
int &attribute_size) -> api_error override;
|
||||
#endif // __APPLE__
|
||||
|
||||
api_error listxattr_impl(std::string api_path, char *buffer, size_t size, int &required_size,
|
||||
bool &return_size) override;
|
||||
[[nodiscard]] auto listxattr_impl(std::string api_path, char *buffer,
|
||||
size_t size, int &required_size,
|
||||
bool &return_size) -> api_error override;
|
||||
|
||||
api_error removexattr_impl(std::string api_path, const char *name) override;
|
||||
[[nodiscard]] auto removexattr_impl(std::string api_path, const char *name)
|
||||
-> api_error override;
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error setxattr_impl(std::string api_path, const char *name, const char *value, size_t size,
|
||||
int flags, uint32_t position) override;
|
||||
[[nodiscard]] auto setxattr_impl(std::string api_path, const char *name,
|
||||
const char *value, size_t size, int flags,
|
||||
uint32_t position) -> api_error override;
|
||||
#else // __APPLE__
|
||||
api_error setxattr_impl(std::string api_path, const char *name, const char *value, size_t size,
|
||||
int flags) override;
|
||||
[[nodiscard]] auto setxattr_impl(std::string api_path, const char *name,
|
||||
const char *value, size_t size, int flags)
|
||||
-> api_error override;
|
||||
#endif // __APPLE__
|
||||
#endif // HAS_SETXATTR
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error setattr_x_impl(std::string api_path, struct setattr_x *attr) override;
|
||||
[[nodiscard]] auto setattr_x_impl(std::string api_path,
|
||||
struct setattr_x *attr)
|
||||
-> api_error override;
|
||||
|
||||
api_error setbkuptime_impl(std::string api_path, const struct timespec *bkuptime) override;
|
||||
[[nodiscard]] auto setbkuptime_impl(std::string api_path,
|
||||
const struct timespec *bkuptime)
|
||||
-> api_error override;
|
||||
|
||||
api_error setchgtime_impl(std::string api_path, const struct timespec *chgtime) override;
|
||||
[[nodiscard]] auto setchgtime_impl(std::string api_path,
|
||||
const struct timespec *chgtime)
|
||||
-> api_error override;
|
||||
|
||||
api_error setcrtime_impl(std::string api_path, const struct timespec *crtime) override;
|
||||
[[nodiscard]] auto setcrtime_impl(std::string api_path,
|
||||
const struct timespec *crtime)
|
||||
-> api_error override;
|
||||
|
||||
api_error setvolname_impl(const char *volname) override;
|
||||
[[nodiscard]] auto setvolname_impl(const char *volname) -> api_error override;
|
||||
|
||||
api_error statfs_x_impl(std::string api_path, struct statfs *stbuf) override;
|
||||
[[nodiscard]] auto statfs_x_impl(std::string api_path, struct statfs *stbuf)
|
||||
-> api_error override;
|
||||
#else // __APPLE__
|
||||
api_error statfs_impl(std::string api_path, struct statvfs *stbuf) override;
|
||||
[[nodiscard]] auto statfs_impl(std::string api_path, struct statvfs *stbuf)
|
||||
-> api_error override;
|
||||
#endif // __APPLE__
|
||||
|
||||
api_error truncate_impl(std::string api_path, off_t size) override;
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] auto truncate_impl(std::string api_path, off_t size,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#else
|
||||
[[nodiscard]] auto truncate_impl(std::string api_path, off_t size)
|
||||
-> api_error override;
|
||||
#endif
|
||||
|
||||
api_error unlink_impl(std::string api_path) override;
|
||||
[[nodiscard]] auto unlink_impl(std::string api_path) -> api_error override;
|
||||
|
||||
api_error utimens_impl(std::string api_path, const struct timespec tv[2]) override;
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] auto utimens_impl(std::string api_path,
|
||||
const struct timespec tv[2],
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#else
|
||||
[[nodiscard]] auto utimens_impl(std::string api_path,
|
||||
const struct timespec tv[2])
|
||||
-> api_error override;
|
||||
#endif
|
||||
|
||||
api_error write_impl(std::string api_path, const char *buffer, size_t write_size,
|
||||
off_t write_offset, struct fuse_file_info *fi,
|
||||
std::size_t &bytes_written) override;
|
||||
|
||||
protected:
|
||||
void notify_fuse_args_parsed(const std::vector<std::string> &args) override;
|
||||
|
||||
void notify_fuse_main_exit(int &ret) override;
|
||||
|
||||
int shutdown() override;
|
||||
|
||||
void update_accessed_time(const std::string &api_path);
|
||||
[[nodiscard]] auto write_impl(std::string api_path, const char *buffer,
|
||||
size_t write_size, off_t write_offset,
|
||||
struct fuse_file_info *fi,
|
||||
std::size_t &bytes_written)
|
||||
-> api_error override;
|
||||
|
||||
public:
|
||||
std::uint64_t get_directory_item_count(const std::string &api_path) const override;
|
||||
[[nodiscard]] auto get_directory_item_count(const std::string &api_path) const
|
||||
-> std::uint64_t override;
|
||||
|
||||
directory_item_list get_directory_items(const std::string &api_path) const override;
|
||||
[[nodiscard]] auto get_directory_items(const std::string &api_path) const
|
||||
-> directory_item_list override;
|
||||
|
||||
std::uint64_t get_file_size(const std::string &api_path) const override;
|
||||
[[nodiscard]] auto get_file_size(const std::string &api_path) const
|
||||
-> std::uint64_t override;
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, api_meta_map &meta) const override;
|
||||
[[nodiscard]] auto get_item_meta(const std::string &api_path,
|
||||
api_meta_map &meta) const
|
||||
-> api_error override;
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, const std::string &name,
|
||||
std::string &value) const override;
|
||||
[[nodiscard]] auto get_item_meta(const std::string &api_path,
|
||||
const std::string &name,
|
||||
std::string &value) const
|
||||
-> api_error override;
|
||||
|
||||
std::uint64_t get_total_drive_space() const override;
|
||||
[[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override;
|
||||
|
||||
std::uint64_t get_total_item_count() const override;
|
||||
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t override;
|
||||
|
||||
std::uint64_t get_used_drive_space() const override;
|
||||
[[nodiscard]] auto get_used_drive_space() const -> std::uint64_t override;
|
||||
|
||||
void get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label) const override;
|
||||
|
||||
bool is_processing(const std::string &api_path) const override;
|
||||
[[nodiscard]] auto is_processing(const std::string &api_path) const
|
||||
-> bool override;
|
||||
|
||||
void populate_stat(const directory_item &di, struct stat &st) const override;
|
||||
|
||||
int rename_directory(const std::string &from_api_path, const std::string &to_api_path) override;
|
||||
[[nodiscard]] auto rename_directory(const std::string &from_api_path,
|
||||
const std::string &to_api_path)
|
||||
-> int override;
|
||||
|
||||
int rename_file(const std::string &from_api_path, const std::string &to_api_path,
|
||||
const bool &overwrite) override;
|
||||
[[nodiscard]] auto rename_file(const std::string &from_api_path,
|
||||
const std::string &to_api_path, bool overwrite)
|
||||
-> int override;
|
||||
|
||||
void set_item_meta(const std::string &api_path, const std::string &key,
|
||||
const std::string &value) override;
|
||||
|
||||
void update_directory_item(directory_item &di) const override;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
137
include/drives/fuse/fuse_drive_base.hpp
Normal file
137
include/drives/fuse/fuse_drive_base.hpp
Normal file
@ -0,0 +1,137 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_FUSE_DRIVE_BASE_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_FUSE_DRIVE_BASE_HPP_
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "drives/fuse/fuse_base.hpp"
|
||||
#include "drives/fuse/i_fuse_drive.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
class i_provider;
|
||||
|
||||
class fuse_drive_base : public fuse_base, public i_fuse_drive {
|
||||
public:
|
||||
explicit fuse_drive_base(app_config &config) : fuse_base(config) {}
|
||||
|
||||
~fuse_drive_base() override = default;
|
||||
|
||||
protected:
|
||||
[[nodiscard]] auto access_impl(std::string api_path, int mask)
|
||||
-> api_error override;
|
||||
|
||||
protected:
|
||||
[[nodiscard]] auto check_access(const std::string &api_path, int mask) const
|
||||
-> api_error;
|
||||
|
||||
[[nodiscard]] auto
|
||||
check_and_perform(const std::string &api_path, int parent_mask,
|
||||
const std::function<api_error(api_meta_map &meta)> &action)
|
||||
-> api_error;
|
||||
|
||||
[[nodiscard]] auto get_current_gid() const -> gid_t;
|
||||
|
||||
[[nodiscard]] auto get_current_uid() const -> uid_t;
|
||||
|
||||
[[nodiscard]] auto get_effective_gid() const -> gid_t;
|
||||
|
||||
[[nodiscard]] auto get_effective_uid() const -> uid_t;
|
||||
|
||||
[[nodiscard]] static auto check_open_flags(int flags, int mask,
|
||||
const api_error &fail_error)
|
||||
-> api_error;
|
||||
|
||||
[[nodiscard]] auto check_owner(const api_meta_map &meta) const -> api_error;
|
||||
|
||||
[[nodiscard]] static auto check_readable(int flags,
|
||||
const api_error &fail_error)
|
||||
-> api_error;
|
||||
|
||||
[[nodiscard]] static auto check_writeable(int flags,
|
||||
const api_error &fail_error)
|
||||
-> api_error;
|
||||
|
||||
#ifdef __APPLE__
|
||||
[[nodiscard]] static auto get_flags_from_meta(const api_meta_map &meta)
|
||||
-> __uint32_t;
|
||||
#endif // __APPLE__
|
||||
|
||||
[[nodiscard]] static auto get_gid_from_meta(const api_meta_map &meta)
|
||||
-> gid_t;
|
||||
|
||||
[[nodiscard]] static auto get_mode_from_meta(const api_meta_map &meta)
|
||||
-> mode_t;
|
||||
|
||||
static void get_timespec_from_meta(const api_meta_map &meta,
|
||||
const std::string &name,
|
||||
struct timespec &ts);
|
||||
|
||||
[[nodiscard]] static auto get_uid_from_meta(const api_meta_map &meta)
|
||||
-> uid_t;
|
||||
|
||||
#ifdef __APPLE__
|
||||
[[nodiscard]] auto parse_xattr_parameters(const char *name,
|
||||
const uint32_t &position,
|
||||
std::string &attribute_name,
|
||||
const std::string &api_path)
|
||||
-> api_error;
|
||||
#else
|
||||
[[nodiscard]] auto parse_xattr_parameters(const char *name,
|
||||
std::string &attribute_name,
|
||||
const std::string &api_path)
|
||||
-> api_error;
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
[[nodiscard]] auto
|
||||
parse_xattr_parameters(const char *name, const char *value, size_t size,
|
||||
const uint32_t &position, std::string &attribute_name,
|
||||
const std::string &api_path) -> api_error;
|
||||
#else
|
||||
[[nodiscard]] auto parse_xattr_parameters(const char *name, const char *value,
|
||||
size_t size,
|
||||
std::string &attribute_name,
|
||||
const std::string &api_path)
|
||||
-> api_error;
|
||||
#endif
|
||||
|
||||
static void populate_stat(const std::string &api_path,
|
||||
std::uint64_t size_or_count,
|
||||
const api_meta_map &meta, bool directory,
|
||||
i_provider &provider, struct stat *st);
|
||||
|
||||
static void set_timespec_from_meta(const api_meta_map &meta,
|
||||
const std::string &name,
|
||||
struct timespec &ts);
|
||||
|
||||
public:
|
||||
[[nodiscard]] auto check_owner(const std::string &api_path) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto check_parent_access(const std::string &api_path,
|
||||
int mask) const -> api_error override;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // _WIN32
|
||||
#endif // INCLUDE_DRIVES_FUSE_FUSE_DRIVE_BASE_HPP_
|
@ -1,26 +1,28 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_I_FUSE_DRIVE_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_I_FUSE_DRIVE_HPP_
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
@ -28,42 +30,59 @@ class i_fuse_drive {
|
||||
INTERFACE_SETUP(i_fuse_drive);
|
||||
|
||||
public:
|
||||
virtual api_error check_parent_access(const std::string &api_path, int mask) const = 0;
|
||||
[[nodiscard]] virtual auto check_owner(const std::string &api_path) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual std::uint64_t get_directory_item_count(const std::string &api_path) const = 0;
|
||||
[[nodiscard]] virtual auto check_parent_access(const std::string &api_path,
|
||||
int mask) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual directory_item_list get_directory_items(const std::string &api_path) const = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_directory_item_count(const std::string &api_path) const
|
||||
-> std::uint64_t = 0;
|
||||
|
||||
virtual std::uint64_t get_file_size(const std::string &api_path) const = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_directory_items(const std::string &api_path) const
|
||||
-> directory_item_list = 0;
|
||||
|
||||
virtual api_error get_item_meta(const std::string &api_path, api_meta_map &meta) const = 0;
|
||||
[[nodiscard]] virtual auto get_file_size(const std::string &api_path) const
|
||||
-> std::uint64_t = 0;
|
||||
|
||||
virtual api_error get_item_meta(const std::string &api_path, const std::string &name,
|
||||
std::string &value) const = 0;
|
||||
[[nodiscard]] virtual auto get_item_meta(const std::string &api_path,
|
||||
api_meta_map &meta) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual std::uint64_t get_total_drive_space() const = 0;
|
||||
[[nodiscard]] virtual auto get_item_meta(const std::string &api_path,
|
||||
const std::string &name,
|
||||
std::string &value) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual std::uint64_t get_total_item_count() const = 0;
|
||||
[[nodiscard]] virtual auto get_total_drive_space() const -> std::uint64_t = 0;
|
||||
|
||||
virtual std::uint64_t get_used_drive_space() const = 0;
|
||||
[[nodiscard]] virtual auto get_total_item_count() const -> std::uint64_t = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_used_drive_space() const -> std::uint64_t = 0;
|
||||
|
||||
virtual void get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label) const = 0;
|
||||
|
||||
virtual bool is_processing(const std::string &api_path) const = 0;
|
||||
[[nodiscard]] virtual auto is_processing(const std::string &api_path) const
|
||||
-> bool = 0;
|
||||
|
||||
virtual void populate_stat(const directory_item &di, struct stat &st) const = 0;
|
||||
virtual void populate_stat(const directory_item &di,
|
||||
struct stat &st) const = 0;
|
||||
|
||||
virtual int rename_directory(const std::string &from_api_path,
|
||||
const std::string &to_api_path) = 0;
|
||||
[[nodiscard]] virtual auto rename_directory(const std::string &from_api_path,
|
||||
const std::string &to_api_path)
|
||||
-> int = 0;
|
||||
|
||||
virtual int rename_file(const std::string &from_api_path, const std::string &to_api_path,
|
||||
const bool &overwrite) = 0;
|
||||
[[nodiscard]] virtual auto rename_file(const std::string &from_api_path,
|
||||
const std::string &to_api_path,
|
||||
bool overwrite) -> int = 0;
|
||||
|
||||
virtual void set_item_meta(const std::string &api_path, const std::string &key,
|
||||
virtual void set_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
const std::string &value) = 0;
|
||||
|
||||
virtual void update_directory_item(directory_item &di) const = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_REMOTEFUSE_I_REMOTE_INSTANCE_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_REMOTEFUSE_I_REMOTE_INSTANCE_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "drives/remote/i_remote_json.hpp"
|
||||
#include "types/remote.hpp"
|
||||
|
||||
@ -28,124 +30,179 @@ class i_remote_instance : public virtual i_remote_json {
|
||||
INTERFACE_SETUP(i_remote_instance);
|
||||
|
||||
public:
|
||||
virtual packet::error_type fuse_access(const char *path, const std::int32_t &mask) = 0;
|
||||
[[nodiscard]] virtual auto fuse_access(const char *path,
|
||||
const std::int32_t &mask)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_chflags(const char *path, const std::uint32_t &flags) = 0;
|
||||
[[nodiscard]] virtual auto fuse_chflags(const char *path, std::uint32_t flags)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_chmod(const char *path, const remote::file_mode &mode) = 0;
|
||||
[[nodiscard]] virtual auto fuse_chmod(const char *path,
|
||||
const remote::file_mode &mode)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_chown(const char *path, const remote::user_id &uid,
|
||||
const remote::group_id &gid) = 0;
|
||||
[[nodiscard]] virtual auto fuse_chown(const char *path,
|
||||
const remote::user_id &uid,
|
||||
const remote::group_id &gid)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_create(const char *path, const remote::file_mode &mode,
|
||||
const remote::open_flags &flags,
|
||||
remote::file_handle &handle) = 0;
|
||||
virtual packet::error_type fuse_destroy() = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
fuse_create(const char *path, const remote::file_mode &mode,
|
||||
const remote::open_flags &flags, remote::file_handle &handle)
|
||||
-> packet::error_type = 0;
|
||||
[[nodiscard]] virtual auto fuse_destroy() -> packet::error_type = 0;
|
||||
|
||||
/*virtual packet::error_type fuse_fallocate(const char *path, const std::int32_t &mode,
|
||||
const remote::file_offset &offset,
|
||||
const remote::file_offset &length,
|
||||
const remote::file_offset &length,
|
||||
const remote::file_handle &handle) = 0;*/
|
||||
/*[[nodiscard]] virtual packet::error_type fuse_fallocate(const char *path,
|
||||
const std::int32_t &mode, const remote::file_offset &offset, const
|
||||
remote::file_offset &length, const remote::file_offset &length, const
|
||||
remote::file_handle &handle) = 0;*/
|
||||
|
||||
virtual packet::error_type fuse_fgetattr(const char *path, remote::stat &st, bool &directory,
|
||||
const remote::file_handle &handle) = 0;
|
||||
[[nodiscard]] virtual auto fuse_fgetattr(const char *path, remote::stat &st,
|
||||
bool &directory,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_fsetattr_x(const char *path, const remote::setattr_x &attr,
|
||||
const remote::file_handle &handle) = 0;
|
||||
[[nodiscard]] virtual auto fuse_fsetattr_x(const char *path,
|
||||
const remote::setattr_x &attr,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_fsync(const char *path, const std::int32_t &datasync,
|
||||
const remote::file_handle &handle) = 0;
|
||||
[[nodiscard]] virtual auto fuse_fsync(const char *path,
|
||||
const std::int32_t &datasync,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_ftruncate(const char *path, const remote::file_offset &size,
|
||||
const remote::file_handle &handle) = 0;
|
||||
[[nodiscard]] virtual auto fuse_ftruncate(const char *path,
|
||||
const remote::file_offset &size,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_getattr(const char *path, remote::stat &st, bool &directory) = 0;
|
||||
[[nodiscard]] virtual auto fuse_getattr(const char *path, remote::stat &st,
|
||||
bool &directory)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
/*virtual packet::error_type fuse_getxattr(const char *path, const char *name, char *value,
|
||||
const remote::file_size &size) = 0;
|
||||
/*[[nodiscard]] virtual packet::error_type fuse_getxattr(const char *path,
|
||||
const char *name, char *value, const remote::file_size &size) = 0;
|
||||
|
||||
virtual packet::error_type fuse_getxattrOSX(const char *path, const char *name, char *value,
|
||||
const remote::file_size &size,
|
||||
const std::uint32_t &position) = 0;*/
|
||||
[[nodiscard]] virtual packet::error_type fuse_getxattrOSX(const char *path,
|
||||
const char *name, char *value, const remote::file_size &size, std::uint32_t
|
||||
position) = 0;*/
|
||||
|
||||
virtual packet::error_type fuse_getxtimes(const char *path, remote::file_time &bkuptime,
|
||||
remote::file_time &crtime) = 0;
|
||||
[[nodiscard]] virtual auto fuse_getxtimes(const char *path,
|
||||
remote::file_time &bkuptime,
|
||||
remote::file_time &crtime)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_init() = 0;
|
||||
[[nodiscard]] virtual auto fuse_init() -> packet::error_type = 0;
|
||||
|
||||
/*virtual packet::error_type fuse_listxattr(const char *path, char *buffer,
|
||||
const remote::file_size &size) = 0;*/
|
||||
[[nodiscard]] /*virtual packet::error_type fuse_listxattr(const char *path,
|
||||
char *buffer, const remote::file_size &size) = 0;*/
|
||||
|
||||
virtual packet::error_type fuse_mkdir(const char *path, const remote::file_mode &mode) = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
fuse_mkdir(const char *path, const remote::file_mode &mode)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_open(const char *path, const remote::open_flags &flags,
|
||||
remote::file_handle &handle) = 0;
|
||||
[[nodiscard]] virtual auto fuse_open(const char *path,
|
||||
const remote::open_flags &flags,
|
||||
remote::file_handle &handle)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_opendir(const char *path, remote::file_handle &handle) = 0;
|
||||
[[nodiscard]] virtual auto fuse_opendir(const char *path,
|
||||
remote::file_handle &handle)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_read(const char *path, char *buffer,
|
||||
[[nodiscard]] virtual auto fuse_read(const char *path, char *buffer,
|
||||
const remote::file_size &readSize,
|
||||
const remote::file_offset &readOffset,
|
||||
const remote::file_handle &handle) = 0;
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_readdir(const char *path, const remote::file_offset &offset,
|
||||
const remote::file_handle &handle, std::string &itemPath) = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
fuse_readdir(const char *path, const remote::file_offset &offset,
|
||||
const remote::file_handle &handle, std::string &itemPath)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_release(const char *path, const remote::file_handle &handle) = 0;
|
||||
[[nodiscard]] virtual auto fuse_release(const char *path,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_releasedir(const char *path, const remote::file_handle &handle) = 0;
|
||||
[[nodiscard]] virtual auto fuse_releasedir(const char *path,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
// virtual packet::error_type fuse_removexattr(const char *path, const char *name) = 0;
|
||||
//[[nodiscard]] virtual packet::error_type fuse_removexattr(const char *path,
|
||||
// const char *name) =
|
||||
// 0;
|
||||
|
||||
virtual packet::error_type fuse_rename(const char *from, const char *to) = 0;
|
||||
[[nodiscard]] virtual auto fuse_rename(const char *from, const char *to)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_rmdir(const char *path) = 0;
|
||||
[[nodiscard]] virtual auto fuse_rmdir(const char *path)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_setattr_x(const char *path, remote::setattr_x &attr) = 0;
|
||||
[[nodiscard]] virtual auto fuse_setattr_x(const char *path,
|
||||
remote::setattr_x &attr)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_setbkuptime(const char *path, const remote::file_time &bkuptime) = 0;
|
||||
[[nodiscard]] virtual auto fuse_setbkuptime(const char *path,
|
||||
const remote::file_time &bkuptime)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_setchgtime(const char *path, const remote::file_time &chgtime) = 0;
|
||||
[[nodiscard]] virtual auto fuse_setchgtime(const char *path,
|
||||
const remote::file_time &chgtime)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_setcrtime(const char *path, const remote::file_time &crtime) = 0;
|
||||
[[nodiscard]] virtual auto fuse_setcrtime(const char *path,
|
||||
const remote::file_time &crtime)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_setvolname(const char *volname) = 0;
|
||||
[[nodiscard]] virtual auto fuse_setvolname(const char *volname)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
/*virtual packet::error_type fuse_setxattr(const char *path, const char *name,
|
||||
const char *value, const remote::file_size &size,
|
||||
const std::int32_t &flags) = 0;
|
||||
virtual packet::error_type fuse_setxattr_osx(const char *path, const char *name,
|
||||
const char *value, const remote::file_size &size,
|
||||
const std::int32_t &flags,
|
||||
const std::uint32_t &position) = 0;*/
|
||||
/*[[nodiscard]] virtual packet::error_type fuse_setxattr(const char *path,
|
||||
const char *name, const char *value, const remote::file_size &size, const
|
||||
std::int32_t &flags) = 0;
|
||||
[[nodiscard]] virtual packet::error_type fuse_setxattr_osx(const char *path,
|
||||
const char *name, const char *value, const remote::file_size &size, const
|
||||
std::int32_t &flags, std::uint32_t position) = 0;*/
|
||||
|
||||
virtual packet::error_type fuse_statfs(const char *path, const std::uint64_t &frsize,
|
||||
remote::statfs &st) = 0;
|
||||
[[nodiscard]] virtual auto fuse_statfs(const char *path, std::uint64_t frsize,
|
||||
remote::statfs &st)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_statfs_x(const char *path, const std::uint64_t &bsize,
|
||||
remote::statfs_x &st) = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
fuse_statfs_x(const char *path, std::uint64_t bsize, remote::statfs_x &st)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_truncate(const char *path, const remote::file_offset &size) = 0;
|
||||
[[nodiscard]] virtual auto fuse_truncate(const char *path,
|
||||
const remote::file_offset &size)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_unlink(const char *path) = 0;
|
||||
[[nodiscard]] virtual auto fuse_unlink(const char *path)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_utimens(const char *path, const remote::file_time *tv,
|
||||
const std::uint64_t &op0, const std::uint64_t &op1) = 0;
|
||||
[[nodiscard]] virtual auto fuse_utimens(const char *path,
|
||||
const remote::file_time *tv,
|
||||
std::uint64_t op0, std::uint64_t op1)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_write(const char *path, const char *buffer,
|
||||
[[nodiscard]] virtual auto fuse_write(const char *path, const char *buffer,
|
||||
const remote::file_size &writeSize,
|
||||
const remote::file_offset &writeOffset,
|
||||
const remote::file_handle &handle) = 0;
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type fuse_write_base64(const char *path, const char *buffer,
|
||||
const remote::file_size &writeSize,
|
||||
const remote::file_offset &writeOffset,
|
||||
const remote::file_handle &handle) = 0;
|
||||
[[nodiscard]] virtual auto fuse_write_base64(
|
||||
const char *path, const char *buffer, const remote::file_size &writeSize,
|
||||
const remote::file_offset &writeOffset, const remote::file_handle &handle)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual void set_fuse_uid_gid(const remote::user_id &uid, const remote::group_id &gid) = 0;
|
||||
virtual void set_fuse_uid_gid(const remote::user_id &uid,
|
||||
const remote::group_id &gid) = 0;
|
||||
};
|
||||
typedef std::function<std::unique_ptr<i_remote_instance>()> remote_instance_factory;
|
||||
|
||||
using remote_instance_factory =
|
||||
std::function<std::unique_ptr<i_remote_instance>()>;
|
||||
} // namespace repertory::remote_fuse
|
||||
|
||||
#endif // INCLUDE_DRIVES_FUSE_REMOTEFUSE_I_REMOTE_INSTANCE_HPP_
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_CLIENT_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_CLIENT_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "comm/packet/packet_client.hpp"
|
||||
#include "drives/fuse/remotefuse/i_remote_instance.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
@ -40,131 +42,183 @@ private:
|
||||
remote::group_id gid_ = 0;
|
||||
|
||||
public:
|
||||
packet::error_type fuse_access(const char *path, const std::int32_t &mask) override;
|
||||
[[nodiscard]] auto fuse_access(const char *path, const std::int32_t &mask)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_chflags(const char *path, const std::uint32_t &flags) override;
|
||||
[[nodiscard]] auto fuse_chflags(const char *path, std::uint32_t flags)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_chmod(const char *path, const remote::file_mode &mode) override;
|
||||
[[nodiscard]] auto fuse_chmod(const char *path, const remote::file_mode &mode)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_chown(const char *path, const remote::user_id &uid,
|
||||
const remote::group_id &gid) override;
|
||||
[[nodiscard]] auto fuse_chown(const char *path, const remote::user_id &uid,
|
||||
const remote::group_id &gid)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_destroy() override;
|
||||
[[nodiscard]] auto fuse_destroy() -> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_fallocate(const char *path, const std::int32_t &mode,
|
||||
const remote::file_offset &offset,
|
||||
const remote::file_offset &length,
|
||||
const remote::file_handle &handle) override ;*/
|
||||
[[nodiscard]] /*packet::error_type fuse_fallocate(const char *path, const
|
||||
std::int32_t &mode, const remote::file_offset &offset, const
|
||||
remote::file_offset &length, const remote::file_handle
|
||||
&handle) override ;*/
|
||||
|
||||
packet::error_type fuse_fgetattr(const char *path, remote::stat &st, bool &directory,
|
||||
const remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto
|
||||
fuse_fgetattr(const char *path, remote::stat &st, bool &directory,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_fsetattr_x(const char *path, const remote::setattr_x &attr,
|
||||
const remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_fsetattr_x(const char *path,
|
||||
const remote::setattr_x &attr,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_fsync(const char *path, const std::int32_t &datasync,
|
||||
const remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_fsync(const char *path, const std::int32_t &datasync,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_ftruncate(const char *path, const remote::file_offset &size,
|
||||
const remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_ftruncate(const char *path,
|
||||
const remote::file_offset &size,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_getattr(const char *path, remote::stat &st, bool &directory) override;
|
||||
[[nodiscard]] auto fuse_getattr(const char *path, remote::stat &st,
|
||||
bool &directory)
|
||||
-> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_getxattr(const char *path, const char *name, char *value,
|
||||
const remote::file_size &size) override ;
|
||||
/*[[nodiscard]] packet::error_type fuse_getxattr(const char *path, const char
|
||||
*name, char *value, const remote::file_size &size) override ;
|
||||
|
||||
packet::error_type fuse_getxattrOSX(const char *path, const char *name, char *value,
|
||||
const remote::file_size &size,
|
||||
const std::uint32_t &position) override ;*/
|
||||
[[nodiscard]] packet::error_type fuse_getxattrOSX(const char *path, const char
|
||||
*name, char *value, const remote::file_size &size, std::uint32_t position)
|
||||
override ;*/
|
||||
|
||||
packet::error_type fuse_getxtimes(const char *path, remote::file_time &bkuptime,
|
||||
remote::file_time &crtime) override;
|
||||
[[nodiscard]] auto fuse_getxtimes(const char *path,
|
||||
remote::file_time &bkuptime,
|
||||
remote::file_time &crtime)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_init() override;
|
||||
[[nodiscard]] auto fuse_init() -> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_listxattr(const char *path, char *buffer,
|
||||
const remote::file_size &size) override ;*/
|
||||
/*[[nodiscard]] packet::error_type fuse_listxattr(const char *path, char
|
||||
*buffer, const remote::file_size &size) override ;*/
|
||||
|
||||
packet::error_type fuse_mkdir(const char *path, const remote::file_mode &mode) override;
|
||||
[[nodiscard]] auto fuse_mkdir(const char *path, const remote::file_mode &mode)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_opendir(const char *path, remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_opendir(const char *path, remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_create(const char *path, const remote::file_mode &mode,
|
||||
const remote::open_flags &flags, remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto
|
||||
fuse_create(const char *path, const remote::file_mode &mode,
|
||||
const remote::open_flags &flags, remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_open(const char *path, const remote::open_flags &flags,
|
||||
remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_open(const char *path,
|
||||
const remote::open_flags &flags,
|
||||
remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_read(const char *path, char *buffer, const remote::file_size &read_size,
|
||||
[[nodiscard]] auto fuse_read(const char *path, char *buffer,
|
||||
const remote::file_size &read_size,
|
||||
const remote::file_offset &read_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_rename(const char *from, const char *to) override;
|
||||
[[nodiscard]] auto fuse_rename(const char *from, const char *to)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_readdir(const char *path, const remote::file_offset &offset,
|
||||
const remote::file_handle &handle, std::string &item_path) override;
|
||||
[[nodiscard]] auto
|
||||
fuse_readdir(const char *path, const remote::file_offset &offset,
|
||||
const remote::file_handle &handle, std::string &item_path)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_release(const char *path, const remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_release(const char *path,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_releasedir(const char *path, const remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_releasedir(const char *path,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_removexattr(const char *path, const char *name) override ;*/
|
||||
/*[[nodiscard]] packet::error_type fuse_removexattr(const char *path, const
|
||||
* char *name) override
|
||||
* ;*/
|
||||
|
||||
packet::error_type fuse_rmdir(const char *path) override;
|
||||
[[nodiscard]] auto fuse_rmdir(const char *path)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setattr_x(const char *path, remote::setattr_x &attr) override;
|
||||
[[nodiscard]] auto fuse_setattr_x(const char *path, remote::setattr_x &attr)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setbkuptime(const char *path, const remote::file_time &bkuptime) override;
|
||||
[[nodiscard]] auto fuse_setbkuptime(const char *path,
|
||||
const remote::file_time &bkuptime)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setchgtime(const char *path, const remote::file_time &chgtime) override;
|
||||
[[nodiscard]] auto fuse_setchgtime(const char *path,
|
||||
const remote::file_time &chgtime)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setcrtime(const char *path, const remote::file_time &crtime) override;
|
||||
[[nodiscard]] auto fuse_setcrtime(const char *path,
|
||||
const remote::file_time &crtime)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setvolname(const char *volname) override;
|
||||
[[nodiscard]] auto fuse_setvolname(const char *volname)
|
||||
-> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_setxattr(const char *path, const char *name, const char *value,
|
||||
const remote::file_size &size,
|
||||
const std::int32_t &flags) override ;
|
||||
[[nodiscard]] /*packet::error_type fuse_setxattr(const char *path, const char
|
||||
*name, const char *value, const remote::file_size &size, const std::int32_t
|
||||
&flags) override ;
|
||||
|
||||
packet::error_type fuse_setxattr_osx(const char *path, const char *name, const char *value,
|
||||
const remote::file_size &size, const std::int32_t &flags,
|
||||
const std::uint32_t &position) override ;*/
|
||||
[[nodiscard]] packet::error_type fuse_setxattr_osx(const char *path, const
|
||||
char *name, const char *value, const remote::file_size &size, const
|
||||
std::int32_t &flags, std::uint32_t position) override ;*/
|
||||
|
||||
packet::error_type fuse_statfs(const char *path, const std::uint64_t &frsize,
|
||||
remote::statfs &st) override;
|
||||
[[nodiscard]] auto
|
||||
fuse_statfs(const char *path, std::uint64_t frsize, remote::statfs &st)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_statfs_x(const char *path, const std::uint64_t &bsize,
|
||||
remote::statfs_x &st) override;
|
||||
[[nodiscard]] auto fuse_statfs_x(const char *path, std::uint64_t bsize,
|
||||
remote::statfs_x &st)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_truncate(const char *path, const remote::file_offset &size) override;
|
||||
[[nodiscard]] auto fuse_truncate(const char *path,
|
||||
const remote::file_offset &size)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_unlink(const char *path) override;
|
||||
[[nodiscard]] auto fuse_unlink(const char *path)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_utimens(const char *path, const remote::file_time *tv,
|
||||
const std::uint64_t &op0, const std::uint64_t &op1) override;
|
||||
[[nodiscard]] auto fuse_utimens(const char *path, const remote::file_time *tv,
|
||||
std::uint64_t op0, std::uint64_t op1)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_write(const char *path, const char *buffer,
|
||||
[[nodiscard]] auto fuse_write(const char *path, const char *buffer,
|
||||
const remote::file_size &write_size,
|
||||
const remote::file_offset &write_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_write_base64(const char *path, const char *buffer,
|
||||
[[nodiscard]] auto fuse_write_base64(const char *path, const char *buffer,
|
||||
const remote::file_size &write_size,
|
||||
const remote::file_offset &write_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type json_create_directory_snapshot(const std::string &path,
|
||||
json &json_data) override;
|
||||
[[nodiscard]] auto json_create_directory_snapshot(const std::string &path,
|
||||
json &json_data)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type json_read_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle,
|
||||
const std::uint32_t &page,
|
||||
json &json_data) override;
|
||||
[[nodiscard]] auto json_read_directory_snapshot(
|
||||
const std::string &path, const remote::file_handle &handle,
|
||||
std::uint32_t page, json &json_data) -> packet::error_type override;
|
||||
|
||||
packet::error_type json_release_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto
|
||||
json_release_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
void set_fuse_uid_gid(const remote::user_id &uid, const remote::group_id &gid) override;
|
||||
void set_fuse_uid_gid(const remote::user_id &uid,
|
||||
const remote::group_id &gid) override;
|
||||
};
|
||||
} // namespace remote_fuse
|
||||
} // namespace repertory
|
||||
|
@ -1,26 +1,29 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_FUSE_DRIVE_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_FUSE_DRIVE_HPP_
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "drives/fuse/fuse_base.hpp"
|
||||
#include "drives/fuse/remotefuse/i_remote_instance.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
|
||||
@ -32,223 +35,206 @@ class lock_data;
|
||||
class server;
|
||||
|
||||
namespace remote_fuse {
|
||||
class remote_fuse_drive final {
|
||||
E_CONSUMER();
|
||||
|
||||
class remote_fuse_drive final : public fuse_base {
|
||||
public:
|
||||
remote_fuse_drive(app_config &config, lock_data &lock, remote_instance_factory factory);
|
||||
remote_fuse_drive(app_config &config, remote_instance_factory factory,
|
||||
lock_data &lock)
|
||||
: fuse_base(config), factory_(std::move(factory)), lock_data_(lock) {}
|
||||
|
||||
~remote_fuse_drive() { E_CONSUMER_RELEASE(); }
|
||||
~remote_fuse_drive() override = default;
|
||||
|
||||
private:
|
||||
app_config &config_;
|
||||
lock_data &lock_;
|
||||
remote_instance_factory factory_;
|
||||
std::string mount_location_;
|
||||
lock_data &lock_data_;
|
||||
std::shared_ptr<console_consumer> console_consumer_;
|
||||
std::shared_ptr<logging_consumer> logging_consumer_;
|
||||
std::shared_ptr<i_remote_instance> remote_instance_;
|
||||
std::shared_ptr<server> server_;
|
||||
bool was_mounted_ = false;
|
||||
|
||||
private:
|
||||
static void shutdown(std::string mount_location);
|
||||
void populate_stat(const remote::stat &r, bool directory, struct stat &st);
|
||||
|
||||
private:
|
||||
class remote_fuse_impl final {
|
||||
public:
|
||||
static app_config *config_;
|
||||
static lock_data *lock_;
|
||||
static std::string *mount_location_;
|
||||
static remote_instance_factory *factory_;
|
||||
static std::unique_ptr<console_consumer> console_consumer_;
|
||||
static std::unique_ptr<logging_consumer> logging_consumer_;
|
||||
static std::unique_ptr<i_remote_instance> remote_instance_;
|
||||
static std::unique_ptr<server> server_;
|
||||
static std::optional<gid_t> forced_gid_;
|
||||
static std::optional<uid_t> forced_uid_;
|
||||
static std::optional<mode_t> forced_umask_;
|
||||
static bool console_enabled_;
|
||||
static bool was_mounted_;
|
||||
|
||||
public:
|
||||
static void tear_down(const int &ret);
|
||||
|
||||
private:
|
||||
static void populate_stat(const remote::stat &r, const bool &directory, struct stat &st);
|
||||
|
||||
public:
|
||||
static int repertory_access(const char *path, int mask);
|
||||
protected:
|
||||
[[nodiscard]] auto access_impl(std::string api_path, int mask)
|
||||
-> api_error override;
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int repertory_chflags(const char *path, uint32_t flags);
|
||||
#endif
|
||||
[[nodiscard]] auto chflags_impl(std::string api_path, uint32_t flags)
|
||||
-> api_error override;
|
||||
#endif // __APPLE__
|
||||
|
||||
static int repertory_chmod(const char *path, mode_t mode);
|
||||
|
||||
static int repertory_chown(const char *path, uid_t uid, gid_t gid);
|
||||
|
||||
static int repertory_create(const char *path, mode_t mode, struct fuse_file_info *fi);
|
||||
|
||||
static void repertory_destroy(void * /*ptr*/);
|
||||
|
||||
/*static int repertory_fallocate(const char *path, int mode, off_t offset, off_t length,
|
||||
struct fuse_file_info *fi) ;*/
|
||||
|
||||
static int repertory_fgetattr(const char *path, struct stat *st, struct fuse_file_info *fi);
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int repertory_fsetattr_x(const char *path, struct setattr_x *attr,
|
||||
struct fuse_file_info *fi);
|
||||
#endif
|
||||
|
||||
static int repertory_fsync(const char *path, int datasync, struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_ftruncate(const char *path, off_t size, struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_getattr(const char *path, struct stat *st);
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int repertory_getxtimes(const char *path, struct timespec *bkuptime,
|
||||
struct timespec *crtime);
|
||||
#endif
|
||||
|
||||
static void *repertory_init(struct fuse_conn_info *conn);
|
||||
|
||||
static int repertory_mkdir(const char *path, mode_t mode);
|
||||
|
||||
static int repertory_open(const char *path, struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_opendir(const char *path, struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_read(const char *path, char *buffer, size_t readSize, off_t readOffset,
|
||||
struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_readdir(const char *path, void *buf, fuse_fill_dir_t fuseFillDir,
|
||||
off_t offset, struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_release(const char *path, struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_releasedir(const char *path, struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_rename(const char *from, const char *to);
|
||||
|
||||
static int repertory_rmdir(const char *path);
|
||||
/*
|
||||
#ifdef HAS_SETXATTR
|
||||
#ifdef __APPLE__
|
||||
static int repertory_getxattr(const char *path, const char *name, char *value, size_t size,
|
||||
uint32_t position) ;
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] auto chmod_impl(std::string api_path, mode_t mode,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#else
|
||||
static int repertory_getxattr(const char *path, const char *name, char *value, size_t size) ;
|
||||
|
||||
[[nodiscard]] auto chmod_impl(std::string api_path, mode_t mode)
|
||||
-> api_error override;
|
||||
#endif
|
||||
static int repertory_listxattr(const char *path, char *buffer, size_t size) ;
|
||||
|
||||
static int repertory_removexattr(const char *path, const char *name) ;
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] auto chown_impl(std::string api_path, uid_t uid, gid_t gid,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#else
|
||||
[[nodiscard]] auto chown_impl(std::string api_path, uid_t uid, gid_t gid)
|
||||
-> api_error override;
|
||||
#endif
|
||||
|
||||
[[nodiscard]] auto create_impl(std::string api_path, mode_t mode,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
void destroy_impl(void * /*ptr*/) override;
|
||||
|
||||
[[nodiscard]] auto fgetattr_impl(std::string api_path, struct stat *st,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int repertory_setxattr(const char *path, const char *name, const char *value,
|
||||
size_t size, int flags, uint32_t position) ;
|
||||
[[nodiscard]] auto fsetattr_x_impl(std::string api_path,
|
||||
struct setattr_x *attr,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#endif // __APPLE__
|
||||
|
||||
[[nodiscard]] auto fsync_impl(std::string api_path, int datasync,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
|
||||
#if FUSE_USE_VERSION < 30
|
||||
[[nodiscard]] auto ftruncate_impl(std::string api_path, off_t size,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#endif
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] auto getattr_impl(std::string api_path, struct stat *st,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#else
|
||||
static int repertory_setxattr(const char *path, const char *name, const char *value,
|
||||
size_t size, int flags) ;
|
||||
[[nodiscard]] auto getattr_impl(std::string api_path, struct stat *st)
|
||||
-> api_error override;
|
||||
#endif
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int repertory_setattr_x(const char *path, struct setattr_x *attr);
|
||||
[[nodiscard]] auto getxtimes_impl(std::string api_path,
|
||||
struct timespec *bkuptime,
|
||||
struct timespec *crtime)
|
||||
-> api_error override;
|
||||
#endif // __APPLE__
|
||||
|
||||
static int repertory_setbkuptime(const char *path, const struct timespec *bkuptime);
|
||||
|
||||
static int repertory_setchgtime(const char *path, const struct timespec *chgtime);
|
||||
|
||||
static int repertory_setcrtime(const char *path, const struct timespec *crtime);
|
||||
|
||||
static int repertory_setvolname(const char *volname);
|
||||
|
||||
static int repertory_statfs_x(const char *path, struct statfs *stbuf);
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto init_impl(struct fuse_conn_info *conn, struct fuse_config *cfg)
|
||||
-> void * override;
|
||||
#else
|
||||
|
||||
static int repertory_statfs(const char *path, struct statvfs *stbuf);
|
||||
|
||||
auto init_impl(struct fuse_conn_info *conn) -> void * override;
|
||||
#endif
|
||||
|
||||
static int repertory_truncate(const char *path, off_t size);
|
||||
[[nodiscard]] auto mkdir_impl(std::string api_path, mode_t mode)
|
||||
-> api_error override;
|
||||
|
||||
static int repertory_unlink(const char *path);
|
||||
void notify_fuse_main_exit(int &ret) override;
|
||||
|
||||
static int repertory_utimens(const char *path, const struct timespec tv[2]);
|
||||
[[nodiscard]] auto open_impl(std::string api_path, struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
|
||||
static int repertory_write(const char *path, const char *buffer, size_t writeSize,
|
||||
off_t writeOffset, struct fuse_file_info *fi);
|
||||
};
|
||||
[[nodiscard]] auto opendir_impl(std::string api_path,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto read_impl(std::string api_path, char *buffer,
|
||||
size_t read_size, off_t read_offset,
|
||||
struct fuse_file_info *fi,
|
||||
std::size_t &bytes_read) -> api_error override;
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] auto readdir_impl(std::string api_path, void *buf,
|
||||
fuse_fill_dir_t fuse_fill_dir, off_t offset,
|
||||
struct fuse_file_info *fi,
|
||||
fuse_readdir_flags flags)
|
||||
-> api_error override;
|
||||
#else
|
||||
[[nodiscard]] auto readdir_impl(std::string api_path, void *buf,
|
||||
fuse_fill_dir_t fuse_fill_dir, off_t offset,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#endif
|
||||
|
||||
[[nodiscard]] auto release_impl(std::string api_path,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto releasedir_impl(std::string api_path,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] auto rename_impl(std::string from_api_path,
|
||||
std::string to_api_path, unsigned int flags)
|
||||
-> api_error override;
|
||||
#else
|
||||
[[nodiscard]] auto rename_impl(std::string from_api_path,
|
||||
std::string to_api_path) -> api_error override;
|
||||
#endif
|
||||
|
||||
[[nodiscard]] auto rmdir_impl(std::string api_path) -> api_error override;
|
||||
|
||||
private:
|
||||
// clang-format off
|
||||
struct fuse_operations fuse_ops_ {
|
||||
.getattr = remote_fuse_impl::repertory_getattr,
|
||||
.readlink = nullptr, // int (*readlink) (const char *, char *, size_t);
|
||||
.getdir = nullptr, // int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
|
||||
.mknod = nullptr, // int (*mknod) (const char *, mode_t, dev_t);
|
||||
.mkdir = remote_fuse_impl::repertory_mkdir,
|
||||
.unlink = remote_fuse_impl::repertory_unlink,
|
||||
.rmdir = remote_fuse_impl::repertory_rmdir,
|
||||
.symlink = nullptr, // int (*symlink) (const char *, const char *);
|
||||
.rename = remote_fuse_impl::repertory_rename,
|
||||
.link = nullptr, // int (*link) (const char *, const char *);
|
||||
.chmod = remote_fuse_impl::repertory_chmod,
|
||||
.chown = remote_fuse_impl::repertory_chown,
|
||||
.truncate = remote_fuse_impl::repertory_truncate,
|
||||
.utime = nullptr, // int (*utime) (const char *, struct utimbuf *);
|
||||
.open = remote_fuse_impl::repertory_open,
|
||||
.read = remote_fuse_impl::repertory_read,
|
||||
.write = remote_fuse_impl::repertory_write,
|
||||
#ifdef __APPLE__
|
||||
.statfs = nullptr,
|
||||
[[nodiscard]] auto setattr_x_impl(std::string api_path,
|
||||
struct setattr_x *attr)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto setbkuptime_impl(std::string api_path,
|
||||
const struct timespec *bkuptime)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto setchgtime_impl(std::string api_path,
|
||||
const struct timespec *chgtime)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto setcrtime_impl(std::string api_path,
|
||||
const struct timespec *crtime)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] virtual auto setvolname_impl(const char *volname)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto statfs_x_impl(std::string api_path, struct statfs *stbuf)
|
||||
-> api_error override;
|
||||
|
||||
#else // __APPLE__
|
||||
[[nodiscard]] auto statfs_impl(std::string api_path, struct statvfs *stbuf)
|
||||
-> api_error override;
|
||||
#endif // __APPLE__
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] auto truncate_impl(std::string api_path, off_t size,
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#else
|
||||
.statfs = remote_fuse_impl::repertory_statfs,
|
||||
[[nodiscard]] auto truncate_impl(std::string api_path, off_t size)
|
||||
-> api_error override;
|
||||
#endif
|
||||
.flush = nullptr, // int (*flush) (const char *, struct fuse_file_info *);
|
||||
.release = remote_fuse_impl::repertory_release,
|
||||
.fsync = remote_fuse_impl::repertory_fsync,
|
||||
#if HAS_SETXATTR
|
||||
.setxattr = nullptr, // remote_fuse_impl::repertory_setxattr,
|
||||
.getxattr = nullptr, // remote_fuse_impl::repertory_getxattr,
|
||||
.listxattr = nullptr, // remote_fuse_impl::repertory_listxattr,
|
||||
.removexattr = nullptr, // remote_fuse_impl::repertory_removexattr,
|
||||
|
||||
[[nodiscard]] auto unlink_impl(std::string api_path) -> api_error override;
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
[[nodiscard]] auto utimens_impl(std::string api_path,
|
||||
const struct timespec tv[2],
|
||||
struct fuse_file_info *fi)
|
||||
-> api_error override;
|
||||
#else
|
||||
.setxattr = nullptr,
|
||||
.getxattr = nullptr,
|
||||
.listxattr = nullptr,
|
||||
.removexattr = nullptr,
|
||||
[[nodiscard]] auto utimens_impl(std::string api_path,
|
||||
const struct timespec tv[2])
|
||||
-> api_error override;
|
||||
#endif
|
||||
.opendir = remote_fuse_impl::repertory_opendir,
|
||||
.readdir = remote_fuse_impl::repertory_readdir,
|
||||
.releasedir = remote_fuse_impl::repertory_releasedir,
|
||||
.fsyncdir = nullptr, // int (*fsyncdir) (const char *, int, struct fuse_file_info *);
|
||||
.init = remote_fuse_impl::repertory_init,
|
||||
.destroy = remote_fuse_impl::repertory_destroy,
|
||||
.access = remote_fuse_impl::repertory_access,
|
||||
.create = remote_fuse_impl::repertory_create,
|
||||
.ftruncate = remote_fuse_impl::repertory_ftruncate,
|
||||
.fgetattr = remote_fuse_impl::repertory_fgetattr,
|
||||
.lock = nullptr, // int (*lock) (const char *, struct fuse_file_info *, int cmd, struct flock *);
|
||||
.utimens = remote_fuse_impl::repertory_utimens,
|
||||
.bmap = nullptr, // int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
|
||||
.flag_nullpath_ok = 0,
|
||||
.flag_nopath = 0,
|
||||
.flag_utime_omit_ok = 1,
|
||||
.flag_reserved = 0,
|
||||
.ioctl = nullptr, // int (*ioctl) (const char *, int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void *data);
|
||||
.poll = nullptr, // int (*poll) (const char *, struct fuse_file_info *, struct fuse_pollhandle *ph, unsigned *reventsp);
|
||||
.write_buf = nullptr, // int (*write_buf) (const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *);
|
||||
.read_buf = nullptr, // int (*read_buf) (const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *);
|
||||
.flock = nullptr, // int (*flock) (const char *, struct fuse_file_info *, int op);
|
||||
.fallocate = nullptr // remote_fuse_impl::repertory_fallocate,
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
public:
|
||||
int mount(std::vector<std::string> drive_args);
|
||||
|
||||
static void display_options(int argc, char *argv[]);
|
||||
|
||||
static void display_version_information(int argc, char *argv[]);
|
||||
[[nodiscard]] auto write_impl(std::string api_path, const char *buffer,
|
||||
size_t write_size, off_t write_offset,
|
||||
struct fuse_file_info *fi,
|
||||
std::size_t &bytes_written)
|
||||
-> api_error override;
|
||||
};
|
||||
} // namespace remote_fuse
|
||||
} // namespace repertory
|
||||
|
@ -1,101 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_FUSE_DRIVE2_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_FUSE_DRIVE2_HPP_
|
||||
#ifndef _WIN32
|
||||
#if 0
|
||||
|
||||
#include "common.hpp"
|
||||
#include "drives/fuse/fuse_base.hpp"
|
||||
#include "drives/fuse/remotefuse/i_remote_instance.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
class console_consumer;
|
||||
class logging_consumer;
|
||||
class lock_data;
|
||||
class server;
|
||||
|
||||
namespace utils {
|
||||
api_error to_api_error(packet::error_type e) { return api_error::success; }
|
||||
} // namespace utils
|
||||
|
||||
namespace remote_fuse {
|
||||
class remote_fuse_drive2 final : public fuse_base {
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
~remote_fuse_drive2() override = default;
|
||||
|
||||
private:
|
||||
std::unique_ptr<i_remote_instance> remote_instance_;
|
||||
|
||||
protected:
|
||||
api_error access_impl(std::string api_path, int mask) override;
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error chflags_impl(std::string api_path, uint32_t flags) override;
|
||||
#endif // __APPLE__
|
||||
|
||||
api_error chmod_impl(std::string api_path, mode_t mode) override;
|
||||
|
||||
public:
|
||||
api_error check_parent_access(const std::string &api_path, int mask) const override;
|
||||
|
||||
std::uint64_t get_directory_item_count(const std::string &api_path) const override;
|
||||
|
||||
directory_item_list get_directory_items(const std::string &api_path) const override;
|
||||
|
||||
std::uint64_t get_file_size(const std::string &api_path) const override;
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, api_meta_map &meta) const override;
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, const std::string &name,
|
||||
std::string &value) const override;
|
||||
|
||||
std::uint64_t get_total_drive_space() const override;
|
||||
|
||||
std::uint64_t get_total_item_count() const override;
|
||||
|
||||
std::uint64_t get_used_drive_space() const override;
|
||||
|
||||
void get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label) const override;
|
||||
|
||||
bool is_processing(const std::string &api_path) const override;
|
||||
|
||||
void populate_stat(const directory_item &di, struct stat &st) const override;
|
||||
|
||||
int rename_directory(const std::string &from_api_path, const std::string &to_api_path) override;
|
||||
|
||||
int rename_file(const std::string &from_api_path, const std::string &to_api_path,
|
||||
const bool &overwrite) override;
|
||||
|
||||
void set_item_meta(const std::string &api_path, const std::string &key,
|
||||
const std::string &value) override;
|
||||
|
||||
void update_directory_item(directory_item &di) const override;
|
||||
};
|
||||
} // namespace remote_fuse
|
||||
} // namespace repertory
|
||||
|
||||
#endif // 0
|
||||
#endif // _WIN32
|
||||
#endif // INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_FUSE_DRIVE2_HPP_
|
@ -1,26 +1,28 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_SERVER_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_SERVER_HPP_
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "drives/directory_cache.hpp"
|
||||
#include "drives/fuse/i_fuse_drive.hpp"
|
||||
#include "drives/remote/remote_server_base.hpp"
|
||||
@ -31,220 +33,303 @@ class app_config;
|
||||
namespace remote_fuse {
|
||||
class remote_server final : public virtual remote_server_base<i_fuse_drive> {
|
||||
public:
|
||||
remote_server(app_config &config, i_fuse_drive &drive, const std::string &mount_location);
|
||||
remote_server(app_config &config, i_fuse_drive &drive,
|
||||
const std::string &mount_location);
|
||||
|
||||
private:
|
||||
directory_cache directory_cache_;
|
||||
|
||||
private:
|
||||
std::string construct_path(std::string path);
|
||||
[[nodiscard]] auto construct_path(std::string path) -> std::string;
|
||||
|
||||
std::string construct_path(const std::wstring &path);
|
||||
[[nodiscard]] auto construct_path(const std::wstring &path) -> std::string;
|
||||
|
||||
static std::string empty_as_zero(const json &data);
|
||||
[[nodiscard]] static auto empty_as_zero(const json &data) -> std::string;
|
||||
|
||||
packet::error_type populate_file_info(const std::string &api_path, remote::file_info &file_info);
|
||||
[[nodiscard]] auto populate_file_info(const std::string &api_path,
|
||||
remote::file_info &file_info)
|
||||
-> packet::error_type;
|
||||
|
||||
void populate_file_info(const std::string &api_path, const UINT64 &file_size,
|
||||
const UINT32 &attributes, remote::file_info &file_info);
|
||||
const UINT32 &attributes,
|
||||
remote::file_info &file_info);
|
||||
|
||||
static void populate_stat(const struct stat &st1, remote::stat &st);
|
||||
static void populate_stat(const struct stat64 &st1, remote::stat &st);
|
||||
|
||||
json &update_to_windows_format(json &item);
|
||||
[[nodiscard]] auto update_to_windows_format(json &item) -> json &;
|
||||
|
||||
protected:
|
||||
void delete_open_directory(void *dir) override;
|
||||
|
||||
public:
|
||||
// FUSE Layer
|
||||
packet::error_type fuse_access(const char *path, const std::int32_t &mask) override;
|
||||
[[nodiscard]] auto fuse_access(const char *path, const std::int32_t &mask)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_chflags(const char *path, const std::uint32_t &flags) override;
|
||||
[[nodiscard]] auto fuse_chflags(const char *path, std::uint32_t flags)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_chmod(const char *path, const remote::file_mode &mode) override;
|
||||
[[nodiscard]] auto fuse_chmod(const char *path, const remote::file_mode &mode)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_chown(const char *path, const remote::user_id &uid,
|
||||
const remote::group_id &gid) override;
|
||||
[[nodiscard]] auto fuse_chown(const char *path, const remote::user_id &uid,
|
||||
const remote::group_id &gid)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_create(const char *path, const remote::file_mode &mode,
|
||||
const remote::open_flags &flags, remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto
|
||||
fuse_create(const char *path, const remote::file_mode &mode,
|
||||
const remote::open_flags &flags, remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_destroy() override;
|
||||
[[nodiscard]] auto fuse_destroy() -> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_fallocate(const char *path, const std::int32_t &mode,
|
||||
const remote::file_offset &offset,
|
||||
const remote::file_offset &length,
|
||||
const remote::file_handle &handle) override ;*/
|
||||
/*[[nodiscard]] packet::error_type fuse_fallocate(const char *path, const
|
||||
std::int32_t &mode, const remote::file_offset &offset, const
|
||||
remote::file_offset &length, const remote::file_handle &handle) override
|
||||
;*/
|
||||
|
||||
packet::error_type fuse_fgetattr(const char *path, remote::stat &st, bool &directory,
|
||||
const remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_fgetattr(const char *path, remote::stat &st,
|
||||
bool &directory,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_fsetattr_x(const char *path, const remote::setattr_x &attr,
|
||||
const remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_fsetattr_x(const char *path,
|
||||
const remote::setattr_x &attr,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_fsync(const char *path, const std::int32_t &datasync,
|
||||
const remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_fsync(const char *path, const std::int32_t &datasync,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_ftruncate(const char *path, const remote::file_offset &size,
|
||||
const remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_ftruncate(const char *path,
|
||||
const remote::file_offset &size,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_getattr(const char *path, remote::stat &st, bool &directory) override;
|
||||
[[nodiscard]] auto fuse_getattr(const char *path, remote::stat &st,
|
||||
bool &directory)
|
||||
-> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_getxattr(const char *path, const char *name, char *value,
|
||||
const remote::file_size &size) override ;
|
||||
/*[[nodiscard]] packet::error_type fuse_getxattr(const char *path, const char
|
||||
*name, char *value, const remote::file_size &size) override ;
|
||||
|
||||
packet::error_type fuse_getxattrOSX(const char *path, const char *name, char *value,
|
||||
const remote::file_size &size,
|
||||
const std::uint32_t &position) override ;*/
|
||||
[[nodiscard]] packet::error_type fuse_getxattrOSX(const char *path, const char
|
||||
*name, char *value, const remote::file_size &size, std::uint32_t position)
|
||||
override ;*/
|
||||
|
||||
packet::error_type fuse_getxtimes(const char *path, remote::file_time &bkuptime,
|
||||
remote::file_time &crtime) override;
|
||||
[[nodiscard]] auto fuse_getxtimes(const char *path,
|
||||
remote::file_time &bkuptime,
|
||||
remote::file_time &crtime)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_init() override;
|
||||
[[nodiscard]] auto fuse_init() -> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_listxattr(const char *path, char *buffer,
|
||||
const remote::file_size &size) override ;*/
|
||||
[[nodiscard]] /*packet::error_type fuse_listxattr(const char *path, char
|
||||
*buffer, const remote::file_size &size) override ;*/
|
||||
|
||||
packet::error_type fuse_mkdir(const char *path, const remote::file_mode &mode) override;
|
||||
[[nodiscard]] auto
|
||||
fuse_mkdir(const char *path, const remote::file_mode &mode)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_open(const char *path, const remote::open_flags &flags,
|
||||
remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_open(const char *path,
|
||||
const remote::open_flags &flags,
|
||||
remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_opendir(const char *path, remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_opendir(const char *path, remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_read(const char *path, char *buffer, const remote::file_size &read_size,
|
||||
[[nodiscard]] auto fuse_read(const char *path, char *buffer,
|
||||
const remote::file_size &read_size,
|
||||
const remote::file_offset &read_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_rename(const char *from, const char *to) override;
|
||||
[[nodiscard]] auto fuse_rename(const char *from, const char *to)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_readdir(const char *path, const remote::file_offset &offset,
|
||||
const remote::file_handle &handle, std::string &item_path) override;
|
||||
[[nodiscard]] auto
|
||||
fuse_readdir(const char *path, const remote::file_offset &offset,
|
||||
const remote::file_handle &handle, std::string &item_path)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_release(const char *path, const remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_release(const char *path,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_releasedir(const char *path, const remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto fuse_releasedir(const char *path,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_removexattr(const char *path, const char *name) override ;*/
|
||||
/*[[nodiscard]] packet::error_type fuse_removexattr(const char *path, const
|
||||
* char *name) override
|
||||
* ;*/
|
||||
|
||||
packet::error_type fuse_rmdir(const char *path) override;
|
||||
[[nodiscard]] auto fuse_rmdir(const char *path)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setattr_x(const char *path, remote::setattr_x &attr) override;
|
||||
[[nodiscard]] auto fuse_setattr_x(const char *path, remote::setattr_x &attr)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setbkuptime(const char *path, const remote::file_time &bkuptime) override;
|
||||
[[nodiscard]] auto fuse_setbkuptime(const char *path,
|
||||
const remote::file_time &bkuptime)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setchgtime(const char *path, const remote::file_time &chgtime) override;
|
||||
[[nodiscard]] auto fuse_setchgtime(const char *path,
|
||||
const remote::file_time &chgtime)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setcrtime(const char *path, const remote::file_time &crtime) override;
|
||||
[[nodiscard]] auto fuse_setcrtime(const char *path,
|
||||
const remote::file_time &crtime)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setvolname(const char *volname) override;
|
||||
[[nodiscard]] auto fuse_setvolname(const char *volname)
|
||||
-> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_setxattr(const char *path, const char *name, const char *value,
|
||||
const remote::file_size &size,
|
||||
const std::int32_t &flags) override ;
|
||||
/*[[nodiscard]] packet::error_type fuse_setxattr(const char *path, const char
|
||||
*name, const char *value, const remote::file_size &size, const std::int32_t
|
||||
&flags) override ;
|
||||
|
||||
packet::error_type fuse_setxattr_osx(const char *path, const char *name, const char *value,
|
||||
const remote::file_size &size, const std::int32_t &flags,
|
||||
const std::uint32_t &position) override ;*/
|
||||
[[nodiscard]] packet::error_type fuse_setxattr_osx(const char *path, const
|
||||
char *name, const char *value, const remote::file_size &size, const
|
||||
std::int32_t &flags, std::uint32_t position) override ;*/
|
||||
|
||||
packet::error_type fuse_statfs(const char *path, const std::uint64_t &frsize,
|
||||
remote::statfs &st) override;
|
||||
[[nodiscard]] auto fuse_statfs(const char *path, std::uint64_t frsize,
|
||||
remote::statfs &st)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_statfs_x(const char *path, const std::uint64_t &bsize,
|
||||
remote::statfs_x &st) override;
|
||||
[[nodiscard]] auto fuse_statfs_x(const char *path, std::uint64_t bsize,
|
||||
remote::statfs_x &st)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_truncate(const char *path, const remote::file_offset &size) override;
|
||||
[[nodiscard]] auto fuse_truncate(const char *path,
|
||||
const remote::file_offset &size)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_unlink(const char *path) override;
|
||||
[[nodiscard]] auto fuse_unlink(const char *path)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_utimens(const char *path, const remote::file_time *tv,
|
||||
const std::uint64_t &op0, const std::uint64_t &op1) override;
|
||||
[[nodiscard]] auto fuse_utimens(const char *path, const remote::file_time *tv,
|
||||
std::uint64_t op0, std::uint64_t op1)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_write(const char *path, const char *buffer,
|
||||
[[nodiscard]] auto fuse_write(const char *path, const char *buffer,
|
||||
const remote::file_size &write_size,
|
||||
const remote::file_offset &write_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_write_base64(const char *path, const char *buffer,
|
||||
[[nodiscard]] auto fuse_write_base64(const char *path, const char *buffer,
|
||||
const remote::file_size &write_size,
|
||||
const remote::file_offset &write_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
void set_fuse_uid_gid(const remote::user_id &, const remote::group_id &) override {}
|
||||
void set_fuse_uid_gid(const remote::user_id &,
|
||||
const remote::group_id &) override {}
|
||||
|
||||
// JSON Layer
|
||||
packet::error_type winfsp_get_dir_buffer(PVOID /*file_desc*/, PVOID *& /*ptr*/) override {
|
||||
[[nodiscard]] auto winfsp_get_dir_buffer(PVOID /*file_desc*/,
|
||||
PVOID *& /*ptr*/)
|
||||
-> packet::error_type override {
|
||||
return STATUS_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
packet::error_type json_create_directory_snapshot(const std::string &path,
|
||||
json &jsonData) override;
|
||||
[[nodiscard]] auto json_create_directory_snapshot(const std::string &path,
|
||||
json &jsonData)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type json_read_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle,
|
||||
const std::uint32_t &page,
|
||||
json &jsonData) override;
|
||||
[[nodiscard]] auto json_read_directory_snapshot(
|
||||
const std::string &path, const remote::file_handle &handle,
|
||||
std::uint32_t page, json &jsonData) -> packet::error_type override;
|
||||
|
||||
packet::error_type json_release_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle) override;
|
||||
[[nodiscard]] auto
|
||||
json_release_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
// WinFSP Layer
|
||||
packet::error_type winfsp_can_delete(PVOID file_desc, PWSTR file_name) override;
|
||||
[[nodiscard]] auto winfsp_can_delete(PVOID file_desc, PWSTR file_name)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags,
|
||||
BOOLEAN &wasClosed) override;
|
||||
[[nodiscard]] auto winfsp_cleanup(PVOID file_desc, PWSTR file_name,
|
||||
UINT32 flags, BOOLEAN &wasClosed)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_close(PVOID file_desc) override;
|
||||
[[nodiscard]] auto winfsp_close(PVOID file_desc)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_create(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
|
||||
UINT32 attributes, UINT64 /*allocation_size*/, PVOID *file_desc,
|
||||
remote::file_info *file_info, std::string &normalized_name,
|
||||
BOOLEAN &exists) override;
|
||||
[[nodiscard]] auto
|
||||
winfsp_create(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
|
||||
UINT32 attributes, UINT64 /*allocation_size*/, PVOID *file_desc,
|
||||
remote::file_info *file_info, std::string &normalized_name,
|
||||
BOOLEAN &exists) -> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_flush(PVOID file_desc, remote::file_info *file_info) override;
|
||||
[[nodiscard]] auto winfsp_flush(PVOID file_desc, remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_get_file_info(PVOID file_desc, remote::file_info *file_info) override;
|
||||
[[nodiscard]] auto winfsp_get_file_info(PVOID file_desc,
|
||||
remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_get_security_by_name(PWSTR file_name, PUINT32 attributes,
|
||||
std::uint64_t * /*securityDescriptorSize*/,
|
||||
std::wstring & /*strDescriptor*/) override;
|
||||
[[nodiscard]] auto
|
||||
winfsp_get_security_by_name(PWSTR file_name, PUINT32 attributes,
|
||||
std::uint64_t * /*securityDescriptorSize*/,
|
||||
std::wstring & /*strDescriptor*/)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label) override;
|
||||
[[nodiscard]] auto winfsp_get_volume_info(UINT64 &total_size,
|
||||
UINT64 &free_size,
|
||||
std::string &volume_label)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_mounted(const std::wstring &location) override;
|
||||
[[nodiscard]] auto winfsp_mounted(const std::wstring &location)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_open(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
|
||||
PVOID *file_desc, remote::file_info *file_info,
|
||||
std::string &normalized_name) override;
|
||||
[[nodiscard]] auto winfsp_open(PWSTR file_name, UINT32 create_options,
|
||||
UINT32 granted_access, PVOID *file_desc,
|
||||
remote::file_info *file_info,
|
||||
std::string &normalized_name)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_overwrite(PVOID file_desc, UINT32 attributes,
|
||||
BOOLEAN replace_attributes, UINT64 /*allocation_size*/,
|
||||
remote::file_info *file_info) override;
|
||||
[[nodiscard]] auto winfsp_overwrite(PVOID file_desc, UINT32 attributes,
|
||||
BOOLEAN replace_attributes,
|
||||
UINT64 /*allocation_size*/,
|
||||
remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
|
||||
PUINT32 bytes_transferred) override;
|
||||
[[nodiscard]] auto winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
|
||||
UINT32 length, PUINT32 bytes_transferred)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/, PWSTR marker,
|
||||
json &itemList) override;
|
||||
[[nodiscard]] auto winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/,
|
||||
PWSTR marker, json &itemList)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_rename(PVOID /*file_desc*/, PWSTR file_name, PWSTR new_file_name,
|
||||
BOOLEAN replace_if_exists) override;
|
||||
[[nodiscard]] auto winfsp_rename(PVOID /*file_desc*/, PWSTR file_name,
|
||||
PWSTR new_file_name,
|
||||
BOOLEAN replace_if_exists)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_set_basic_info(PVOID file_desc, UINT32 attributes, UINT64 creation_time,
|
||||
UINT64 last_access_time, UINT64 last_write_time,
|
||||
UINT64 change_time,
|
||||
remote::file_info *file_info) override;
|
||||
[[nodiscard]] auto winfsp_set_basic_info(
|
||||
PVOID file_desc, UINT32 attributes, UINT64 creation_time,
|
||||
UINT64 last_access_time, UINT64 last_write_time, UINT64 change_time,
|
||||
remote::file_info *file_info) -> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_set_file_size(PVOID file_desc, UINT64 newSize,
|
||||
[[nodiscard]] auto winfsp_set_file_size(PVOID file_desc, UINT64 newSize,
|
||||
BOOLEAN set_allocation_size,
|
||||
remote::file_info *file_info) override;
|
||||
remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_unmounted(const std::wstring &location) override;
|
||||
[[nodiscard]] auto winfsp_unmounted(const std::wstring &location)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
|
||||
BOOLEAN write_to_end, BOOLEAN constrained_io,
|
||||
PUINT32 bytes_transferred, remote::file_info *file_info) override;
|
||||
[[nodiscard]] auto
|
||||
winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
|
||||
BOOLEAN write_to_end, BOOLEAN constrained_io,
|
||||
PUINT32 bytes_transferred, remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
};
|
||||
} // namespace remote_fuse
|
||||
} // namespace repertory
|
||||
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_I_OPEN_FILE_TABLE_HPP_
|
||||
#define INCLUDE_DRIVES_I_OPEN_FILE_TABLE_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_provider;
|
||||
class i_open_file_table {
|
||||
INTERFACE_SETUP(i_open_file_table);
|
||||
|
||||
public:
|
||||
typedef std::function<bool(i_open_file_table &oft, i_provider &provider)>
|
||||
locked_operation_callback;
|
||||
|
||||
public:
|
||||
virtual void close(const std::uint64_t &handle) = 0;
|
||||
|
||||
virtual bool contains_restore(const std::string &api_path) const = 0;
|
||||
|
||||
virtual bool evict_file(const std::string &api_path) = 0;
|
||||
|
||||
virtual void force_schedule_upload(const filesystem_item &fsi) = 0;
|
||||
|
||||
virtual directory_item_list get_directory_items(const std::string &api_path) const = 0;
|
||||
|
||||
virtual std::uint64_t get_open_count(const std::string &api_path) const = 0;
|
||||
|
||||
virtual bool get_open_file(const std::string &api_path, filesystem_item *&fsi) = 0;
|
||||
|
||||
virtual std::unordered_map<std::string, std::size_t> get_open_files() const = 0;
|
||||
|
||||
virtual bool has_no_open_file_handles() const = 0;
|
||||
|
||||
virtual api_error open(const filesystem_item &fsi, std::uint64_t &handle) = 0;
|
||||
|
||||
virtual bool perform_locked_operation(locked_operation_callback locked_operation) = 0;
|
||||
|
||||
virtual api_error set_item_meta(const std::string &api_path, const std::string &key,
|
||||
const std::string &value) = 0;
|
||||
|
||||
virtual void update_directory_item(directory_item &di) const = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DRIVES_I_OPEN_FILE_TABLE_HPP_
|
@ -1,751 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_OPEN_FILE_TABLE_HPP_
|
||||
#define INCLUDE_DRIVES_OPEN_FILE_TABLE_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "db/retry_db.hpp"
|
||||
#include "download/i_download_manager.hpp"
|
||||
#include "drives/i_open_file_table.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/global_data.hpp"
|
||||
#include "utils/native_file.hpp"
|
||||
#include "utils/path_utils.hpp"
|
||||
#include "utils/polling.hpp"
|
||||
|
||||
namespace repertory {
|
||||
template <typename flags> class open_file_table final : public virtual i_open_file_table {
|
||||
public:
|
||||
open_file_table(i_provider &provider, const app_config &config, i_download_manager &dm)
|
||||
: provider_(provider), config_(config), dm_(dm), retry_db_(config) {
|
||||
// Set initial value for used cache space
|
||||
global_data::instance().initialize_used_cache_space(
|
||||
utils::file::calculate_used_space(config_.get_cache_directory(), false));
|
||||
polling::instance().set_callback(
|
||||
{"last_close_clear", false, [this] {
|
||||
std::vector<std::string> keys;
|
||||
unique_mutex_lock l(last_close_mutex_);
|
||||
std::transform(last_close_lookup_.begin(), last_close_lookup_.end(),
|
||||
std::back_inserter(keys), [](const auto &kv) { return kv.first; });
|
||||
l.unlock();
|
||||
for (const auto &key : keys) {
|
||||
l.lock();
|
||||
remove_if_expired(key, last_close_lookup_[key]);
|
||||
l.unlock();
|
||||
}
|
||||
}});
|
||||
}
|
||||
|
||||
~open_file_table() override { polling::instance().remove_callback("last_close_clear"); }
|
||||
|
||||
private:
|
||||
struct open_file_info {
|
||||
filesystem_item item;
|
||||
api_meta_map meta;
|
||||
};
|
||||
|
||||
private:
|
||||
i_provider &provider_;
|
||||
const app_config &config_;
|
||||
i_download_manager &dm_;
|
||||
retry_db retry_db_;
|
||||
std::unordered_map<std::string, std::shared_ptr<open_file_info>> open_file_lookup_;
|
||||
mutable std::recursive_mutex open_file_mutex_;
|
||||
std::unordered_map<std::uint64_t, open_file_info *> open_handle_lookup_;
|
||||
std::uint64_t next_handle_ = 1u;
|
||||
bool stop_requested_ = false;
|
||||
std::mutex retry_mutex_;
|
||||
std::unique_ptr<std::thread> retry_thread_;
|
||||
std::condition_variable retry_notify_;
|
||||
std::mutex start_stop_mutex_;
|
||||
std::mutex last_close_mutex_;
|
||||
std::unordered_map<std::string, std::uint64_t> last_close_lookup_;
|
||||
|
||||
private:
|
||||
api_error get_filesystem_item(const std::string &api_path, const bool &directory,
|
||||
filesystem_item &fsi) {
|
||||
auto ret = api_error::item_not_found;
|
||||
|
||||
const auto it = open_file_lookup_.find(api_path);
|
||||
if (it != open_file_lookup_.end()) {
|
||||
fsi = it->second->item;
|
||||
ret = api_error::success;
|
||||
} else {
|
||||
ret = provider_.get_filesystem_item(api_path, directory, fsi);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::uint64_t get_next_handle() {
|
||||
std::uint64_t ret = 0u;
|
||||
while ((ret = next_handle_++) == 0u) {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
api_error handle_file_rename(const std::string &from_api_path, const std::string &to_api_path) {
|
||||
auto ret = api_error::file_in_use;
|
||||
if (dm_.pause_download(from_api_path)) {
|
||||
if ((ret = provider_.rename_file(from_api_path, to_api_path)) == api_error::success) {
|
||||
swap_renamed_items(from_api_path, to_api_path);
|
||||
dm_.rename_download(from_api_path, to_api_path);
|
||||
dm_.resume_download(to_api_path);
|
||||
|
||||
retry_db_.rename(from_api_path, to_api_path);
|
||||
} else {
|
||||
dm_.resume_download(from_api_path);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void handle_file_upload(filesystem_item &fsi) {
|
||||
fsi.changed = false;
|
||||
handle_file_upload(&fsi);
|
||||
}
|
||||
|
||||
void handle_file_upload(const filesystem_item *fsi) {
|
||||
// Remove from retry queue, if present
|
||||
retry_db_.remove(fsi->api_path);
|
||||
|
||||
// Upload file and add to retry queue on failure
|
||||
auto nf = native_file::attach(fsi->handle);
|
||||
nf->flush();
|
||||
if (provider_.upload_file(fsi->api_path, fsi->source_path, fsi->encryption_token) !=
|
||||
api_error::success) {
|
||||
retry_db_.set(fsi->api_path);
|
||||
event_system::instance().raise<failed_upload_queued>(fsi->api_path);
|
||||
}
|
||||
}
|
||||
|
||||
bool remove_if_expired(const std::string &api_path, const std::uint64_t &time) {
|
||||
auto ret = false;
|
||||
#ifdef _WIN32
|
||||
const auto delay = std::chrono::minutes(config_.get_eviction_delay_mins());
|
||||
const auto last_check = std::chrono::system_clock::from_time_t(time);
|
||||
if ((ret = ((last_check + delay) <= std::chrono::system_clock::now())))
|
||||
#else
|
||||
if ((ret = ((time + ((config_.get_eviction_delay_mins() * 60L) * NANOS_PER_SECOND)) <=
|
||||
utils::get_time_now())))
|
||||
#endif
|
||||
{
|
||||
last_close_lookup_.erase(api_path);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool retry_delete_file(const std::string &file) {
|
||||
auto deleted = false;
|
||||
for (std::uint8_t i = 0u; not(deleted = utils::file::delete_file(file)) && (i < 100u); i++) {
|
||||
std::this_thread::sleep_for(10ms);
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
void swap_renamed_items(std::string from_api_path, std::string to_api_path) {
|
||||
const auto it = open_file_lookup_.find(from_api_path);
|
||||
if (it != open_file_lookup_.end()) {
|
||||
open_file_lookup_[to_api_path] = open_file_lookup_[from_api_path];
|
||||
open_file_lookup_.erase(from_api_path);
|
||||
auto &fsi = open_file_lookup_[to_api_path]->item;
|
||||
fsi.api_path = to_api_path;
|
||||
fsi.api_parent = utils::path::get_parent_api_path(to_api_path);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
bool has_no_open_file_handles() const override {
|
||||
recur_mutex_lock l(open_file_mutex_);
|
||||
return std::find_if(open_file_lookup_.cbegin(), open_file_lookup_.cend(), [](const auto &kv) {
|
||||
return not kv.second->item.directory;
|
||||
}) == open_file_lookup_.cend();
|
||||
}
|
||||
|
||||
void close(const std::uint64_t &handle) override {
|
||||
recur_mutex_lock l(open_file_mutex_);
|
||||
const auto it = open_handle_lookup_.find(handle);
|
||||
if (it != open_handle_lookup_.end()) {
|
||||
auto *oi = it->second;
|
||||
open_handle_lookup_.erase(handle);
|
||||
|
||||
auto &fsi = oi->item;
|
||||
const auto was_changed = fsi.changed;
|
||||
|
||||
// Handle meta change
|
||||
if (fsi.meta_changed) {
|
||||
if (provider_.set_item_meta(fsi.api_path, oi->meta) == api_error::success) {
|
||||
fsi.meta_changed = false;
|
||||
} else {
|
||||
event_system::instance().raise<repertory_exception>(
|
||||
__FUNCTION__, "failed to set file meta: " + fsi.api_path);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle source path change
|
||||
if (not fsi.directory && fsi.source_path_changed) {
|
||||
if (provider_.set_source_path(fsi.api_path, fsi.source_path) == api_error::success) {
|
||||
fsi.source_path_changed = false;
|
||||
} else {
|
||||
event_system::instance().raise<repertory_exception>(
|
||||
__FUNCTION__, "failed to set source path: " + fsi.api_path + "|" + fsi.source_path);
|
||||
}
|
||||
}
|
||||
|
||||
// Update last close time in lookup table
|
||||
if (not fsi.directory) {
|
||||
mutex_lock l2(last_close_mutex_);
|
||||
last_close_lookup_[fsi.api_path] = utils::get_time_now();
|
||||
}
|
||||
|
||||
// Handle file change
|
||||
#ifdef __APPLE__
|
||||
// Special handling for OS X - only upload if handle being closed is writable
|
||||
if (not fsi.directory && was_changed && (fsi.open_data[handle] & O_ACCMODE))
|
||||
#else
|
||||
if (not fsi.directory && was_changed)
|
||||
#endif
|
||||
{
|
||||
handle_file_upload(fsi);
|
||||
}
|
||||
|
||||
// Close internal handle if no more open files
|
||||
auto &od = fsi.open_data;
|
||||
od.erase(handle);
|
||||
event_system::instance().raise<filesystem_item_handle_closed>(
|
||||
fsi.api_path, handle, fsi.source_path, fsi.directory, was_changed);
|
||||
if (od.empty()) {
|
||||
native_file::attach(fsi.handle)->close();
|
||||
|
||||
event_system::instance().raise<filesystem_item_closed>(fsi.api_path, fsi.source_path,
|
||||
fsi.directory, was_changed);
|
||||
open_file_lookup_.erase(fsi.api_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
void close_all(const std::string &api_path) {
|
||||
recur_mutex_lock l(open_file_mutex_);
|
||||
const auto it = open_file_lookup_.find(api_path);
|
||||
if (it != open_file_lookup_.end()) {
|
||||
auto *oi = it->second.get();
|
||||
std::vector<std::uint64_t> handles;
|
||||
for (const auto &kv : open_handle_lookup_) {
|
||||
if (kv.second == oi) {
|
||||
handles.emplace_back(kv.first);
|
||||
}
|
||||
}
|
||||
|
||||
while (!handles.empty()) {
|
||||
close(handles.back());
|
||||
handles.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // _WIN32
|
||||
|
||||
bool contains_restore(const std::string &api_path) const override {
|
||||
return dm_.contains_restore(api_path);
|
||||
}
|
||||
|
||||
api_error derive_file_size(const std::string &api_path, std::uint64_t &file_size) {
|
||||
auto ret = api_error::success;
|
||||
file_size = 0u;
|
||||
|
||||
if (provider_.is_file(api_path)) {
|
||||
unique_recur_mutex_lock l(open_file_mutex_);
|
||||
const auto it = open_file_lookup_.find(api_path);
|
||||
if (it == open_file_lookup_.end()) {
|
||||
l.unlock();
|
||||
ret = provider_.get_file_size(api_path, file_size);
|
||||
} else {
|
||||
file_size = open_file_lookup_[api_path]->item.size;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
api_error derive_item_data(const std::string &api_path, api_meta_map &meta) {
|
||||
auto ret = api_error::success;
|
||||
meta.clear();
|
||||
|
||||
unique_recur_mutex_lock l(open_file_mutex_);
|
||||
const auto it = open_file_lookup_.find(api_path);
|
||||
if (it == open_file_lookup_.end()) {
|
||||
l.unlock();
|
||||
ret = provider_.get_item_meta(api_path, meta);
|
||||
} else {
|
||||
meta = open_file_lookup_[api_path]->meta;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
api_error derive_item_data(const directory_item &di, std::uint64_t &file_size,
|
||||
api_meta_map &meta) {
|
||||
return derive_item_data(di.api_path, di.directory, file_size, meta);
|
||||
}
|
||||
|
||||
api_error derive_item_data(const std::string &api_path, const bool &directory,
|
||||
std::uint64_t &file_size, api_meta_map &meta) {
|
||||
auto ret = api_error::success;
|
||||
meta.clear();
|
||||
file_size = 0;
|
||||
|
||||
unique_recur_mutex_lock l(open_file_mutex_);
|
||||
const auto it = open_file_lookup_.find(api_path);
|
||||
if (it == open_file_lookup_.end()) {
|
||||
l.unlock();
|
||||
ret = provider_.get_item_meta(api_path, meta);
|
||||
if ((ret == api_error::success) && not directory) {
|
||||
ret = provider_.get_file_size(api_path, file_size);
|
||||
}
|
||||
} else {
|
||||
meta = open_file_lookup_[api_path]->meta;
|
||||
if (not directory) {
|
||||
file_size = open_file_lookup_[api_path]->item.size;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool evict_file(const std::string &api_path) override {
|
||||
auto ret = false;
|
||||
auto allow_eviction = true;
|
||||
// Ensure enough time has passed since file was closed
|
||||
{
|
||||
mutex_lock l(last_close_mutex_);
|
||||
const auto it = last_close_lookup_.find(api_path);
|
||||
if (it != last_close_lookup_.end()) {
|
||||
allow_eviction = remove_if_expired(api_path, it->second);
|
||||
}
|
||||
}
|
||||
|
||||
if (allow_eviction) {
|
||||
recur_mutex_lock l(open_file_mutex_);
|
||||
// Ensure item is not in upload retry queue
|
||||
if (not retry_db_.exists(api_path) && (get_open_count(api_path) == 0u)) {
|
||||
// Ensure item is not currently downloading
|
||||
if (not dm_.is_processing(api_path)) {
|
||||
filesystem_item fsi{};
|
||||
if (provider_.get_filesystem_item(api_path, false, fsi) == api_error::success) {
|
||||
std::uint64_t file_size = 0u;
|
||||
if ((ret = (utils::file::get_file_size(fsi.source_path, file_size) &&
|
||||
retry_delete_file(fsi.source_path)))) {
|
||||
global_data::instance().update_used_space(file_size, 0, true);
|
||||
event_system::instance().raise<filesystem_item_evicted>(fsi.api_path,
|
||||
fsi.source_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void force_schedule_upload(const filesystem_item &fsi) override {
|
||||
recur_mutex_lock l(open_file_mutex_);
|
||||
filesystem_item *fsi_ptr = nullptr;
|
||||
if (get_open_file(fsi.api_path, fsi_ptr)) {
|
||||
handle_file_upload(*fsi_ptr);
|
||||
} else {
|
||||
handle_file_upload(&fsi);
|
||||
}
|
||||
}
|
||||
|
||||
directory_item_list get_directory_items(const std::string &api_path) const override {
|
||||
directory_item_list list;
|
||||
provider_.get_directory_items(api_path, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
std::uint64_t get_open_count(const std::string &api_path) const override {
|
||||
std::uint64_t ret = 0u;
|
||||
recur_mutex_lock l(open_file_mutex_);
|
||||
const auto it = open_file_lookup_.find(api_path);
|
||||
if (it != open_file_lookup_.end()) {
|
||||
ret = it->second->item.open_data.size();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool get_open_file(const std::string &api_path, filesystem_item *&fsi) override {
|
||||
auto ret = false;
|
||||
|
||||
recur_mutex_lock l(open_file_mutex_);
|
||||
const auto it = open_file_lookup_.find(api_path);
|
||||
if (it != open_file_lookup_.end()) {
|
||||
fsi = &it->second->item;
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool get_open_file(const std::uint64_t &handle, filesystem_item *&fsi) {
|
||||
auto ret = false;
|
||||
recur_mutex_lock l(open_file_mutex_);
|
||||
const auto it = open_handle_lookup_.find(handle);
|
||||
if (it != open_handle_lookup_.end()) {
|
||||
fsi = &it->second->item;
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, std::size_t> get_open_files() const override {
|
||||
std::unordered_map<std::string, std::size_t> ret;
|
||||
unique_recur_mutex_lock l(open_file_mutex_);
|
||||
for (const auto &kv : open_file_lookup_) {
|
||||
ret.insert({kv.first, kv.second->item.open_data.size()});
|
||||
}
|
||||
l.unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
api_error open(const filesystem_item &fsi, std::uint64_t &handle) override {
|
||||
auto ret = api_error::success;
|
||||
|
||||
recur_mutex_lock l(open_file_mutex_);
|
||||
if (open_file_lookup_.find(fsi.api_path) == open_file_lookup_.end()) {
|
||||
api_meta_map meta;
|
||||
if ((ret = provider_.get_item_meta(fsi.api_path, meta)) == api_error::success) {
|
||||
auto oi = std::make_shared<open_file_info>();
|
||||
oi->meta = meta;
|
||||
oi->item = fsi;
|
||||
oi->item.lock = std::make_shared<std::recursive_mutex>();
|
||||
open_file_lookup_.insert({fsi.api_path, oi});
|
||||
|
||||
event_system::instance().raise<filesystem_item_opened>(
|
||||
oi->item.api_path, oi->item.source_path, oi->item.directory);
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == api_error::success) {
|
||||
ret = Open(fsi.api_path, fsi.directory, utils::file::get_read_write_open_flags(), handle);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
api_error Open(const std::string &api_path, const bool &directory, const flags &f,
|
||||
std::uint64_t &handle) {
|
||||
auto ret = api_error::success;
|
||||
|
||||
recur_mutex_lock l(open_file_mutex_);
|
||||
if (open_file_lookup_.find(api_path) == open_file_lookup_.end()) {
|
||||
api_meta_map meta;
|
||||
if ((ret = provider_.get_item_meta(api_path, meta)) == api_error::success) {
|
||||
auto oi = std::make_shared<open_file_info>();
|
||||
oi->meta = meta;
|
||||
if ((ret = provider_.get_filesystem_item(api_path, directory, oi->item)) ==
|
||||
api_error::success) {
|
||||
open_file_lookup_.insert({api_path, oi});
|
||||
event_system::instance().raise<filesystem_item_opened>(
|
||||
oi->item.api_path, oi->item.source_path, oi->item.directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == api_error::success) {
|
||||
auto *oi = open_file_lookup_[api_path].get();
|
||||
auto &fsi = oi->item;
|
||||
if (fsi.directory == directory) {
|
||||
handle = get_next_handle();
|
||||
fsi.open_data.insert({handle, f});
|
||||
open_handle_lookup_.insert({handle, oi});
|
||||
} else {
|
||||
ret = directory ? api_error::file_exists : api_error::directory_exists;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool perform_locked_operation(locked_operation_callback locked_operation) override {
|
||||
recur_mutex_lock l(open_file_mutex_);
|
||||
return locked_operation(*this, provider_);
|
||||
}
|
||||
|
||||
api_error remove_file(const std::string &api_path) {
|
||||
recur_mutex_lock l(open_file_mutex_);
|
||||
|
||||
filesystem_item fsi{};
|
||||
auto ret = api_error::file_in_use;
|
||||
if ((get_open_count(api_path) == 0u) &&
|
||||
((ret = provider_.get_filesystem_item(api_path, false, fsi)) == api_error::success) &&
|
||||
((ret = provider_.remove_file(api_path)) == api_error::success)) {
|
||||
std::uint64_t file_size = 0u;
|
||||
utils::file::get_file_size(fsi.source_path, file_size);
|
||||
if (retry_delete_file(fsi.source_path) && file_size) {
|
||||
global_data::instance().update_used_space(file_size, 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef HAS_SETXATTR
|
||||
api_error remove_xattr_meta(const std::string &api_path, const std::string &name) {
|
||||
auto ret = api_error::xattr_not_found;
|
||||
if (utils::collection_excludes(META_USED_NAMES, name)) {
|
||||
unique_recur_mutex_lock l(open_file_mutex_);
|
||||
if (open_file_lookup_.find(api_path) == open_file_lookup_.end()) {
|
||||
l.unlock();
|
||||
ret = provider_.remove_item_meta(api_path, name);
|
||||
} else if (open_file_lookup_[api_path]->meta.find(name) !=
|
||||
open_file_lookup_[api_path]->meta.end()) {
|
||||
open_file_lookup_[api_path]->item.meta_changed = true;
|
||||
open_file_lookup_[api_path]->meta.erase(name);
|
||||
ret = api_error::success;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
api_error rename_directory(const std::string &from_api_path, const std::string &to_api_path) {
|
||||
unique_recur_mutex_lock l(open_file_mutex_);
|
||||
auto ret = api_error::not_implemented;
|
||||
if (provider_.is_rename_supported()) {
|
||||
ret = api_error::directory_not_found;
|
||||
// Ensure source directory exists
|
||||
if (provider_.is_directory(from_api_path)) {
|
||||
ret = api_error::directory_exists;
|
||||
// Ensure destination directory does not exist
|
||||
if (not provider_.is_directory(to_api_path)) {
|
||||
ret = api_error::file_exists;
|
||||
// Ensure destination is not a file
|
||||
if (not provider_.is_file(from_api_path)) {
|
||||
ret = api_error::directory_not_found;
|
||||
// Ensure parent destination directory exists
|
||||
directory_item_list list;
|
||||
if (provider_.is_directory(utils::path::get_parent_api_path(to_api_path)) &&
|
||||
((ret = provider_.create_directory_clone_source_meta(from_api_path, to_api_path)) ==
|
||||
api_error::success) &&
|
||||
((ret = provider_.get_directory_items(from_api_path, list)) ==
|
||||
api_error::success)) {
|
||||
// Rename all items - directories MUST BE returned first
|
||||
for (std::size_t i = 0u; (ret == api_error::success) && (i < list.size()); i++) {
|
||||
const auto &api_path = list[i].api_path;
|
||||
if ((api_path != ".") && (api_path != "..")) {
|
||||
const auto old_api_path = api_path;
|
||||
const auto new_api_path = utils::path::create_api_path(utils::path::combine(
|
||||
to_api_path, {old_api_path.substr(from_api_path.size())}));
|
||||
if (list[i].directory) {
|
||||
ret = rename_directory(old_api_path, new_api_path);
|
||||
} else {
|
||||
ret = rename_file(old_api_path, new_api_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == api_error::success) {
|
||||
swap_renamed_items(from_api_path, to_api_path);
|
||||
ret = provider_.remove_directory(from_api_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
api_error rename_file(const std::string &from_api_path, const std::string &to_api_path,
|
||||
const bool &overwrite = true) {
|
||||
auto ret = api_error::not_implemented;
|
||||
if (provider_.is_rename_supported()) {
|
||||
// Don't rename if paths are the same
|
||||
if ((ret = (from_api_path == to_api_path) ? api_error::file_exists : api_error::success) ==
|
||||
api_error::success) {
|
||||
retry_db_.pause();
|
||||
|
||||
unique_recur_mutex_lock l(open_file_mutex_);
|
||||
// Check allow overwrite if file exists
|
||||
if (not overwrite && provider_.is_file(to_api_path)) {
|
||||
l.unlock();
|
||||
ret = api_error::file_exists;
|
||||
} else {
|
||||
// Don't rename if source does not exist
|
||||
if ((ret = provider_.is_file(from_api_path)
|
||||
? api_error::success
|
||||
: api_error::item_not_found) == api_error::success) {
|
||||
// Don't rename if destination file is downloading
|
||||
if ((ret = dm_.is_processing(to_api_path) ? api_error::file_in_use
|
||||
: api_error::success) == api_error::success) {
|
||||
// Don't rename if destination file has open handles
|
||||
ret = api_error::file_in_use;
|
||||
if (get_open_count(to_api_path) == 0u) {
|
||||
if (provider_.is_file(
|
||||
to_api_path)) { // Handle destination file exists (should overwrite)
|
||||
filesystem_item fsi{};
|
||||
if ((ret = get_filesystem_item(to_api_path, false, fsi)) == api_error::success) {
|
||||
ret = api_error::os_error;
|
||||
std::uint64_t file_size = 0u;
|
||||
if (utils::file::get_file_size(fsi.source_path, file_size)) {
|
||||
ret = provider_.remove_file(to_api_path);
|
||||
if ((ret == api_error::success) || (ret == api_error::item_not_found)) {
|
||||
if (retry_delete_file(fsi.source_path) && file_size) {
|
||||
global_data::instance().update_used_space(file_size, 0, false);
|
||||
}
|
||||
ret = handle_file_rename(from_api_path, to_api_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
l.unlock();
|
||||
} else if (provider_.is_directory(to_api_path)) { // Handle destination is directory
|
||||
l.unlock();
|
||||
ret = api_error::directory_exists;
|
||||
} else if (provider_.is_directory(utils::path::get_parent_api_path(
|
||||
to_api_path))) { // Handle rename if destination directory exists
|
||||
ret = handle_file_rename(from_api_path, to_api_path);
|
||||
l.unlock();
|
||||
} else { // Destination directory not found
|
||||
l.unlock();
|
||||
ret = api_error::directory_not_found;
|
||||
}
|
||||
}
|
||||
} else if (provider_.is_directory(from_api_path)) {
|
||||
l.unlock();
|
||||
ret = api_error::directory_exists;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
retry_db_.resume();
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
api_error set_item_meta(const std::string &api_path, const std::string &key,
|
||||
const std::string &value) override {
|
||||
unique_recur_mutex_lock l(open_file_mutex_);
|
||||
if (open_file_lookup_.find(api_path) == open_file_lookup_.end()) {
|
||||
l.unlock();
|
||||
return provider_.set_item_meta(api_path, key, value);
|
||||
}
|
||||
|
||||
if (open_file_lookup_[api_path]->meta[key] != value) {
|
||||
open_file_lookup_[api_path]->item.meta_changed = true;
|
||||
open_file_lookup_[api_path]->meta[key] = value;
|
||||
}
|
||||
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
api_error set_item_meta(const std::string &api_path, const api_meta_map &meta) {
|
||||
auto ret = api_error::success;
|
||||
auto it = meta.begin();
|
||||
for (std::size_t i = 0u; (ret == api_error::success) && (i < meta.size()); i++) {
|
||||
ret = set_item_meta(api_path, it->first, it->second);
|
||||
it++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void start() {
|
||||
mutex_lock start_stop_lock(start_stop_mutex_);
|
||||
if (not retry_thread_) {
|
||||
stop_requested_ = false;
|
||||
retry_thread_ = std::make_unique<std::thread>([this] {
|
||||
while (not stop_requested_) {
|
||||
const auto processed = retry_db_.process_all([this](const std::string &api_path) -> bool {
|
||||
auto success = false;
|
||||
event_system::instance().raise<failed_upload_retry>(api_path);
|
||||
unique_recur_mutex_lock open_file_lock(open_file_mutex_);
|
||||
if (open_file_lookup_.find(api_path) == open_file_lookup_.end()) {
|
||||
open_file_lock.unlock();
|
||||
|
||||
filesystem_item fsi{};
|
||||
const auto res = provider_.get_filesystem_item(api_path, false, fsi);
|
||||
if ((res == api_error::success) ||
|
||||
((res == api_error::item_not_found) && provider_.is_file(api_path))) {
|
||||
if (provider_.upload_file(api_path, fsi.source_path, fsi.encryption_token) ==
|
||||
api_error::success) {
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove deleted files
|
||||
if (not success && not provider_.is_file(api_path)) {
|
||||
success = true;
|
||||
}
|
||||
} else {
|
||||
// File is open, so force re-upload on close
|
||||
open_file_lookup_[api_path]->item.changed = true;
|
||||
open_file_lock.unlock();
|
||||
success = true;
|
||||
}
|
||||
|
||||
return success;
|
||||
});
|
||||
if (not processed && not stop_requested_) {
|
||||
unique_mutex_lock retryLock(retry_mutex_);
|
||||
if (not stop_requested_) {
|
||||
retry_notify_.wait_for(retryLock, 5s);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void stop() {
|
||||
mutex_lock start_stop_lock(start_stop_mutex_);
|
||||
if (retry_thread_) {
|
||||
event_system::instance().raise<service_shutdown>("open_file_table");
|
||||
stop_requested_ = true;
|
||||
|
||||
unique_mutex_lock retry_lock(retry_mutex_);
|
||||
retry_notify_.notify_all();
|
||||
retry_lock.unlock();
|
||||
|
||||
retry_thread_->join();
|
||||
retry_thread_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void update_directory_item(directory_item &di) const override {
|
||||
recur_mutex_lock l(open_file_mutex_);
|
||||
const auto it = open_file_lookup_.find(di.api_path);
|
||||
if (it != open_file_lookup_.end()) {
|
||||
const auto &ofi = open_file_lookup_.at(di.api_path);
|
||||
di.meta = ofi->meta;
|
||||
if (not di.directory) {
|
||||
di.size = ofi->item.size;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DRIVES_OPEN_FILE_TABLE_HPP_
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_REMOTE_I_REMOTEJSON_HPP_
|
||||
#define INCLUDE_DRIVES_REMOTE_I_REMOTEJSON_HPP_
|
||||
#ifndef INCLUDE_DRIVES_REMOTE_I_REMOTE_JSON_HPP_
|
||||
#define INCLUDE_DRIVES_REMOTE_I_REMOTE_JSON_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "comm/packet/packet.hpp"
|
||||
|
||||
namespace repertory {
|
||||
@ -27,18 +29,19 @@ class i_remote_json {
|
||||
INTERFACE_SETUP(i_remote_json);
|
||||
|
||||
public:
|
||||
virtual packet::error_type json_create_directory_snapshot(const std::string &path,
|
||||
json &json_data) = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
json_create_directory_snapshot(const std::string &path, json &json_data)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type json_read_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle,
|
||||
const std::uint32_t &page,
|
||||
json &json_data) = 0;
|
||||
[[nodiscard]] virtual auto json_read_directory_snapshot(
|
||||
const std::string &path, const remote::file_handle &handle,
|
||||
std::uint32_t page, json &json_data) -> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type
|
||||
[[nodiscard]] virtual auto
|
||||
json_release_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle) = 0;
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DRIVES_REMOTE_I_REMOTEJSON_HPP_
|
||||
#endif // INCLUDE_DRIVES_REMOTE_I_REMOTE_JSON_HPP_
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_REMOTE_REMOTE_OPEN_FILE_TABLE_HPP_
|
||||
#define INCLUDE_DRIVES_REMOTE_REMOTE_OPEN_FILE_TABLE_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/remote.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
@ -34,6 +36,7 @@ protected:
|
||||
struct compat_open_info {
|
||||
std::size_t count = 0u;
|
||||
std::string client_id = "";
|
||||
std::string path;
|
||||
};
|
||||
|
||||
struct open_info {
|
||||
@ -45,11 +48,11 @@ protected:
|
||||
|
||||
private:
|
||||
std::unordered_map<remote::file_handle, compat_open_info> compat_lookup_;
|
||||
std::mutex compat_mutex_;
|
||||
std::recursive_mutex compat_mutex_;
|
||||
std::unordered_map<std::string, std::vector<void *>> directory_lookup_;
|
||||
std::mutex directory_mutex_;
|
||||
std::unordered_map<OSHandle, open_info> file_lookup_;
|
||||
std::mutex file_mutex_;
|
||||
std::recursive_mutex directory_mutex_;
|
||||
std::unordered_map<native_handle, open_info> file_lookup_;
|
||||
mutable std::recursive_mutex file_mutex_;
|
||||
|
||||
protected:
|
||||
void add_directory(const std::string &client_id, void *dir);
|
||||
@ -59,36 +62,52 @@ protected:
|
||||
virtual void delete_open_directory(void *dir) = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
bool get_directory_buffer(const OSHandle &handle, PVOID *&buffer);
|
||||
#endif
|
||||
[[nodiscard]] auto get_directory_buffer(const native_handle &handle,
|
||||
PVOID *&buffer) -> bool;
|
||||
#endif // _WIN32
|
||||
|
||||
bool get_open_info(const OSHandle &handle, open_info &oi);
|
||||
[[nodiscard]] auto get_open_file_path(const native_handle &handle)
|
||||
-> std::string;
|
||||
|
||||
std::string get_open_file_path(const OSHandle &handle);
|
||||
[[nodiscard]] auto get_open_info(const native_handle &handle, open_info &oi)
|
||||
-> bool;
|
||||
|
||||
bool has_open_directory(const std::string &client_id, void *dir);
|
||||
[[nodiscard]] auto has_open_directory(const std::string &client_id, void *dir)
|
||||
-> bool;
|
||||
|
||||
int has_compat_open_info(const remote::file_handle &handle, const int &error_return);
|
||||
[[nodiscard]] auto has_compat_open_info(const remote::file_handle &handle,
|
||||
int error_return) -> int;
|
||||
|
||||
template <typename error_type>
|
||||
error_type has_open_info(const OSHandle &handle, const error_type &error_return) {
|
||||
mutex_lock file_lock(file_mutex_);
|
||||
return ((file_lookup_.find(handle) == file_lookup_.end()) ? error_return : 0);
|
||||
[[nodiscard]] auto has_open_info(const native_handle &handle,
|
||||
const error_type &error_return)
|
||||
-> error_type {
|
||||
recur_mutex_lock file_lock(file_mutex_);
|
||||
return ((file_lookup_.find(handle) == file_lookup_.end()) ? error_return
|
||||
: 0);
|
||||
}
|
||||
|
||||
void remove_all(const std::string &file_path);
|
||||
|
||||
void remove_compat_open_info(const remote::file_handle &handle);
|
||||
|
||||
bool remove_directory(const std::string &client_id, void *dir);
|
||||
auto remove_directory(const std::string &client_id, void *dir) -> bool;
|
||||
|
||||
void remove_open_info(const OSHandle &handle);
|
||||
void remove_open_info(const native_handle &handle);
|
||||
|
||||
void set_client_id(const OSHandle &handle, const std::string &client_id);
|
||||
void set_client_id(const native_handle &handle, const std::string &client_id);
|
||||
|
||||
void set_compat_client_id(const remote::file_handle &handle, const std::string &client_id);
|
||||
void set_compat_client_id(const remote::file_handle &handle,
|
||||
const std::string &client_id);
|
||||
|
||||
void set_compat_open_info(const remote::file_handle &handle);
|
||||
void set_compat_open_info(const remote::file_handle &handle,
|
||||
const std::string &file_path);
|
||||
|
||||
void set_open_info(const OSHandle &handle, open_info oi);
|
||||
void set_open_info(const native_handle &handle, open_info oi);
|
||||
|
||||
public:
|
||||
[[nodiscard]] auto get_open_file_count(const std::string &file_path) const
|
||||
-> std::size_t;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,26 +1,28 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_WINFSP_I_WINFSP_DRIVE_HPP_
|
||||
#define INCLUDE_DRIVES_WINFSP_I_WINFSP_DRIVE_HPP_
|
||||
#ifdef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/remote.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
@ -29,31 +31,43 @@ class i_winfsp_drive {
|
||||
INTERFACE_SETUP(i_winfsp_drive);
|
||||
|
||||
public:
|
||||
virtual std::uint64_t get_directory_item_count(const std::string &api_path) const = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_directory_item_count(const std::string &api_path) const
|
||||
-> std::uint64_t = 0;
|
||||
|
||||
virtual directory_item_list get_directory_items(const std::string &api_path) const = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_directory_items(const std::string &api_path) const
|
||||
-> directory_item_list = 0;
|
||||
|
||||
virtual std::uint64_t get_file_size(const std::string &api_path) const = 0;
|
||||
[[nodiscard]] virtual auto get_file_size(const std::string &api_path) const
|
||||
-> std::uint64_t = 0;
|
||||
|
||||
virtual api_error get_item_meta(const std::string &api_path, const std::string &name,
|
||||
std::string &value) const = 0;
|
||||
[[nodiscard]] virtual auto get_item_meta(const std::string &api_path,
|
||||
const std::string &name,
|
||||
std::string &value) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual api_error get_item_meta(const std::string &api_path, api_meta_map &meta) const = 0;
|
||||
[[nodiscard]] virtual auto get_item_meta(const std::string &api_path,
|
||||
api_meta_map &meta) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual NTSTATUS get_security_by_name(PWSTR file_name, PUINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR descriptor,
|
||||
std::uint64_t *descriptor_size) = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_security_by_name(PWSTR file_name, PUINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR descriptor,
|
||||
std::uint64_t *descriptor_size) -> NTSTATUS = 0;
|
||||
|
||||
virtual std::uint64_t get_total_drive_space() const = 0;
|
||||
[[nodiscard]] virtual auto get_total_drive_space() const -> std::uint64_t = 0;
|
||||
|
||||
virtual std::uint64_t get_total_item_count() const = 0;
|
||||
[[nodiscard]] virtual auto get_total_item_count() const -> std::uint64_t = 0;
|
||||
|
||||
virtual std::uint64_t get_used_drive_space() const = 0;
|
||||
[[nodiscard]] virtual auto get_used_drive_space() const -> std::uint64_t = 0;
|
||||
|
||||
virtual void get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label) const = 0;
|
||||
|
||||
virtual api_error populate_file_info(const std::string &api_path, remote::file_info &fi) = 0;
|
||||
[[nodiscard]] virtual auto populate_file_info(const std::string &api_path,
|
||||
remote::file_info &fi)
|
||||
-> api_error = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_WINFSP_REMOTEWINFSP_I_REMOTE_INSTANCE_HPP_
|
||||
#define INCLUDE_DRIVES_WINFSP_REMOTEWINFSP_I_REMOTE_INSTANCE_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "drives/remote/i_remote_json.hpp"
|
||||
|
||||
namespace repertory::remote_winfsp {
|
||||
@ -27,68 +29,89 @@ class i_remote_instance : public virtual i_remote_json {
|
||||
INTERFACE_SETUP(i_remote_instance);
|
||||
|
||||
public:
|
||||
virtual packet::error_type winfsp_can_delete(PVOID fileDesc, PWSTR fileName) = 0;
|
||||
virtual auto winfsp_can_delete(PVOID fileDesc, PWSTR fileName)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_cleanup(PVOID fileDesc, PWSTR fileName, UINT32 flags,
|
||||
BOOLEAN &wasClosed) = 0;
|
||||
virtual auto winfsp_cleanup(PVOID fileDesc, PWSTR fileName, UINT32 flags,
|
||||
BOOLEAN &wasClosed) -> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_close(PVOID fileDesc) = 0;
|
||||
virtual auto winfsp_close(PVOID fileDesc) -> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_create(PWSTR fileName, UINT32 createOptions,
|
||||
UINT32 grantedAccess, UINT32 fileAttributes,
|
||||
UINT64 allocationSize, PVOID *fileDesc,
|
||||
remote::file_info *fileInfo, std::string &normalizedName,
|
||||
BOOLEAN &exists) = 0;
|
||||
virtual auto winfsp_create(PWSTR fileName, UINT32 createOptions,
|
||||
UINT32 grantedAccess, UINT32 fileAttributes,
|
||||
UINT64 allocationSize, PVOID *fileDesc,
|
||||
remote::file_info *fileInfo,
|
||||
std::string &normalizedName, BOOLEAN &exists)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_flush(PVOID fileDesc, remote::file_info *fileInfo) = 0;
|
||||
virtual auto winfsp_flush(PVOID fileDesc, remote::file_info *fileInfo)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_get_dir_buffer(PVOID fileDesc, PVOID *&ptr) = 0;
|
||||
virtual auto winfsp_get_dir_buffer(PVOID fileDesc, PVOID *&ptr)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_get_file_info(PVOID fileDesc, remote::file_info *fileInfo) = 0;
|
||||
virtual auto winfsp_get_file_info(PVOID fileDesc, remote::file_info *fileInfo)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_get_security_by_name(PWSTR fileName, PUINT32 fileAttributes,
|
||||
std::uint64_t *securityDescriptorSize,
|
||||
std::wstring &strDescriptor) = 0;
|
||||
virtual auto
|
||||
winfsp_get_security_by_name(PWSTR fileName, PUINT32 fileAttributes,
|
||||
std::uint64_t *securityDescriptorSize,
|
||||
std::wstring &strDescriptor)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_get_volume_info(UINT64 &totalSize, UINT64 &freeSize,
|
||||
std::string &volumeLabel) = 0;
|
||||
virtual auto winfsp_get_volume_info(UINT64 &totalSize, UINT64 &freeSize,
|
||||
std::string &volumeLabel)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_mounted(const std::wstring &location) = 0;
|
||||
virtual auto winfsp_mounted(const std::wstring &location)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_open(PWSTR fileName, UINT32 createOptions, UINT32 grantedAccess,
|
||||
PVOID *fileDesc, remote::file_info *fileInfo,
|
||||
std::string &normalizedName) = 0;
|
||||
virtual auto winfsp_open(PWSTR fileName, UINT32 createOptions,
|
||||
UINT32 grantedAccess, PVOID *fileDesc,
|
||||
remote::file_info *fileInfo,
|
||||
std::string &normalizedName)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_overwrite(PVOID fileDesc, UINT32 fileAttributes,
|
||||
BOOLEAN replaceFileAttributes, UINT64 allocationSize,
|
||||
remote::file_info *fileInfo) = 0;
|
||||
virtual auto winfsp_overwrite(PVOID fileDesc, UINT32 fileAttributes,
|
||||
BOOLEAN replaceFileAttributes,
|
||||
UINT64 allocationSize,
|
||||
remote::file_info *fileInfo)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_read(PVOID fileDesc, PVOID buffer, UINT64 offset, UINT32 length,
|
||||
PUINT32 bytesTransferred) = 0;
|
||||
virtual auto winfsp_read(PVOID fileDesc, PVOID buffer, UINT64 offset,
|
||||
UINT32 length, PUINT32 bytesTransferred)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_read_directory(PVOID fileDesc, PWSTR pattern, PWSTR marker,
|
||||
json &itemList) = 0;
|
||||
virtual auto winfsp_read_directory(PVOID fileDesc, PWSTR pattern,
|
||||
PWSTR marker, json &itemList)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_rename(PVOID fileDesc, PWSTR fileName, PWSTR newFileName,
|
||||
BOOLEAN replaceIfExists) = 0;
|
||||
virtual auto winfsp_rename(PVOID fileDesc, PWSTR fileName, PWSTR newFileName,
|
||||
BOOLEAN replaceIfExists) -> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_set_basic_info(PVOID fileDesc, UINT32 fileAttributes,
|
||||
UINT64 creationTime, UINT64 lastAccessTime,
|
||||
UINT64 lastWriteTime, UINT64 changeTime,
|
||||
remote::file_info *fileInfo) = 0;
|
||||
virtual auto winfsp_set_basic_info(PVOID fileDesc, UINT32 fileAttributes,
|
||||
UINT64 creationTime, UINT64 lastAccessTime,
|
||||
UINT64 lastWriteTime, UINT64 changeTime,
|
||||
remote::file_info *fileInfo)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_set_file_size(PVOID fileDesc, UINT64 newSize,
|
||||
BOOLEAN setAllocationSize,
|
||||
remote::file_info *fileInfo) = 0;
|
||||
virtual auto winfsp_set_file_size(PVOID fileDesc, UINT64 newSize,
|
||||
BOOLEAN setAllocationSize,
|
||||
remote::file_info *fileInfo)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_unmounted(const std::wstring &location) = 0;
|
||||
virtual auto winfsp_unmounted(const std::wstring &location)
|
||||
-> packet::error_type = 0;
|
||||
|
||||
virtual packet::error_type winfsp_write(PVOID fileDesc, PVOID buffer, UINT64 offset,
|
||||
UINT32 length, BOOLEAN writeToEndOfFile,
|
||||
BOOLEAN constrainedIo, PUINT32 bytesTransferred,
|
||||
remote::file_info *fileInfo) = 0;
|
||||
virtual auto winfsp_write(PVOID fileDesc, PVOID buffer, UINT64 offset,
|
||||
UINT32 length, BOOLEAN writeToEndOfFile,
|
||||
BOOLEAN constrainedIo, PUINT32 bytesTransferred,
|
||||
remote::file_info *fileInfo)
|
||||
-> packet::error_type = 0;
|
||||
};
|
||||
typedef std::function<std::unique_ptr<i_remote_instance>()> remote_instance_factory;
|
||||
|
||||
using remote_instance_factory =
|
||||
std::function<std::unique_ptr<i_remote_instance>()>;
|
||||
} // namespace repertory::remote_winfsp
|
||||
|
||||
#endif // INCLUDE_DRIVES_WINFSP_REMOTEWINFSP_I_REMOTE_INSTANCE_HPP_
|
||||
|
@ -1,34 +1,37 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_WINFSP_REMOTEWINFSP_REMOTE_CLIENT_HPP_
|
||||
#define INCLUDE_DRIVES_WINFSP_REMOTEWINFSP_REMOTE_CLIENT_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "comm/packet/packet.hpp"
|
||||
#include "comm/packet/packet_client.hpp"
|
||||
#include "drives/winfsp/remotewinfsp/i_remote_instance.hpp"
|
||||
#include "drives/remote/remote_open_file_table.hpp"
|
||||
#include "drives/winfsp/remotewinfsp/i_remote_instance.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
namespace remote_winfsp {
|
||||
class remote_client final : public remote_open_file_table, public virtual i_remote_instance {
|
||||
class remote_client final : public remote_open_file_table,
|
||||
public virtual i_remote_instance {
|
||||
public:
|
||||
explicit remote_client(const app_config &config);
|
||||
|
||||
@ -40,84 +43,97 @@ private:
|
||||
#ifdef _WIN32
|
||||
#define to_handle(x) (x)
|
||||
#else
|
||||
static OSHandle to_handle(PVOID file_desc) {
|
||||
return static_cast<OSHandle>(reinterpret_cast<std::uint64_t>(file_desc));
|
||||
}
|
||||
static auto to_handle(PVOID file_desc) -> native_handle;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void delete_open_directory(void * /*dir*/) override {}
|
||||
|
||||
public:
|
||||
packet::error_type json_create_directory_snapshot(const std::string &path,
|
||||
json &json_data) override;
|
||||
auto json_create_directory_snapshot(const std::string &path, json &json_data)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type json_read_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle,
|
||||
const std::uint32_t &page,
|
||||
json &json_data) override;
|
||||
auto json_read_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle,
|
||||
std::uint32_t page, json &json_data)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type json_release_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle) override;
|
||||
auto json_release_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_can_delete(PVOID file_desc, PWSTR file_name) override;
|
||||
auto winfsp_can_delete(PVOID file_desc, PWSTR file_name)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags,
|
||||
BOOLEAN &was_closed) override;
|
||||
auto winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags,
|
||||
BOOLEAN &was_closed) -> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_close(PVOID file_desc) override;
|
||||
auto winfsp_close(PVOID file_desc) -> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_create(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
|
||||
UINT32 attributes, UINT64 allocation_size, PVOID *file_desc,
|
||||
remote::file_info *file_info, std::string &normalized_name,
|
||||
BOOLEAN &exists) override;
|
||||
auto winfsp_create(PWSTR file_name, UINT32 create_options,
|
||||
UINT32 granted_access, UINT32 attributes,
|
||||
UINT64 allocation_size, PVOID *file_desc,
|
||||
remote::file_info *file_info, std::string &normalized_name,
|
||||
BOOLEAN &exists) -> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_flush(PVOID file_desc, remote::file_info *file_info) override;
|
||||
auto winfsp_flush(PVOID file_desc, remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_get_dir_buffer(PVOID file_desc, PVOID *&ptr) override;
|
||||
auto winfsp_get_dir_buffer(PVOID file_desc, PVOID *&ptr)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_get_file_info(PVOID file_desc, remote::file_info *file_info) override;
|
||||
auto winfsp_get_file_info(PVOID file_desc, remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_get_security_by_name(PWSTR file_name, PUINT32 attributes,
|
||||
std::uint64_t *descriptor_size,
|
||||
std::wstring &string_descriptor) override;
|
||||
auto winfsp_get_security_by_name(PWSTR file_name, PUINT32 attributes,
|
||||
std::uint64_t *descriptor_size,
|
||||
std::wstring &string_descriptor)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label) override;
|
||||
auto winfsp_get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_mounted(const std::wstring &location) override;
|
||||
auto winfsp_mounted(const std::wstring &location)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_open(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
|
||||
PVOID *file_desc, remote::file_info *file_info,
|
||||
std::string &normalized_name) override;
|
||||
auto winfsp_open(PWSTR file_name, UINT32 create_options,
|
||||
UINT32 granted_access, PVOID *file_desc,
|
||||
remote::file_info *file_info, std::string &normalized_name)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_overwrite(PVOID file_desc, UINT32 attributes,
|
||||
BOOLEAN replace_attributes, UINT64 allocation_size,
|
||||
remote::file_info *file_info) override;
|
||||
auto winfsp_overwrite(PVOID file_desc, UINT32 attributes,
|
||||
BOOLEAN replace_attributes, UINT64 allocation_size,
|
||||
remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
|
||||
PUINT32 bytes_transferred) override;
|
||||
auto winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
|
||||
PUINT32 bytes_transferred) -> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_read_directory(PVOID file_desc, PWSTR pattern, PWSTR marker,
|
||||
json &itemList) override;
|
||||
auto winfsp_read_directory(PVOID file_desc, PWSTR pattern, PWSTR marker,
|
||||
json &itemList) -> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_rename(PVOID file_desc, PWSTR file_name, PWSTR new_file_name,
|
||||
BOOLEAN replace_if_exists) override;
|
||||
auto winfsp_rename(PVOID file_desc, PWSTR file_name, PWSTR new_file_name,
|
||||
BOOLEAN replace_if_exists) -> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_set_basic_info(PVOID file_desc, UINT32 attributes, UINT64 creation_time,
|
||||
UINT64 last_access_time, UINT64 last_write_time,
|
||||
UINT64 change_time,
|
||||
remote::file_info *file_info) override;
|
||||
auto winfsp_set_basic_info(PVOID file_desc, UINT32 attributes,
|
||||
UINT64 creation_time, UINT64 last_access_time,
|
||||
UINT64 last_write_time, UINT64 change_time,
|
||||
remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
|
||||
BOOLEAN set_allocation_size,
|
||||
remote::file_info *file_info) override;
|
||||
auto winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
|
||||
BOOLEAN set_allocation_size,
|
||||
remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_unmounted(const std::wstring &location) override;
|
||||
auto winfsp_unmounted(const std::wstring &location)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
|
||||
BOOLEAN write_to_end, BOOLEAN constrained_io,
|
||||
PUINT32 bytes_transferred, remote::file_info *file_info) override;
|
||||
auto winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
|
||||
BOOLEAN write_to_end, BOOLEAN constrained_io,
|
||||
PUINT32 bytes_transferred, remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
};
|
||||
} // namespace remote_winfsp
|
||||
} // namespace repertory
|
||||
|
@ -1,20 +1,23 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
// NOTE: Most of the WinFSP pass-through code has been modified from:
|
||||
// https://github.com/billziss-gh/winfsp/blob/master/tst/passthrough-cpp/passthrough-cpp.cpp
|
||||
@ -22,7 +25,6 @@
|
||||
#define INCLUDE_DRIVES_WINFSP_REMOTEWINFSP_REMOTE_SERVER_HPP_
|
||||
#ifdef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "comm/packet/packet.hpp"
|
||||
#include "drives/remote/remote_server_base.hpp"
|
||||
#include "drives/winfsp/i_winfsp_drive.hpp"
|
||||
@ -32,207 +34,250 @@ class app_config;
|
||||
namespace remote_winfsp {
|
||||
class remote_server final : public virtual remote_server_base<i_winfsp_drive> {
|
||||
public:
|
||||
remote_server(app_config &config, i_winfsp_drive &drive, const std::string &mount_location)
|
||||
: remote_server_base(config, drive, mount_location) {}
|
||||
remote_server(app_config &config, i_winfsp_drive &drive,
|
||||
const std::string &mount_location)
|
||||
: remote_server_base(config, drive,
|
||||
utils::string::to_lower(mount_location)) {}
|
||||
|
||||
private:
|
||||
std::string construct_path(std::string path);
|
||||
[[nodiscard]] auto construct_path(std::string path) -> std::string;
|
||||
|
||||
packet::error_type populate_file_info(const std::string &api_path, remote::file_info &file_info);
|
||||
[[nodiscard]] auto populate_file_info(const std::string &api_path,
|
||||
remote::file_info &file_info)
|
||||
-> packet::error_type;
|
||||
|
||||
void populate_stat(const char *path, const bool &directory, remote::stat &st,
|
||||
void populate_stat(const char *path, bool directory, remote::stat &st,
|
||||
const struct _stat64 &st1);
|
||||
|
||||
public:
|
||||
// FUSE Layer
|
||||
packet::error_type fuse_access(const char *path, const std::int32_t &mask) override;
|
||||
auto fuse_access(const char *path, const std::int32_t &mask)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_chflags(const char *path, const std::uint32_t &flags) override;
|
||||
auto fuse_chflags(const char *path, std::uint32_t flags)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_chmod(const char *path, const remote::file_mode &mode) override;
|
||||
auto fuse_chmod(const char *path, const remote::file_mode &mode)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_chown(const char *path, const remote::user_id &uid,
|
||||
const remote::group_id &gid) override;
|
||||
auto fuse_chown(const char *path, const remote::user_id &uid,
|
||||
const remote::group_id &gid) -> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_destroy() override;
|
||||
auto fuse_destroy() -> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_fallocate(const char *path, const std::int32_t &mode,
|
||||
const remote::file_offset &offset,
|
||||
const remote::file_offset &length,
|
||||
const remote::file_handle &handle) override ;*/
|
||||
/*packet::error_type fuse_fallocate(const char *path, const std::int32_t
|
||||
&mode, const remote::file_offset &offset, const remote::file_offset
|
||||
&length, const remote::file_handle &handle) override ;*/
|
||||
|
||||
packet::error_type fuse_fgetattr(const char *path, remote::stat &st, bool &directory,
|
||||
const remote::file_handle &handle) override;
|
||||
auto fuse_fgetattr(const char *path, remote::stat &st, bool &directory,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_fsetattr_x(const char *path, const remote::setattr_x &attr,
|
||||
const remote::file_handle &handle) override;
|
||||
auto fuse_fsetattr_x(const char *path, const remote::setattr_x &attr,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_fsync(const char *path, const std::int32_t &datasync,
|
||||
const remote::file_handle &handle) override;
|
||||
auto fuse_fsync(const char *path, const std::int32_t &datasync,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_ftruncate(const char *path, const remote::file_offset &size,
|
||||
const remote::file_handle &handle) override;
|
||||
auto fuse_ftruncate(const char *path, const remote::file_offset &size,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_getattr(const char *path, remote::stat &st, bool &directory) override;
|
||||
auto fuse_getattr(const char *path, remote::stat &st, bool &directory)
|
||||
-> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_getxattr(const char *path, const char *name, char *value,
|
||||
const remote::file_size &size) override ;
|
||||
/*packet::error_type fuse_getxattr(const char *path, const char *name, char
|
||||
*value, const remote::file_size &size) override ;
|
||||
|
||||
packet::error_type fuse_getxattrOSX(const char *path, const char *name, char *value,
|
||||
const remote::file_size &size,
|
||||
const std::uint32_t &position) override ;*/
|
||||
packet::error_type fuse_getxattrOSX(const char *path, const char *name, char
|
||||
*value, const remote::file_size &size, std::uint32_t position) override ;*/
|
||||
|
||||
packet::error_type fuse_getxtimes(const char *path, remote::file_time &bkuptime,
|
||||
remote::file_time &crtime) override;
|
||||
auto fuse_getxtimes(const char *path, remote::file_time &bkuptime,
|
||||
remote::file_time &crtime) -> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_init() override;
|
||||
auto fuse_init() -> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_listxattr(const char *path, char *buffer,
|
||||
const remote::file_size &size) override ;*/
|
||||
const remote::file_size &size) override
|
||||
;*/
|
||||
|
||||
packet::error_type fuse_mkdir(const char *path, const remote::file_mode &mode) override;
|
||||
auto fuse_mkdir(const char *path, const remote::file_mode &mode)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_opendir(const char *path, remote::file_handle &handle) override;
|
||||
auto fuse_opendir(const char *path, remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_create(const char *path, const remote::file_mode &mode,
|
||||
const remote::open_flags &flags,
|
||||
remote::file_handle &handle) override;
|
||||
auto fuse_create(const char *path, const remote::file_mode &mode,
|
||||
const remote::open_flags &flags, remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_open(const char *path, const remote::open_flags &flags,
|
||||
remote::file_handle &handle) override;
|
||||
auto fuse_open(const char *path, const remote::open_flags &flags,
|
||||
remote::file_handle &handle) -> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_read(const char *path, char *buffer, const remote::file_size &read_size,
|
||||
const remote::file_offset &read_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
auto fuse_read(const char *path, char *buffer,
|
||||
const remote::file_size &read_size,
|
||||
const remote::file_offset &read_offset,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_rename(const char *from, const char *to) override;
|
||||
auto fuse_rename(const char *from, const char *to)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_write(const char *path, const char *buffer,
|
||||
const remote::file_size &write_size,
|
||||
const remote::file_offset &write_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
auto fuse_write(const char *path, const char *buffer,
|
||||
const remote::file_size &write_size,
|
||||
const remote::file_offset &write_offset,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_write_base64(const char *path, const char *buffer,
|
||||
const remote::file_size &write_size,
|
||||
const remote::file_offset &write_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
auto fuse_write_base64(const char *path, const char *buffer,
|
||||
const remote::file_size &write_size,
|
||||
const remote::file_offset &write_offset,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_readdir(const char *path, const remote::file_offset &offset,
|
||||
const remote::file_handle &handle,
|
||||
std::string &item_path) override;
|
||||
auto fuse_readdir(const char *path, const remote::file_offset &offset,
|
||||
const remote::file_handle &handle, std::string &item_path)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_release(const char *path, const remote::file_handle &handle) override;
|
||||
auto fuse_release(const char *path, const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_releasedir(const char *path, const remote::file_handle &handle) override;
|
||||
auto fuse_releasedir(const char *path, const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_removexattr(const char *path, const char *name) override ;*/
|
||||
/*packet::error_type fuse_removexattr(const char *path, const char *name)
|
||||
* override ;*/
|
||||
|
||||
packet::error_type fuse_rmdir(const char *path) override;
|
||||
auto fuse_rmdir(const char *path) -> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setattr_x(const char *path, remote::setattr_x &attr) override;
|
||||
auto fuse_setattr_x(const char *path, remote::setattr_x &attr)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setbkuptime(const char *path, const remote::file_time &bkuptime) override;
|
||||
auto fuse_setbkuptime(const char *path, const remote::file_time &bkuptime)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setchgtime(const char *path, const remote::file_time &chgtime) override;
|
||||
auto fuse_setchgtime(const char *path, const remote::file_time &chgtime)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setcrtime(const char *path, const remote::file_time &crtime) override;
|
||||
auto fuse_setcrtime(const char *path, const remote::file_time &crtime)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_setvolname(const char *volname) override;
|
||||
auto fuse_setvolname(const char *volname) -> packet::error_type override;
|
||||
|
||||
/*packet::error_type fuse_setxattr(const char *path, const char *name, const char *value,
|
||||
const remote::file_size &size,
|
||||
const std::int32_t &flags) override ;
|
||||
/*packet::error_type fuse_setxattr(const char *path, const char *name, const
|
||||
char *value, const remote::file_size &size, const std::int32_t &flags)
|
||||
override ;
|
||||
|
||||
packet::error_type fuse_setxattr_osx(const char *path, const char *name, const char *value,
|
||||
const remote::file_size &size, const std::int32_t &flags,
|
||||
const std::uint32_t &position) override ;*/
|
||||
packet::error_type fuse_setxattr_osx(const char *path, const char *name, const
|
||||
char *value, const remote::file_size &size, const std::int32_t &flags,
|
||||
std::uint32_t position) override ;*/
|
||||
|
||||
packet::error_type fuse_statfs(const char *path, const std::uint64_t &frsize,
|
||||
remote::statfs &st) override;
|
||||
auto fuse_statfs(const char *path, std::uint64_t frsize, remote::statfs &st)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_statfs_x(const char *path, const std::uint64_t &bsize,
|
||||
remote::statfs_x &st) override;
|
||||
auto fuse_statfs_x(const char *path, std::uint64_t bsize,
|
||||
remote::statfs_x &st) -> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_truncate(const char *path, const remote::file_offset &size) override;
|
||||
auto fuse_truncate(const char *path, const remote::file_offset &size)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_unlink(const char *path) override;
|
||||
auto fuse_unlink(const char *path) -> packet::error_type override;
|
||||
|
||||
packet::error_type fuse_utimens(const char *path, const remote::file_time *tv,
|
||||
const std::uint64_t &op0, const std::uint64_t &op1) override;
|
||||
auto fuse_utimens(const char *path, const remote::file_time *tv,
|
||||
std::uint64_t op0, std::uint64_t op1)
|
||||
-> packet::error_type override;
|
||||
|
||||
void set_fuse_uid_gid(const remote::user_id &, const remote::group_id &) override {}
|
||||
void set_fuse_uid_gid(const remote::user_id &,
|
||||
const remote::group_id &) override {}
|
||||
|
||||
// JSON Layer
|
||||
packet::error_type json_create_directory_snapshot(const std::string &path,
|
||||
json &json_data) override;
|
||||
auto json_create_directory_snapshot(const std::string &path, json &json_data)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type json_read_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle,
|
||||
const std::uint32_t &page,
|
||||
json &json_data) override;
|
||||
auto json_read_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle,
|
||||
std::uint32_t page, json &json_data)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type json_release_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle) override;
|
||||
auto json_release_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type override;
|
||||
|
||||
// WinFSP Layer
|
||||
packet::error_type winfsp_can_delete(PVOID file_desc, PWSTR file_name) override;
|
||||
auto winfsp_can_delete(PVOID file_desc, PWSTR file_name)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags,
|
||||
BOOLEAN &was_closed) override;
|
||||
auto winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags,
|
||||
BOOLEAN &was_closed) -> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_close(PVOID file_desc) override;
|
||||
auto winfsp_close(PVOID file_desc) -> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_create(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
|
||||
UINT32 attributes, UINT64 allocation_size, PVOID *file_desc,
|
||||
remote::file_info *file_info, std::string &normalized_name,
|
||||
BOOLEAN &exists) override;
|
||||
auto winfsp_create(PWSTR file_name, UINT32 create_options,
|
||||
UINT32 granted_access, UINT32 attributes,
|
||||
UINT64 allocation_size, PVOID *file_desc,
|
||||
remote::file_info *file_info, std::string &normalized_name,
|
||||
BOOLEAN &exists) -> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_flush(PVOID file_desc, remote::file_info *file_info) override;
|
||||
auto winfsp_flush(PVOID file_desc, remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_get_dir_buffer(PVOID file_desc, PVOID *&ptr) override;
|
||||
auto winfsp_get_dir_buffer(PVOID file_desc, PVOID *&ptr)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_get_file_info(PVOID file_desc, remote::file_info *file_info) override;
|
||||
auto winfsp_get_file_info(PVOID file_desc, remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_get_security_by_name(PWSTR file_name, PUINT32 attributes,
|
||||
std::uint64_t *descriptor_size,
|
||||
std::wstring &string_descriptor) override;
|
||||
auto winfsp_get_security_by_name(PWSTR file_name, PUINT32 attributes,
|
||||
std::uint64_t *descriptor_size,
|
||||
std::wstring &string_descriptor)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label) override;
|
||||
auto winfsp_get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_mounted(const std::wstring &location) override;
|
||||
auto winfsp_mounted(const std::wstring &location)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_open(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
|
||||
PVOID *file_desc, remote::file_info *file_info,
|
||||
std::string &normalized_name) override;
|
||||
auto winfsp_open(PWSTR file_name, UINT32 create_options,
|
||||
UINT32 granted_access, PVOID *file_desc,
|
||||
remote::file_info *file_info, std::string &normalized_name)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_overwrite(PVOID file_desc, UINT32 attributes,
|
||||
BOOLEAN replace_attributes, UINT64 allocation_size,
|
||||
remote::file_info *file_info) override;
|
||||
auto winfsp_overwrite(PVOID file_desc, UINT32 attributes,
|
||||
BOOLEAN replace_attributes, UINT64 allocation_size,
|
||||
remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
|
||||
PUINT32 bytes_transferred) override;
|
||||
auto winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
|
||||
PUINT32 bytes_transferred) -> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_read_directory(PVOID file_desc, PWSTR pattern, PWSTR marker,
|
||||
json &item_list) override;
|
||||
auto winfsp_read_directory(PVOID file_desc, PWSTR pattern, PWSTR marker,
|
||||
json &item_list) -> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_rename(PVOID file_desc, PWSTR file_name, PWSTR new_file_name,
|
||||
BOOLEAN replace_if_exists) override;
|
||||
auto winfsp_rename(PVOID file_desc, PWSTR file_name, PWSTR new_file_name,
|
||||
BOOLEAN replace_if_exists) -> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_set_basic_info(PVOID file_desc, UINT32 attributes, UINT64 creation_time,
|
||||
UINT64 last_access_time, UINT64 last_write_time,
|
||||
UINT64 change_time,
|
||||
remote::file_info *file_info) override;
|
||||
auto winfsp_set_basic_info(PVOID file_desc, UINT32 attributes,
|
||||
UINT64 creation_time, UINT64 last_access_time,
|
||||
UINT64 last_write_time, UINT64 change_time,
|
||||
remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_set_file_size(PVOID file_desc, UINT64 newSize,
|
||||
BOOLEAN set_allocation_size,
|
||||
remote::file_info *file_info) override;
|
||||
auto winfsp_set_file_size(PVOID file_desc, UINT64 newSize,
|
||||
BOOLEAN set_allocation_size,
|
||||
remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_unmounted(const std::wstring &location) override;
|
||||
auto winfsp_unmounted(const std::wstring &location)
|
||||
-> packet::error_type override;
|
||||
|
||||
packet::error_type winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
|
||||
BOOLEAN write_to_end, BOOLEAN constrained_io,
|
||||
PUINT32 bytes_transferred, remote::file_info *file_info) override;
|
||||
auto winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
|
||||
BOOLEAN write_to_end, BOOLEAN constrained_io,
|
||||
PUINT32 bytes_transferred, remote::file_info *file_info)
|
||||
-> packet::error_type override;
|
||||
};
|
||||
} // namespace remote_winfsp
|
||||
} // namespace repertory
|
||||
|
@ -1,26 +1,28 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_WINFSP_REMOTEWINFSP_REMOTE_WINFSP_DRIVE_HPP_
|
||||
#define INCLUDE_DRIVES_WINFSP_REMOTEWINFSP_REMOTE_WINFSP_DRIVE_HPP_
|
||||
#ifdef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "drives/winfsp/remotewinfsp/i_remote_instance.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
|
||||
@ -33,16 +35,16 @@ class remote_winfsp_drive final : public virtual FileSystemBase {
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
remote_winfsp_drive(app_config &config, lock_data &lockData,
|
||||
remote_instance_factory remoteInstanceFactory);
|
||||
remote_winfsp_drive(app_config &config, remote_instance_factory factory,
|
||||
lock_data &lock);
|
||||
|
||||
~remote_winfsp_drive() override { E_CONSUMER_RELEASE(); }
|
||||
|
||||
public:
|
||||
class winfsp_service : virtual public Service {
|
||||
public:
|
||||
winfsp_service(lock_data &lock, remote_winfsp_drive &drive, std::vector<std::string> drive_args,
|
||||
app_config &config);
|
||||
winfsp_service(lock_data &lock, remote_winfsp_drive &drive,
|
||||
std::vector<std::string> drive_args, app_config &config);
|
||||
|
||||
~winfsp_service() override = default;
|
||||
|
||||
@ -54,9 +56,9 @@ public:
|
||||
FileSystemHost host_;
|
||||
|
||||
protected:
|
||||
NTSTATUS OnStart(ULONG, PWSTR *) override;
|
||||
auto OnStart(ULONG, PWSTR *) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS OnStop() override;
|
||||
auto OnStop() -> NTSTATUS override;
|
||||
};
|
||||
|
||||
private:
|
||||
@ -68,64 +70,76 @@ private:
|
||||
std::string mount_location_;
|
||||
|
||||
private:
|
||||
void PopulateFileInfo(const json &item, FSP_FSCTL_FILE_INFO &file_info);
|
||||
void populate_file_info(const json &item, FSP_FSCTL_FILE_INFO &file_info);
|
||||
|
||||
static void SetFileInfo(FileInfo &dest, const remote::file_info &src);
|
||||
static void set_file_info(FileInfo &dest, const remote::file_info &src);
|
||||
|
||||
public:
|
||||
NTSTATUS CanDelete(PVOID file_node, PVOID file_desc, PWSTR file_name) override;
|
||||
auto CanDelete(PVOID file_node, PVOID file_desc, PWSTR file_name)
|
||||
-> NTSTATUS override;
|
||||
|
||||
VOID Cleanup(PVOID file_node, PVOID file_desc, PWSTR file_name, ULONG flags) override;
|
||||
VOID Cleanup(PVOID file_node, PVOID file_desc, PWSTR file_name,
|
||||
ULONG flags) override;
|
||||
|
||||
VOID Close(PVOID file_node, PVOID file_desc) override;
|
||||
|
||||
NTSTATUS Create(PWSTR file_name, UINT32 create_options, UINT32 granted_access, UINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR descriptor, UINT64 allocation_size, PVOID *file_node,
|
||||
PVOID *file_desc, OpenFileInfo *ofi) override;
|
||||
auto Create(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
|
||||
UINT32 attributes, PSECURITY_DESCRIPTOR descriptor,
|
||||
UINT64 allocation_size, PVOID *file_node, PVOID *file_desc,
|
||||
OpenFileInfo *ofi) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS Flush(PVOID file_node, PVOID file_desc, FileInfo *file_info) override;
|
||||
auto Flush(PVOID file_node, PVOID file_desc, FileInfo *file_info)
|
||||
-> NTSTATUS override;
|
||||
|
||||
NTSTATUS GetFileInfo(PVOID file_node, PVOID file_desc, FileInfo *file_info) override;
|
||||
auto GetFileInfo(PVOID file_node, PVOID file_desc, FileInfo *file_info)
|
||||
-> NTSTATUS override;
|
||||
|
||||
NTSTATUS GetSecurityByName(PWSTR file_name, PUINT32 attributes, PSECURITY_DESCRIPTOR descriptor,
|
||||
SIZE_T *descriptor_size) override;
|
||||
auto GetSecurityByName(PWSTR file_name, PUINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR descriptor,
|
||||
SIZE_T *descriptor_size) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS GetVolumeInfo(VolumeInfo *volume_info) override;
|
||||
auto GetVolumeInfo(VolumeInfo *volume_info) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS Init(PVOID host) override;
|
||||
auto Init(PVOID host) -> NTSTATUS override;
|
||||
|
||||
int mount(const std::vector<std::string> &drive_args);
|
||||
[[nodiscard]] auto mount(const std::vector<std::string> &drive_args) -> int;
|
||||
|
||||
NTSTATUS Mounted(PVOID host) override;
|
||||
auto Mounted(PVOID host) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS Open(PWSTR file_name, UINT32 create_options, UINT32 granted_access, PVOID *file_node,
|
||||
PVOID *file_desc, OpenFileInfo *ofi) override;
|
||||
auto Open(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
|
||||
PVOID *file_node, PVOID *file_desc, OpenFileInfo *ofi)
|
||||
-> NTSTATUS override;
|
||||
|
||||
NTSTATUS Overwrite(PVOID file_node, PVOID file_desc, UINT32 attributes,
|
||||
BOOLEAN replace_attributes, UINT64 allocation_size,
|
||||
FileInfo *file_info) override;
|
||||
auto Overwrite(PVOID file_node, PVOID file_desc, UINT32 attributes,
|
||||
BOOLEAN replace_attributes, UINT64 allocation_size,
|
||||
FileInfo *file_info) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS Read(PVOID file_node, PVOID file_desc, PVOID buffer, UINT64 offset, ULONG length,
|
||||
PULONG bytes_transferred) override;
|
||||
auto Read(PVOID file_node, PVOID file_desc, PVOID buffer, UINT64 offset,
|
||||
ULONG length, PULONG bytes_transferred) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS ReadDirectory(PVOID file_node, PVOID file_desc, PWSTR pattern, PWSTR marker,
|
||||
PVOID buffer, ULONG buffer_length, PULONG bytes_transferred) override;
|
||||
auto ReadDirectory(PVOID file_node, PVOID file_desc, PWSTR pattern,
|
||||
PWSTR marker, PVOID buffer, ULONG buffer_length,
|
||||
PULONG bytes_transferred) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS Rename(PVOID file_node, PVOID file_desc, PWSTR file_name, PWSTR new_file_name,
|
||||
BOOLEAN replace_if_exists) override;
|
||||
auto Rename(PVOID file_node, PVOID file_desc, PWSTR file_name,
|
||||
PWSTR new_file_name, BOOLEAN replace_if_exists)
|
||||
-> NTSTATUS override;
|
||||
|
||||
NTSTATUS SetBasicInfo(PVOID file_node, PVOID file_desc, UINT32 attributes, UINT64 creation_time,
|
||||
UINT64 last_access_time, UINT64 last_write_time, UINT64 change_time,
|
||||
FileInfo *file_info) override;
|
||||
auto SetBasicInfo(PVOID file_node, PVOID file_desc, UINT32 attributes,
|
||||
UINT64 creation_time, UINT64 last_access_time,
|
||||
UINT64 last_write_time, UINT64 change_time,
|
||||
FileInfo *file_info) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS SetFileSize(PVOID file_node, PVOID file_desc, UINT64 new_size,
|
||||
BOOLEAN set_allocation_size, FileInfo *file_info) override;
|
||||
auto SetFileSize(PVOID file_node, PVOID file_desc, UINT64 new_size,
|
||||
BOOLEAN set_allocation_size, FileInfo *file_info)
|
||||
-> NTSTATUS override;
|
||||
|
||||
VOID Unmounted(PVOID host) override;
|
||||
|
||||
NTSTATUS Write(PVOID file_node, PVOID file_desc, PVOID buffer, UINT64 offset, ULONG length,
|
||||
BOOLEAN write_to_end, BOOLEAN constrained_io, PULONG bytes_transferred,
|
||||
FileInfo *file_info) override;
|
||||
auto Write(PVOID file_node, PVOID file_desc, PVOID buffer, UINT64 offset,
|
||||
ULONG length, BOOLEAN write_to_end, BOOLEAN constrained_io,
|
||||
PULONG bytes_transferred, FileInfo *file_info)
|
||||
-> NTSTATUS override;
|
||||
|
||||
void shutdown() { ::GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0); }
|
||||
|
||||
|
@ -1,40 +1,42 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_WINFSP_WINFSP_DRIVE_HPP_
|
||||
#define INCLUDE_DRIVES_WINFSP_WINFSP_DRIVE_HPP_
|
||||
#ifdef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "download/download_manager.hpp"
|
||||
#include "drives/eviction.hpp"
|
||||
#include "drives/i_open_file_table.hpp"
|
||||
#include "drives/open_file_table.hpp"
|
||||
#include "drives/winfsp/i_winfsp_drive.hpp"
|
||||
#include "drives/winfsp/remotewinfsp/remote_server.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "file_manager/file_manager.hpp"
|
||||
#include "rpc/server/full_server.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
class lock_data;
|
||||
class i_provider;
|
||||
class winfsp_drive final : public virtual i_winfsp_drive, public virtual FileSystemBase {
|
||||
|
||||
class winfsp_drive final : public virtual i_winfsp_drive,
|
||||
public virtual FileSystemBase {
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
@ -45,8 +47,8 @@ public:
|
||||
private:
|
||||
class winfsp_service final : virtual public Service {
|
||||
public:
|
||||
winfsp_service(lock_data &lock, winfsp_drive &drive, std::vector<std::string> drive_args,
|
||||
app_config &config);
|
||||
winfsp_service(lock_data &lock, winfsp_drive &drive,
|
||||
std::vector<std::string> drive_args, app_config &config);
|
||||
|
||||
~winfsp_service() override = default;
|
||||
|
||||
@ -58,9 +60,9 @@ private:
|
||||
app_config &config_;
|
||||
|
||||
protected:
|
||||
NTSTATUS OnStart(ULONG, PWSTR *) override;
|
||||
auto OnStart(ULONG, PWSTR *) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS OnStop() override;
|
||||
auto OnStop() -> NTSTATUS override;
|
||||
};
|
||||
|
||||
private:
|
||||
@ -68,104 +70,128 @@ private:
|
||||
app_config &config_;
|
||||
lock_data &lock_;
|
||||
std::unique_ptr<full_server> server_;
|
||||
std::unique_ptr<open_file_table<open_file_data>> oft_;
|
||||
std::unique_ptr<download_manager> download_manager_;
|
||||
std::unique_ptr<file_manager> fm_;
|
||||
std::unique_ptr<eviction> eviction_;
|
||||
std::unique_ptr<remote_winfsp::remote_server> remote_server_;
|
||||
|
||||
private:
|
||||
static std::string parse_mount_location(const std::wstring &mount_location);
|
||||
static auto parse_mount_location(const std::wstring &mount_location)
|
||||
-> std::string;
|
||||
|
||||
void populate_file_info(const std::string &api_path, const std::uint64_t &file_size,
|
||||
const api_meta_map &meta, FSP_FSCTL_OPEN_FILE_INFO &ofi);
|
||||
void populate_file_info(const std::string &api_path, std::uint64_t file_size,
|
||||
const api_meta_map &meta,
|
||||
FSP_FSCTL_OPEN_FILE_INFO &ofi);
|
||||
|
||||
void populate_file_info(const std::uint64_t &file_size, api_meta_map meta,
|
||||
void populate_file_info(std::uint64_t file_size, api_meta_map meta,
|
||||
FSP_FSCTL_FILE_INFO &fi);
|
||||
|
||||
static void set_file_info(remote::file_info &dest, const FSP_FSCTL_FILE_INFO &src);
|
||||
static void set_file_info(remote::file_info &dest,
|
||||
const FSP_FSCTL_FILE_INFO &src);
|
||||
|
||||
public:
|
||||
NTSTATUS CanDelete(PVOID file_node, PVOID file_desc, PWSTR file_name) override;
|
||||
auto CanDelete(PVOID file_node, PVOID file_desc, PWSTR file_name)
|
||||
-> NTSTATUS override;
|
||||
|
||||
VOID Cleanup(PVOID file_node, PVOID file_desc, PWSTR file_name, ULONG flags) override;
|
||||
VOID Cleanup(PVOID file_node, PVOID file_desc, PWSTR file_name,
|
||||
ULONG flags) override;
|
||||
|
||||
VOID Close(PVOID file_node, PVOID file_desc) override;
|
||||
|
||||
NTSTATUS Create(PWSTR file_name, UINT32 create_options, UINT32 granted_access, UINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR descriptor, UINT64 allocation_size, PVOID *file_node,
|
||||
PVOID *file_desc, OpenFileInfo *ofi) override;
|
||||
auto Create(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
|
||||
UINT32 attributes, PSECURITY_DESCRIPTOR descriptor,
|
||||
UINT64 allocation_size, PVOID *file_node, PVOID *file_desc,
|
||||
OpenFileInfo *ofi) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS Flush(PVOID file_node, PVOID file_desc, FileInfo *file_info) override;
|
||||
auto Flush(PVOID file_node, PVOID file_desc, FileInfo *file_info)
|
||||
-> NTSTATUS override;
|
||||
|
||||
std::uint64_t get_directory_item_count(const std::string &api_path) const override;
|
||||
[[nodiscard]] auto get_directory_item_count(const std::string &api_path) const
|
||||
-> std::uint64_t override;
|
||||
|
||||
directory_item_list get_directory_items(const std::string &api_path) const override;
|
||||
[[nodiscard]] auto get_directory_items(const std::string &api_path) const
|
||||
-> directory_item_list override;
|
||||
|
||||
NTSTATUS GetFileInfo(PVOID file_node, PVOID file_desc, FileInfo *file_info) override;
|
||||
auto GetFileInfo(PVOID file_node, PVOID file_desc, FileInfo *file_info)
|
||||
-> NTSTATUS override;
|
||||
|
||||
std::uint64_t get_file_size(const std::string &api_path) const override;
|
||||
[[nodiscard]] auto get_file_size(const std::string &api_path) const
|
||||
-> std::uint64_t override;
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, api_meta_map &meta) const override;
|
||||
[[nodiscard]] auto get_item_meta(const std::string &api_path,
|
||||
api_meta_map &meta) const
|
||||
-> api_error override;
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, const std::string &name,
|
||||
std::string &value) const override;
|
||||
[[nodiscard]] auto get_item_meta(const std::string &api_path,
|
||||
const std::string &name,
|
||||
std::string &value) const
|
||||
-> api_error override;
|
||||
|
||||
NTSTATUS get_security_by_name(PWSTR file_name, PUINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR descriptor,
|
||||
std::uint64_t *descriptor_size) override;
|
||||
[[nodiscard]] auto get_security_by_name(PWSTR file_name, PUINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR descriptor,
|
||||
std::uint64_t *descriptor_size)
|
||||
-> NTSTATUS override;
|
||||
|
||||
NTSTATUS GetSecurityByName(PWSTR file_name, PUINT32 attributes, PSECURITY_DESCRIPTOR descriptor,
|
||||
SIZE_T *descriptor_size) override;
|
||||
auto GetSecurityByName(PWSTR file_name, PUINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR descriptor,
|
||||
SIZE_T *descriptor_size) -> NTSTATUS override;
|
||||
|
||||
std::uint64_t get_total_drive_space() const override;
|
||||
[[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override;
|
||||
|
||||
std::uint64_t get_total_item_count() const override;
|
||||
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t override;
|
||||
|
||||
std::uint64_t get_used_drive_space() const override;
|
||||
[[nodiscard]] auto get_used_drive_space() const -> std::uint64_t override;
|
||||
|
||||
void get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label) const override;
|
||||
|
||||
NTSTATUS GetVolumeInfo(VolumeInfo *volume_info) override;
|
||||
auto GetVolumeInfo(VolumeInfo *volume_info) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS Init(PVOID host) override;
|
||||
auto Init(PVOID host) -> NTSTATUS override;
|
||||
|
||||
int mount(const std::vector<std::string> &drive_args);
|
||||
[[nodiscard]] auto mount(const std::vector<std::string> &drive_args) -> int;
|
||||
|
||||
NTSTATUS Mounted(PVOID host) override;
|
||||
auto Mounted(PVOID host) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS Open(PWSTR file_name, UINT32 create_options, UINT32 granted_access, PVOID *file_node,
|
||||
PVOID *file_desc, OpenFileInfo *ofi) override;
|
||||
auto Open(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
|
||||
PVOID *file_node, PVOID *file_desc, OpenFileInfo *ofi)
|
||||
-> NTSTATUS override;
|
||||
|
||||
NTSTATUS Overwrite(PVOID file_node, PVOID file_desc, UINT32 attributes,
|
||||
BOOLEAN replace_attributes, UINT64 allocation_size,
|
||||
FileInfo *file_info) override;
|
||||
auto Overwrite(PVOID file_node, PVOID file_desc, UINT32 attributes,
|
||||
BOOLEAN replace_attributes, UINT64 allocation_size,
|
||||
FileInfo *file_info) -> NTSTATUS override;
|
||||
|
||||
api_error populate_file_info(const std::string &api_path, remote::file_info &file_info) override;
|
||||
[[nodiscard]] auto populate_file_info(const std::string &api_path,
|
||||
remote::file_info &file_info)
|
||||
-> api_error override;
|
||||
|
||||
NTSTATUS Read(PVOID file_node, PVOID file_desc, PVOID buffer, UINT64 offset, ULONG length,
|
||||
PULONG bytes_transferred) override;
|
||||
auto Read(PVOID file_node, PVOID file_desc, PVOID buffer, UINT64 offset,
|
||||
ULONG length, PULONG bytes_transferred) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS ReadDirectory(PVOID file_node, PVOID file_desc, PWSTR pattern, PWSTR marker,
|
||||
PVOID buffer, ULONG bufferLength, PULONG bytes_transferred) override;
|
||||
auto ReadDirectory(PVOID file_node, PVOID file_desc, PWSTR pattern,
|
||||
PWSTR marker, PVOID buffer, ULONG bufferLength,
|
||||
PULONG bytes_transferred) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS Rename(PVOID file_node, PVOID file_desc, PWSTR file_name, PWSTR newFileName,
|
||||
BOOLEAN replace_if_exists) override;
|
||||
auto Rename(PVOID file_node, PVOID file_desc, PWSTR file_name,
|
||||
PWSTR newFileName, BOOLEAN replace_if_exists)
|
||||
-> NTSTATUS override;
|
||||
|
||||
NTSTATUS SetBasicInfo(PVOID file_node, PVOID file_desc, UINT32 attributes, UINT64 creation_time,
|
||||
UINT64 last_access_time, UINT64 last_write_time, UINT64 change_time,
|
||||
FileInfo *file_info) override;
|
||||
auto SetBasicInfo(PVOID file_node, PVOID file_desc, UINT32 attributes,
|
||||
UINT64 creation_time, UINT64 last_access_time,
|
||||
UINT64 last_write_time, UINT64 change_time,
|
||||
FileInfo *file_info) -> NTSTATUS override;
|
||||
|
||||
NTSTATUS SetFileSize(PVOID file_node, PVOID file_desc, UINT64 new_size,
|
||||
BOOLEAN set_allocation_size, FileInfo *file_info) override;
|
||||
auto SetFileSize(PVOID file_node, PVOID file_desc, UINT64 new_size,
|
||||
BOOLEAN set_allocation_size, FileInfo *file_info)
|
||||
-> NTSTATUS override;
|
||||
|
||||
VOID Unmounted(PVOID host) override;
|
||||
|
||||
NTSTATUS Write(PVOID file_node, PVOID file_desc, PVOID buffer, UINT64 offset, ULONG length,
|
||||
BOOLEAN write_to_end, BOOLEAN constrained_io, PULONG bytes_transferred,
|
||||
FileInfo *file_info) override;
|
||||
auto Write(PVOID file_node, PVOID file_desc, PVOID buffer, UINT64 offset,
|
||||
ULONG length, BOOLEAN write_to_end, BOOLEAN constrained_io,
|
||||
PULONG bytes_transferred, FileInfo *file_info)
|
||||
-> NTSTATUS override;
|
||||
|
||||
void shutdown() { ::GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0); }
|
||||
void shutdown();
|
||||
|
||||
static void display_options(int argc, char *argv[]) {}
|
||||
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_EVENTS_CONSUMERS_CONSOLE_CONSUMER_HPP_
|
||||
#define INCLUDE_EVENTS_CONSUMERS_CONSOLE_CONSUMER_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
|
||||
namespace repertory {
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_EVENTS_CONSUMERS_LOGGING_CONSUMER_HPP_
|
||||
#define INCLUDE_EVENTS_CONSUMERS_LOGGING_CONSUMER_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
|
||||
namespace repertory {
|
||||
@ -47,11 +49,11 @@ private:
|
||||
FILE *log_file_ = nullptr;
|
||||
|
||||
private:
|
||||
void check_log_roll(const size_t &count);
|
||||
void check_log_roll(std::size_t count);
|
||||
|
||||
void close_log_file();
|
||||
|
||||
void logging_thread(const bool &drain = false);
|
||||
void logging_thread(bool drain);
|
||||
|
||||
void process_event(const event &event);
|
||||
|
||||
|
@ -1,38 +1,39 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_EVENTS_EVENT_HPP_
|
||||
#define INCLUDE_EVENTS_EVENT_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
namespace repertory {
|
||||
enum class event_level { error, warn, normal, debug, verbose };
|
||||
|
||||
event_level event_level_from_string(std::string level);
|
||||
auto event_level_from_string(std::string level) -> event_level;
|
||||
|
||||
std::string event_level_to_string(const event_level &level);
|
||||
auto event_level_to_string(const event_level &level) -> std::string;
|
||||
|
||||
class event {
|
||||
protected:
|
||||
explicit event(const bool &allow_async) : allow_async_(allow_async) {}
|
||||
explicit event(bool allow_async) : allow_async_(allow_async) {}
|
||||
|
||||
event(const std::stringstream &ss, json j, const bool &allow_async)
|
||||
event(const std::stringstream &ss, json j, bool allow_async)
|
||||
: allow_async_(allow_async), ss_(ss.str()), j_(std::move(j)) {}
|
||||
|
||||
public:
|
||||
@ -46,17 +47,17 @@ protected:
|
||||
json j_;
|
||||
|
||||
public:
|
||||
virtual std::shared_ptr<event> clone() const = 0;
|
||||
[[nodiscard]] virtual auto clone() const -> std::shared_ptr<event> = 0;
|
||||
|
||||
bool get_allow_async() const { return allow_async_; }
|
||||
[[nodiscard]] auto get_allow_async() const -> bool { return allow_async_; }
|
||||
|
||||
virtual event_level get_event_level() const = 0;
|
||||
[[nodiscard]] virtual auto get_event_level() const -> event_level = 0;
|
||||
|
||||
json get_json() const { return j_; }
|
||||
[[nodiscard]] auto get_json() const -> json { return j_; }
|
||||
|
||||
virtual std::string get_name() const = 0;
|
||||
[[nodiscard]] virtual auto get_name() const -> std::string = 0;
|
||||
|
||||
virtual std::string get_single_line() const = 0;
|
||||
[[nodiscard]] virtual auto get_single_line() const -> std::string = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -1,243 +1,259 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_EVENTS_EVENT_SYSTEM_HPP_
|
||||
#define INCLUDE_EVENTS_EVENT_SYSTEM_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "events/event.hpp"
|
||||
#include "events/t_event_system.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
typedef t_event_system<event> event_system;
|
||||
typedef event_system::event_consumer event_consumer;
|
||||
using event_system = t_event_system<event>;
|
||||
using event_consumer = event_system::event_consumer;
|
||||
|
||||
#define E_CAST(t) ((std::string)t)
|
||||
#define E_DOUBLE(d) utils::string::from_double(d)
|
||||
#define E_DOUBLE_PRECISE(d) \
|
||||
([](const double &d) -> std::string { \
|
||||
std::stringstream ss; \
|
||||
ss << std::fixed << std::setprecision(2) << d; \
|
||||
return ss.str(); \
|
||||
#define E_DOUBLE(d) std::to_string(d)
|
||||
#define E_DOUBLE_PRECISE(d) \
|
||||
([](const double &d) -> std::string { \
|
||||
std::stringstream ss; \
|
||||
ss << std::fixed << std::setprecision(2) << d; \
|
||||
return ss.str(); \
|
||||
})(d)
|
||||
#define E_FROM_BOOL(t) utils::string::from_bool(t)
|
||||
#define E_FROM_BOOL(t) std::to_string(t)
|
||||
#define E_FROM_EXCEPTION(e) std::string(e.what() ? e.what() : "")
|
||||
#define E_FROM_INT32(t) utils::string::from_int32(t)
|
||||
#define E_FROM_INT64(t) utils::string::from_int64(t)
|
||||
#define E_FROM_UINT16(t) utils::string::from_uint16(t)
|
||||
#define E_FROM_STRING_ARRAY(a) \
|
||||
([](const auto &array) -> std::string { \
|
||||
std::stringstream ret; \
|
||||
for (const auto &item : array) { \
|
||||
ret << (std::string(item) + " "); \
|
||||
} \
|
||||
return std::string(ret).TrimRight(); \
|
||||
#define E_FROM_INT32(t) std::to_string(t)
|
||||
#define E_FROM_INT64(t) std::to_string(t)
|
||||
#define E_FROM_UINT16(t) std::to_string(t)
|
||||
#define E_FROM_STRING_ARRAY(a) \
|
||||
([](const auto &array) -> std::string { \
|
||||
std::stringstream ret; \
|
||||
for (const auto &item : array) { \
|
||||
ret << (std::string(item) + " "); \
|
||||
} \
|
||||
return std::string(ret).TrimRight(); \
|
||||
})(a)
|
||||
|
||||
#define E_PERCENT(d) \
|
||||
([](const double &d) -> std::string { \
|
||||
std::stringstream ss; \
|
||||
ss << std::fixed << std::setprecision(2) << d; \
|
||||
ss << "%"; \
|
||||
return ss; \
|
||||
#define E_PERCENT(d) \
|
||||
([](const double &d) -> std::string { \
|
||||
std::stringstream ss; \
|
||||
ss << std::fixed << std::setprecision(2) << d; \
|
||||
ss << "%"; \
|
||||
return ss; \
|
||||
})(d)
|
||||
#define E_STRING(t) t
|
||||
#define E_FROM_UINT8(t) utils::string::from_uint8(t)
|
||||
#define E_FROM_UINT32(t) utils::string::from_uint32(t)
|
||||
#define E_FROM_UINT64(t) utils::string::from_uint64(t)
|
||||
#define E_FROM_UINT8(t) std::to_string(t)
|
||||
#define E_FROM_UINT32(t) std::to_string(t)
|
||||
#define E_FROM_UINT64(t) std::to_string(t)
|
||||
#define E_FROM_SIZE_T(t) std::to_string(t)
|
||||
#define E_FROM_API_FILE_ERROR(e) api_error_to_string(e)
|
||||
|
||||
#define E_PROP(type, name, short_name, ts) \
|
||||
private: \
|
||||
void init_##short_name(const type &tv) { \
|
||||
ss_ << "|" << #short_name << "|" << ts(tv); \
|
||||
j_[#name] = ts(tv); \
|
||||
} \
|
||||
\
|
||||
public: \
|
||||
json get_##name() const { return j_[#name]; }
|
||||
#define E_PROP(type, name, short_name, ts) \
|
||||
private: \
|
||||
void init_##short_name(const type &val) { \
|
||||
ss_ << "|" << #short_name << "|" << ts(val); \
|
||||
j_[#name] = ts(val); \
|
||||
} \
|
||||
\
|
||||
public: \
|
||||
[[nodiscard]] auto get_##name() const->json { return j_[#name]; }
|
||||
|
||||
#define E_BEGIN(name, el) \
|
||||
class name final : public virtual event { \
|
||||
private: \
|
||||
name(const std::stringstream &ss, const json &j, const bool &allow_async) \
|
||||
: event(ss, j, allow_async) {} \
|
||||
\
|
||||
public: \
|
||||
~name() override = default; \
|
||||
\
|
||||
public: \
|
||||
static const event_level level = event_level::el; \
|
||||
\
|
||||
public: \
|
||||
std::string get_name() const override { return #name; } \
|
||||
\
|
||||
event_level get_event_level() const override { return name::level; } \
|
||||
\
|
||||
std::string get_single_line() const override { \
|
||||
const auto s = ss_.str(); \
|
||||
return get_name() + (s.empty() ? "" : s); \
|
||||
} \
|
||||
\
|
||||
std::shared_ptr<event> clone() const override { \
|
||||
return std::shared_ptr<name>(new name(ss_, j_, get_allow_async())); \
|
||||
#define E_BEGIN(name, el) \
|
||||
class name final : public virtual event { \
|
||||
private: \
|
||||
name(const std::stringstream &ss, const json &j, bool allow_async) \
|
||||
: event(ss, j, allow_async) {} \
|
||||
\
|
||||
public: \
|
||||
~name() override = default; \
|
||||
\
|
||||
public: \
|
||||
static const event_level level = event_level::el; \
|
||||
\
|
||||
public: \
|
||||
[[nodiscard]] auto get_name() const -> std::string override { \
|
||||
return #name; \
|
||||
} \
|
||||
\
|
||||
[[nodiscard]] auto get_event_level() const -> event_level override { \
|
||||
return name::level; \
|
||||
} \
|
||||
\
|
||||
[[nodiscard]] auto get_single_line() const -> std::string override { \
|
||||
const auto s = ss_.str(); \
|
||||
return get_name() + (s.empty() ? "" : s); \
|
||||
} \
|
||||
\
|
||||
[[nodiscard]] auto clone() const -> std::shared_ptr<event> override { \
|
||||
return std::shared_ptr<name>(new name(ss_, j_, get_allow_async())); \
|
||||
}
|
||||
#define E_END() }
|
||||
|
||||
#define E_SIMPLE(event_name, el, allow_async) \
|
||||
E_BEGIN(event_name, el) \
|
||||
public: \
|
||||
event_name() : event(allow_async) {} \
|
||||
#define E_SIMPLE(event_name, el, allow_async) \
|
||||
E_BEGIN(event_name, el) \
|
||||
public: \
|
||||
event_name() : event(allow_async) {} \
|
||||
E_END()
|
||||
|
||||
#define E_SIMPLE1(event_name, el, allow_async, type, name, short_name, tc) \
|
||||
E_BEGIN(event_name, el) \
|
||||
explicit event_name(const type &tv) : event(allow_async) { init_##short_name(tv); } \
|
||||
E_PROP(type, name, short_name, tc) \
|
||||
#define E_SIMPLE1(event_name, el, allow_async, type, name, short_name, tc) \
|
||||
E_BEGIN(event_name, el) \
|
||||
explicit event_name(const type &tv) : event(allow_async) { \
|
||||
init_##short_name(tv); \
|
||||
} \
|
||||
E_PROP(type, name, short_name, tc) \
|
||||
E_END()
|
||||
|
||||
#define E_SIMPLE2(event_name, el, allow_async, type, name, short_name, tc, type2, name2, \
|
||||
short_name2, tc2) \
|
||||
E_BEGIN(event_name, el) \
|
||||
explicit event_name(const type &tv, const type2 &tv2) : event(allow_async) { \
|
||||
init_##short_name(tv); \
|
||||
init_##short_name2(tv2); \
|
||||
} \
|
||||
E_PROP(type, name, short_name, tc) \
|
||||
E_PROP(type2, name2, short_name2, tc2) \
|
||||
#define E_SIMPLE2(event_name, el, allow_async, type, name, short_name, tc, \
|
||||
type2, name2, short_name2, tc2) \
|
||||
E_BEGIN(event_name, el) \
|
||||
explicit event_name(const type &tv, const type2 &tv2) : event(allow_async) { \
|
||||
init_##short_name(tv); \
|
||||
init_##short_name2(tv2); \
|
||||
} \
|
||||
E_PROP(type, name, short_name, tc) \
|
||||
E_PROP(type2, name2, short_name2, tc2) \
|
||||
E_END()
|
||||
|
||||
#define E_SIMPLE3(event_name, el, allow_async, type, name, short_name, tc, type2, name2, \
|
||||
short_name2, tc2, type3, name3, short_name3, tc3) \
|
||||
E_BEGIN(event_name, el) \
|
||||
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3) : event(allow_async) { \
|
||||
init_##short_name(tv); \
|
||||
init_##short_name2(tv2); \
|
||||
init_##short_name3(tv3); \
|
||||
} \
|
||||
E_PROP(type, name, short_name, tc) \
|
||||
E_PROP(type2, name2, short_name2, tc2) \
|
||||
E_PROP(type3, name3, short_name3, tc3) \
|
||||
#define E_SIMPLE3(event_name, el, allow_async, type, name, short_name, tc, \
|
||||
type2, name2, short_name2, tc2, type3, name3, short_name3, \
|
||||
tc3) \
|
||||
E_BEGIN(event_name, el) \
|
||||
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3) \
|
||||
: event(allow_async) { \
|
||||
init_##short_name(tv); \
|
||||
init_##short_name2(tv2); \
|
||||
init_##short_name3(tv3); \
|
||||
} \
|
||||
E_PROP(type, name, short_name, tc) \
|
||||
E_PROP(type2, name2, short_name2, tc2) \
|
||||
E_PROP(type3, name3, short_name3, tc3) \
|
||||
E_END()
|
||||
|
||||
#define E_SIMPLE4(event_name, el, allow_async, type, name, short_name, tc, type2, name2, \
|
||||
short_name2, tc2, type3, name3, short_name3, tc3, type4, name4, short_name4, \
|
||||
tc4) \
|
||||
E_BEGIN(event_name, el) \
|
||||
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, const type4 &tv4) \
|
||||
: event(allow_async) { \
|
||||
init_##short_name(tv); \
|
||||
init_##short_name2(tv2); \
|
||||
init_##short_name3(tv3); \
|
||||
init_##short_name4(tv4); \
|
||||
} \
|
||||
E_PROP(type, name, short_name, tc) \
|
||||
E_PROP(type2, name2, short_name2, tc2) \
|
||||
E_PROP(type3, name3, short_name3, tc3) \
|
||||
E_PROP(type4, name4, short_name4, tc4) \
|
||||
#define E_SIMPLE4(event_name, el, allow_async, type, name, short_name, tc, \
|
||||
type2, name2, short_name2, tc2, type3, name3, short_name3, \
|
||||
tc3, type4, name4, short_name4, tc4) \
|
||||
E_BEGIN(event_name, el) \
|
||||
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \
|
||||
const type4 &tv4) \
|
||||
: event(allow_async) { \
|
||||
init_##short_name(tv); \
|
||||
init_##short_name2(tv2); \
|
||||
init_##short_name3(tv3); \
|
||||
init_##short_name4(tv4); \
|
||||
} \
|
||||
E_PROP(type, name, short_name, tc) \
|
||||
E_PROP(type2, name2, short_name2, tc2) \
|
||||
E_PROP(type3, name3, short_name3, tc3) \
|
||||
E_PROP(type4, name4, short_name4, tc4) \
|
||||
E_END()
|
||||
|
||||
#define E_SIMPLE5(event_name, el, allow_async, type, name, short_name, tc, type2, name2, \
|
||||
short_name2, tc2, type3, name3, short_name3, tc3, type4, name4, short_name4, \
|
||||
tc4, type5, name5, short_name5, tc5) \
|
||||
E_BEGIN(event_name, el) \
|
||||
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, const type4 &tv4, \
|
||||
const type5 &tv5) \
|
||||
: event(allow_async) { \
|
||||
init_##short_name(tv); \
|
||||
init_##short_name2(tv2); \
|
||||
init_##short_name3(tv3); \
|
||||
init_##short_name4(tv4); \
|
||||
init_##short_name5(tv5); \
|
||||
} \
|
||||
E_PROP(type, name, short_name, tc) \
|
||||
E_PROP(type2, name2, short_name2, tc2) \
|
||||
E_PROP(type3, name3, short_name3, tc3) \
|
||||
E_PROP(type4, name4, short_name4, tc4) \
|
||||
E_PROP(type5, name5, short_name5, tc5) \
|
||||
#define E_SIMPLE5(event_name, el, allow_async, type, name, short_name, tc, \
|
||||
type2, name2, short_name2, tc2, type3, name3, short_name3, \
|
||||
tc3, type4, name4, short_name4, tc4, type5, name5, \
|
||||
short_name5, tc5) \
|
||||
E_BEGIN(event_name, el) \
|
||||
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \
|
||||
const type4 &tv4, const type5 &tv5) \
|
||||
: event(allow_async) { \
|
||||
init_##short_name(tv); \
|
||||
init_##short_name2(tv2); \
|
||||
init_##short_name3(tv3); \
|
||||
init_##short_name4(tv4); \
|
||||
init_##short_name5(tv5); \
|
||||
} \
|
||||
E_PROP(type, name, short_name, tc) \
|
||||
E_PROP(type2, name2, short_name2, tc2) \
|
||||
E_PROP(type3, name3, short_name3, tc3) \
|
||||
E_PROP(type4, name4, short_name4, tc4) \
|
||||
E_PROP(type5, name5, short_name5, tc5) \
|
||||
E_END()
|
||||
|
||||
#define E_SIMPLE6(event_name, el, allow_async, type, name, short_name, tc, type2, name2, \
|
||||
short_name2, tc2, type3, name3, short_name3, tc3, type4, name4, short_name4, \
|
||||
tc4, type5, name5, short_name5, tc5, type6, name6, short_name6, tc6) \
|
||||
E_BEGIN(event_name, el) \
|
||||
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, const type4 &tv4, \
|
||||
const type5 &tv5, const type6 &tv6) \
|
||||
: event(allow_async) { \
|
||||
init_##short_name(tv); \
|
||||
init_##short_name2(tv2); \
|
||||
init_##short_name3(tv3); \
|
||||
init_##short_name4(tv4); \
|
||||
init_##short_name5(tv5); \
|
||||
init_##short_name6(tv6); \
|
||||
} \
|
||||
E_PROP(type, name, short_name, tc) \
|
||||
E_PROP(type2, name2, short_name2, tc2) \
|
||||
E_PROP(type3, name3, short_name3, tc3) \
|
||||
E_PROP(type4, name4, short_name4, tc4) \
|
||||
E_PROP(type5, name5, short_name5, tc5) \
|
||||
E_PROP(type6, name6, short_name6, tc6) \
|
||||
#define E_SIMPLE6(event_name, el, allow_async, type, name, short_name, tc, \
|
||||
type2, name2, short_name2, tc2, type3, name3, short_name3, \
|
||||
tc3, type4, name4, short_name4, tc4, type5, name5, \
|
||||
short_name5, tc5, type6, name6, short_name6, tc6) \
|
||||
E_BEGIN(event_name, el) \
|
||||
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \
|
||||
const type4 &tv4, const type5 &tv5, const type6 &tv6) \
|
||||
: event(allow_async) { \
|
||||
init_##short_name(tv); \
|
||||
init_##short_name2(tv2); \
|
||||
init_##short_name3(tv3); \
|
||||
init_##short_name4(tv4); \
|
||||
init_##short_name5(tv5); \
|
||||
init_##short_name6(tv6); \
|
||||
} \
|
||||
E_PROP(type, name, short_name, tc) \
|
||||
E_PROP(type2, name2, short_name2, tc2) \
|
||||
E_PROP(type3, name3, short_name3, tc3) \
|
||||
E_PROP(type4, name4, short_name4, tc4) \
|
||||
E_PROP(type5, name5, short_name5, tc5) \
|
||||
E_PROP(type6, name6, short_name6, tc6) \
|
||||
E_END()
|
||||
|
||||
#define E_SIMPLE7(event_name, el, allow_async, type, name, short_name, tc, type2, name2, \
|
||||
short_name2, tc2, type3, name3, short_name3, tc3, type4, name4, short_name4, \
|
||||
tc4, type5, name5, short_name5, tc5, type6, name6, short_name6, tc6, type7, \
|
||||
name7, short_name7, tc7) \
|
||||
E_BEGIN(event_name, el) \
|
||||
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, const type4 &tv4, \
|
||||
const type5 &tv5, const type6 &tv6, const type7 &tv7) \
|
||||
: event(allow_async) { \
|
||||
init_##short_name(tv); \
|
||||
init_##short_name2(tv2); \
|
||||
init_##short_name3(tv3); \
|
||||
init_##short_name4(tv4); \
|
||||
init_##short_name5(tv5); \
|
||||
init_##short_name6(tv6); \
|
||||
init_##short_name7(tv7); \
|
||||
} \
|
||||
E_PROP(type, name, short_name, tc) \
|
||||
E_PROP(type2, name2, short_name2, tc2) \
|
||||
E_PROP(type3, name3, short_name3, tc3) \
|
||||
E_PROP(type4, name4, short_name4, tc4) \
|
||||
E_PROP(type5, name5, short_name5, tc5) \
|
||||
E_PROP(type6, name6, short_name6, tc6) \
|
||||
E_PROP(type7, name7, short_name7, tc7) \
|
||||
#define E_SIMPLE7(event_name, el, allow_async, type, name, short_name, tc, \
|
||||
type2, name2, short_name2, tc2, type3, name3, short_name3, \
|
||||
tc3, type4, name4, short_name4, tc4, type5, name5, \
|
||||
short_name5, tc5, type6, name6, short_name6, tc6, type7, \
|
||||
name7, short_name7, tc7) \
|
||||
E_BEGIN(event_name, el) \
|
||||
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \
|
||||
const type4 &tv4, const type5 &tv5, const type6 &tv6, \
|
||||
const type7 &tv7) \
|
||||
: event(allow_async) { \
|
||||
init_##short_name(tv); \
|
||||
init_##short_name2(tv2); \
|
||||
init_##short_name3(tv3); \
|
||||
init_##short_name4(tv4); \
|
||||
init_##short_name5(tv5); \
|
||||
init_##short_name6(tv6); \
|
||||
init_##short_name7(tv7); \
|
||||
} \
|
||||
E_PROP(type, name, short_name, tc) \
|
||||
E_PROP(type2, name2, short_name2, tc2) \
|
||||
E_PROP(type3, name3, short_name3, tc3) \
|
||||
E_PROP(type4, name4, short_name4, tc4) \
|
||||
E_PROP(type5, name5, short_name5, tc5) \
|
||||
E_PROP(type6, name6, short_name6, tc6) \
|
||||
E_PROP(type7, name7, short_name7, tc7) \
|
||||
E_END()
|
||||
|
||||
#define E_CONSUMER() \
|
||||
private: \
|
||||
#define E_CONSUMER() \
|
||||
private: \
|
||||
std::vector<std::shared_ptr<repertory::event_consumer>> event_consumers_
|
||||
|
||||
#define E_CONSUMER_RELEASE() event_consumers_.clear()
|
||||
|
||||
#define E_SUBSCRIBE(name, callback) \
|
||||
event_consumers_.emplace_back( \
|
||||
std::make_shared<repertory::event_consumer>(#name, [this](const event &e) { callback(e); }))
|
||||
#define E_SUBSCRIBE(name, callback) \
|
||||
event_consumers_.emplace_back(std::make_shared<repertory::event_consumer>( \
|
||||
#name, [this](const event &e) { callback(e); }))
|
||||
|
||||
#define E_SUBSCRIBE_EXACT(name, callback) \
|
||||
event_consumers_.emplace_back(std::make_shared<repertory::event_consumer>( \
|
||||
#name, [this](const event &e) { callback(dynamic_cast<const name &>(e)); }))
|
||||
#define E_SUBSCRIBE_EXACT(name, callback) \
|
||||
event_consumers_.emplace_back(std::make_shared<repertory::event_consumer>( \
|
||||
#name, \
|
||||
[this](const event &e) { callback(dynamic_cast<const name &>(e)); }))
|
||||
|
||||
#define E_SUBSCRIBE_ALL(callback) \
|
||||
event_consumers_.emplace_back( \
|
||||
std::make_shared<repertory::event_consumer>([this](const event &e) { callback(e); }))
|
||||
#define E_SUBSCRIBE_ALL(callback) \
|
||||
event_consumers_.emplace_back(std::make_shared<repertory::event_consumer>( \
|
||||
[this](const event &e) { callback(e); }))
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_EVENTS_EVENT_SYSTEM_HPP_
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_EVENTS_EVENTS_HPP_
|
||||
#define INCLUDE_EVENTS_EVENTS_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
@ -56,6 +58,17 @@ E_SIMPLE4(comm_auth_logout_end, normal, true,
|
||||
int, http, http, E_FROM_INT32
|
||||
);
|
||||
|
||||
E_SIMPLE1(comm_del_begin, verbose, true,
|
||||
std::string, url, url, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE4(comm_del_end, verbose, true,
|
||||
std::string, url, url, E_STRING,
|
||||
CURLcode, curl, curl, E_FROM_INT32,
|
||||
int, http, http, E_FROM_INT32,
|
||||
std::string, result, res, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE1(comm_get_begin, verbose, true,
|
||||
std::string, url, url, E_STRING
|
||||
);
|
||||
@ -166,6 +179,11 @@ E_SIMPLE1(directory_removed, normal, true,
|
||||
std::string, api_path, ap, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE2(directory_removed_externally, warn, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, source, src, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE2(directory_remove_failed, error, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, error, err, E_STRING
|
||||
@ -273,6 +291,13 @@ E_SIMPLE5(filesystem_item_handle_closed, verbose, true,
|
||||
bool, changed, changed, E_FROM_BOOL
|
||||
);
|
||||
|
||||
E_SIMPLE4(filesystem_item_handle_opened, verbose, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::uint64_t, handle, handle, E_FROM_UINT64,
|
||||
std::string, source, src, E_STRING,
|
||||
bool, directory, dir, E_FROM_BOOL
|
||||
);
|
||||
|
||||
E_SIMPLE2(filesystem_item_evicted, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, source, src, E_STRING
|
||||
@ -293,20 +318,11 @@ E_SIMPLE1(file_unpinned, normal, true,
|
||||
std::string, api_path, ap, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE2(file_upload_begin, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, source, src, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE2(file_upload_completed, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, source, src, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(file_upload_end, normal, true,
|
||||
E_SIMPLE4(file_upload_completed, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, source, src, E_STRING,
|
||||
api_error, result, res, E_FROM_API_FILE_ERROR
|
||||
api_error, result, res, E_FROM_API_FILE_ERROR,
|
||||
bool, cancelled, cancel, E_FROM_BOOL
|
||||
);
|
||||
|
||||
E_SIMPLE3(file_upload_failed, error, true,
|
||||
@ -330,7 +346,13 @@ E_SIMPLE2(file_upload_removed, debug, true,
|
||||
std::string, source, src, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE2(file_upload_retry, normal, true,
|
||||
E_SIMPLE3(file_upload_retry, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, source, src, E_STRING,
|
||||
api_error, result, res, E_FROM_API_FILE_ERROR
|
||||
);
|
||||
|
||||
E_SIMPLE2(file_upload_started, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, source, src, E_STRING
|
||||
);
|
||||
@ -371,6 +393,17 @@ E_SIMPLE2(provider_offline, error, true,
|
||||
std::uint16_t, port, port, E_FROM_UINT16
|
||||
);
|
||||
|
||||
E_SIMPLE2(provider_upload_begin, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, source, src, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(provider_upload_end, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, source, src, E_STRING,
|
||||
api_error, result, res, E_FROM_API_FILE_ERROR
|
||||
);
|
||||
|
||||
E_SIMPLE2(repertory_exception, error, true,
|
||||
std::string, function, func, E_STRING,
|
||||
std::string, message, msg, E_STRING
|
||||
@ -380,30 +413,18 @@ E_SIMPLE1(rpc_server_exception, error, true,
|
||||
std::string, exception, exception, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE1(service_shutdown, debug, true,
|
||||
E_SIMPLE1(service_shutdown_begin, debug, true,
|
||||
std::string, service, svc, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(skynet_import_decryption_failed, error, true,
|
||||
std::string, skylink, skylink, E_STRING,
|
||||
std::string, sub_file, sf, E_STRING,
|
||||
api_error, result, res, E_FROM_API_FILE_ERROR
|
||||
E_SIMPLE1(service_shutdown_end, debug, true,
|
||||
std::string, service, svc, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(skynet_import_directory_failed, error, true,
|
||||
std::string, skylink, skylink, E_STRING,
|
||||
std::string, sub_directory, sd, E_STRING,
|
||||
api_error, result, res, E_FROM_API_FILE_ERROR
|
||||
E_SIMPLE1(service_started, debug, true,
|
||||
std::string, service, svc, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(skynet_import_file_failed, error, true,
|
||||
std::string, skylink, skylink, E_STRING,
|
||||
std::string, sub_file, sf, E_STRING,
|
||||
api_error, result, res, E_FROM_API_FILE_ERROR
|
||||
);
|
||||
|
||||
E_SIMPLE(skynet_portal_list_changed, normal, true);
|
||||
|
||||
E_SIMPLE(unmount_requested, normal, true);
|
||||
#ifndef _WIN32
|
||||
E_SIMPLE2(unmount_result, normal, true,
|
||||
|
@ -1,25 +1,27 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_EVENTS_T_EVENT_SYSTEM_HPP_
|
||||
#define INCLUDE_EVENTS_T_EVENT_SYSTEM_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "events/event.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
@ -28,8 +30,8 @@ template <typename event_type> class t_event_system final {
|
||||
public:
|
||||
t_event_system(const t_event_system &) = delete;
|
||||
t_event_system(t_event_system &&) = delete;
|
||||
t_event_system &operator=(const t_event_system &) = delete;
|
||||
t_event_system &operator=(t_event_system &&) = delete;
|
||||
auto operator=(const t_event_system &) -> t_event_system & = delete;
|
||||
auto operator=(t_event_system &&) -> t_event_system & = delete;
|
||||
|
||||
protected:
|
||||
t_event_system() = default;
|
||||
@ -44,7 +46,8 @@ public:
|
||||
t_event_system::instance().attach(this);
|
||||
}
|
||||
|
||||
event_consumer(const std::string &event_name, std::function<void(const event &)> callback)
|
||||
event_consumer(const std::string &event_name,
|
||||
std::function<void(const event &)> callback)
|
||||
: callback_(std::move(callback)) {
|
||||
t_event_system::instance().attach(event_name, this);
|
||||
}
|
||||
@ -62,17 +65,18 @@ private:
|
||||
static t_event_system event_system_;
|
||||
|
||||
public:
|
||||
static t_event_system &instance();
|
||||
static auto instance() -> t_event_system &;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::deque<event_consumer *>> event_consumers_;
|
||||
std::unordered_map<std::string, std::deque<event_consumer *>>
|
||||
event_consumers_;
|
||||
std::recursive_mutex consumer_mutex_;
|
||||
std::vector<std::shared_ptr<event_type>> event_list_;
|
||||
std::condition_variable event_notify_;
|
||||
std::mutex event_mutex_;
|
||||
std::unique_ptr<std::thread> event_thread_;
|
||||
std::mutex run_mutex_;
|
||||
bool stop_requested_ = false;
|
||||
stop_type stop_requested_ = false;
|
||||
|
||||
private:
|
||||
void process_events() {
|
||||
@ -80,7 +84,7 @@ private:
|
||||
{
|
||||
unique_mutex_lock l(event_mutex_);
|
||||
if (not stop_requested_ && event_list_.empty()) {
|
||||
event_notify_.wait_for(l, 5s);
|
||||
event_notify_.wait_for(l, 1s);
|
||||
}
|
||||
|
||||
if (not event_list_.empty()) {
|
||||
@ -89,14 +93,16 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
const auto notify_events = [this](const std::string &name, const event_type &event) {
|
||||
const auto notify_events = [this](const std::string &name,
|
||||
const event_type &event) {
|
||||
std::deque<std::future<void>> futures;
|
||||
recur_mutex_lock l(consumer_mutex_);
|
||||
if (event_consumers_.find(name) != event_consumers_.end()) {
|
||||
for (auto *ec : event_consumers_[name]) {
|
||||
if (event.get_allow_async()) {
|
||||
futures.emplace_back(
|
||||
std::async(std::launch::async, [ec, &event]() { ec->notify_event(event); }));
|
||||
futures.emplace_back(std::async(std::launch::async, [ec, &event]() {
|
||||
ec->notify_event(event);
|
||||
}));
|
||||
} else {
|
||||
ec->notify_event(event);
|
||||
}
|
||||
@ -138,10 +144,10 @@ public:
|
||||
|
||||
void release(event_consumer *ec) {
|
||||
recur_mutex_lock l(consumer_mutex_);
|
||||
auto it =
|
||||
std::find_if(event_consumers_.begin(), event_consumers_.end(), [&](const auto &kv) -> bool {
|
||||
return utils::collection_includes(kv.second, ec);
|
||||
});
|
||||
auto it = std::find_if(event_consumers_.begin(), event_consumers_.end(),
|
||||
[&](const auto &kv) -> bool {
|
||||
return utils::collection_includes(kv.second, ec);
|
||||
});
|
||||
|
||||
if (it != event_consumers_.end()) {
|
||||
auto &q = (*it).second;
|
||||
@ -166,10 +172,11 @@ public:
|
||||
if (event_thread_) {
|
||||
stop_requested_ = true;
|
||||
event_notify_.notify_all();
|
||||
|
||||
event_thread_->join();
|
||||
event_thread_.reset();
|
||||
|
||||
process_events();
|
||||
stop_requested_ = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
102
include/file_manager/events.hpp
Normal file
102
include/file_manager/events.hpp
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_FILE_MANAGER_EVENTS_HPP_
|
||||
#define INCLUDE_FILE_MANAGER_EVENTS_HPP_
|
||||
|
||||
#include "events/events.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
// clang-format off
|
||||
E_SIMPLE2(download_begin, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE5(download_chunk_begin, debug, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING,
|
||||
std::size_t, chunk, chunk, E_FROM_SIZE_T,
|
||||
std::size_t, total, total, E_FROM_SIZE_T,
|
||||
std::size_t, complete, complete, E_FROM_SIZE_T
|
||||
);
|
||||
|
||||
E_SIMPLE6(download_chunk_end, debug, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING,
|
||||
std::size_t, chunk, chunk, E_FROM_SIZE_T,
|
||||
std::size_t, total, total, E_FROM_SIZE_T,
|
||||
std::size_t, complete, complete, E_FROM_SIZE_T,
|
||||
api_error, result, result, E_FROM_API_FILE_ERROR
|
||||
);
|
||||
|
||||
E_SIMPLE3(download_end, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING,
|
||||
api_error, result, result, E_FROM_API_FILE_ERROR
|
||||
);
|
||||
|
||||
E_SIMPLE3(download_progress, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING,
|
||||
double, progress, prog, E_DOUBLE_PRECISE
|
||||
);
|
||||
|
||||
E_SIMPLE2(download_restored, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(download_restore_failed, error, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING,
|
||||
std::string, error, err, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE2(download_resumed, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE2(download_stored, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE2(download_stored_removed, normal, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(download_stored_failed, error, true,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
std::string, dest_path, dest, E_STRING,
|
||||
std::string, error, err, E_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE1(download_timeout, warn, true,
|
||||
std::string, api_path, ap, E_STRING
|
||||
);
|
||||
// clang-format on
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_FILE_MANAGER_EVENTS_HPP_
|
560
include/file_manager/file_manager.hpp
Normal file
560
include/file_manager/file_manager.hpp
Normal file
@ -0,0 +1,560 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_FILE_MANAGER_FILE_MANAGER_HPP_
|
||||
#define INCLUDE_FILE_MANAGER_FILE_MANAGER_HPP_
|
||||
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "file_manager/i_file_manager.hpp"
|
||||
#include "file_manager/i_open_file.hpp"
|
||||
#include "file_manager/i_upload_manager.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/native_file.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
class i_provider;
|
||||
|
||||
class file_manager final : public i_file_manager, public i_upload_manager {
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
class open_file_base : public i_closeable_open_file {
|
||||
public:
|
||||
open_file_base(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi, i_provider &provider);
|
||||
|
||||
open_file_base(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi,
|
||||
std::map<std::uint64_t, open_file_data> open_data,
|
||||
i_provider &provider);
|
||||
|
||||
~open_file_base() override = default;
|
||||
|
||||
public:
|
||||
open_file_base() = delete;
|
||||
open_file_base(const open_file_base &) noexcept = delete;
|
||||
open_file_base(open_file_base &&) noexcept = delete;
|
||||
auto operator=(open_file_base &&) noexcept -> open_file_base & = delete;
|
||||
auto operator=(const open_file_base &) noexcept
|
||||
-> open_file_base & = delete;
|
||||
|
||||
public:
|
||||
class download final {
|
||||
public:
|
||||
download() = default;
|
||||
|
||||
~download() = default;
|
||||
|
||||
public:
|
||||
download(const download &) noexcept = delete;
|
||||
download(download &&) noexcept = delete;
|
||||
auto operator=(download &&) noexcept -> download & = delete;
|
||||
auto operator=(const download &) noexcept -> download & = delete;
|
||||
|
||||
private:
|
||||
bool complete_ = false;
|
||||
api_error error_ = api_error::success;
|
||||
std::mutex mtx_;
|
||||
std::condition_variable notify_;
|
||||
|
||||
public:
|
||||
void notify(const api_error &e);
|
||||
|
||||
auto wait() -> api_error;
|
||||
};
|
||||
|
||||
class io_item final {
|
||||
public:
|
||||
io_item(std::function<api_error()> action) : action_(std::move(action)) {}
|
||||
|
||||
~io_item() = default;
|
||||
|
||||
public:
|
||||
io_item() = delete;
|
||||
io_item(const io_item &) noexcept = delete;
|
||||
io_item(io_item &&) noexcept = delete;
|
||||
auto operator=(io_item &&) noexcept -> io_item & = delete;
|
||||
auto operator=(const io_item &) noexcept -> io_item & = delete;
|
||||
|
||||
private:
|
||||
std::function<api_error()> action_;
|
||||
std::mutex mtx_;
|
||||
std::condition_variable notify_;
|
||||
std::optional<api_error> result_;
|
||||
|
||||
public:
|
||||
void action();
|
||||
|
||||
[[nodiscard]] auto get_result() -> api_error;
|
||||
};
|
||||
|
||||
protected:
|
||||
std::uint64_t chunk_size_;
|
||||
std::uint8_t chunk_timeout_;
|
||||
filesystem_item fsi_;
|
||||
std::size_t last_chunk_size_;
|
||||
std::map<std::uint64_t, open_file_data> open_data_;
|
||||
i_provider &provider_;
|
||||
|
||||
private:
|
||||
api_error error_ = api_error::success;
|
||||
mutable std::mutex error_mtx_;
|
||||
stop_type io_stop_requested_ = false;
|
||||
std::unique_ptr<std::thread> io_thread_;
|
||||
|
||||
protected:
|
||||
std::unordered_map<std::size_t, std::shared_ptr<download>>
|
||||
active_downloads_;
|
||||
mutable std::recursive_mutex file_mtx_;
|
||||
std::atomic<std::chrono::system_clock::time_point> last_access_ =
|
||||
std::chrono::system_clock::now();
|
||||
bool modified_ = false;
|
||||
native_file_ptr nf_;
|
||||
mutable std::mutex io_thread_mtx_;
|
||||
std::condition_variable io_thread_notify_;
|
||||
std::deque<std::shared_ptr<io_item>> io_thread_queue_;
|
||||
|
||||
private:
|
||||
void file_io_thread();
|
||||
|
||||
protected:
|
||||
[[nodiscard]] auto do_io(std::function<api_error()> action) -> api_error;
|
||||
|
||||
virtual auto is_download_complete() const -> bool = 0;
|
||||
|
||||
void reset_timeout();
|
||||
|
||||
auto set_api_error(const api_error &e) -> api_error;
|
||||
|
||||
public:
|
||||
void add(std::uint64_t handle, open_file_data ofd) override;
|
||||
|
||||
[[nodiscard]] auto can_close() const -> bool override;
|
||||
|
||||
auto close() -> bool override;
|
||||
|
||||
[[nodiscard]] auto get_api_error() const -> api_error;
|
||||
|
||||
[[nodiscard]] auto get_api_path() const -> std::string override;
|
||||
|
||||
[[nodiscard]] auto get_chunk_size() const -> std::size_t override {
|
||||
return chunk_size_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_file_size() const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto get_filesystem_item() const -> filesystem_item override;
|
||||
|
||||
[[nodiscard]] auto get_handles() const
|
||||
-> std::vector<std::uint64_t> override;
|
||||
|
||||
[[nodiscard]] auto get_open_data() const
|
||||
-> std::map<std::uint64_t, open_file_data> override;
|
||||
|
||||
[[nodiscard]] auto get_open_data(std::uint64_t handle) const
|
||||
-> open_file_data override;
|
||||
|
||||
[[nodiscard]] auto get_open_file_count() const -> std::size_t override;
|
||||
|
||||
[[nodiscard]] auto get_source_path() const -> std::string override {
|
||||
return fsi_.source_path;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_directory() const -> bool override {
|
||||
return fsi_.directory;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_modified() const -> bool override;
|
||||
|
||||
void remove(std::uint64_t handle) override;
|
||||
|
||||
void set_api_path(const std::string &api_path) override;
|
||||
};
|
||||
|
||||
class open_file final : public open_file_base {
|
||||
public:
|
||||
open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi, i_provider &provider, i_upload_manager &um);
|
||||
|
||||
open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi,
|
||||
std::map<std::uint64_t, open_file_data> open_data,
|
||||
i_provider &provider, i_upload_manager &um);
|
||||
|
||||
open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi, i_provider &provider,
|
||||
std::optional<boost::dynamic_bitset<>> read_state,
|
||||
i_upload_manager &um);
|
||||
|
||||
private:
|
||||
open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi,
|
||||
std::map<std::uint64_t, open_file_data> open_data,
|
||||
i_provider &provider,
|
||||
std::optional<boost::dynamic_bitset<>> read_state,
|
||||
i_upload_manager &um);
|
||||
|
||||
public:
|
||||
open_file() = delete;
|
||||
open_file(const open_file &) noexcept = delete;
|
||||
open_file(open_file &&) noexcept = delete;
|
||||
auto operator=(open_file &&) noexcept -> open_file & = delete;
|
||||
auto operator=(const open_file &) noexcept -> open_file & = delete;
|
||||
|
||||
public:
|
||||
~open_file() override;
|
||||
|
||||
private:
|
||||
i_upload_manager &um_;
|
||||
|
||||
private:
|
||||
bool notified_ = false;
|
||||
std::size_t read_chunk_index_ = 0u;
|
||||
boost::dynamic_bitset<> read_state_;
|
||||
std::unique_ptr<std::thread> reader_thread_;
|
||||
std::unique_ptr<std::thread> download_thread_;
|
||||
stop_type stop_requested_ = false;
|
||||
|
||||
private:
|
||||
void download_chunk(std::size_t chunk, bool skip_active, bool should_reset);
|
||||
|
||||
void download_range(std::size_t start_chunk_index,
|
||||
std::size_t end_chunk_index_inclusive,
|
||||
bool should_reset);
|
||||
|
||||
private:
|
||||
void update_background_reader(std::size_t read_chunk);
|
||||
|
||||
protected:
|
||||
auto is_download_complete() const -> bool override {
|
||||
return read_state_.all();
|
||||
}
|
||||
|
||||
public:
|
||||
auto close() -> bool override;
|
||||
|
||||
[[nodiscard]] auto get_read_state() const
|
||||
-> boost::dynamic_bitset<> override;
|
||||
|
||||
[[nodiscard]] auto get_read_state(std::size_t chunk) const -> bool override;
|
||||
|
||||
[[nodiscard]] auto is_complete() const -> bool override;
|
||||
|
||||
auto is_write_supported() const -> bool override { return true; }
|
||||
|
||||
[[nodiscard]] auto native_operation(const native_operation_callback &cb)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto native_operation(std::uint64_t new_file_size,
|
||||
const native_operation_callback &cb)
|
||||
-> api_error override;
|
||||
|
||||
void remove(std::uint64_t handle) override;
|
||||
|
||||
[[nodiscard]] auto read(std::size_t read_size, std::uint64_t read_offset,
|
||||
data_buffer &data) -> api_error override;
|
||||
|
||||
[[nodiscard]] auto resize(std::uint64_t new_file_size)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto write(std::uint64_t write_offset,
|
||||
const data_buffer &data,
|
||||
std::size_t &bytes_written) -> api_error override;
|
||||
};
|
||||
|
||||
class ring_buffer_open_file final : public open_file_base {
|
||||
public:
|
||||
ring_buffer_open_file(std::string buffer_directory,
|
||||
std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi, i_provider &provider);
|
||||
|
||||
ring_buffer_open_file(std::string buffer_directory,
|
||||
std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||
filesystem_item fsi, i_provider &provider,
|
||||
std::size_t ring_size);
|
||||
|
||||
~ring_buffer_open_file() override;
|
||||
|
||||
public:
|
||||
ring_buffer_open_file() = delete;
|
||||
ring_buffer_open_file(const ring_buffer_open_file &) noexcept = delete;
|
||||
ring_buffer_open_file(ring_buffer_open_file &&) noexcept = delete;
|
||||
auto operator=(ring_buffer_open_file &&) noexcept
|
||||
-> ring_buffer_open_file & = delete;
|
||||
auto operator=(const ring_buffer_open_file &) noexcept
|
||||
-> ring_buffer_open_file & = delete;
|
||||
|
||||
private:
|
||||
boost::dynamic_bitset<> ring_state_;
|
||||
std::size_t total_chunks_;
|
||||
|
||||
private:
|
||||
std::unique_ptr<std::thread> chunk_forward_thread_;
|
||||
std::unique_ptr<std::thread> chunk_reverse_thread_;
|
||||
std::condition_variable chunk_notify_;
|
||||
mutable std::mutex chunk_mtx_;
|
||||
std::size_t current_chunk_ = 0u;
|
||||
std::size_t first_chunk_ = 0u;
|
||||
std::size_t last_chunk_;
|
||||
|
||||
private:
|
||||
auto download_chunk(std::size_t chunk) -> api_error;
|
||||
|
||||
void forward_reader_thread(std::size_t count);
|
||||
|
||||
void reverse_reader_thread(std::size_t count);
|
||||
|
||||
protected:
|
||||
auto is_download_complete() const -> bool override;
|
||||
|
||||
public:
|
||||
void forward(std::size_t count);
|
||||
|
||||
[[nodiscard]] auto get_current_chunk() const -> std::size_t {
|
||||
return current_chunk_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_first_chunk() const -> std::size_t {
|
||||
return first_chunk_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_last_chunk() const -> std::size_t {
|
||||
return last_chunk_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_read_state() const
|
||||
-> boost::dynamic_bitset<> override;
|
||||
|
||||
[[nodiscard]] auto get_read_state(std::size_t chunk) const -> bool override;
|
||||
|
||||
[[nodiscard]] auto get_total_chunks() const -> std::size_t {
|
||||
return total_chunks_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_complete() const -> bool override { return true; }
|
||||
|
||||
auto is_write_supported() const -> bool override { return false; }
|
||||
|
||||
[[nodiscard]] auto native_operation(const native_operation_callback &cb)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto native_operation(std::uint64_t,
|
||||
const native_operation_callback &)
|
||||
-> api_error override {
|
||||
return api_error::not_supported;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto read(std::size_t read_size, std::uint64_t read_offset,
|
||||
data_buffer &data) -> api_error override;
|
||||
|
||||
[[nodiscard]] auto resize(std::uint64_t) -> api_error override {
|
||||
return api_error::not_supported;
|
||||
}
|
||||
|
||||
void reverse(std::size_t count);
|
||||
|
||||
void set(std::size_t first_chunk, std::size_t current_chunk);
|
||||
|
||||
void set_api_path(const std::string &api_path) override;
|
||||
|
||||
[[nodiscard]] auto write(std::uint64_t, const data_buffer &, std::size_t &)
|
||||
-> api_error override {
|
||||
return api_error::not_supported;
|
||||
}
|
||||
};
|
||||
|
||||
class upload final {
|
||||
public:
|
||||
upload(filesystem_item fsi, i_provider &provider);
|
||||
|
||||
~upload();
|
||||
|
||||
public:
|
||||
upload() = delete;
|
||||
upload(const upload &) noexcept = delete;
|
||||
upload(upload &&) noexcept = delete;
|
||||
auto operator=(upload &&) noexcept -> upload & = delete;
|
||||
auto operator=(const upload &) noexcept -> upload & = delete;
|
||||
|
||||
private:
|
||||
filesystem_item fsi_;
|
||||
i_provider &provider_;
|
||||
|
||||
private:
|
||||
bool cancelled_ = false;
|
||||
api_error error_ = api_error::success;
|
||||
std::unique_ptr<std::thread> thread_;
|
||||
stop_type stop_requested_ = false;
|
||||
|
||||
private:
|
||||
void upload_thread();
|
||||
|
||||
public:
|
||||
void cancel();
|
||||
|
||||
[[nodiscard]] auto get_api_error() const -> api_error { return error_; }
|
||||
|
||||
[[nodiscard]] auto get_api_path() const -> std::string {
|
||||
return fsi_.api_path;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_source_path() const -> std::string {
|
||||
return fsi_.source_path;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_cancelled() const -> bool { return cancelled_; }
|
||||
|
||||
void stop();
|
||||
};
|
||||
|
||||
public:
|
||||
file_manager(app_config &config, i_provider &provider);
|
||||
|
||||
~file_manager() override;
|
||||
|
||||
public:
|
||||
file_manager() = delete;
|
||||
file_manager(const file_manager &) noexcept = delete;
|
||||
file_manager(file_manager &&) noexcept = delete;
|
||||
auto operator=(file_manager &&) noexcept -> file_manager & = delete;
|
||||
auto operator=(const file_manager &) noexcept -> file_manager & = delete;
|
||||
|
||||
private:
|
||||
app_config &config_;
|
||||
i_provider &provider_;
|
||||
std::unique_ptr<rocksdb::DB> db_;
|
||||
|
||||
private:
|
||||
rocksdb::ColumnFamilyHandle *default_family_{};
|
||||
std::uint64_t next_handle_ = 0u;
|
||||
mutable std::recursive_mutex open_file_mtx_;
|
||||
std::unordered_map<std::string, std::shared_ptr<i_closeable_open_file>>
|
||||
open_file_lookup_;
|
||||
std::unordered_map<std::uint64_t, i_closeable_open_file *>
|
||||
open_handle_lookup_;
|
||||
stop_type stop_requested_ = false;
|
||||
rocksdb::ColumnFamilyHandle *upload_family_{};
|
||||
rocksdb::ColumnFamilyHandle *upload_active_family_{};
|
||||
std::unordered_map<std::string, std::unique_ptr<upload>> upload_lookup_;
|
||||
mutable std::mutex upload_mtx_;
|
||||
std::condition_variable upload_notify_;
|
||||
std::unique_ptr<std::thread> upload_thread_;
|
||||
|
||||
private:
|
||||
void close_timed_out_files();
|
||||
|
||||
auto get_open_file_count(const std::string &api_path) const -> std::size_t;
|
||||
|
||||
auto open(const std::string &api_path, bool directory,
|
||||
const open_file_data &ofd, std::uint64_t &handle,
|
||||
std::shared_ptr<i_open_file> &f,
|
||||
std::shared_ptr<i_closeable_open_file> of) -> api_error;
|
||||
|
||||
void queue_upload(const std::string &api_path, const std::string &source_path,
|
||||
bool no_lock);
|
||||
|
||||
void remove_upload(const std::string &api_path, bool no_lock);
|
||||
|
||||
void swap_renamed_items(std::string from_api_path, std::string to_api_path);
|
||||
|
||||
void upload_completed(const file_upload_completed &e);
|
||||
|
||||
void upload_handler();
|
||||
|
||||
public:
|
||||
[[nodiscard]] auto get_next_handle() -> std::uint64_t;
|
||||
|
||||
auto handle_file_rename(const std::string &from_api_path,
|
||||
const std::string &to_api_path) -> api_error;
|
||||
|
||||
void queue_upload(const i_open_file &o) override;
|
||||
|
||||
void remove_resume(const std::string &api_path,
|
||||
const std::string &source_path) override;
|
||||
|
||||
void remove_upload(const std::string &api_path) override;
|
||||
|
||||
void store_resume(const i_open_file &o) override;
|
||||
|
||||
public:
|
||||
void close(std::uint64_t handle);
|
||||
|
||||
void close_all(const std::string &api_path);
|
||||
|
||||
[[nodiscard]] auto create(const std::string &api_path, api_meta_map &meta,
|
||||
open_file_data ofd, std::uint64_t &handle,
|
||||
std::shared_ptr<i_open_file> &f) -> api_error;
|
||||
|
||||
[[nodiscard]] auto evict_file(const std::string &api_path) -> bool override;
|
||||
|
||||
[[nodiscard]] auto get_directory_items(const std::string &api_path) const
|
||||
-> directory_item_list override;
|
||||
|
||||
[[nodiscard]] auto get_open_file(std::uint64_t handle, bool write_supported,
|
||||
std::shared_ptr<i_open_file> &f) -> bool;
|
||||
|
||||
[[nodiscard]] auto get_open_file_count() const -> std::size_t;
|
||||
|
||||
[[nodiscard]] auto get_open_files() const
|
||||
-> std::unordered_map<std::string, std::size_t> override;
|
||||
|
||||
[[nodiscard]] auto get_open_handle_count() const -> std::size_t;
|
||||
|
||||
[[nodiscard]] auto get_stored_downloads() const -> std::vector<json>;
|
||||
|
||||
[[nodiscard]] auto has_no_open_file_handles() const -> bool override;
|
||||
|
||||
[[nodiscard]] auto is_processing(const std::string &api_path) const
|
||||
-> bool override;
|
||||
|
||||
#ifdef REPERTORY_TESTING
|
||||
[[nodiscard]] auto open(std::shared_ptr<i_closeable_open_file> of,
|
||||
const open_file_data &ofd, std::uint64_t &handle,
|
||||
std::shared_ptr<i_open_file> &f) -> api_error;
|
||||
#endif
|
||||
[[nodiscard]] auto open(const std::string &api_path, bool directory,
|
||||
const open_file_data &ofd, std::uint64_t &handle,
|
||||
std::shared_ptr<i_open_file> &f) -> api_error;
|
||||
|
||||
auto perform_locked_operation(locked_operation_callback locked_operation)
|
||||
-> bool override;
|
||||
|
||||
[[nodiscard]] auto remove_file(const std::string &api_path) -> api_error;
|
||||
|
||||
[[nodiscard]] auto rename_directory(const std::string &from_api_path,
|
||||
const std::string &to_api_path)
|
||||
-> api_error;
|
||||
|
||||
[[nodiscard]] auto rename_file(const std::string &from_api_path,
|
||||
const std::string &to_api_path, bool overwrite)
|
||||
-> api_error;
|
||||
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
|
||||
void update_used_space(std::uint64_t &used_space) const override;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_FILE_MANAGER_FILE_MANAGER_HPP_
|
60
include/file_manager/i_file_manager.hpp
Normal file
60
include/file_manager/i_file_manager.hpp
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_FILE_MANAGER_I_FILE_MANAGER_HPP_
|
||||
#define INCLUDE_FILE_MANAGER_I_FILE_MANAGER_HPP_
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_provider;
|
||||
|
||||
class i_file_manager {
|
||||
INTERFACE_SETUP(i_file_manager);
|
||||
|
||||
public:
|
||||
using locked_operation_callback = std::function<bool(i_provider &)>;
|
||||
|
||||
public:
|
||||
[[nodiscard]] virtual auto evict_file(const std::string &api_path)
|
||||
-> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
get_directory_items(const std::string &api_path) const
|
||||
-> directory_item_list = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_open_files() const
|
||||
-> std::unordered_map<std::string, std::size_t> = 0;
|
||||
|
||||
[[nodiscard]] virtual auto has_no_open_file_handles() const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto is_processing(const std::string &api_path) const
|
||||
-> bool = 0;
|
||||
|
||||
virtual auto
|
||||
perform_locked_operation(locked_operation_callback locked_operation)
|
||||
-> bool = 0;
|
||||
|
||||
virtual void update_used_space(std::uint64_t &used_space) const = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_FILE_MANAGER_I_FILE_MANAGER_HPP_
|
105
include/file_manager/i_open_file.hpp
Normal file
105
include/file_manager/i_open_file.hpp
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_FILE_MANAGER_I_OPEN_FILE_HPP_
|
||||
#define INCLUDE_FILE_MANAGER_I_OPEN_FILE_HPP_
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_open_file {
|
||||
INTERFACE_SETUP(i_open_file);
|
||||
|
||||
public:
|
||||
using native_operation_callback = std::function<api_error(native_handle)>;
|
||||
|
||||
public:
|
||||
[[nodiscard]] virtual auto get_api_path() const -> std::string = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_chunk_size() const -> std::size_t = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_file_size() const -> std::uint64_t = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_filesystem_item() const -> filesystem_item = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_open_data(std::uint64_t handle) const
|
||||
-> open_file_data = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_open_file_count() const -> std::size_t = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_read_state() const
|
||||
-> boost::dynamic_bitset<> = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_read_state(std::size_t chunk) const
|
||||
-> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_source_path() const -> std::string = 0;
|
||||
|
||||
[[nodiscard]] virtual auto is_directory() const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
native_operation(const native_operation_callback &cb) -> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
native_operation(std::uint64_t new_file_size,
|
||||
const native_operation_callback &cb) -> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto read(std::size_t read_size,
|
||||
std::uint64_t read_offset, data_buffer &data)
|
||||
-> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto resize(std::uint64_t new_file_size)
|
||||
-> api_error = 0;
|
||||
|
||||
virtual void set_api_path(const std::string &api_path) = 0;
|
||||
|
||||
[[nodiscard]] virtual auto write(std::uint64_t write_offset,
|
||||
const data_buffer &data,
|
||||
std::size_t &bytes_written) -> api_error = 0;
|
||||
};
|
||||
|
||||
class i_closeable_open_file : public i_open_file {
|
||||
INTERFACE_SETUP(i_closeable_open_file);
|
||||
|
||||
public:
|
||||
virtual void add(std::uint64_t handle, open_file_data ofd) = 0;
|
||||
|
||||
[[nodiscard]] virtual auto can_close() const -> bool = 0;
|
||||
|
||||
virtual auto close() -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_handles() const
|
||||
-> std::vector<std::uint64_t> = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_open_data() const
|
||||
-> std::map<std::uint64_t, open_file_data> = 0;
|
||||
|
||||
[[nodiscard]] virtual auto is_complete() const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto is_modified() const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto is_write_supported() const -> bool = 0;
|
||||
|
||||
virtual void remove(std::uint64_t handle) = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_FILE_MANAGER_I_OPEN_FILE_HPP_
|
43
include/file_manager/i_upload_manager.hpp
Normal file
43
include/file_manager/i_upload_manager.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_FILE_MANAGER_I_UPLOAD_MANAGER_HPP_
|
||||
#define INCLUDE_FILE_MANAGER_I_UPLOAD_MANAGER_HPP_
|
||||
|
||||
namespace repertory {
|
||||
class i_open_file;
|
||||
|
||||
class i_upload_manager {
|
||||
INTERFACE_SETUP(i_upload_manager);
|
||||
|
||||
public:
|
||||
virtual void queue_upload(const i_open_file &o) = 0;
|
||||
|
||||
virtual void remove_resume(const std::string &api_path,
|
||||
const std::string &source_path) = 0;
|
||||
|
||||
virtual void remove_upload(const std::string &api_path) = 0;
|
||||
|
||||
virtual void store_resume(const i_open_file &o) = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_FILE_MANAGER_I_UPLOAD_MANAGER_HPP_
|
@ -1,20 +1,23 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_PLATFORM_PLATFORM_HPP_
|
||||
#define INCLUDE_PLATFORM_PLATFORM_HPP_
|
||||
|
@ -1,29 +1,33 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_PLATFORM_UNIXPLATFORM_HPP_
|
||||
#define INCLUDE_PLATFORM_UNIXPLATFORM_HPP_
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_provider;
|
||||
|
||||
class lock_data final {
|
||||
public:
|
||||
explicit lock_data(const provider_type &pt, std::string unique_id /*= ""*/);
|
||||
@ -40,22 +44,38 @@ private:
|
||||
int lock_status_ = EWOULDBLOCK;
|
||||
|
||||
private:
|
||||
static std::string get_state_directory();
|
||||
[[nodiscard]] static auto get_state_directory() -> std::string;
|
||||
|
||||
static std::string get_lock_data_file();
|
||||
[[nodiscard]] static auto get_lock_data_file() -> std::string;
|
||||
|
||||
std::string get_lock_file();
|
||||
[[nodiscard]] auto get_lock_file() -> std::string;
|
||||
|
||||
private:
|
||||
static int wait_for_lock(const int &fd, const std::uint8_t &retry_count = 30u);
|
||||
[[nodiscard]] static auto wait_for_lock(int fd,
|
||||
std::uint8_t retry_count = 30u)
|
||||
-> int;
|
||||
|
||||
public:
|
||||
bool get_mount_state(json &mount_state);
|
||||
[[nodiscard]] auto get_mount_state(json &mount_state) -> bool;
|
||||
|
||||
lock_result grab_lock(const std::uint8_t &retry_count = 30u);
|
||||
[[nodiscard]] auto grab_lock(std::uint8_t retry_count = 30u) -> lock_result;
|
||||
|
||||
bool set_mount_state(const bool &active, const std::string &mount_location, const int &pid);
|
||||
[[nodiscard]] auto set_mount_state(bool active,
|
||||
const std::string &mount_location, int pid)
|
||||
-> bool;
|
||||
};
|
||||
|
||||
[[nodiscard]] auto create_meta_attributes(
|
||||
std::uint64_t accessed_date, std::uint32_t attributes,
|
||||
std::uint64_t changed_date, std::uint64_t creation_date, bool directory,
|
||||
const std::string &encryption_token, std::uint32_t gid,
|
||||
const std::string &key, std::uint32_t mode, std::uint64_t modified_date,
|
||||
std::uint32_t osx_backup, std::uint32_t osx_flags, std::uint64_t size,
|
||||
const std::string &source_path, std::uint32_t uid,
|
||||
std::uint64_t written_date) -> api_meta_map;
|
||||
|
||||
[[nodiscard]] auto provider_meta_handler(i_provider &provider, bool directory,
|
||||
const api_file &file) -> api_error;
|
||||
} // namespace repertory
|
||||
|
||||
#endif // _WIN32
|
||||
|
@ -1,39 +1,47 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_PLATFORM_WINPLATFORM_HPP_
|
||||
#define INCLUDE_PLATFORM_WINPLATFORM_HPP_
|
||||
#ifdef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_provider;
|
||||
|
||||
class lock_data final {
|
||||
public:
|
||||
explicit lock_data(const provider_type &pt, std::string unique_id /*= ""*/)
|
||||
: pt_(pt), unique_id_(std::move(unique_id)),
|
||||
mutex_id_("repertory_" + app_config::get_provider_name(pt) + "_" + unique_id_),
|
||||
: pt_(pt),
|
||||
unique_id_(std::move(unique_id)),
|
||||
mutex_id_("repertory_" + app_config::get_provider_name(pt) + "_" +
|
||||
unique_id_),
|
||||
mutex_handle_(::CreateMutex(nullptr, FALSE, &mutex_id_[0u])) {}
|
||||
|
||||
lock_data()
|
||||
: pt_(provider_type::sia), unique_id_(""), mutex_id_(""),
|
||||
: pt_(provider_type::sia),
|
||||
unique_id_(""),
|
||||
mutex_id_(""),
|
||||
mutex_handle_(INVALID_HANDLE_VALUE) {}
|
||||
|
||||
~lock_data() { release(); }
|
||||
@ -46,19 +54,33 @@ private:
|
||||
DWORD mutex_state_ = WAIT_FAILED;
|
||||
|
||||
public:
|
||||
bool get_mount_state(const provider_type &pt, json &mount_state);
|
||||
[[nodiscard]] auto get_mount_state(const provider_type &pt, json &mount_state)
|
||||
-> bool;
|
||||
|
||||
bool get_mount_state(json &mount_state);
|
||||
[[nodiscard]] auto get_mount_state(json &mount_state) -> bool;
|
||||
|
||||
std::string get_unique_id() const { return unique_id_; }
|
||||
[[nodiscard]] auto get_unique_id() const -> std::string { return unique_id_; }
|
||||
|
||||
lock_result grab_lock(const std::uint8_t &retryCount = 30);
|
||||
[[nodiscard]] auto grab_lock(std::uint8_t retry_count = 30) -> lock_result;
|
||||
|
||||
void release();
|
||||
|
||||
bool set_mount_state(const bool &active, const std::string &mountLocation,
|
||||
const std::int64_t &pid);
|
||||
[[nodiscard]] auto set_mount_state(bool active,
|
||||
const std::string &mount_location,
|
||||
const std::int64_t &pid) -> bool;
|
||||
};
|
||||
|
||||
[[nodiscard]] auto create_meta_attributes(
|
||||
std::uint64_t accessed_date, std::uint32_t attributes,
|
||||
std::uint64_t changed_date, std::uint64_t creation_date, bool directory,
|
||||
const std::string &encryption_token, std::uint32_t gid,
|
||||
const std::string &key, std::uint32_t mode, std::uint64_t modified_date,
|
||||
std::uint32_t osx_backup, std::uint32_t osx_flags, std::uint64_t size,
|
||||
const std::string &source_path, std::uint32_t uid,
|
||||
std::uint64_t written_date) -> api_meta_map;
|
||||
|
||||
[[nodiscard]] auto provider_meta_handler(i_provider &provider, bool directory,
|
||||
const api_file &file) -> api_error;
|
||||
} // namespace repertory
|
||||
|
||||
#endif // _WIN32
|
||||
|
@ -1,30 +1,34 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_PROVIDERS_BASE_PROVIDER_HPP_
|
||||
#define INCLUDE_PROVIDERS_BASE_PROVIDER_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "db/meta_db.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
class i_file_manager;
|
||||
|
||||
class base_provider : public i_provider {
|
||||
public:
|
||||
explicit base_provider(app_config &config);
|
||||
@ -33,90 +37,168 @@ public:
|
||||
|
||||
private:
|
||||
app_config &config_;
|
||||
std::atomic<std::uint64_t> used_space_{0U};
|
||||
|
||||
protected:
|
||||
api_item_added_callback api_item_added_;
|
||||
meta_db meta_db_;
|
||||
std::unique_ptr<meta_db> meta_db_;
|
||||
mutable std::recursive_mutex notify_added_mutex_;
|
||||
i_open_file_table *oft_ = nullptr;
|
||||
i_file_manager *fm_ = nullptr;
|
||||
stop_type stop_requested_ = false;
|
||||
|
||||
protected:
|
||||
app_config &get_config() { return config_; }
|
||||
void calculate_used_drive_space(bool add_missing);
|
||||
|
||||
app_config &get_config() const { return config_; }
|
||||
[[nodiscard]] virtual auto
|
||||
check_file_exists(const std::string &api_path) const -> api_error = 0;
|
||||
|
||||
virtual std::string format_api_path(std::string api_path) const { return api_path; }
|
||||
void cleanup();
|
||||
|
||||
virtual std::string &restore_api_path(std::string &api_path) const { return api_path; }
|
||||
[[nodiscard]] auto get_config() -> app_config & { return config_; }
|
||||
|
||||
void notify_directory_added(const std::string &api_path, const std::string &api_parent) const {
|
||||
const_cast<base_provider *>(this)->notify_directory_added(api_path, api_parent);
|
||||
[[nodiscard]] auto get_config() const -> app_config & { return config_; }
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
handle_rename_file(const std::string &from_api_path,
|
||||
const std::string &to_api_path,
|
||||
const std::string &source_path) -> api_error = 0;
|
||||
|
||||
[[nodiscard]] auto notify_directory_added(const std::string &api_path,
|
||||
const std::string &api_parent) const
|
||||
-> api_error {
|
||||
return const_cast<base_provider *>(this)->notify_directory_added(
|
||||
api_path, api_parent);
|
||||
}
|
||||
|
||||
virtual void notify_directory_added(const std::string &api_path, const std::string &api_parent);
|
||||
[[nodiscard]] virtual auto
|
||||
notify_directory_added(const std::string &api_path,
|
||||
const std::string &api_parent) -> api_error;
|
||||
|
||||
api_error notify_file_added(const std::string &api_path, const std::string &api_parent,
|
||||
const std::uint64_t &size) const {
|
||||
return const_cast<base_provider *>(this)->notify_file_added(api_path, api_parent, size);
|
||||
[[nodiscard]] auto notify_file_added(const std::string &api_path,
|
||||
const std::string &api_parent,
|
||||
std::uint64_t size) const -> api_error {
|
||||
return const_cast<base_provider *>(this)->notify_file_added(
|
||||
api_path, api_parent, size);
|
||||
}
|
||||
|
||||
virtual api_error notify_file_added(const std::string &api_path, const std::string &api_parent,
|
||||
const std::uint64_t &size) = 0;
|
||||
[[nodiscard]] virtual auto notify_file_added(const std::string &api_path,
|
||||
const std::string &api_parent,
|
||||
std::uint64_t size)
|
||||
-> api_error = 0;
|
||||
|
||||
void remove_item_meta(const std::string &api_path) {
|
||||
return meta_db_.remove_item_meta(format_api_path(api_path));
|
||||
[[nodiscard]] virtual auto
|
||||
populate_directory_items(const std::string &api_path,
|
||||
directory_item_list &list) const -> api_error = 0;
|
||||
|
||||
[[nodiscard]] virtual auto populate_file(const std::string &api_path,
|
||||
api_file &file) const
|
||||
-> api_error = 0;
|
||||
|
||||
auto processed_orphaned_file(const std::string &source_path,
|
||||
const std::string &api_path = "") const -> bool;
|
||||
|
||||
void remove_deleted_files();
|
||||
|
||||
void remove_expired_orphaned_files();
|
||||
|
||||
void remove_unknown_source_files();
|
||||
|
||||
[[nodiscard]] auto remove_item_meta(const std::string &api_path)
|
||||
-> api_error {
|
||||
return meta_db_->remove_item_meta(api_path);
|
||||
}
|
||||
|
||||
void update_filesystem_item(const bool &directory, const api_error &error,
|
||||
const std::string &api_path, filesystem_item &fsi) const;
|
||||
void update_filesystem_item(bool directory, const api_error &error,
|
||||
const std::string &api_path,
|
||||
filesystem_item &fsi) const;
|
||||
|
||||
public:
|
||||
api_error create_directory_clone_source_meta(const std::string &source_api_path,
|
||||
const std::string &api_path) override;
|
||||
[[nodiscard]] auto
|
||||
create_directory_clone_source_meta(const std::string &source_api_path,
|
||||
const std::string &api_path)
|
||||
-> api_error override;
|
||||
|
||||
api_error create_file(const std::string &api_path, api_meta_map &meta) override;
|
||||
[[nodiscard]] auto create_file(const std::string &api_path,
|
||||
api_meta_map &meta) -> api_error override;
|
||||
|
||||
api_error get_api_path_from_source(const std::string &source_path,
|
||||
std::string &api_path) const override;
|
||||
[[nodiscard]] auto get_api_path_from_source(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
-> api_error override;
|
||||
|
||||
api_error get_filesystem_item(const std::string &api_path, const bool &directory,
|
||||
filesystem_item &fsi) const override;
|
||||
[[nodiscard]] auto get_directory_items(const std::string &api_path,
|
||||
directory_item_list &list) const
|
||||
-> api_error override;
|
||||
|
||||
api_error get_filesystem_item_and_file(const std::string &api_path, api_file &file,
|
||||
filesystem_item &fsi) const override;
|
||||
[[nodiscard]] auto get_file(const std::string &api_path, api_file &file) const
|
||||
-> api_error override;
|
||||
|
||||
api_error get_filesystem_item_from_source_path(const std::string &source_path,
|
||||
filesystem_item &fsi) const override;
|
||||
[[nodiscard]] auto get_file_size(const std::string &api_path,
|
||||
std::uint64_t &file_size) const
|
||||
-> api_error override;
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, api_meta_map &meta) const override;
|
||||
[[nodiscard]] auto get_filesystem_item(const std::string &api_path,
|
||||
bool directory,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error override;
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, const std::string &key,
|
||||
std::string &value) const override;
|
||||
[[nodiscard]] auto get_filesystem_item_and_file(const std::string &api_path,
|
||||
api_file &file,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error override;
|
||||
|
||||
std::vector<std::string> get_pinned_files() const override { return meta_db_.get_pinned_files(); }
|
||||
[[nodiscard]] auto
|
||||
get_filesystem_item_from_source_path(const std::string &source_path,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error override;
|
||||
|
||||
std::uint64_t get_used_drive_space() const override;
|
||||
[[nodiscard]] auto get_item_meta(const std::string &api_path,
|
||||
api_meta_map &meta) const
|
||||
-> api_error override;
|
||||
|
||||
bool is_file_writeable(const std::string &) const override { return true; }
|
||||
[[nodiscard]] auto get_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
std::string &value) const
|
||||
-> api_error override;
|
||||
|
||||
api_error remove_item_meta(const std::string &api_path, const std::string &key) override {
|
||||
return meta_db_.remove_item_meta(format_api_path(api_path), key);
|
||||
[[nodiscard]] auto get_pinned_files() const
|
||||
-> std::vector<std::string> override {
|
||||
return meta_db_->get_pinned_files();
|
||||
}
|
||||
|
||||
api_error set_item_meta(const std::string &api_path, const std::string &key,
|
||||
const std::string &value) override {
|
||||
return meta_db_.set_item_meta(format_api_path(api_path), key, value);
|
||||
[[nodiscard]] auto get_used_drive_space() const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto is_file_writeable(const std::string &) const
|
||||
-> bool override {
|
||||
return true;
|
||||
}
|
||||
|
||||
api_error set_item_meta(const std::string &api_path, const api_meta_map &meta) override {
|
||||
return meta_db_.set_item_meta(format_api_path(api_path), meta);
|
||||
[[nodiscard]] auto remove_item_meta(const std::string &api_path,
|
||||
const std::string &key)
|
||||
-> api_error override {
|
||||
return meta_db_->remove_item_meta(api_path, key);
|
||||
}
|
||||
|
||||
api_error set_source_path(const std::string &api_path, const std::string &source_path) override {
|
||||
return meta_db_.set_source_path(format_api_path(api_path), source_path);
|
||||
[[nodiscard]] auto rename_file(const std::string &from_api_path,
|
||||
const std::string &to_api_path)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto set_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
const std::string &value)
|
||||
-> api_error override {
|
||||
return meta_db_->set_item_meta(api_path, key, value);
|
||||
}
|
||||
|
||||
bool start(api_item_added_callback api_item_added, i_open_file_table *oft) override;
|
||||
[[nodiscard]] auto set_item_meta(const std::string &api_path,
|
||||
const api_meta_map &meta)
|
||||
-> api_error override {
|
||||
return meta_db_->set_item_meta(api_path, meta);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto start(api_item_added_callback api_item_added,
|
||||
i_file_manager *fm) -> bool override;
|
||||
|
||||
void stop() override;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
218
include/providers/encrypt/encrypt_provider.hpp
Normal file
218
include/providers/encrypt/encrypt_provider.hpp
Normal file
@ -0,0 +1,218 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_PROVIDERS_ENCRYPT_ENCRYPT_PROVIDER_HPP_
|
||||
#define INCLUDE_PROVIDERS_ENCRYPT_ENCRYPT_PROVIDER_HPP_
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "utils/encrypting_reader.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class encrypt_provider final : public i_provider {
|
||||
public:
|
||||
explicit encrypt_provider(app_config &config);
|
||||
|
||||
~encrypt_provider() override = default;
|
||||
|
||||
private:
|
||||
struct reader_info final {
|
||||
std::chrono::system_clock::time_point last_access_time =
|
||||
std::chrono::system_clock::now();
|
||||
std::unique_ptr<utils::encryption::encrypting_reader> reader{};
|
||||
std::mutex reader_mtx;
|
||||
};
|
||||
|
||||
private:
|
||||
app_config &config_;
|
||||
std::unique_ptr<rocksdb::DB> db_;
|
||||
rocksdb::ColumnFamilyHandle *dir_family_{};
|
||||
rocksdb::ColumnFamilyHandle *file_family_{};
|
||||
rocksdb::ColumnFamilyHandle *source_family_{};
|
||||
const std::string DB_NAME = "meta_db";
|
||||
|
||||
private:
|
||||
i_file_manager *fm_ = nullptr;
|
||||
std::unordered_map<std::string, std::shared_ptr<reader_info>>
|
||||
reader_lookup_{};
|
||||
std::recursive_mutex reader_lookup_mtx_{};
|
||||
|
||||
private:
|
||||
static auto create_api_file(const std::string api_path, bool directory,
|
||||
const std::string &source_path) -> api_file;
|
||||
|
||||
static void create_item_meta(api_meta_map &meta, bool directory,
|
||||
const api_file &file);
|
||||
|
||||
[[nodiscard]] auto
|
||||
process_directory_entry(const std::filesystem::directory_entry &dir_entry,
|
||||
const encrypt_config &cfg,
|
||||
std::string &api_path) const -> bool;
|
||||
void remove_deleted_files();
|
||||
|
||||
public:
|
||||
[[nodiscard]] auto create_directory(const std::string &api_path,
|
||||
api_meta_map &meta) -> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
create_directory_clone_source_meta(const std::string & /*source_api_path*/,
|
||||
const std::string & /*api_path*/)
|
||||
-> api_error override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto create_file(const std::string & /*api_path*/,
|
||||
api_meta_map & /*meta*/)
|
||||
-> api_error override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_api_path_from_source(const std::string & /*source_path*/,
|
||||
std::string & /*api_path*/) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_directory_item_count(const std::string &api_path) const
|
||||
-> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto get_directory_items(const std::string &api_path,
|
||||
directory_item_list &list) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_file(const std::string &api_path, api_file &file) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_file_list(api_file_list &list) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_file_size(const std::string &api_path,
|
||||
std::uint64_t &file_size) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_filesystem_item(const std::string &api_path,
|
||||
bool directory,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_filesystem_item_and_file(const std::string &api_path,
|
||||
api_file &file,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_filesystem_item_from_source_path(const std::string &source_path,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_pinned_files() const
|
||||
-> std::vector<std::string> override;
|
||||
|
||||
[[nodiscard]] auto get_item_meta(const std::string &api_path,
|
||||
api_meta_map &meta) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
std::string &value) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto get_provider_type() const -> provider_type override {
|
||||
return provider_type::encrypt;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_used_drive_space() const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto is_direct_only() const -> bool override { return true; }
|
||||
|
||||
[[nodiscard]] auto is_directory(const std::string &api_path,
|
||||
bool &exists) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto is_file(const std::string &api_path, bool &exists) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto is_file_writeable(const std::string &api_path) const
|
||||
-> bool override;
|
||||
|
||||
[[nodiscard]] auto is_online() const -> bool override;
|
||||
|
||||
[[nodiscard]] auto is_rename_supported() const -> bool override;
|
||||
|
||||
[[nodiscard]] auto read_file_bytes(const std::string &api_path,
|
||||
std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data,
|
||||
stop_type &stop_requested)
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto remove_directory(const std::string & /*api_path*/)
|
||||
-> api_error override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto remove_file(const std::string & /*api_path*/)
|
||||
-> api_error override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto remove_item_meta(const std::string & /*api_path*/,
|
||||
const std::string & /*key*/)
|
||||
-> api_error override {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto rename_file(const std::string & /*from_api_path*/,
|
||||
const std::string & /*to_api_path*/)
|
||||
-> api_error override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto set_item_meta(const std::string & /*api_path*/,
|
||||
const std::string & /*key*/,
|
||||
const std::string & /*value*/)
|
||||
-> api_error override {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto set_item_meta(const std::string & /*api_path*/,
|
||||
const api_meta_map & /*meta*/)
|
||||
-> api_error override {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto start(api_item_added_callback api_item_added,
|
||||
i_file_manager *fm) -> bool override;
|
||||
|
||||
void stop() override;
|
||||
|
||||
[[nodiscard]] auto upload_file(const std::string & /*api_path*/,
|
||||
const std::string & /*source_path*/,
|
||||
const std::string & /*encryption_token*/,
|
||||
stop_type & /*stop_requested*/)
|
||||
-> api_error override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_PROVIDERS_ENCRYPT_ENCRYPT_PROVIDER_HPP_
|
@ -1,114 +1,156 @@
|
||||
/*
|
||||
Copyright <2018-2022> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_PROVIDERS_I_PROVIDER_HPP_
|
||||
#define INCLUDE_PROVIDERS_I_PROVIDER_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_open_file_table;
|
||||
class i_file_manager;
|
||||
|
||||
class i_provider {
|
||||
INTERFACE_SETUP(i_provider);
|
||||
|
||||
public:
|
||||
virtual api_error create_directory(const std::string &api_path, const api_meta_map &meta) = 0;
|
||||
[[nodiscard]] virtual auto create_directory(const std::string &api_path,
|
||||
api_meta_map &meta)
|
||||
-> api_error = 0;
|
||||
|
||||
virtual api_error create_directory_clone_source_meta(const std::string &source_api_path,
|
||||
const std::string &api_path) = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
create_directory_clone_source_meta(const std::string &source_api_path,
|
||||
const std::string &api_path)
|
||||
-> api_error = 0;
|
||||
|
||||
virtual api_error create_file(const std::string &api_path, api_meta_map &meta) = 0;
|
||||
[[nodiscard]] virtual auto create_file(const std::string &api_path,
|
||||
api_meta_map &meta) -> api_error = 0;
|
||||
|
||||
virtual api_error get_api_path_from_source(const std::string &source_path,
|
||||
std::string &api_path) const = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_api_path_from_source(const std::string &source_path,
|
||||
std::string &api_path) const -> api_error = 0;
|
||||
|
||||
virtual api_error get_file_list(api_file_list &list) const = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_directory_item_count(const std::string &api_path) const
|
||||
-> std::uint64_t = 0;
|
||||
|
||||
virtual std::uint64_t get_directory_item_count(const std::string &api_path) const = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_directory_items(const std::string &api_path,
|
||||
directory_item_list &list) const -> api_error = 0;
|
||||
|
||||
virtual api_error get_directory_items(const std::string &api_path,
|
||||
directory_item_list &list) const = 0;
|
||||
[[nodiscard]] virtual auto get_file(const std::string &api_path,
|
||||
api_file &file) const -> api_error = 0;
|
||||
|
||||
virtual api_error get_file(const std::string &api_path, api_file &file) const = 0;
|
||||
[[nodiscard]] virtual auto get_file_list(api_file_list &list) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual api_error get_file_size(const std::string &api_path, std::uint64_t &file_size) const = 0;
|
||||
[[nodiscard]] virtual auto get_file_size(const std::string &api_path,
|
||||
std::uint64_t &file_size) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual api_error get_filesystem_item(const std::string &api_path, const bool &directory,
|
||||
filesystem_item &fsi) const = 0;
|
||||
[[nodiscard]] virtual auto get_filesystem_item(const std::string &api_path,
|
||||
bool directory,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual api_error get_filesystem_item_and_file(const std::string &api_path, api_file &file,
|
||||
filesystem_item &fsi) const = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_filesystem_item_and_file(const std::string &api_path, api_file &file,
|
||||
filesystem_item &fsi) const -> api_error = 0;
|
||||
|
||||
virtual api_error get_filesystem_item_from_source_path(const std::string &source_path,
|
||||
filesystem_item &fsi) const = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
get_filesystem_item_from_source_path(const std::string &source_path,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual std::vector<std::string> get_pinned_files() const = 0;
|
||||
[[nodiscard]] virtual auto get_item_meta(const std::string &api_path,
|
||||
api_meta_map &meta) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual api_error get_item_meta(const std::string &api_path, api_meta_map &meta) const = 0;
|
||||
[[nodiscard]] virtual auto get_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
std::string &value) const
|
||||
-> api_error = 0;
|
||||
|
||||
virtual api_error get_item_meta(const std::string &api_path, const std::string &key,
|
||||
std::string &value) const = 0;
|
||||
[[nodiscard]] virtual auto get_pinned_files() const
|
||||
-> std::vector<std::string> = 0;
|
||||
|
||||
virtual std::uint64_t get_total_drive_space() const = 0;
|
||||
[[nodiscard]] virtual auto get_provider_type() const -> provider_type = 0;
|
||||
|
||||
virtual std::uint64_t get_total_item_count() const = 0;
|
||||
[[nodiscard]] virtual auto get_total_drive_space() const -> std::uint64_t = 0;
|
||||
|
||||
virtual provider_type get_provider_type() const = 0;
|
||||
[[nodiscard]] virtual auto get_total_item_count() const -> std::uint64_t = 0;
|
||||
|
||||
virtual std::uint64_t get_used_drive_space() const = 0;
|
||||
[[nodiscard]] virtual auto get_used_drive_space() const -> std::uint64_t = 0;
|
||||
|
||||
virtual bool is_directory(const std::string &api_path) const = 0;
|
||||
[[nodiscard]] virtual auto is_direct_only() const -> bool = 0;
|
||||
|
||||
virtual bool is_file(const std::string &api_path) const = 0;
|
||||
[[nodiscard]] virtual auto is_directory(const std::string &api_path,
|
||||
bool &exists) const -> api_error = 0;
|
||||
|
||||
virtual bool is_file_writeable(const std::string &api_path) const = 0;
|
||||
[[nodiscard]] virtual auto is_file(const std::string &api_path,
|
||||
bool &exists) const -> api_error = 0;
|
||||
|
||||
virtual bool is_online() const = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
is_file_writeable(const std::string &api_path) const -> bool = 0;
|
||||
|
||||
virtual bool is_rename_supported() const = 0;
|
||||
[[nodiscard]] virtual auto is_online() const -> bool = 0;
|
||||
|
||||
virtual api_error read_file_bytes(const std::string &api_path, const std::size_t &size,
|
||||
const std::uint64_t &offset, std::vector<char> &data,
|
||||
const bool &stop_requested) = 0;
|
||||
[[nodiscard]] virtual auto is_rename_supported() const -> bool = 0;
|
||||
|
||||
virtual api_error remove_directory(const std::string &api_path) = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
read_file_bytes(const std::string &api_path, std::size_t size,
|
||||
std::uint64_t offset, data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error = 0;
|
||||
|
||||
virtual api_error remove_file(const std::string &api_path) = 0;
|
||||
[[nodiscard]] virtual auto remove_directory(const std::string &api_path)
|
||||
-> api_error = 0;
|
||||
|
||||
virtual api_error remove_item_meta(const std::string &api_path, const std::string &key) = 0;
|
||||
[[nodiscard]] virtual auto remove_file(const std::string &api_path)
|
||||
-> api_error = 0;
|
||||
|
||||
virtual api_error rename_file(const std::string &fromApiPath, const std::string &toApiPath) = 0;
|
||||
[[nodiscard]] virtual auto remove_item_meta(const std::string &api_path,
|
||||
const std::string &key)
|
||||
-> api_error = 0;
|
||||
|
||||
virtual api_error set_item_meta(const std::string &api_path, const std::string &key,
|
||||
const std::string &value) = 0;
|
||||
[[nodiscard]] virtual auto rename_file(const std::string &from_api_path,
|
||||
const std::string &to_api_path)
|
||||
-> api_error = 0;
|
||||
|
||||
virtual api_error set_item_meta(const std::string &api_path, const api_meta_map &meta) = 0;
|
||||
[[nodiscard]] virtual auto set_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
const std::string &value)
|
||||
-> api_error = 0;
|
||||
|
||||
virtual api_error set_source_path(const std::string &api_path,
|
||||
const std::string &source_path) = 0;
|
||||
[[nodiscard]] virtual auto set_item_meta(const std::string &api_path,
|
||||
const api_meta_map &meta)
|
||||
-> api_error = 0;
|
||||
|
||||
virtual bool start(api_item_added_callback api_item_added, i_open_file_table *oft) = 0;
|
||||
[[nodiscard]] virtual auto start(api_item_added_callback api_item_added,
|
||||
i_file_manager *fm) -> bool = 0;
|
||||
|
||||
virtual void stop() = 0;
|
||||
|
||||
virtual api_error upload_file(const std::string &api_path, const std::string &source_path,
|
||||
const std::string &encryption_token) = 0;
|
||||
[[nodiscard]] virtual auto
|
||||
upload_file(const std::string &api_path, const std::string &source_path,
|
||||
const std::string &encryption_token, stop_type &stop_requested)
|
||||
-> api_error = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user