refactor
This commit is contained in:
@@ -43,8 +43,8 @@
|
||||
#include "utils/time.hpp"
|
||||
|
||||
namespace {
|
||||
[[nodiscard]] auto
|
||||
create_resume_entry(const repertory::i_open_file &file) -> json {
|
||||
[[nodiscard]] auto create_resume_entry(const repertory::i_open_file &file)
|
||||
-> json {
|
||||
return {
|
||||
{"chunk_size", file.get_chunk_size()},
|
||||
{"path", file.get_api_path()},
|
||||
@@ -338,7 +338,7 @@ auto file_manager::get_stored_downloads() const -> std::vector<json> {
|
||||
auto result = utils::db::sqlite::db_select{*db_, resume_table}.go();
|
||||
while (result.has_row()) {
|
||||
try {
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (not result.get_row(row)) {
|
||||
continue;
|
||||
}
|
||||
@@ -375,7 +375,7 @@ auto file_manager::handle_file_rename(const std::string &from_api_path,
|
||||
.where("api_path")
|
||||
.equals(from_api_path)
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
should_upload = result.get_row(row) && row.has_value();
|
||||
if (should_upload && source_path.empty()) {
|
||||
source_path = row->get_column("source_path").get_value<std::string>();
|
||||
@@ -438,10 +438,11 @@ auto file_manager::open(const std::string &api_path, bool directory,
|
||||
return open(api_path, directory, ofd, handle, file, nullptr);
|
||||
}
|
||||
|
||||
auto file_manager::open(
|
||||
const std::string &api_path, bool directory, const open_file_data &ofd,
|
||||
std::uint64_t &handle, std::shared_ptr<i_open_file> &file,
|
||||
std::shared_ptr<i_closeable_open_file> closeable_file) -> api_error {
|
||||
auto file_manager::open(const std::string &api_path, bool directory,
|
||||
const open_file_data &ofd, std::uint64_t &handle,
|
||||
std::shared_ptr<i_open_file> &file,
|
||||
std::shared_ptr<i_closeable_open_file> closeable_file)
|
||||
-> api_error {
|
||||
const auto create_and_add_handle =
|
||||
[&](std::shared_ptr<i_closeable_open_file> cur_file) {
|
||||
handle = get_next_handle();
|
||||
@@ -700,8 +701,8 @@ auto file_manager::rename_directory(const std::string &from_api_path,
|
||||
}
|
||||
|
||||
auto file_manager::rename_file(const std::string &from_api_path,
|
||||
const std::string &to_api_path,
|
||||
bool overwrite) -> api_error {
|
||||
const std::string &to_api_path, bool overwrite)
|
||||
-> api_error {
|
||||
if (not provider_.is_rename_supported()) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
@@ -800,7 +801,7 @@ void file_manager::start() {
|
||||
auto result = utils::db::sqlite::db_select{*db_, upload_active_table}.go();
|
||||
while (result.has_row()) {
|
||||
try {
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
active_items.emplace_back(active_item{
|
||||
row->get_column("api_path").get_value<std::string>(),
|
||||
@@ -824,7 +825,7 @@ void file_manager::start() {
|
||||
|
||||
while (result.has_row()) {
|
||||
try {
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (not(result.get_row(row) && row.has_value())) {
|
||||
return;
|
||||
}
|
||||
@@ -1039,7 +1040,7 @@ void file_manager::upload_handler() {
|
||||
.limit(1)
|
||||
.go();
|
||||
try {
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
auto api_path = row->get_column("api_path").get_value<std::string>();
|
||||
auto source_path =
|
||||
|
@@ -69,9 +69,10 @@ const std::map<std::string, std::string> sql_create_tables = {
|
||||
namespace repertory {
|
||||
encrypt_provider::encrypt_provider(app_config &config) : config_(config) {}
|
||||
|
||||
auto encrypt_provider::create_api_file(
|
||||
const std::string &api_path, bool directory,
|
||||
const std::string &source_path) -> api_file {
|
||||
auto encrypt_provider::create_api_file(const std::string &api_path,
|
||||
bool directory,
|
||||
const std::string &source_path)
|
||||
-> api_file {
|
||||
auto times = utils::file::get_times(source_path);
|
||||
if (not times.has_value()) {
|
||||
throw std::runtime_error("failed to get file times");
|
||||
@@ -97,10 +98,10 @@ auto encrypt_provider::create_api_file(
|
||||
void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory,
|
||||
const api_file &file) {
|
||||
#if defined(_WIN32)
|
||||
struct _stat64 buf {};
|
||||
struct _stat64 buf{};
|
||||
_stat64(file.source_path.c_str(), &buf);
|
||||
#else // !defined(_WIN32)
|
||||
struct stat buf {};
|
||||
struct stat buf{};
|
||||
stat(file.source_path.c_str(), &buf);
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
@@ -187,8 +188,9 @@ auto encrypt_provider::do_fs_operation(
|
||||
return callback(cfg, source_path);
|
||||
}
|
||||
|
||||
auto encrypt_provider::get_api_path_from_source(
|
||||
const std::string &source_path, std::string &api_path) const -> api_error {
|
||||
auto encrypt_provider::get_api_path_from_source(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
@@ -197,7 +199,7 @@ auto encrypt_provider::get_api_path_from_source(
|
||||
.where("source_path")
|
||||
.equals(source_path)
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
api_path = row->get_column("data")
|
||||
.get_value_as_json()
|
||||
@@ -253,8 +255,9 @@ auto encrypt_provider::get_directory_item_count(
|
||||
return count;
|
||||
}
|
||||
|
||||
auto encrypt_provider::get_directory_items(
|
||||
const std::string &api_path, directory_item_list &list) const -> api_error {
|
||||
auto encrypt_provider::get_directory_items(const std::string &api_path,
|
||||
directory_item_list &list) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
return do_fs_operation(
|
||||
@@ -273,7 +276,7 @@ auto encrypt_provider::get_directory_items(
|
||||
.where("source_path")
|
||||
.equals(dir_entry->get_path())
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
current_api_path =
|
||||
row->get_column("api_path").get_value<std::string>();
|
||||
@@ -302,7 +305,7 @@ auto encrypt_provider::get_directory_items(
|
||||
.where("source_path")
|
||||
.equals(dir_entry->get_path())
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
api_path_data =
|
||||
row->get_column("data").get_value<std::string>();
|
||||
@@ -385,7 +388,7 @@ auto encrypt_provider::get_file(const std::string &api_path,
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (not(result.get_row(row) && row.has_value())) {
|
||||
return api_error::item_not_found;
|
||||
}
|
||||
@@ -427,8 +430,9 @@ auto encrypt_provider::get_file_list(api_file_list &list) const -> api_error {
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto encrypt_provider::get_file_size(
|
||||
const std::string &api_path, std::uint64_t &file_size) const -> api_error {
|
||||
auto encrypt_provider::get_file_size(const std::string &api_path,
|
||||
std::uint64_t &file_size) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
@@ -437,7 +441,7 @@ auto encrypt_provider::get_file_size(
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (not(result.get_row(row) && row.has_value())) {
|
||||
return api_error::item_not_found;
|
||||
}
|
||||
@@ -454,15 +458,16 @@ auto encrypt_provider::get_file_size(
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto encrypt_provider::get_filesystem_item(
|
||||
const std::string &api_path, bool directory,
|
||||
filesystem_item &fsi) const -> api_error {
|
||||
auto encrypt_provider::get_filesystem_item(const std::string &api_path,
|
||||
bool directory,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error {
|
||||
auto result = utils::db::sqlite::db_select{*db_, source_table}
|
||||
.column("source_path")
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (not(result.get_row(row) && row.has_value())) {
|
||||
return api_error::item_not_found;
|
||||
}
|
||||
@@ -532,9 +537,10 @@ auto encrypt_provider::get_filesystem_item_from_source_path(
|
||||
return get_filesystem_item(api_path, false, fsi);
|
||||
}
|
||||
|
||||
auto encrypt_provider::get_filesystem_item_and_file(
|
||||
const std::string &api_path, api_file &file,
|
||||
filesystem_item &fsi) const -> api_error {
|
||||
auto encrypt_provider::get_filesystem_item_and_file(const std::string &api_path,
|
||||
api_file &file,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
@@ -576,7 +582,7 @@ auto encrypt_provider::get_item_meta(const std::string &api_path,
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (not(result.get_row(row) && row.has_value())) {
|
||||
return api_error::item_not_found;
|
||||
}
|
||||
@@ -624,7 +630,7 @@ auto encrypt_provider::get_total_item_count() const -> std::uint64_t {
|
||||
.count("api_path", "count")
|
||||
.go();
|
||||
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
return static_cast<std::uint64_t>(
|
||||
row->get_column("count").get_value<std::int64_t>());
|
||||
@@ -647,7 +653,7 @@ auto encrypt_provider::is_directory(const std::string &api_path,
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (not(result.get_row(row) && row.has_value())) {
|
||||
exists = false;
|
||||
return api_error::success;
|
||||
@@ -661,14 +667,14 @@ auto encrypt_provider::is_directory(const std::string &api_path,
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
auto encrypt_provider::is_file(const std::string &api_path,
|
||||
bool &exists) const -> api_error {
|
||||
auto encrypt_provider::is_file(const std::string &api_path, bool &exists) const
|
||||
-> api_error {
|
||||
auto result = utils::db::sqlite::db_select{*db_, source_table}
|
||||
.column("source_path")
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (not(result.get_row(row) && row.has_value())) {
|
||||
exists = false;
|
||||
return api_error::success;
|
||||
@@ -730,7 +736,7 @@ auto encrypt_provider::process_directory_entry(
|
||||
.where("source_path")
|
||||
.equals(current_source_path)
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
current_api_path = row->get_column("api_path").get_value<std::string>();
|
||||
}
|
||||
@@ -780,7 +786,7 @@ auto encrypt_provider::process_directory_entry(
|
||||
.where("source_path")
|
||||
.equals(dir_entry.get_path())
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
api_path_data = row->get_column("data").get_value<std::string>();
|
||||
}
|
||||
@@ -854,7 +860,7 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
|
||||
.where("api_path")
|
||||
.equals(api_path)
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (not(result.get_row(row) && row.has_value())) {
|
||||
return api_error::item_not_found;
|
||||
}
|
||||
@@ -958,11 +964,11 @@ void encrypt_provider::remove_deleted_files() {
|
||||
};
|
||||
|
||||
std::vector<removed_item> removed_list{};
|
||||
std::vector<utils::db::sqlite::db_select::row> row_list{};
|
||||
std::vector<utils::db::sqlite::db_result::row> row_list{};
|
||||
|
||||
auto result = utils::db::sqlite::db_select{*db_, source_table}.go();
|
||||
while (result.has_row()) {
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
row_list.push_back(row.value());
|
||||
}
|
||||
@@ -1037,7 +1043,7 @@ auto encrypt_provider::start(api_item_added_callback /*api_item_added*/,
|
||||
.where("api_path")
|
||||
.equals("/")
|
||||
.go();
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
source_path = row->get_column("source_path").get_value<std::string>();
|
||||
} else {
|
||||
|
@@ -66,7 +66,7 @@ auto meta_db::get_api_path(const std::string &source_path,
|
||||
.limit(1)
|
||||
.go();
|
||||
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
api_path = row->get_column("api_path").get_value<std::string>();
|
||||
return api_error::success;
|
||||
@@ -81,7 +81,7 @@ auto meta_db::get_api_path_list() -> std::vector<std::string> {
|
||||
auto result =
|
||||
utils::db::sqlite::db_select{*db_, table_name}.column("api_path").go();
|
||||
while (result.has_row()) {
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
ret.push_back(row->get_column("api_path").get_value<std::string>());
|
||||
}
|
||||
@@ -90,8 +90,8 @@ auto meta_db::get_api_path_list() -> std::vector<std::string> {
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto meta_db::get_item_meta(const std::string &api_path,
|
||||
api_meta_map &meta) -> api_error {
|
||||
auto meta_db::get_item_meta(const std::string &api_path, api_meta_map &meta)
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto result = utils::db::sqlite::db_select{*db_, table_name}
|
||||
@@ -106,7 +106,7 @@ auto meta_db::get_item_meta(const std::string &api_path,
|
||||
}
|
||||
|
||||
try {
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
meta = json::parse(row->get_column("data").get_value<std::string>())
|
||||
.get<api_meta_map>();
|
||||
@@ -145,7 +145,7 @@ auto meta_db::get_item_meta(const std::string &api_path, const std::string &key,
|
||||
}
|
||||
|
||||
try {
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
value =
|
||||
key == META_SOURCE
|
||||
@@ -183,7 +183,7 @@ auto meta_db::get_pinned_files() const -> std::vector<std::string> {
|
||||
.equals(1)
|
||||
.go();
|
||||
while (result.has_row()) {
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
ret.emplace_back(row->get_column("api_path").get_value<std::string>());
|
||||
}
|
||||
@@ -205,7 +205,7 @@ auto meta_db::get_total_item_count() const -> std::uint64_t {
|
||||
.count("api_path", "count")
|
||||
.go();
|
||||
|
||||
std::optional<utils::db::sqlite::db_select::row> row;
|
||||
std::optional<utils::db::sqlite::db_result::row> row;
|
||||
if (result.get_row(row) && row.has_value()) {
|
||||
ret = static_cast<std::uint64_t>(
|
||||
row->get_column("count").get_value<std::int64_t>());
|
||||
@@ -274,8 +274,8 @@ auto meta_db::set_item_meta(const std::string &api_path,
|
||||
return update_item_meta(api_path, existing_meta);
|
||||
}
|
||||
|
||||
auto meta_db::update_item_meta(const std::string &api_path,
|
||||
api_meta_map meta) -> api_error {
|
||||
auto meta_db::update_item_meta(const std::string &api_path, api_meta_map meta)
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto directory = utils::string::to_bool(meta[META_DIRECTORY]);
|
||||
|
Reference in New Issue
Block a user