v2.0.2-rc (#27)
Some checks reported errors
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit
Some checks reported errors
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit
## v2.0.2-rc ### BREAKING CHANGES * Refactored `config.json` - will need to verify configuration settings prior to mounting ### Issues * \#12 \[Unit Test\] Complete all providers unit tests * \#14 \[Unit Test\] SQLite mini-ORM unit tests and cleanup * \#16 Add support for bucket name in Sia provider * \#17 Update to common c++ build system * A single 64-bit Linux Jenkins server is used to build all Linux and Windows versions * All dependency sources are now included * MSVC is no longer supported * MSYS2 is required for building Windows binaries on Windows * OS X support is temporarily disabled * \#19 \[bug\] Rename file is broken for files that are existing * \#23 \[bug\] Incorrect file size displayed while upload is pending * \#24 RocksDB implementations should be transactional * \#25 Writes should block when maximum cache size is reached * \#26 Complete ring buffer and direct download support ### Changes from v2.0.1-rc * Ability to choose between RocksDB and SQLite databases * Added direct reads and implemented download fallback * Corrected file times on S3 and Sia providers * Corrected handling of `chown()` and `chmod()` * Fixed erroneous download of chunks after resize Reviewed-on: #27
This commit is contained in:
112
repertory/librepertory/include/utils/cli_utils.hpp
Normal file
112
repertory/librepertory/include/utils/cli_utils.hpp
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
Copyright <2018-2024> <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 REPERTORY_INCLUDE_UTILS_CLI_UTILS_HPP_
|
||||
#define REPERTORY_INCLUDE_UTILS_CLI_UTILS_HPP_
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory::utils::cli {
|
||||
using option = std::array<std::string, 2>;
|
||||
|
||||
namespace options {
|
||||
static const option check_version_option = {"-cv", "--check_version"};
|
||||
static const option display_config_option = {"-dc", "--display_config"};
|
||||
static const option data_directory_option = {"-dd", "--data_directory"};
|
||||
static const option encrypt_option = {"-en", "--encrypt"};
|
||||
static const option drive_information_option = {"-di", "--drive_information"};
|
||||
static const option name_option = {"-na", "--name"};
|
||||
static const option s3_option = {"-s3", "--s3"};
|
||||
static const option generate_config_option = {"-gc", "--generate_config"};
|
||||
static const option get_option = {"-get", "--get"};
|
||||
static const option get_directory_items_option = {"-gdi",
|
||||
"--get_directory_items"};
|
||||
static const option get_pinned_files_option = {"-gpf", "--get_pinned_files"};
|
||||
static const option help_option = {"-h", "--help"};
|
||||
static const option hidden_option = {"-hidden", "--hidden"};
|
||||
static const option open_files_option = {"-of", "--open_files"};
|
||||
static const option pin_file_option = {"-pf", "--pin_file"};
|
||||
static const option pinned_status_option = {"-ps", "--pinned_status"};
|
||||
static const option password_option = {"-pw", "--password"};
|
||||
static const option remote_mount_option = {"-rm", "--remote_mount"};
|
||||
static const option set_option = {"-set", "--set"};
|
||||
static const option status_option = {"-status", "--status"};
|
||||
static const option unmount_option = {"-unmount", "--unmount"};
|
||||
static const option unpin_file_option = {"-uf", "--unpin_file"};
|
||||
static const option user_option = {"-us", "--user"};
|
||||
static const option version_option = {"-V", "--version"};
|
||||
|
||||
static const std::vector<option> option_list = {
|
||||
check_version_option,
|
||||
display_config_option,
|
||||
data_directory_option,
|
||||
drive_information_option,
|
||||
encrypt_option,
|
||||
s3_option,
|
||||
name_option,
|
||||
generate_config_option,
|
||||
get_option,
|
||||
get_directory_items_option,
|
||||
get_pinned_files_option,
|
||||
help_option,
|
||||
hidden_option,
|
||||
open_files_option,
|
||||
password_option,
|
||||
pin_file_option,
|
||||
pinned_status_option,
|
||||
remote_mount_option,
|
||||
set_option,
|
||||
status_option,
|
||||
unmount_option,
|
||||
unpin_file_option,
|
||||
user_option,
|
||||
version_option,
|
||||
};
|
||||
} // namespace options
|
||||
|
||||
// Prototypes
|
||||
void get_api_authentication_data(std::string &user, std::string &password,
|
||||
std::uint16_t &port, const provider_type &prov,
|
||||
const std::string &data_directory);
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_provider_type_from_args(std::vector<const char *> args) -> provider_type;
|
||||
|
||||
[[nodiscard]] auto has_option(std::vector<const char *> args,
|
||||
const std::string &option_name) -> bool;
|
||||
|
||||
[[nodiscard]] auto has_option(std::vector<const char *> args,
|
||||
const option &opt) -> bool;
|
||||
|
||||
[[nodiscard]] auto parse_option(std::vector<const char *> args,
|
||||
const std::string &option_name,
|
||||
std::uint8_t count) -> std::vector<std::string>;
|
||||
|
||||
[[nodiscard]] auto parse_string_option(std::vector<const char *> args,
|
||||
const option &opt,
|
||||
std::string &value) -> exit_code;
|
||||
|
||||
[[nodiscard]] auto
|
||||
parse_drive_options(std::vector<const char *> args, provider_type &prov,
|
||||
std::string &data_directory) -> std::vector<std::string>;
|
||||
} // namespace repertory::utils::cli
|
||||
|
||||
#endif // REPERTORY_INCLUDE_UTILS_CLI_UTILS_HPP_
|
95
repertory/librepertory/include/utils/error_utils.hpp
Normal file
95
repertory/librepertory/include/utils/error_utils.hpp
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
Copyright <2018-2024> <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 REPERTORY_INCLUDE_UTILS_ERROR_UTILS_HPP_
|
||||
#define REPERTORY_INCLUDE_UTILS_ERROR_UTILS_HPP_
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory::utils::error {
|
||||
void raise_error(std::string_view function, std::string_view msg);
|
||||
|
||||
void raise_error(std::string_view function, const api_error &err,
|
||||
std::string_view msg);
|
||||
|
||||
void raise_error(std::string_view function, const std::exception &exception);
|
||||
|
||||
void raise_error(std::string_view function, const std::exception &exception,
|
||||
std::string_view msg);
|
||||
|
||||
void raise_error(std::string_view function, std::int64_t err,
|
||||
std::string_view msg);
|
||||
|
||||
void raise_error(std::string_view function, const json &err,
|
||||
std::string_view msg);
|
||||
|
||||
void raise_error(std::string_view function, const api_error &err,
|
||||
std::string_view file_path, std::string_view msg);
|
||||
|
||||
void raise_error(std::string_view function, std::int64_t err,
|
||||
std::string_view file_path, std::string_view msg);
|
||||
|
||||
void raise_error(std::string_view function, const std::exception &exception,
|
||||
std::string_view file_path, std::string_view msg);
|
||||
|
||||
void raise_api_path_error(std::string_view function, std::string_view api_path,
|
||||
const api_error &err, std::string_view msg);
|
||||
|
||||
void raise_api_path_error(std::string_view function, std::string_view api_path,
|
||||
const std::exception &exception);
|
||||
|
||||
void raise_api_path_error(std::string_view function, std::string_view api_path,
|
||||
const std::exception &exception,
|
||||
std::string_view msg);
|
||||
|
||||
void raise_api_path_error(std::string_view function, std::string_view api_path,
|
||||
std::int64_t err, std::string_view msg);
|
||||
|
||||
void raise_api_path_error(std::string_view function, std::string_view api_path,
|
||||
const json &err, std::string_view msg);
|
||||
|
||||
void raise_api_path_error(std::string_view function, std::string_view api_path,
|
||||
std::string_view source_path, const api_error &err,
|
||||
std::string_view msg);
|
||||
|
||||
void raise_api_path_error(std::string_view function, std::string_view api_path,
|
||||
std::string_view source_path, std::int64_t err,
|
||||
std::string_view msg);
|
||||
|
||||
void raise_api_path_error(std::string_view function, std::string_view api_path,
|
||||
std::string_view source_path,
|
||||
const std::exception &exception,
|
||||
std::string_view msg);
|
||||
|
||||
void raise_url_error(std::string_view function, std::string_view url,
|
||||
CURLcode err, std::string_view msg);
|
||||
|
||||
void raise_url_error(std::string_view function, std::string_view url,
|
||||
std::string_view source_path,
|
||||
const std::exception &exception);
|
||||
|
||||
void raise_url_error(std::string_view function, std::string_view url,
|
||||
std::string_view source_path,
|
||||
const std::exception &exception, std::string_view msg);
|
||||
|
||||
} // namespace repertory::utils::error
|
||||
|
||||
#endif // REPERTORY_INCLUDE_UTILS_ERROR_UTILS_HPP_
|
38
repertory/librepertory/include/utils/file_utils.hpp
Normal file
38
repertory/librepertory/include/utils/file_utils.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright <2018-2024> <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 REPERTORY_INCLUDE_UTILS_FILE_UTILS_HPP_
|
||||
#define REPERTORY_INCLUDE_UTILS_FILE_UTILS_HPP_
|
||||
|
||||
#include "utils/file.hpp"
|
||||
|
||||
namespace repertory::utils::file {
|
||||
[[nodiscard]] auto
|
||||
get_directory_files(std::string_view path, bool oldest_first,
|
||||
bool recursive = false) -> std::deque<std::string>;
|
||||
|
||||
[[nodiscard]] auto
|
||||
read_file_lines(const std::string &path) -> std::vector<std::string>;
|
||||
|
||||
[[nodiscard]] auto reset_modified_time(const std::string &path) -> bool;
|
||||
} // namespace repertory::utils::file
|
||||
|
||||
#endif // REPERTORY_INCLUDE_UTILS_FILE_UTILS_HPP_
|
89
repertory/librepertory/include/utils/polling.hpp
Normal file
89
repertory/librepertory/include/utils/polling.hpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
Copyright <2018-2024> <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 REPERTORY_INCLUDE_UTILS_POLLING_HPP_
|
||||
#define REPERTORY_INCLUDE_UTILS_POLLING_HPP_
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
|
||||
class polling final {
|
||||
public:
|
||||
enum struct frequency {
|
||||
high,
|
||||
low,
|
||||
medium,
|
||||
second,
|
||||
size,
|
||||
};
|
||||
|
||||
struct polling_item final {
|
||||
std::string name;
|
||||
frequency freq;
|
||||
std::function<void(const stop_type &stop_requested)> action;
|
||||
};
|
||||
|
||||
public:
|
||||
polling(const polling &) = delete;
|
||||
polling(polling &&) = delete;
|
||||
auto operator=(const polling &) -> polling & = delete;
|
||||
auto operator=(polling &&) -> polling & = delete;
|
||||
|
||||
private:
|
||||
polling() = default;
|
||||
|
||||
~polling() { stop(); }
|
||||
|
||||
private:
|
||||
static polling instance_;
|
||||
|
||||
public:
|
||||
static auto instance() -> polling & { return instance_; }
|
||||
|
||||
private:
|
||||
app_config *config_{nullptr};
|
||||
std::array<std::unique_ptr<std::thread>,
|
||||
static_cast<std::size_t>(frequency::size)>
|
||||
frequency_threads_;
|
||||
std::unordered_map<std::string, polling_item> items_;
|
||||
std::mutex mutex_;
|
||||
std::condition_variable notify_;
|
||||
std::mutex start_stop_mutex_;
|
||||
stop_type stop_requested_{false};
|
||||
|
||||
private:
|
||||
void frequency_thread(std::function<std::uint32_t()> get_frequency_seconds,
|
||||
frequency freq);
|
||||
|
||||
public:
|
||||
void remove_callback(const std::string &name);
|
||||
|
||||
void set_callback(const polling_item &item);
|
||||
|
||||
void start(app_config *config);
|
||||
|
||||
void stop();
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_INCLUDE_UTILS_POLLING_HPP_
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Copyright <2018-2024> <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 REPERTORY_INCLUDE_UTILS_SINGLE_THREAD_SERVICE_BASE_HPP_
|
||||
#define REPERTORY_INCLUDE_UTILS_SINGLE_THREAD_SERVICE_BASE_HPP_
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class single_thread_service_base {
|
||||
public:
|
||||
explicit single_thread_service_base(std::string service_name)
|
||||
: service_name_(std::move(service_name)) {}
|
||||
|
||||
virtual ~single_thread_service_base() { stop(); }
|
||||
|
||||
private:
|
||||
const std::string service_name_;
|
||||
mutable std::mutex mtx_;
|
||||
mutable std::condition_variable notify_;
|
||||
stop_type stop_requested_ = false;
|
||||
std::unique_ptr<std::thread> thread_;
|
||||
|
||||
protected:
|
||||
[[nodiscard]] auto get_mutex() const -> std::mutex & { return mtx_; }
|
||||
|
||||
[[nodiscard]] auto get_notify() const -> std::condition_variable & {
|
||||
return notify_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_stop_requested() const -> bool {
|
||||
return stop_requested_;
|
||||
}
|
||||
|
||||
void notify_all() const;
|
||||
|
||||
virtual void on_start() {}
|
||||
|
||||
virtual void on_stop() {}
|
||||
|
||||
virtual void service_function() = 0;
|
||||
|
||||
public:
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_INCLUDE_UTILS_SINGLE_THREAD_SERVICE_BASE_HPP_
|
116
repertory/librepertory/include/utils/tasks.hpp
Normal file
116
repertory/librepertory/include/utils/tasks.hpp
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
Copyright <2018-2024> <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 REPERTORY_INCLUDE_UTILS_TASKS_HPP_
|
||||
#define REPERTORY_INCLUDE_UTILS_TASKS_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
|
||||
class tasks final {
|
||||
public:
|
||||
struct task final {
|
||||
std::function<void(const stop_type &task_stopped)> action;
|
||||
};
|
||||
|
||||
class i_task {
|
||||
INTERFACE_SETUP(i_task);
|
||||
|
||||
public:
|
||||
virtual auto wait() const -> bool = 0;
|
||||
};
|
||||
|
||||
using task_ptr = std::shared_ptr<i_task>;
|
||||
|
||||
private:
|
||||
class task_wait final : public i_task {
|
||||
public:
|
||||
task_wait() = default;
|
||||
task_wait(const task_wait &) = delete;
|
||||
task_wait(task_wait &&) = delete;
|
||||
|
||||
~task_wait() override { set_result(false); }
|
||||
|
||||
auto operator=(const task_wait &) -> task_wait & = delete;
|
||||
auto operator=(task_wait &&) -> task_wait & = delete;
|
||||
|
||||
private:
|
||||
bool complete{false};
|
||||
mutable std::mutex mtx;
|
||||
mutable std::condition_variable notify;
|
||||
bool success{false};
|
||||
|
||||
public:
|
||||
void set_result(bool result);
|
||||
|
||||
auto wait() const -> bool override;
|
||||
};
|
||||
|
||||
struct scheduled_task final {
|
||||
task item;
|
||||
|
||||
std::shared_ptr<task_wait> wait{
|
||||
std::make_shared<task_wait>(),
|
||||
};
|
||||
};
|
||||
|
||||
public:
|
||||
tasks(const tasks &) = delete;
|
||||
tasks(tasks &&) = delete;
|
||||
auto operator=(const tasks &) -> tasks & = delete;
|
||||
auto operator=(tasks &&) -> tasks & = delete;
|
||||
|
||||
private:
|
||||
tasks() = default;
|
||||
|
||||
~tasks() { stop(); }
|
||||
|
||||
private:
|
||||
static tasks instance_;
|
||||
|
||||
public:
|
||||
static auto instance() -> tasks & { return instance_; }
|
||||
|
||||
private:
|
||||
app_config *config_{nullptr};
|
||||
std::atomic<std::uint64_t> count_{0U};
|
||||
std::mutex mutex_;
|
||||
std::condition_variable notify_;
|
||||
std::mutex start_stop_mutex_;
|
||||
stop_type stop_requested_{false};
|
||||
std::vector<std::unique_ptr<std::jthread>> task_threads_;
|
||||
std::deque<scheduled_task> tasks_;
|
||||
|
||||
private:
|
||||
void task_thread();
|
||||
|
||||
public:
|
||||
auto schedule(task item) -> task_ptr;
|
||||
|
||||
void start(app_config *config);
|
||||
|
||||
void stop();
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_INCLUDE_UTILS_TASKS_HPP_
|
59
repertory/librepertory/include/utils/throttle.hpp
Normal file
59
repertory/librepertory/include/utils/throttle.hpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
Copyright <2018-2024> <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 REPERTORY_INCLUDE_UTILS_THROTTLE_HPP_
|
||||
#define REPERTORY_INCLUDE_UTILS_THROTTLE_HPP_
|
||||
|
||||
namespace repertory {
|
||||
class throttle final {
|
||||
public:
|
||||
throttle() : max_size_(10u) {}
|
||||
|
||||
explicit throttle(std::size_t max_size) : max_size_(max_size) {}
|
||||
|
||||
public:
|
||||
throttle(const throttle &) noexcept = delete;
|
||||
throttle(throttle &&) noexcept = delete;
|
||||
auto operator=(const throttle &) -> throttle & = delete;
|
||||
auto operator=(throttle &&) -> throttle & = delete;
|
||||
|
||||
public:
|
||||
~throttle() { shutdown(); }
|
||||
|
||||
private:
|
||||
const std::size_t max_size_;
|
||||
std::size_t count_ = 0u;
|
||||
bool shutdown_ = false;
|
||||
std::mutex mutex_;
|
||||
std::condition_variable notify_;
|
||||
|
||||
public:
|
||||
void decrement();
|
||||
|
||||
void increment_or_wait();
|
||||
|
||||
void reset();
|
||||
|
||||
void shutdown();
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_INCLUDE_UTILS_THROTTLE_HPP_
|
50
repertory/librepertory/include/utils/timeout.hpp
Normal file
50
repertory/librepertory/include/utils/timeout.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Copyright <2018-2024> <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 REPERTORY_INCLUDE_UTILS_TIMEOUT_HPP_
|
||||
#define REPERTORY_INCLUDE_UTILS_TIMEOUT_HPP_
|
||||
|
||||
namespace repertory {
|
||||
class timeout final {
|
||||
public:
|
||||
timeout(const timeout &) noexcept = delete;
|
||||
timeout(timeout &&) noexcept = delete;
|
||||
auto operator=(const timeout &) noexcept -> timeout & = delete;
|
||||
auto operator=(timeout &&) noexcept -> timeout & = delete;
|
||||
|
||||
public:
|
||||
timeout(std::function<void()> timeout_callback,
|
||||
const std::chrono::system_clock::duration &duration = 10s);
|
||||
|
||||
~timeout() { disable(); }
|
||||
|
||||
private:
|
||||
bool timeout_killed_;
|
||||
std::unique_ptr<std::thread> timeout_thread_;
|
||||
std::mutex timeout_mutex_;
|
||||
std::condition_variable timeout_notify_;
|
||||
|
||||
public:
|
||||
void disable();
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_INCLUDE_UTILS_TIMEOUT_HPP_
|
52
repertory/librepertory/include/utils/unix/unix_utils.hpp
Normal file
52
repertory/librepertory/include/utils/unix/unix_utils.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Copyright <2018-2024> <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 REPERTORY_INCLUDE_UTILS_UNIX_UNIX_UTILS_HPP_
|
||||
#define REPERTORY_INCLUDE_UTILS_UNIX_UNIX_UTILS_HPP_
|
||||
#if !defined(_WIN32)
|
||||
|
||||
#include "types/remote.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/unix.hpp"
|
||||
|
||||
namespace repertory::utils {
|
||||
#if defined(__linux__)
|
||||
inline const std::array<std::string, 4U> attribute_namespaces = {
|
||||
"security",
|
||||
"system",
|
||||
"trusted",
|
||||
"user",
|
||||
};
|
||||
#endif
|
||||
|
||||
[[nodiscard]] auto from_api_error(const api_error &err) -> int;
|
||||
|
||||
[[nodiscard]] auto to_api_error(int err) -> api_error;
|
||||
|
||||
[[nodiscard]] auto unix_error_to_windows(int err) -> std::uint32_t;
|
||||
|
||||
void windows_create_to_unix(const UINT32 &create_options,
|
||||
const UINT32 &granted_access, std::uint32_t &flags,
|
||||
remote::file_mode &mode);
|
||||
} // namespace repertory::utils
|
||||
|
||||
#endif // !_WIN32
|
||||
#endif // REPERTORY_INCLUDE_UTILS_UNIX_UNIX_UTILS_HPP_
|
48
repertory/librepertory/include/utils/utils.hpp
Normal file
48
repertory/librepertory/include/utils/utils.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Copyright <2018-2024> <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 REPERTORY_INCLUDE_UTILS_UTILS_HPP_
|
||||
#define REPERTORY_INCLUDE_UTILS_UTILS_HPP_
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
|
||||
namespace utils {
|
||||
void calculate_allocation_size(bool directory, std::uint64_t file_size,
|
||||
UINT64 allocation_size,
|
||||
std::string &allocation_meta_size);
|
||||
|
||||
[[nodiscard]] auto
|
||||
create_rocksdb(const app_config &cfg, const std::string &name,
|
||||
const std::vector<rocksdb::ColumnFamilyDescriptor> &families,
|
||||
std::vector<rocksdb::ColumnFamilyHandle *> &handles, bool clear)
|
||||
-> std::unique_ptr<rocksdb::TransactionDB>;
|
||||
|
||||
[[nodiscard]] auto create_volume_label(const provider_type &prov)
|
||||
-> std::string;
|
||||
|
||||
[[nodiscard]] auto get_attributes_from_meta(const api_meta_map &meta) -> DWORD;
|
||||
} // namespace utils
|
||||
} // namespace repertory
|
||||
|
||||
#endif // REPERTORY_INCLUDE_UTILS_UTILS_HPP_
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright <2018-2024> <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 REPERTORY_INCLUDE_UTILS_WINDOWS_WINDOWS_UTILS_HPP_
|
||||
#define REPERTORY_INCLUDE_UTILS_WINDOWS_WINDOWS_UTILS_HPP_
|
||||
#if defined(_WIN32)
|
||||
|
||||
#include "types/remote.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/windows.hpp"
|
||||
|
||||
namespace repertory::utils {
|
||||
[[nodiscard]] auto
|
||||
get_accessed_time_from_meta(const api_meta_map &meta) -> std::uint64_t;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_changed_time_from_meta(const api_meta_map &meta) -> std::uint64_t;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_creation_time_from_meta(const api_meta_map &meta) -> std::uint64_t;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_written_time_from_meta(const api_meta_map &meta) -> std::uint64_t;
|
||||
|
||||
[[nodiscard]] auto from_api_error(const api_error &e) -> NTSTATUS;
|
||||
|
||||
[[nodiscard]] auto unix_access_mask_to_windows(std::int32_t mask) -> int;
|
||||
|
||||
[[nodiscard]] auto
|
||||
unix_open_flags_to_flags_and_perms(const remote::file_mode &mode,
|
||||
const remote::open_flags &flags,
|
||||
std::int32_t &perms) -> int;
|
||||
} // namespace repertory::utils
|
||||
|
||||
#endif // _WIN32
|
||||
#endif // REPERTORY_INCLUDE_UTILS_WINDOWS_WINDOWS_UTILS_HPP_
|
Reference in New Issue
Block a user