22 Commits

Author SHA1 Message Date
47f5b82b4e refactor
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
2025-01-24 13:30:25 -06:00
ebee5ec857 refactor 2025-01-24 13:29:38 -06:00
bfe7b8915d refactor 2025-01-24 12:50:16 -06:00
8547fb7d43 refactor 2025-01-24 12:24:53 -06:00
4f2ff33226 refactor 2025-01-24 10:18:03 -06:00
600b658109 refactor event system 2025-01-24 10:16:00 -06:00
374eb67f6b refactor event system 2025-01-24 10:14:47 -06:00
7848dcebe4 refactor event system 2025-01-24 10:14:05 -06:00
a34443ed94 refactor event system 2025-01-24 09:44:28 -06:00
ff985e724d refactor 2025-01-24 09:42:15 -06:00
1ee478ca71 refactor 2025-01-24 09:40:02 -06:00
807a6e90f8 refactor event system 2025-01-24 09:38:43 -06:00
694d4d4662 refactor event system 2025-01-24 09:35:47 -06:00
ebdc4877a8 refactor event system 2025-01-24 08:32:00 -06:00
993356dec6 refactor event system 2025-01-24 08:26:13 -06:00
dea69815ef refactor event system 2025-01-24 08:24:03 -06:00
5da7b6a51a refactor event system 2025-01-24 08:19:18 -06:00
ad5a1cd5ff refactor event system 2025-01-24 08:10:33 -06:00
33e9208190 refactor event system 2025-01-24 08:02:41 -06:00
3d25364540 refactor event system 2025-01-24 07:52:58 -06:00
b00d219f34 refactor event system 2025-01-24 07:36:23 -06:00
f1a0b6add1 refactor event system 2025-01-24 06:52:45 -06:00
94 changed files with 2020 additions and 832 deletions

View File

@ -37,7 +37,7 @@ public:
~console_consumer(); ~console_consumer();
private: private:
static void process_event2(const i_event &evt); static void process_event(const i_event &evt);
}; };
} // namespace repertory } // namespace repertory

View File

@ -40,7 +40,7 @@ private:
5ULL}; 5ULL};
private: private:
static void process_event2(const i_event &evt); static void process_event(const i_event &evt);
}; };
} // namespace repertory } // namespace repertory

View File

@ -127,14 +127,10 @@ private: \
#define E_CONSUMER_RELEASE() event_consumers_.clear() #define E_CONSUMER_RELEASE() event_consumers_.clear()
#define E_SUBSCRIBE(name, callback) \ #define E_SUBSCRIBE(event, callback) \
event_consumers_.emplace_back(std::make_shared<repertory::event_consumer>( \ event_consumers_.emplace_back(std::make_shared<repertory::event_consumer>( \
#name, [this](const i_event &evt) { callback(evt); })) event::name, [this](const i_event &evt) { \
callback(dynamic_cast<const event &>(evt)); \
#define E_SUBSCRIBE_EXACT(name, callback) \
event_consumers_.emplace_back(std::make_shared<repertory::event_consumer>( \
#name, [this](const i_event &evt) { \
callback(dynamic_cast<const name &>(evt)); \
})) }))
#define E_SUBSCRIBE_ALL(callback) \ #define E_SUBSCRIBE_ALL(callback) \

View File

@ -1,120 +0,0 @@
/*
Copyright <2018-2025> <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_EVENTS_EVENTS_HPP_
#define REPERTORY_INCLUDE_EVENTS_EVENTS_HPP_
#if 0
#include "types/repertory.hpp"
namespace repertory {
// clang-format off
E_SIMPLE2(download_restored, info,
std::string, api_path, ap, E_FROM_STRING,
std::string, dest_path, dest, E_FROM_STRING
);
E_SIMPLE3(download_restore_failed, error,
std::string, api_path, ap, E_FROM_STRING,
std::string, dest_path, dest, E_FROM_STRING,
std::string, error, err, E_FROM_STRING
);
E_SIMPLE3(download_resume_add_failed, error,
std::string, api_path, ap, E_FROM_STRING,
std::string, dest_path, dest, E_FROM_STRING,
std::string, error, err, E_FROM_STRING
);
E_SIMPLE2(download_resume_added, debug,
std::string, api_path, ap, E_FROM_STRING,
std::string, dest_path, dest, E_FROM_STRING
);
E_SIMPLE2(download_resume_removed, debug,
std::string, api_path, ap, E_FROM_STRING,
std::string, dest_path, dest, E_FROM_STRING
);
E_SIMPLE3(download_type_selected, debug,
std::string, api_path, ap, E_FROM_STRING,
std::string, source, src, E_FROM_STRING,
download_type, download_type, type, E_FROM_DOWNLOAD_TYPE
);
E_SIMPLE1(item_timeout, trace,
std::string, api_path, ap, E_FROM_STRING
);
E_SIMPLE2(invalid_cache_size, warn,
std::uint64_t, cache_size, sz, E_FROM_UINT64,
std::uint64_t, by, by, E_FROM_UINT64
);
E_SIMPLE2(max_cache_size_reached, warn,
std::uint64_t, cache_size, sz, E_FROM_UINT64,
std::uint64_t, max_cache_size, max, E_FROM_UINT64
);
E_SIMPLE2(packet_client_timeout, error,
std::string, event_name, en, E_FROM_STRING,
std::string, message, msg, E_FROM_STRING
);
//FUSE
E_SIMPLE3(fuse_event, debug,
std::string, function, func, E_FROM_STRING,
std::string, api_path, ap, E_FROM_STRING,
int, result, res, E_FROM_INT32
);
E_SIMPLE1(fuse_args_parsed, info,
std::string, arguments, args, E_FROM_STRING
);
E_SIMPLE3(remote_fuse_server_event, debug,
std::string, function, func, E_FROM_STRING,
std::string, api_path, ap, E_FROM_STRING,
packet::error_type, result, res, E_FROM_INT32
);
//WINFSP
E_SIMPLE3(winfsp_event, debug,
std::string, function, func, E_FROM_STRING,
std::string, api_path, ap, E_FROM_STRING,
NTSTATUS, result, res, E_FROM_INT32
);
E_SIMPLE(drive_stop_timed_out, info);
E_SIMPLE3(remote_winfsp_client_event, debug,
std::string, function, func, E_FROM_STRING,
std::string, api_path, ap, E_FROM_STRING,
packet::error_type, result, res, E_FROM_INT32
);
E_SIMPLE3(remote_winfsp_server_event, debug,
std::string, function, FUNC, E_FROM_STRING,
std::string, api_path, AP, E_FROM_STRING,
packet::error_type, result, RES, E_FROM_INT32
);
// clang-format on
} // namespace repertory
#endif // 0
#endif // REPERTORY_INCLUDE_EVENTS_EVENTS_HPP_

View File

@ -33,6 +33,7 @@ struct curl_error final : public i_event {
function_name(std::string{function_name_}), function_name(std::string{function_name_}),
url(std::move(url_)) {} url(std::move(url_)) {}
static constexpr const event_level level{event_level::error};
static constexpr const std::string_view name{"curl_error"}; static constexpr const std::string_view name{"curl_error"};
CURLcode code{}; CURLcode code{};
@ -40,7 +41,7 @@ struct curl_error final : public i_event {
std::string url; std::string url;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::error; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -31,13 +31,14 @@ struct debug_log final : public i_event {
debug_log(std::string_view function_name_, std::string msg_) debug_log(std::string_view function_name_, std::string msg_)
: function_name(std::string(function_name_)), msg(std::move(msg_)) {} : function_name(std::string(function_name_)), msg(std::move(msg_)) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"debug_log"}; static constexpr const std::string_view name{"debug_log"};
std::string function_name; std::string function_name;
std::string msg; std::string msg;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::debug; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -34,6 +34,7 @@ struct directory_remove_failed final : public i_event {
error(error_), error(error_),
function_name(std::string(function_name_)) {} function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::error};
static constexpr const std::string_view name{"directory_remove_failed"}; static constexpr const std::string_view name{"directory_remove_failed"};
std::string api_path; std::string api_path;
@ -41,7 +42,7 @@ struct directory_remove_failed final : public i_event {
std::string function_name; std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::error; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -32,13 +32,14 @@ struct directory_removed final : public i_event {
: api_path(std::move(api_path_)), : api_path(std::move(api_path_)),
function_name(std::string(function_name_)) {} function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"directory_removed"}; static constexpr const std::string_view name{"directory_removed"};
std::string api_path; std::string api_path;
std::string function_name; std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::debug; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -35,6 +35,7 @@ struct directory_removed_externally final : public i_event {
function_name(std::string(function_name_)), function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::warn};
static constexpr const std::string_view name{"directory_removed_externally"}; static constexpr const std::string_view name{"directory_removed_externally"};
std::string api_path; std::string api_path;
@ -42,7 +43,7 @@ struct directory_removed_externally final : public i_event {
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::warn; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -34,6 +34,7 @@ struct download_begin final : public i_event {
dest_path(std::move(dest_path_)), dest_path(std::move(dest_path_)),
function_name(std::string(function_name_)) {} function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"download_begin"}; static constexpr const std::string_view name{"download_begin"};
std::string api_path; std::string api_path;
@ -41,7 +42,7 @@ struct download_begin final : public i_event {
std::string function_name; std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -35,6 +35,7 @@ struct download_end final : public i_event {
error(error_), error(error_),
function_name(std::string(function_name_)) {} function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"download_end"}; static constexpr const std::string_view name{"download_end"};
std::string api_path; std::string api_path;
@ -43,7 +44,7 @@ struct download_end final : public i_event {
std::string function_name; std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -35,6 +35,7 @@ struct download_progress final : public i_event {
function_name(std::string(function_name_)), function_name(std::string(function_name_)),
progress(progress_) {} progress(progress_) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"download_progress"}; static constexpr const std::string_view name{"download_progress"};
std::string api_path; std::string api_path;
@ -43,7 +44,7 @@ struct download_progress final : public i_event {
double progress{}; double progress{};
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -0,0 +1,81 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_DOWNLOAD_RESTORE_FAILED_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESTORE_FAILED_HPP_
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct download_restore_failed final : public i_event {
download_restore_failed() = default;
download_restore_failed(std::string api_path_, std::string dest_path_,
std::string error_, std::string_view function_name_)
: api_path(std::move(api_path_)),
dest_path(std::move(dest_path_)),
error(std::move(error_)),
function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::error};
static constexpr const std::string_view name{"download_restore_failed"};
std::string api_path;
std::string dest_path;
std::string error;
std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|ap|{}|dp|{}|error|{}", name, function_name,
api_path, dest_path, error);
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::download_restore_failed> {
static void to_json(json &data,
const repertory::download_restore_failed &value) {
data["api_path"] = value.api_path;
data["dest_path"] = value.dest_path;
data["error"] = value.error;
data["function_name"] = value.function_name;
}
static void from_json(const json &data,
repertory::download_restore_failed &value) {
data.at("api_path").get_to<std::string>(value.api_path);
data.at("dest_path").get_to<std::string>(value.dest_path);
data.at("error").get_to<std::string>(value.error);
data.at("function_name").get_to<std::string>(value.function_name);
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESTORE_FAILED_HPP_

View File

@ -0,0 +1,75 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_DOWNLOAD_RESTORED_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESTORED_HPP_
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct download_restored final : public i_event {
download_restored() = default;
download_restored(std::string api_path_, std::string dest_path_,
std::string_view function_name_)
: api_path(std::move(api_path_)),
dest_path(std::move(dest_path_)),
function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"download_restored"};
std::string api_path;
std::string dest_path;
std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|ap|{}|dp|{}", name, function_name, api_path,
dest_path);
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::download_restored> {
static void to_json(json &data, const repertory::download_restored &value) {
data["api_path"] = value.api_path;
data["dest_path"] = value.dest_path;
data["function_name"] = value.function_name;
}
static void from_json(const json &data, repertory::download_restored &value) {
data.at("api_path").get_to<std::string>(value.api_path);
data.at("dest_path").get_to<std::string>(value.dest_path);
data.at("function_name").get_to<std::string>(value.function_name);
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESTORED_HPP_

View File

@ -0,0 +1,82 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_DOWNLOAD_RESUME_ADD_FAILED_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESUME_ADD_FAILED_HPP_
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct download_resume_add_failed final : public i_event {
download_resume_add_failed() = default;
download_resume_add_failed(std::string api_path_, std::string dest_path_,
std::string error_,
std::string_view function_name_)
: api_path(std::move(api_path_)),
dest_path(std::move(dest_path_)),
error(std::move(error_)),
function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::error};
static constexpr const std::string_view name{"download_resume_add_failed"};
std::string api_path;
std::string dest_path;
std::string error;
std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|ap|{}|dp|{}|error|{}", name, function_name,
api_path, dest_path, error);
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::download_resume_add_failed> {
static void to_json(json &data,
const repertory::download_resume_add_failed &value) {
data["api_path"] = value.api_path;
data["dest_path"] = value.dest_path;
data["error"] = value.error;
data["function_name"] = value.function_name;
}
static void from_json(const json &data,
repertory::download_resume_add_failed &value) {
data.at("api_path").get_to<std::string>(value.api_path);
data.at("dest_path").get_to<std::string>(value.dest_path);
data.at("error").get_to<std::string>(value.error);
data.at("function_name").get_to<std::string>(value.function_name);
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESUME_ADD_FAILED_HPP_

View File

@ -0,0 +1,77 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_DOWNLOAD_RESUME_ADDED_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESUME_ADDED_HPP_
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct download_resume_added final : public i_event {
download_resume_added() = default;
download_resume_added(std::string api_path_, std::string dest_path_,
std::string_view function_name_)
: api_path(std::move(api_path_)),
dest_path(std::move(dest_path_)),
function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"download_resume_added"};
std::string api_path;
std::string dest_path;
std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|ap|{}|dp|{}", name, function_name, api_path,
dest_path);
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::download_resume_added> {
static void to_json(json &data,
const repertory::download_resume_added &value) {
data["api_path"] = value.api_path;
data["dest_path"] = value.dest_path;
data["function_name"] = value.function_name;
}
static void from_json(const json &data,
repertory::download_resume_added &value) {
data.at("api_path").get_to<std::string>(value.api_path);
data.at("dest_path").get_to<std::string>(value.dest_path);
data.at("function_name").get_to<std::string>(value.function_name);
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESUME_ADDED_HPP_

View File

@ -0,0 +1,77 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_DOWNLOAD_RESUME_REMOVED_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESUME_REMOVED_HPP_
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct download_resume_removed final : public i_event {
download_resume_removed() = default;
download_resume_removed(std::string api_path_, std::string dest_path_,
std::string_view function_name_)
: api_path(std::move(api_path_)),
dest_path(std::move(dest_path_)),
function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"download_resume_removed"};
std::string api_path;
std::string dest_path;
std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|ap|{}|dp|{}", name, function_name, api_path,
dest_path);
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::download_resume_removed> {
static void to_json(json &data,
const repertory::download_resume_removed &value) {
data["api_path"] = value.api_path;
data["dest_path"] = value.dest_path;
data["function_name"] = value.function_name;
}
static void from_json(const json &data,
repertory::download_resume_removed &value) {
data.at("api_path").get_to<std::string>(value.api_path);
data.at("dest_path").get_to<std::string>(value.dest_path);
data.at("function_name").get_to<std::string>(value.function_name);
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESUME_REMOVED_HPP_

View File

@ -0,0 +1,82 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_DOWNLOAD_TYPE_SELECTED_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_TYPE_SELECTED_HPP_
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct download_type_selected final : public i_event {
download_type_selected() = default;
download_type_selected(std::string api_path_, std::string dest_path_,
std::string_view function_name_, download_type type_)
: api_path(std::move(api_path_)),
dest_path(std::move(dest_path_)),
function_name(std::string(function_name_)),
type(type_) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"download_type_selected"};
std::string api_path;
std::string dest_path;
std::string function_name;
download_type type{};
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|ap|{}|dp|{}|type|{}", name, function_name,
api_path, dest_path, download_type_to_string(type));
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::download_type_selected> {
static void to_json(json &data,
const repertory::download_type_selected &value) {
data["api_path"] = value.api_path;
data["dest_path"] = value.dest_path;
data["function_name"] = value.function_name;
data["type"] = repertory::download_type_to_string(value.type);
}
static void from_json(const json &data,
repertory::download_type_selected &value) {
data.at("api_path").get_to<std::string>(value.api_path);
data.at("dest_path").get_to<std::string>(value.dest_path);
data.at("function_name").get_to<std::string>(value.function_name);
value.type = repertory::download_type_from_string(
data.at("type").get<std::string>());
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_TYPE_SELECTED_HPP_

View File

@ -29,20 +29,21 @@
namespace repertory { namespace repertory {
struct drive_mount_failed final : public i_event { struct drive_mount_failed final : public i_event {
drive_mount_failed() = default; drive_mount_failed() = default;
drive_mount_failed(std::string_view function_name_, drive_mount_failed(NTSTATUS error_, std::string_view function_name_,
std::string mount_location_, NTSTATUS status_) std::string mount_location_)
: function_name(std::string(function_name_)), : error(error_),
mount_location(std::move(mount_location_)), function_name(std::string(function_name_)),
status(status_) {} mount_location(std::move(mount_location_)) {}
static constexpr const event_level level{event_level::error};
static constexpr const std::string_view name{"drive_mount_failed"}; static constexpr const std::string_view name{"drive_mount_failed"};
NTSTATUS error{};
std::string function_name; std::string function_name;
std::string mount_location; std::string mount_location;
NTSTATUS status{};
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::error; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {
@ -51,7 +52,7 @@ struct drive_mount_failed final : public i_event {
[[nodiscard]] auto get_single_line() const -> std::string override { [[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|location|{}|status|{}", name, function_name, return fmt::format("{}|func|{}|location|{}|status|{}", name, function_name,
mount_location, status); mount_location, error);
} }
}; };
} // namespace repertory } // namespace repertory
@ -59,16 +60,16 @@ struct drive_mount_failed final : public i_event {
NLOHMANN_JSON_NAMESPACE_BEGIN NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::drive_mount_failed> { template <> struct adl_serializer<repertory::drive_mount_failed> {
static void to_json(json &data, const repertory::drive_mount_failed &value) { static void to_json(json &data, const repertory::drive_mount_failed &value) {
data["error"] = value.error;
data["function_name"] = value.function_name; data["function_name"] = value.function_name;
data["mount_location"] = value.mount_location; data["mount_location"] = value.mount_location;
data["status"] = value.status;
} }
static void from_json(const json &data, static void from_json(const json &data,
repertory::drive_mount_failed &value) { repertory::drive_mount_failed &value) {
data.at("error").get_to<NTSTATUS>(value.error);
data.at("function_name").get_to<std::string>(value.function_name); data.at("function_name").get_to<std::string>(value.function_name);
data.at("mount_location").get_to<std::string>(value.mount_location); data.at("mount_location").get_to<std::string>(value.mount_location);
data.at("status").get_to<NTSTATUS>(value.status);
} }
}; };
NLOHMANN_JSON_NAMESPACE_END NLOHMANN_JSON_NAMESPACE_END

View File

@ -34,6 +34,7 @@ struct drive_mount_result final : public i_event {
mount_location(std::move(mount_location_)), mount_location(std::move(mount_location_)),
result(std::move(result_)) {} result(std::move(result_)) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"drive_mount_result"}; static constexpr const std::string_view name{"drive_mount_result"};
std::string function_name; std::string function_name;
@ -41,7 +42,7 @@ struct drive_mount_result final : public i_event {
std::string result; std::string result;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -32,13 +32,14 @@ struct drive_mounted final : public i_event {
: function_name(std::string(function_name_)), : function_name(std::string(function_name_)),
mount_location(std::move(mount_location_)) {} mount_location(std::move(mount_location_)) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"drive_mounted"}; static constexpr const std::string_view name{"drive_mounted"};
std::string function_name; std::string function_name;
std::string mount_location; std::string mount_location;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -0,0 +1,67 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_DRIVE_STOP_TIMED_OUT_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_DRIVE_STOP_TIMED_OUT_HPP_
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct drive_stop_timed_out final : public i_event {
drive_stop_timed_out() = default;
drive_stop_timed_out(std::string_view function_name_)
: function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::warn};
static constexpr const std::string_view name{"drive_stop_timed_out"};
std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}", name, function_name);
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::drive_stop_timed_out> {
static void to_json(json &data,
const repertory::drive_stop_timed_out &value) {
data["function_name"] = value.function_name;
}
static void from_json(const json &data,
repertory::drive_stop_timed_out &value) {
data.at("function_name").get_to<std::string>(value.function_name);
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DRIVE_STOP_TIMED_OUT_HPP_

View File

@ -33,13 +33,14 @@ struct drive_unmount_pending final : public i_event {
: function_name(std::string(function_name_)), : function_name(std::string(function_name_)),
mount_location(std::move(mount_location_)) {} mount_location(std::move(mount_location_)) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"drive_unmount_pending"}; static constexpr const std::string_view name{"drive_unmount_pending"};
std::string function_name; std::string function_name;
std::string mount_location; std::string mount_location;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -32,13 +32,14 @@ struct drive_unmounted final : public i_event {
: function_name(std::string(function_name_)), : function_name(std::string(function_name_)),
mount_location(std::move(mount_location_)) {} mount_location(std::move(mount_location_)) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"drive_unmounted"}; static constexpr const std::string_view name{"drive_unmounted"};
std::string function_name; std::string function_name;
std::string mount_location; std::string mount_location;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -28,16 +28,17 @@
namespace repertory { namespace repertory {
struct event_level_changed final : public i_event { struct event_level_changed final : public i_event {
event_level_changed() = default; event_level_changed() = default;
event_level_changed(std::string_view function_name_, event_level level_) event_level_changed(std::string_view function_name_, event_level new_level_)
: function_name(std::string(function_name_)), level(level_) {} : function_name(std::string(function_name_)), new_level(new_level_) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"event_level_changed"}; static constexpr const std::string_view name{"event_level_changed"};
std::string function_name; std::string function_name;
event_level level{}; event_level new_level{};
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {
@ -46,7 +47,7 @@ struct event_level_changed final : public i_event {
[[nodiscard]] auto get_single_line() const -> std::string override { [[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|level|{}", name, function_name, return fmt::format("{}|func|{}|level|{}", name, function_name,
event_level_to_string(level)); event_level_to_string(new_level));
} }
}; };
} // namespace repertory } // namespace repertory
@ -54,14 +55,14 @@ struct event_level_changed final : public i_event {
NLOHMANN_JSON_NAMESPACE_BEGIN NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::event_level_changed> { template <> struct adl_serializer<repertory::event_level_changed> {
static void to_json(json &data, const repertory::event_level_changed &value) { static void to_json(json &data, const repertory::event_level_changed &value) {
data["event_level"] = repertory::event_level_to_string(value.level); data["new_level"] = repertory::event_level_to_string(value.new_level);
data["function_name"] = value.function_name; data["function_name"] = value.function_name;
} }
static void from_json(const json &data, static void from_json(const json &data,
repertory::event_level_changed &value) { repertory::event_level_changed &value) {
value.level = repertory::event_level_from_string( value.new_level = repertory::event_level_from_string(
data.at("event_level").get<std::string>()); data.at("new_level").get<std::string>());
data.at("function_name").get_to<std::string>(value.function_name); data.at("function_name").get_to<std::string>(value.function_name);
} }
}; };

View File

@ -32,13 +32,14 @@ struct file_pinned final : public i_event {
: api_path(std::move(api_path_)), : api_path(std::move(api_path_)),
function_name(std::string(function_name_)) {} function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"file_pinned"}; static constexpr const std::string_view name{"file_pinned"};
std::string api_path; std::string api_path;
std::string function_name; std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -34,6 +34,7 @@ struct file_remove_failed final : public i_event {
error(error_), error(error_),
function_name(std::string(function_name_)) {} function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::error};
static constexpr const std::string_view name{"file_remove_failed"}; static constexpr const std::string_view name{"file_remove_failed"};
std::string api_path; std::string api_path;
@ -41,7 +42,7 @@ struct file_remove_failed final : public i_event {
std::string function_name; std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::error; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -32,13 +32,14 @@ struct file_removed final : public i_event {
: api_path(std::move(api_path_)), : api_path(std::move(api_path_)),
function_name(std::string(function_name_)) {} function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"file_removed"}; static constexpr const std::string_view name{"file_removed"};
std::string api_path; std::string api_path;
std::string function_name; std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::debug; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -35,6 +35,7 @@ struct file_removed_externally final : public i_event {
function_name(std::string(function_name_)), function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::warn};
static constexpr const std::string_view name{"file_removed_externally"}; static constexpr const std::string_view name{"file_removed_externally"};
std::string api_path; std::string api_path;
@ -42,7 +43,7 @@ struct file_removed_externally final : public i_event {
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::warn; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -32,13 +32,14 @@ struct file_unpinned final : public i_event {
: api_path(std::move(api_path_)), : api_path(std::move(api_path_)),
function_name(std::string(function_name_)) {} function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"file_unpinned"}; static constexpr const std::string_view name{"file_unpinned"};
std::string api_path; std::string api_path;
std::string function_name; std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -37,6 +37,7 @@ struct file_upload_completed final : public i_event {
function_name(std::string(function_name_)), function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"file_upload_completed"}; static constexpr const std::string_view name{"file_upload_completed"};
std::string api_path; std::string api_path;
@ -46,7 +47,7 @@ struct file_upload_completed final : public i_event {
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -35,6 +35,7 @@ struct file_upload_failed final : public i_event {
function_name(std::string(function_name_)), function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::warn};
static constexpr const std::string_view name{"file_upload_failed"}; static constexpr const std::string_view name{"file_upload_failed"};
std::string api_path; std::string api_path;
@ -43,7 +44,7 @@ struct file_upload_failed final : public i_event {
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::warn; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -34,6 +34,7 @@ struct file_upload_not_found final : public i_event {
function_name(std::string(function_name_)), function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::warn};
static constexpr const std::string_view name{"file_upload_not_found"}; static constexpr const std::string_view name{"file_upload_not_found"};
std::string api_path; std::string api_path;
@ -41,7 +42,7 @@ struct file_upload_not_found final : public i_event {
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::warn; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -34,6 +34,7 @@ struct file_upload_queued final : public i_event {
function_name(std::string(function_name_)), function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"file_upload_queued"}; static constexpr const std::string_view name{"file_upload_queued"};
std::string api_path; std::string api_path;
@ -41,7 +42,7 @@ struct file_upload_queued final : public i_event {
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -32,13 +32,14 @@ struct file_upload_removed final : public i_event {
: api_path(std::move(api_path_)), : api_path(std::move(api_path_)),
function_name(std::string(function_name_)) {} function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"file_upload_removed"}; static constexpr const std::string_view name{"file_upload_removed"};
std::string api_path; std::string api_path;
std::string function_name; std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::debug; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -28,22 +28,23 @@
namespace repertory { namespace repertory {
struct file_upload_retry final : public i_event { struct file_upload_retry final : public i_event {
file_upload_retry() = default; file_upload_retry() = default;
file_upload_retry(std::string api_path_, std::string error_, file_upload_retry(std::string api_path_, api_error error_,
std::string_view function_name_, std::string source_path_) std::string_view function_name_, std::string source_path_)
: api_path(std::move(api_path_)), : api_path(std::move(api_path_)),
error(std::move(error_)), error(std::move(error_)),
function_name(std::string(function_name_)), function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::warn};
static constexpr const std::string_view name{"file_upload_retry"}; static constexpr const std::string_view name{"file_upload_retry"};
std::string api_path; std::string api_path;
std::string error; api_error error{};
std::string function_name; std::string function_name;
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::warn; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {
@ -51,8 +52,8 @@ struct file_upload_retry final : public i_event {
} }
[[nodiscard]] auto get_single_line() const -> std::string override { [[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|ap|{}|error|{}|sp|{}", name, function_name, return fmt::format("{}|func|{}|ap|{}|sp|{}|error|{}", name, function_name,
api_path, error, source_path); api_path, source_path, api_error_to_string(error));
} }
}; };
} // namespace repertory } // namespace repertory
@ -61,14 +62,15 @@ NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::file_upload_retry> { template <> struct adl_serializer<repertory::file_upload_retry> {
static void to_json(json &data, const repertory::file_upload_retry &value) { static void to_json(json &data, const repertory::file_upload_retry &value) {
data["api_path"] = value.api_path; data["api_path"] = value.api_path;
data["error"] = value.error; data["error"] = repertory::api_error_to_string(value.error);
data["function_name"] = value.function_name; data["function_name"] = value.function_name;
data["source_path"] = value.source_path; data["source_path"] = value.source_path;
} }
static void from_json(const json &data, repertory::file_upload_retry &value) { static void from_json(const json &data, repertory::file_upload_retry &value) {
data.at("api_path").get_to<std::string>(value.api_path); data.at("api_path").get_to<std::string>(value.api_path);
data.at("error").get_to<std::string>(value.error); value.error =
repertory::api_error_from_string(data.at("error").get<std::string>());
data.at("function_name").get_to<std::string>(value.function_name); data.at("function_name").get_to<std::string>(value.function_name);
data.at("source_path").get_to<std::string>(value.source_path); data.at("source_path").get_to<std::string>(value.source_path);
} }

View File

@ -35,6 +35,7 @@ struct filesystem_item_added final : public i_event {
directory(directory_), directory(directory_),
function_name(std::string(function_name_)) {} function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"filesystem_item_added"}; static constexpr const std::string_view name{"filesystem_item_added"};
std::string api_parent; std::string api_parent;
@ -43,7 +44,7 @@ struct filesystem_item_added final : public i_event {
std::string function_name; std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::debug; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -37,6 +37,7 @@ struct filesystem_item_closed final : public i_event {
function_name(std::string(function_name_)), function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::trace};
static constexpr const std::string_view name{"filesystem_item_closed"}; static constexpr const std::string_view name{"filesystem_item_closed"};
std::string api_path; std::string api_path;
@ -46,7 +47,7 @@ struct filesystem_item_closed final : public i_event {
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::trace; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -35,6 +35,7 @@ struct filesystem_item_evicted final : public i_event {
function_name(std::string(function_name_)), function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"filesystem_item_evicted"}; static constexpr const std::string_view name{"filesystem_item_evicted"};
std::string api_path; std::string api_path;
@ -42,7 +43,7 @@ struct filesystem_item_evicted final : public i_event {
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::debug; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -39,6 +39,7 @@ struct filesystem_item_handle_closed final : public i_event {
handle(handle_), handle(handle_),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::trace};
static constexpr const std::string_view name{"filesystem_item_handle_closed"}; static constexpr const std::string_view name{"filesystem_item_handle_closed"};
std::string api_path; std::string api_path;
@ -49,7 +50,7 @@ struct filesystem_item_handle_closed final : public i_event {
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::trace; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -37,6 +37,7 @@ struct filesystem_item_handle_opened final : public i_event {
handle(handle_), handle(handle_),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::trace};
static constexpr const std::string_view name{"filesystem_item_handle_opened"}; static constexpr const std::string_view name{"filesystem_item_handle_opened"};
std::string api_path; std::string api_path;
@ -46,7 +47,7 @@ struct filesystem_item_handle_opened final : public i_event {
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::trace; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -36,6 +36,7 @@ struct filesystem_item_opened final : public i_event {
function_name(std::string(function_name_)), function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::trace};
static constexpr const std::string_view name{"filesystem_item_opened"}; static constexpr const std::string_view name{"filesystem_item_opened"};
std::string api_path; std::string api_path;
@ -44,7 +45,7 @@ struct filesystem_item_opened final : public i_event {
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::trace; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -0,0 +1,70 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_FUSE_ARGS_PARSED_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_FUSE_ARGS_PARSED_HPP_
#if !defined(_WIN32)
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct fuse_args_parsed final : public i_event {
fuse_args_parsed() = default;
fuse_args_parsed(std::string_view args_, std::string_view function_name_)
: args(std::move(args_)), function_name(std::string{function_name_}) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"fuse_args_parsed"};
std::string args;
std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|args|{}", name, function_name, args);
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::fuse_args_parsed> {
static void to_json(json &data, const repertory::fuse_args_parsed &value) {
data["args"] = value.args;
data["function_name"] = value.function_name;
}
static void from_json(const json &data, repertory::fuse_args_parsed &value) {
data.at("args").get_to<std::string>(value.args);
data.at("function_name").get_to<std::string>(value.function_name);
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // !defined(_WIN32)
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_FUSE_ARGS_PARSED_HPP_

View File

@ -0,0 +1,77 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_FUSE_EVENT_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_FUSE_EVENT_HPP_
#if !defined(_WIN32)
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct fuse_event final : public i_event {
fuse_event() = default;
fuse_event(std::string_view api_path_, std::int32_t error_,
std::string_view function_name_)
: api_path(std::string{api_path_}),
error(error_),
function_name(std::string{function_name_}) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"fuse_event"};
std::string api_path;
std::int32_t error{};
std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|ap|{}|error|{}", name, function_name,
api_path, error);
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::fuse_event> {
static void to_json(json &data, const repertory::fuse_event &value) {
data["api_path"] = value.api_path;
data["error"] = value.error;
data["function_name"] = value.function_name;
}
static void from_json(const json &data, repertory::fuse_event &value) {
data.at("api_path").get_to<std::string>(value.api_path);
data.at("error").get_to<std::int32_t>(value.error);
data.at("function_name").get_to<std::string>(value.function_name);
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // !defined(_WIN32)
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_FUSE_EVENT_HPP_

View File

@ -0,0 +1,76 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_INVALID_CACHE_SIZE_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_INVALID_CACHE_SIZE_HPP_
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct invalid_cache_size final : public i_event {
invalid_cache_size() = default;
invalid_cache_size(std::uint64_t cache_size_, std::string_view function_name_,
std::uint64_t invalid_size_)
: cache_size(cache_size_),
function_name(std::string{function_name_}),
invalid_size(invalid_size_) {}
static constexpr const event_level level{event_level::warn};
static constexpr const std::string_view name{"invalid_cache_size"};
std::uint64_t cache_size{};
std::string function_name;
std::uint64_t invalid_size{};
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|size|{}|by|{}", name, function_name,
cache_size, invalid_size);
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::invalid_cache_size> {
static void to_json(json &data, const repertory::invalid_cache_size &value) {
data["cache_size"] = value.cache_size;
data["function_name"] = value.function_name;
data["invalid_size"] = value.invalid_size;
}
static void from_json(const json &data,
repertory::invalid_cache_size &value) {
data.at("cache_size").get_to<std::uint64_t>(value.cache_size);
data.at("function_name").get_to<std::string>(value.function_name);
data.at("invalid_size").get_to<std::uint64_t>(value.invalid_size);
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_INVALID_CACHE_SIZE_HPP_

View File

@ -0,0 +1,69 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_ITEM_TIMEOUT_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_ITEM_TIMEOUT_HPP_
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct item_timeout final : public i_event {
item_timeout() = default;
item_timeout(std::string api_path_, std::string_view function_name_)
: api_path(std::move(api_path_)),
function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::trace};
static constexpr const std::string_view name{"item_timeout"};
std::string api_path;
std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|ap|{}", name, function_name, api_path);
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::item_timeout> {
static void to_json(json &data, const repertory::item_timeout &value) {
data["api_path"] = value.api_path;
data["function_name"] = value.function_name;
}
static void from_json(const json &data, repertory::item_timeout &value) {
data.at("api_path").get_to<std::string>(value.api_path);
data.at("function_name").get_to<std::string>(value.function_name);
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_ITEM_TIMEOUT_HPP_

View File

@ -0,0 +1,78 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_MAX_CACHE_SIZE_REACHED_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_MAX_CACHE_SIZE_REACHED_HPP_
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct max_cache_size_reached final : public i_event {
max_cache_size_reached() = default;
max_cache_size_reached(std::uint64_t cache_size_,
std::string_view function_name_,
std::uint64_t max_cache_size_)
: cache_size(cache_size_),
function_name(std::string{function_name_}),
max_cache_size(max_cache_size_) {}
static constexpr const event_level level{event_level::warn};
static constexpr const std::string_view name{"max_cache_size_reached"};
std::uint64_t cache_size{};
std::string function_name;
std::uint64_t max_cache_size{};
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|size|{}|max|{}", name, function_name,
cache_size, max_cache_size);
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::max_cache_size_reached> {
static void to_json(json &data,
const repertory::max_cache_size_reached &value) {
data["cache_size"] = value.cache_size;
data["function_name"] = value.function_name;
data["max_cache_size"] = value.max_cache_size;
}
static void from_json(const json &data,
repertory::max_cache_size_reached &value) {
data.at("cache_size").get_to<std::uint64_t>(value.cache_size);
data.at("function_name").get_to<std::string>(value.function_name);
data.at("max_cache_size").get_to<std::uint64_t>(value.max_cache_size);
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_MAX_CACHE_SIZE_REACHED_HPP_

View File

@ -33,13 +33,14 @@ struct orphaned_file_detected final : public i_event {
: function_name(std::string(function_name_)), : function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::warn};
static constexpr const std::string_view name{"orphaned_file_detected"}; static constexpr const std::string_view name{"orphaned_file_detected"};
std::string function_name; std::string function_name;
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -36,8 +36,10 @@ struct orphaned_file_processing_failed final : public i_event {
function_name(std::string(function_name_)), function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::error};
static constexpr const std::string_view name{ static constexpr const std::string_view name{
"orphaned_file_processing_failed"}; "orphaned_file_processing_failed",
};
std::string dest_path; std::string dest_path;
std::string error; std::string error;
@ -45,7 +47,7 @@ struct orphaned_file_processing_failed final : public i_event {
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -33,13 +33,14 @@ struct orphaned_source_file_detected final : public i_event {
: function_name(std::string(function_name_)), : function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::warn};
static constexpr const std::string_view name{"orphaned_source_file_detected"}; static constexpr const std::string_view name{"orphaned_source_file_detected"};
std::string function_name; std::string function_name;
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -33,13 +33,14 @@ struct orphaned_source_file_removed final : public i_event {
: function_name(std::string(function_name_)), : function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::warn};
static constexpr const std::string_view name{"orphaned_source_file_removed"}; static constexpr const std::string_view name{"orphaned_source_file_removed"};
std::string function_name; std::string function_name;
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -0,0 +1,77 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_PACKET_CLIENT_TIMEOUT_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_PACKET_CLIENT_TIMEOUT_HPP_
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct packet_client_timeout final : public i_event {
packet_client_timeout() = default;
packet_client_timeout(std::string event_name_,
std::string_view function_name_, std::string msg_)
: event_name(std::move(event_name_)),
function_name(std::string(function_name_)),
msg(std::move(msg_)) {}
static constexpr const event_level level{event_level::warn};
static constexpr const std::string_view name{"packet_client_timeout"};
std::string event_name;
std::string function_name;
std::string msg;
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|event|{}|msg|{}", name, function_name,
event_name, msg);
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::packet_client_timeout> {
static void to_json(json &data,
const repertory::packet_client_timeout &value) {
data["event_name"] = value.event_name;
data["function_name"] = value.function_name;
data["msg"] = value.msg;
}
static void from_json(const json &data,
repertory::packet_client_timeout &value) {
data.at("event_name").get_to<std::string>(value.event_name);
data.at("function_name").get_to<std::string>(value.function_name);
data.at("msg").get_to<std::string>(value.msg);
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_PACKET_CLIENT_TIMEOUT_HPP_

View File

@ -32,13 +32,14 @@ struct polling_item_begin final : public i_event {
: function_name(std::string(function_name_)), : function_name(std::string(function_name_)),
item_name(std::move(item_name_)) {} item_name(std::move(item_name_)) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"polling_item_begin"}; static constexpr const std::string_view name{"polling_item_begin"};
std::string function_name; std::string function_name;
std::string item_name; std::string item_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::debug; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -32,13 +32,14 @@ struct polling_item_end final : public i_event {
: function_name(std::string(function_name_)), : function_name(std::string(function_name_)),
item_name(std::move(item_name_)) {} item_name(std::move(item_name_)) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"polling_item_end"}; static constexpr const std::string_view name{"polling_item_end"};
std::string function_name; std::string function_name;
std::string item_name; std::string item_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::debug; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -34,6 +34,7 @@ struct provider_offline final : public i_event {
host_name_or_ip(std::move(host_name_or_ip_)), host_name_or_ip(std::move(host_name_or_ip_)),
port(port_) {} port(port_) {}
static constexpr const event_level level{event_level::warn};
static constexpr const std::string_view name{"provider_offline"}; static constexpr const std::string_view name{"provider_offline"};
std::string function_name; std::string function_name;
@ -41,7 +42,7 @@ struct provider_offline final : public i_event {
std::uint16_t port{}; std::uint16_t port{};
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::debug; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -34,6 +34,7 @@ struct provider_upload_begin final : public i_event {
function_name(std::string(function_name_)), function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"provider_upload_begin"}; static constexpr const std::string_view name{"provider_upload_begin"};
std::string api_path; std::string api_path;
@ -41,7 +42,7 @@ struct provider_upload_begin final : public i_event {
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::warn; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -35,6 +35,7 @@ struct provider_upload_end final : public i_event {
function_name(std::string(function_name_)), function_name(std::string(function_name_)),
source_path(std::move(source_path_)) {} source_path(std::move(source_path_)) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"provider_upload_end"}; static constexpr const std::string_view name{"provider_upload_end"};
std::string api_path; std::string api_path;
@ -43,7 +44,7 @@ struct provider_upload_end final : public i_event {
std::string source_path; std::string source_path;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -0,0 +1,77 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_REMOTE_SERVER_EVENT_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_REMOTE_SERVER_EVENT_HPP_
#include "comm/packet/packet.hpp"
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct remote_server_event final : public i_event {
remote_server_event() = default;
remote_server_event(std::string api_path_, packet::error_type error_,
std::string_view function_name_)
: api_path(std::move(api_path_)),
error(error_),
function_name(std::string{function_name_}) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"remote_server_event"};
std::string api_path;
packet::error_type error{};
std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|ap|{}|error|{}", name, function_name,
api_path, error);
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::remote_server_event> {
static void to_json(json &data, const repertory::remote_server_event &value) {
data["api_path"] = value.api_path;
data["error"] = value.error;
data["function_name"] = value.function_name;
}
static void from_json(const json &data,
repertory::remote_server_event &value) {
data.at("api_path").get_to<std::string>(value.api_path);
data.at("error").get_to<repertory::packet::error_type>(value.error);
data.at("function_name").get_to<std::string>(value.function_name);
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_REMOTE_SERVER_EVENT_HPP_

View File

@ -31,13 +31,14 @@ struct repertory_exception final : public i_event {
repertory_exception(std::string_view function_name_, std::string msg_) repertory_exception(std::string_view function_name_, std::string msg_)
: function_name(std::string(function_name_)), msg(std::move(msg_)) {} : function_name(std::string(function_name_)), msg(std::move(msg_)) {}
static constexpr const event_level level{event_level::error};
static constexpr const std::string_view name{"repertory_exception"}; static constexpr const std::string_view name{"repertory_exception"};
std::string function_name; std::string function_name;
std::string msg; std::string msg;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::error; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -33,13 +33,14 @@ struct service_start_begin final : public i_event {
: function_name(std::string(function_name_)), : function_name(std::string(function_name_)),
service_name(std::move(service_name_)) {} service_name(std::move(service_name_)) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"service_start_begin"}; static constexpr const std::string_view name{"service_start_begin"};
std::string function_name; std::string function_name;
std::string service_name; std::string service_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::debug; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -32,13 +32,14 @@ struct service_start_end final : public i_event {
: function_name(std::string(function_name_)), : function_name(std::string(function_name_)),
service_name(std::move(service_name_)) {} service_name(std::move(service_name_)) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"service_start_end"}; static constexpr const std::string_view name{"service_start_end"};
std::string function_name; std::string function_name;
std::string service_name; std::string service_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::debug; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -32,13 +32,14 @@ struct service_stop_begin final : public i_event {
: function_name(std::string(function_name_)), : function_name(std::string(function_name_)),
service_name(std::move(service_name_)) {} service_name(std::move(service_name_)) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"service_stop_begin"}; static constexpr const std::string_view name{"service_stop_begin"};
std::string function_name; std::string function_name;
std::string service_name; std::string service_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::debug; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -32,13 +32,14 @@ struct service_stop_end final : public i_event {
: function_name(std::string(function_name_)), : function_name(std::string(function_name_)),
service_name(std::move(service_name_)) {} service_name(std::move(service_name_)) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"service_stop_end"}; static constexpr const std::string_view name{"service_stop_end"};
std::string function_name; std::string function_name;
std::string service_name; std::string service_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::debug; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -31,12 +31,13 @@ struct unmount_requested final : public i_event {
unmount_requested(std::string_view function_name_) unmount_requested(std::string_view function_name_)
: function_name(std::string(function_name_)) {} : function_name(std::string(function_name_)) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"unmount_requested"}; static constexpr const std::string_view name{"unmount_requested"};
std::string function_name; std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -35,6 +35,7 @@ struct unmount_result final : public i_event {
mount_location(std::move(mount_location_)), mount_location(std::move(mount_location_)),
result(result_) {} result(result_) {}
static constexpr const event_level level{event_level::info};
static constexpr const std::string_view name{"unmount_result"}; static constexpr const std::string_view name{"unmount_result"};
std::string function_name; std::string function_name;
@ -42,7 +43,7 @@ struct unmount_result final : public i_event {
std::int32_t result{}; std::int32_t result{};
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return event_level::info; return level;
} }
[[nodiscard]] auto get_name() const -> std::string_view override { [[nodiscard]] auto get_name() const -> std::string_view override {

View File

@ -0,0 +1,77 @@
/*
Copyright <2018-2025> <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_EVENTS_TYPES_WINFSP_EVENT_HPP_
#define REPERTORY_INCLUDE_EVENTS_TYPES_WINFSP_EVENT_HPP_
#if defined(_WIN32)
#include "events/i_event.hpp"
#include "types/repertory.hpp"
namespace repertory {
struct winfsp_event final : public i_event {
winfsp_event() = default;
winfsp_event(std::string api_path_, NTSTATUS error_,
std::string_view function_name_)
: api_path(std::move(api_path_)),
error(error_),
function_name(std::string{function_name_}) {}
static constexpr const event_level level{event_level::debug};
static constexpr const std::string_view name{"winfsp_event"};
std::string api_path;
NTSTATUS error{};
std::string function_name;
[[nodiscard]] auto get_event_level() const -> event_level override {
return level;
}
[[nodiscard]] auto get_name() const -> std::string_view override {
return name;
}
[[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|ap|{}|error|{}", name, function_name,
api_path, error);
}
};
} // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::winfsp_event> {
static void to_json(json &data, const repertory::winfsp_event &value) {
data["api_path"] = value.api_path;
data["error"] = value.error;
data["function_name"] = value.function_name;
}
static void from_json(const json &data, repertory::winfsp_event &value) {
data.at("api_path").get_to<std::string>(value.api_path);
data.at("error").get_to<NTSTATUS>(value.error);
data.at("function_name").get_to<std::string>(value.function_name);
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // defined(_WIN32)
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_WINFSP_EVENT_HPP_

View File

@ -31,18 +31,18 @@ public:
private: private:
const rpc_host_info host_info_; const rpc_host_info host_info_;
std::atomic<std::uint32_t> request_id_; std::atomic<std::uint32_t> request_id_{0U};
public: public:
[[nodiscard]] auto get_drive_information() -> rpc_response; [[nodiscard]] auto get_drive_information() -> rpc_response;
[[nodiscard]] auto get_config() -> rpc_response; [[nodiscard]] auto get_config() -> rpc_response;
[[nodiscard]] auto [[nodiscard]] auto get_config_value_by_name(const std::string &name)
get_config_value_by_name(const std::string &name) -> rpc_response; -> rpc_response;
[[nodiscard]] auto [[nodiscard]] auto get_directory_items(const std::string &api_path)
get_directory_items(const std::string &api_path) -> rpc_response; -> rpc_response;
[[nodiscard]] auto get_open_files() -> rpc_response; [[nodiscard]] auto get_open_files() -> rpc_response;
@ -52,9 +52,9 @@ public:
[[nodiscard]] auto pinned_status(const std::string &api_file) -> rpc_response; [[nodiscard]] auto pinned_status(const std::string &api_file) -> rpc_response;
[[nodiscard]] auto [[nodiscard]] auto set_config_value_by_name(const std::string &name,
set_config_value_by_name(const std::string &name, const std::string &value)
const std::string &value) -> rpc_response; -> rpc_response;
[[nodiscard]] auto unmount() -> rpc_response; [[nodiscard]] auto unmount() -> rpc_response;

View File

@ -32,13 +32,13 @@ public:
public: public:
timeout(std::function<void()> timeout_callback, timeout(std::function<void()> timeout_callback,
const std::chrono::system_clock::duration &duration = 10s); std::chrono::system_clock::duration duration);
~timeout() { disable(); } ~timeout() { disable(); }
private: private:
std::atomic<bool> timeout_killed_; std::atomic<bool> timeout_killed_;
std::unique_ptr<std::thread> timeout_thread_; std::unique_ptr<std::thread> timeout_thread_{nullptr};
std::mutex timeout_mutex_; std::mutex timeout_mutex_;
std::condition_variable timeout_notify_; std::condition_variable timeout_notify_;

View File

@ -22,6 +22,7 @@
#include "comm/packet/packet_client.hpp" #include "comm/packet/packet_client.hpp"
#include "events/event_system.hpp" #include "events/event_system.hpp"
#include "events/types/packet_client_timeout.hpp"
#include "platform/platform.hpp" #include "platform/platform.hpp"
#include "types/repertory.hpp" #include "types/repertory.hpp"
#include "utils/collection.hpp" #include "utils/collection.hpp"
@ -105,8 +106,8 @@ void packet_client::put_client(std::shared_ptr<client> &cli) {
} }
} }
auto packet_client::read_packet(client &cli, auto packet_client::read_packet(client &cli, packet &response) const
packet &response) const -> packet::error_type { -> packet::error_type {
data_buffer buffer(sizeof(std::uint32_t)); data_buffer buffer(sizeof(std::uint32_t));
const auto read_buffer = [&]() { const auto read_buffer = [&]() {
std::uint32_t offset{}; std::uint32_t offset{};
@ -147,8 +148,8 @@ void packet_client::resolve() {
.resolve(cfg_.host_name_or_ip, std::to_string(cfg_.api_port)); .resolve(cfg_.host_name_or_ip, std::to_string(cfg_.api_port));
} }
auto packet_client::send(std::string_view method, auto packet_client::send(std::string_view method, std::uint32_t &service_flags)
std::uint32_t &service_flags) -> packet::error_type { -> packet::error_type {
packet request; packet request;
return send(method, request, service_flags); return send(method, request, service_flags);
} }
@ -160,8 +161,8 @@ auto packet_client::send(std::string_view method, packet &request,
} }
auto packet_client::send(std::string_view method, packet &request, auto packet_client::send(std::string_view method, packet &request,
packet &response, packet &response, std::uint32_t &service_flags)
std::uint32_t &service_flags) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto success = false; auto success = false;
@ -184,7 +185,7 @@ auto packet_client::send(std::string_view method, packet &request,
timeout request_timeout( timeout request_timeout(
[method, current_client]() { [method, current_client]() {
event_system::instance().raise<packet_client_timeout>( event_system::instance().raise<packet_client_timeout>(
"request", std::string{method}); "request", function_name, std::string{method});
packet_client::close(*current_client); packet_client::close(*current_client);
}, },
std::chrono::milliseconds(cfg_.send_timeout_ms)); std::chrono::milliseconds(cfg_.send_timeout_ms));
@ -206,7 +207,7 @@ auto packet_client::send(std::string_view method, packet &request,
timeout response_timeout( timeout response_timeout(
[method, current_client]() { [method, current_client]() {
event_system::instance().raise<packet_client_timeout>( event_system::instance().raise<packet_client_timeout>(
"response", std::string{method}); "response", function_name, std::string{method});
packet_client::close(*current_client); packet_client::close(*current_client);
}, },
std::chrono::milliseconds(cfg_.recv_timeout_ms)); std::chrono::milliseconds(cfg_.recv_timeout_ms));

View File

@ -39,12 +39,11 @@ auto directory_cache::get_directory(std::uint64_t handle)
-> std::shared_ptr<directory_iterator> { -> std::shared_ptr<directory_iterator> {
recur_mutex_lock directory_lock(directory_mutex_); recur_mutex_lock directory_lock(directory_mutex_);
auto iter = auto iter =
std::find_if(directory_lookup_.begin(), directory_lookup_.end(), std::ranges::find_if(directory_lookup_, [handle](auto &&item) -> bool {
[handle](auto &&item) -> bool { auto &&handles = item.second.handles;
auto &&handles = item.second.handles; return std::find(handles.begin(), handles.end(), handle) !=
return std::find(handles.begin(), handles.end(), handle) != item.second.handles.end();
item.second.handles.end(); });
});
if (iter != directory_lookup_.end()) { if (iter != directory_lookup_.end()) {
return iter->second.iterator; return iter->second.iterator;
} }
@ -68,12 +67,11 @@ auto directory_cache::remove_directory(const std::string &api_path)
void directory_cache::remove_directory(std::uint64_t handle) { void directory_cache::remove_directory(std::uint64_t handle) {
recur_mutex_lock directory_lock(directory_mutex_); recur_mutex_lock directory_lock(directory_mutex_);
auto iter = auto iter =
std::find_if(directory_lookup_.begin(), directory_lookup_.end(), std::ranges::find_if(directory_lookup_, [handle](auto &&item) -> bool {
[handle](auto &&item) -> bool { auto &&handles = item.second.handles;
auto &&handles = item.second.handles; return std::find(handles.begin(), handles.end(), handle) !=
return std::find(handles.begin(), handles.end(), handle) != item.second.handles.end();
item.second.handles.end(); });
});
if (iter == directory_lookup_.end()) { if (iter == directory_lookup_.end()) {
return; return;
} }

View File

@ -102,10 +102,9 @@ auto directory_iterator::get_directory_item(std::size_t offset,
auto directory_iterator::get_directory_item(const std::string &api_path, auto directory_iterator::get_directory_item(const std::string &api_path,
directory_item &di) -> api_error { directory_item &di) -> api_error {
auto iter = auto iter = std::ranges::find_if(items_, [&api_path](auto &&item) -> bool {
std::find_if(items_.begin(), items_.end(), [&](const auto &item) -> bool { return api_path == item.api_path;
return api_path == item.api_path; });
});
if (iter == items_.end()) { if (iter == items_.end()) {
return api_error::item_not_found; return api_error::item_not_found;
} }
@ -126,10 +125,10 @@ auto directory_iterator::get_json(std::size_t offset, json &item) -> int {
auto directory_iterator::get_next_directory_offset( auto directory_iterator::get_next_directory_offset(
const std::string &api_path) const -> std::size_t { const std::string &api_path) const -> std::size_t {
const auto iter = std::find_if(items_.begin(), items_.end(), const auto iter =
[&api_path](const auto &dir_item) -> bool { std::ranges::find_if(items_, [&api_path](auto &&dir_item) -> bool {
return api_path == dir_item.api_path; return api_path == dir_item.api_path;
}); });
return (iter == items_.end()) ? 0U return (iter == items_.end()) ? 0U
: static_cast<std::size_t>( : static_cast<std::size_t>(

View File

@ -25,6 +25,8 @@
#include "app_config.hpp" #include "app_config.hpp"
#include "events/event_system.hpp" #include "events/event_system.hpp"
#include "events/types/fuse_args_parsed.hpp"
#include "events/types/fuse_event.hpp"
#include "events/types/unmount_requested.hpp" #include "events/types/unmount_requested.hpp"
#include "events/types/unmount_result.hpp" #include "events/types/unmount_result.hpp"
#include "initialize.hpp" #include "initialize.hpp"
@ -90,7 +92,7 @@ fuse_base::fuse_base(app_config &config) : config_(config) {
fuse_ops_.flag_reserved = 0; fuse_ops_.flag_reserved = 0;
#endif // FUSE_USE_VERSION < 30 #endif // FUSE_USE_VERSION < 30
E_SUBSCRIBE_EXACT(unmount_requested, [this](const unmount_requested &) { E_SUBSCRIBE(unmount_requested, [this](const unmount_requested &) {
std::thread([this]() { this->shutdown(); }).detach(); std::thread([this]() { this->shutdown(); }).detach();
}); });
} }
@ -118,8 +120,8 @@ auto fuse_base::chflags_(const char *path, uint32_t flags) -> int {
#endif // __APPLE__ #endif // __APPLE__
#if FUSE_USE_VERSION >= 30 #if FUSE_USE_VERSION >= 30
auto fuse_base::chmod_(const char *path, mode_t mode, auto fuse_base::chmod_(const char *path, mode_t mode, struct fuse_file_info *fi)
struct fuse_file_info *fi) -> int { -> int {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
return instance().execute_callback( return instance().execute_callback(
@ -186,7 +188,7 @@ void fuse_base::display_options(
#if FUSE_USE_VERSION >= 30 #if FUSE_USE_VERSION >= 30
fuse_cmdline_help(); fuse_cmdline_help();
#else #else
struct fuse_operations fuse_ops {}; struct fuse_operations fuse_ops{};
fuse_main(args.size(), fuse_main(args.size(),
reinterpret_cast<char **>(const_cast<char **>(args.data())), reinterpret_cast<char **>(const_cast<char **>(args.data())),
&fuse_ops, nullptr); &fuse_ops, nullptr);
@ -196,7 +198,7 @@ void fuse_base::display_options(
} }
void fuse_base::display_version_information(std::vector<const char *> args) { void fuse_base::display_version_information(std::vector<const char *> args) {
struct fuse_operations fuse_ops {}; struct fuse_operations fuse_ops{};
fuse_main(static_cast<int>(args.size()), fuse_main(static_cast<int>(args.size()),
reinterpret_cast<char **>(const_cast<char **>(args.data())), reinterpret_cast<char **>(const_cast<char **>(args.data())),
&fuse_ops, nullptr); &fuse_ops, nullptr);
@ -334,8 +336,8 @@ auto fuse_base::getxtimes_(const char *path, struct timespec *bkuptime,
#endif // __APPLE__ #endif // __APPLE__
#if FUSE_USE_VERSION >= 30 #if FUSE_USE_VERSION >= 30
auto fuse_base::init_(struct fuse_conn_info *conn, auto fuse_base::init_(struct fuse_conn_info *conn, struct fuse_config *cfg)
struct fuse_config *cfg) -> void * { -> void * {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
return execute_void_pointer_callback(function_name, [&]() -> void * { return execute_void_pointer_callback(function_name, [&]() -> void * {
@ -408,7 +410,7 @@ auto fuse_base::mount(std::vector<std::string> args) -> int {
char *mount_location{nullptr}; char *mount_location{nullptr};
#if FUSE_USE_VERSION >= 30 #if FUSE_USE_VERSION >= 30
struct fuse_cmdline_opts opts {}; struct fuse_cmdline_opts opts{};
fuse_parse_cmdline(&fa, &opts); fuse_parse_cmdline(&fa, &opts);
mount_location = opts.mountpoint; mount_location = opts.mountpoint;
#else #else
@ -477,8 +479,8 @@ auto fuse_base::read_(const char *path, char *buffer, size_t read_size,
#if FUSE_USE_VERSION >= 30 #if FUSE_USE_VERSION >= 30
auto fuse_base::readdir_(const char *path, void *buf, auto fuse_base::readdir_(const char *path, void *buf,
fuse_fill_dir_t fuse_fill_dir, off_t offset, fuse_fill_dir_t fuse_fill_dir, off_t offset,
struct fuse_file_info *fi, struct fuse_file_info *fi, fuse_readdir_flags flags)
fuse_readdir_flags flags) -> int { -> int {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
return instance().execute_callback( return instance().execute_callback(
@ -510,8 +512,8 @@ auto fuse_base::release_(const char *path, struct fuse_file_info *fi) -> int {
}); });
} }
auto fuse_base::releasedir_(const char *path, auto fuse_base::releasedir_(const char *path, struct fuse_file_info *fi)
struct fuse_file_info *fi) -> int { -> int {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
return instance().execute_callback( return instance().execute_callback(
@ -521,8 +523,8 @@ auto fuse_base::releasedir_(const char *path,
} }
#if FUSE_USE_VERSION >= 30 #if FUSE_USE_VERSION >= 30
auto fuse_base::rename_(const char *from, const char *to, auto fuse_base::rename_(const char *from, const char *to, unsigned int flags)
unsigned int flags) -> int { -> int {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
return instance().execute_callback( return instance().execute_callback(
@ -601,12 +603,17 @@ auto fuse_base::listxattr_(const char *path, char *buffer, size_t size) -> int {
} }
void fuse_base::notify_fuse_args_parsed(const std::vector<std::string> &args) { void fuse_base::notify_fuse_args_parsed(const std::vector<std::string> &args) {
event_system::instance().raise<fuse_args_parsed>(std::accumulate( REPERTORY_USES_FUNCTION_NAME();
args.begin(), args.end(), std::string(),
[](auto &&command_line, auto &&arg) -> auto { event_system::instance().raise<fuse_args_parsed>(
command_line += (command_line.empty() ? arg : (" " + std::string(arg))); std::accumulate(args.begin(), args.end(), std::string(),
return command_line; [](auto &&command_line, auto &&arg) -> auto {
})); command_line +=
(command_line.empty() ? arg
: (" " + std::string(arg)));
return command_line;
}),
function_name);
} }
auto fuse_base::parse_args(std::vector<std::string> &args) -> int { auto fuse_base::parse_args(std::vector<std::string> &args) -> int {
@ -701,7 +708,7 @@ void fuse_base::raise_fuse_event(std::string_view function_name,
(config_.get_event_level() >= event_level::trace)) { (config_.get_event_level() >= event_level::trace)) {
std::string func{function_name}; std::string func{function_name};
event_system::instance().raise<fuse_event>( event_system::instance().raise<fuse_event>(
utils::string::right_trim(func, '_'), std::string{api_path}, ret); api_path, ret, utils::string::right_trim(func, '_'));
} }
} }
@ -754,7 +761,7 @@ void fuse_base::shutdown() {
auto res = unmount(get_mount_location()); auto res = unmount(get_mount_location());
event_system::instance().raise<unmount_result>(function_name, event_system::instance().raise<unmount_result>(function_name,
get_mount_location(), res); get_mount_location(), res);
} }
#if defined(__APPLE__) #if defined(__APPLE__)
@ -767,8 +774,8 @@ auto fuse_base::setattr_x_(const char *path, struct setattr_x *attr) -> int {
}); });
} }
auto fuse_base::setbkuptime_(const char *path, auto fuse_base::setbkuptime_(const char *path, const struct timespec *bkuptime)
const struct timespec *bkuptime) -> int { -> int {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
return instance().execute_callback( return instance().execute_callback(
@ -777,8 +784,8 @@ auto fuse_base::setbkuptime_(const char *path,
}); });
} }
auto fuse_base::setchgtime_(const char *path, auto fuse_base::setchgtime_(const char *path, const struct timespec *chgtime)
const struct timespec *chgtime) -> int { -> int {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
return instance().execute_callback( return instance().execute_callback(
@ -787,8 +794,8 @@ auto fuse_base::setchgtime_(const char *path,
}); });
} }
auto fuse_base::setcrtime_(const char *path, auto fuse_base::setcrtime_(const char *path, const struct timespec *crtime)
const struct timespec *crtime) -> int { -> int {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
return instance().execute_callback( return instance().execute_callback(

View File

@ -33,6 +33,7 @@
#include "events/event_system.hpp" #include "events/event_system.hpp"
#include "events/types/drive_mount_result.hpp" #include "events/types/drive_mount_result.hpp"
#include "events/types/drive_mounted.hpp" #include "events/types/drive_mounted.hpp"
#include "events/types/drive_stop_timed_out.hpp"
#include "events/types/drive_unmount_pending.hpp" #include "events/types/drive_unmount_pending.hpp"
#include "events/types/drive_unmounted.hpp" #include "events/types/drive_unmounted.hpp"
#include "platform/platform.hpp" #include "platform/platform.hpp"
@ -281,6 +282,7 @@ void fuse_drive::stop_all() {
}); });
if (future.wait_for(30s) == std::future_status::timeout) { if (future.wait_for(30s) == std::future_status::timeout) {
event_system::instance().raise<drive_stop_timed_out>(function_name);
app_config::set_stop_requested(); app_config::set_stop_requested();
future.wait(); future.wait();
} }
@ -294,7 +296,7 @@ void fuse_drive::destroy_impl(void *ptr) {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
event_system::instance().raise<drive_unmount_pending>(function_name, event_system::instance().raise<drive_unmount_pending>(function_name,
get_mount_location()); get_mount_location());
stop_all(); stop_all();
@ -303,7 +305,7 @@ void fuse_drive::destroy_impl(void *ptr) {
fuse_base::destroy_impl(ptr); fuse_base::destroy_impl(ptr);
event_system::instance().raise<drive_unmounted>(function_name, event_system::instance().raise<drive_unmounted>(function_name,
get_mount_location()); get_mount_location());
} }
auto fuse_drive::fallocate_impl(std::string /*api_path*/, int mode, auto fuse_drive::fallocate_impl(std::string /*api_path*/, int mode,
@ -617,7 +619,7 @@ void *fuse_drive::init_impl(struct fuse_conn_info *conn) {
} }
event_system::instance().raise<drive_mounted>(function_name, event_system::instance().raise<drive_mounted>(function_name,
get_mount_location()); get_mount_location());
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::raise_error(function_name, e, "exception during fuse init"); utils::error::raise_error(function_name, e, "exception during fuse init");

View File

@ -28,6 +28,7 @@
#include "drives/directory_iterator.hpp" #include "drives/directory_iterator.hpp"
#include "drives/remote/remote_open_file_table.hpp" #include "drives/remote/remote_open_file_table.hpp"
#include "events/event_system.hpp" #include "events/event_system.hpp"
#include "events/types/remote_server_event.hpp"
#include "platform/platform.hpp" #include "platform/platform.hpp"
#include "types/remote.hpp" #include "types/remote.hpp"
#include "types/repertory.hpp" #include "types/repertory.hpp"
@ -36,15 +37,15 @@
#include "utils/file.hpp" #include "utils/file.hpp"
#include "utils/path.hpp" #include "utils/path.hpp"
#include "utils/time.hpp" #include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory::remote_fuse { namespace repertory::remote_fuse {
#define RAISE_REMOTE_FUSE_SERVER_EVENT(func, file, ret) \ #define RAISE_REMOTE_FUSE_SERVER_EVENT(func, file, ret) \
if (config_.get_enable_drive_events() && \ if (config_.get_enable_drive_events() && \
(((config_.get_event_level() >= remote_fuse_server_event::level) && \ (((config_.get_event_level() >= remote_server_event::level) && \
((ret) < 0)) || \ ((ret) < 0)) || \
(config_.get_event_level() >= event_level::trace))) \ (config_.get_event_level() >= event_level::trace))) \
event_system::instance().raise<remote_fuse_server_event>(std::string{func}, \ event_system::instance().raise<remote_server_event>(file, ret, func)
file, ret)
remote_server::remote_server(app_config &config, i_fuse_drive &drive, remote_server::remote_server(app_config &config, i_fuse_drive &drive,
const std::string &mount_location) const std::string &mount_location)
@ -200,8 +201,8 @@ auto remote_server::fuse_access(const char *path, const std::int32_t &mask)
return ret; return ret;
} }
auto remote_server::fuse_chflags(const char *path, auto remote_server::fuse_chflags(const char *path, std::uint32_t flags)
std::uint32_t flags) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path); const auto api_path = utils::path::create_api_path(path);
@ -313,9 +314,10 @@ length); ret = ((res < 0) ? -errno : 0); #endif
return ret; return ret;
}*/ }*/
auto remote_server::fuse_fgetattr( auto remote_server::fuse_fgetattr(const char *path, remote::stat &r_stat,
const char *path, remote::stat &r_stat, bool &directory, bool &directory,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
r_stat = {}; r_stat = {};
@ -325,7 +327,7 @@ auto remote_server::fuse_fgetattr(
auto res = has_open_info(static_cast<native_handle>(handle), EBADF); auto res = has_open_info(static_cast<native_handle>(handle), EBADF);
if (res == 0) { if (res == 0) {
directory = utils::file::directory(file_path).exists(); directory = utils::file::directory(file_path).exists();
struct stat64 unix_st {}; struct stat64 unix_st{};
res = fstat64(static_cast<native_handle>(handle), &unix_st); res = fstat64(static_cast<native_handle>(handle), &unix_st);
if (res == 0) { if (res == 0) {
populate_stat(unix_st, r_stat); populate_stat(unix_st, r_stat);
@ -337,9 +339,10 @@ auto remote_server::fuse_fgetattr(
return ret; return ret;
} }
auto remote_server::fuse_fsetattr_x( auto remote_server::fuse_fsetattr_x(const char *path,
const char *path, const remote::setattr_x &attr, const remote::setattr_x &attr,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path); const auto api_path = utils::path::create_api_path(path);
@ -455,9 +458,10 @@ auto remote_server::fuse_fsync(const char *path, const std::int32_t &datasync,
return ret; return ret;
} }
auto remote_server::fuse_ftruncate( auto remote_server::fuse_ftruncate(const char *path,
const char *path, const remote::file_offset &size, const remote::file_offset &size,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
@ -485,7 +489,7 @@ auto remote_server::fuse_getattr(const char *path, remote::stat &r_stat,
directory = utils::file::directory(file_path).exists(); directory = utils::file::directory(file_path).exists();
struct stat64 unix_st {}; struct stat64 unix_st{};
auto res = stat64(file_path.c_str(), &unix_st); auto res = stat64(file_path.c_str(), &unix_st);
if (res == 0) { if (res == 0) {
populate_stat(unix_st, r_stat); populate_stat(unix_st, r_stat);
@ -550,9 +554,10 @@ STATUS_NOT_IMPLEMENTED; #endif RAISE_REMOTE_FUSE_SERVER_EVENT(function_name,
file_path, ret); return ret; file_path, ret); return ret;
}*/ }*/
auto remote_server::fuse_getxtimes( auto remote_server::fuse_getxtimes(const char *path,
const char *path, remote::file_time &bkuptime, remote::file_time &bkuptime,
remote::file_time &crtime) -> packet::error_type { remote::file_time &crtime)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path); const auto api_path = utils::path::create_api_path(path);
@ -657,10 +662,11 @@ auto remote_server::fuse_opendir(const char *path, remote::file_handle &handle)
return ret; return ret;
} }
auto remote_server::fuse_read( auto remote_server::fuse_read(const char *path, char *buffer,
const char *path, char *buffer, const remote::file_size &read_size, const remote::file_size &read_size,
const remote::file_offset &read_offset, const remote::file_offset &read_offset,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
@ -681,8 +687,8 @@ auto remote_server::fuse_read(
return static_cast<packet::error_type>(ret); return static_cast<packet::error_type>(ret);
} }
auto remote_server::fuse_rename(const char *from, auto remote_server::fuse_rename(const char *from, const char *to)
const char *to) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto from_path = utils::path::combine(mount_location_, {from}); const auto from_path = utils::path::combine(mount_location_, {from});
@ -720,8 +726,9 @@ auto remote_server::fuse_readdir(const char *path,
return ret; return ret;
} }
auto remote_server::fuse_release( auto remote_server::fuse_release(const char *path,
const char *path, const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
packet::error_type ret = 0; packet::error_type ret = 0;
@ -738,8 +745,9 @@ auto remote_server::fuse_release(
return ret; return ret;
} }
auto remote_server::fuse_releasedir( auto remote_server::fuse_releasedir(const char *path,
const char *path, const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
@ -784,8 +792,9 @@ auto remote_server::fuse_setattr_x(const char *path, remote::setattr_x &attr)
return ret; return ret;
} }
auto remote_server::fuse_setbkuptime( auto remote_server::fuse_setbkuptime(const char *path,
const char *path, const remote::file_time &bkuptime) -> packet::error_type { const remote::file_time &bkuptime)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path); const auto api_path = utils::path::create_api_path(path);
@ -804,8 +813,9 @@ auto remote_server::fuse_setbkuptime(
return ret; return ret;
} }
auto remote_server::fuse_setchgtime( auto remote_server::fuse_setchgtime(const char *path,
const char *path, const remote::file_time &chgtime) -> packet::error_type { const remote::file_time &chgtime)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path); const auto api_path = utils::path::create_api_path(path);
@ -824,8 +834,9 @@ auto remote_server::fuse_setchgtime(
return ret; return ret;
} }
auto remote_server::fuse_setcrtime( auto remote_server::fuse_setcrtime(const char *path,
const char *path, const remote::file_time &crtime) -> packet::error_type { const remote::file_time &crtime)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path); const auto api_path = utils::path::create_api_path(path);
@ -916,8 +927,9 @@ auto remote_server::fuse_statfs_x(const char *path, std::uint64_t bsize,
return 0; return 0;
} }
auto remote_server::fuse_truncate( auto remote_server::fuse_truncate(const char *path,
const char *path, const remote::file_offset &size) -> packet::error_type { const remote::file_offset &size)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
@ -938,8 +950,8 @@ auto remote_server::fuse_unlink(const char *path) -> packet::error_type {
} }
auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv, auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
std::uint64_t op0, std::uint64_t op0, std::uint64_t op1)
std::uint64_t op1) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
@ -966,10 +978,11 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
return ret; return ret;
} }
auto remote_server::fuse_write( auto remote_server::fuse_write(const char *path, const char *buffer,
const char *path, const char *buffer, const remote::file_size &write_size, const remote::file_size &write_size,
const remote::file_offset &write_offset, const remote::file_offset &write_offset,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
@ -999,8 +1012,8 @@ auto remote_server::fuse_write_base64(
} }
// WinFSP Layer // WinFSP Layer
auto remote_server::winfsp_can_delete(PVOID file_desc, auto remote_server::winfsp_can_delete(PVOID file_desc, PWSTR file_name)
PWSTR file_name) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_name); const auto relative_path = utils::string::to_utf8(file_name);
@ -1025,8 +1038,8 @@ auto remote_server::winfsp_can_delete(PVOID file_desc,
} }
auto remote_server::winfsp_cleanup(PVOID /*file_desc*/, PWSTR file_name, auto remote_server::winfsp_cleanup(PVOID /*file_desc*/, PWSTR file_name,
UINT32 flags, UINT32 flags, BOOLEAN &was_deleted)
BOOLEAN &was_deleted) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_name); const auto relative_path = utils::string::to_utf8(file_name);
@ -1103,8 +1116,8 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, UINT32 attributes, UINT32 granted_access, UINT32 attributes,
UINT64 /*allocation_size*/, PVOID *file_desc, UINT64 /*allocation_size*/, PVOID *file_desc,
remote::file_info *file_info, remote::file_info *file_info,
std::string &normalized_name, std::string &normalized_name, BOOLEAN &exists)
BOOLEAN &exists) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_name); const auto relative_path = utils::string::to_utf8(file_name);
@ -1176,8 +1189,9 @@ auto remote_server::winfsp_flush(PVOID file_desc, remote::file_info *file_info)
return ret; return ret;
} }
auto remote_server::winfsp_get_file_info( auto remote_server::winfsp_get_file_info(PVOID file_desc,
PVOID file_desc, remote::file_info *file_info) -> packet::error_type { remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto handle = reinterpret_cast<remote::file_handle>(file_desc); const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
@ -1220,9 +1234,10 @@ auto remote_server::winfsp_get_security_by_name(
return ret; return ret;
} }
auto remote_server::winfsp_get_volume_info( auto remote_server::winfsp_get_volume_info(UINT64 &total_size,
UINT64 &total_size, UINT64 &free_size, UINT64 &free_size,
std::string &volume_label) -> packet::error_type { std::string &volume_label)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
drive_.get_volume_info(total_size, free_size, volume_label); drive_.get_volume_info(total_size, free_size, volume_label);
@ -1239,10 +1254,11 @@ auto remote_server::winfsp_mounted(const std::wstring &location)
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
auto remote_server::winfsp_open( auto remote_server::winfsp_open(PWSTR file_name, UINT32 create_options,
PWSTR file_name, UINT32 create_options, UINT32 granted_access, UINT32 granted_access, PVOID *file_desc,
PVOID *file_desc, remote::file_info *file_info, remote::file_info *file_info,
std::string &normalized_name) -> packet::error_type { std::string &normalized_name)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_name); const auto relative_path = utils::string::to_utf8(file_name);
@ -1283,10 +1299,11 @@ auto remote_server::winfsp_open(
return ret; return ret;
} }
auto remote_server::winfsp_overwrite( auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
PVOID file_desc, UINT32 attributes, BOOLEAN replace_attributes, BOOLEAN replace_attributes,
UINT64 /*allocation_size*/, UINT64 /*allocation_size*/,
remote::file_info *file_info) -> packet::error_type { remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto handle = reinterpret_cast<remote::file_handle>(file_desc); const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
@ -1402,9 +1419,10 @@ auto remote_server::winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/,
return ret; return ret;
} }
auto remote_server::winfsp_rename( auto remote_server::winfsp_rename(PVOID /*file_desc*/, PWSTR file_name,
PVOID /*file_desc*/, PWSTR file_name, PWSTR new_file_name, PWSTR new_file_name,
BOOLEAN replace_if_exists) -> packet::error_type { BOOLEAN replace_if_exists)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_name); const auto relative_path = utils::string::to_utf8(file_name);
@ -1498,9 +1516,10 @@ auto remote_server::winfsp_set_basic_info(
return ret; return ret;
} }
auto remote_server::winfsp_set_file_size( auto remote_server::winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
PVOID file_desc, UINT64 new_size, BOOLEAN set_allocation_size, BOOLEAN set_allocation_size,
remote::file_info *file_info) -> packet::error_type { remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto handle = reinterpret_cast<remote::file_handle>(file_desc); const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
@ -1536,10 +1555,12 @@ auto remote_server::winfsp_unmounted(const std::wstring &location)
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
auto remote_server::winfsp_write( auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length, UINT32 length, BOOLEAN write_to_end,
BOOLEAN write_to_end, BOOLEAN constrained_io, PUINT32 bytes_transferred, BOOLEAN constrained_io,
remote::file_info *file_info) -> packet::error_type { PUINT32 bytes_transferred,
remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
*bytes_transferred = 0; *bytes_transferred = 0;
@ -1587,8 +1608,9 @@ auto remote_server::winfsp_write(
return ret; return ret;
} }
auto remote_server::json_create_directory_snapshot( auto remote_server::json_create_directory_snapshot(const std::string &path,
const std::string &path, json &json_data) -> packet::error_type { json &json_data)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path); const auto api_path = utils::path::create_api_path(path);
@ -1647,8 +1669,8 @@ auto remote_server::json_read_directory_snapshot(
} }
auto remote_server::json_release_directory_snapshot( auto remote_server::json_release_directory_snapshot(
const std::string &path, const std::string &path, const remote::file_handle &handle)
const remote::file_handle &handle) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path); const auto file_path = construct_path(path);

View File

@ -32,19 +32,11 @@
#include "version.hpp" #include "version.hpp"
namespace repertory::remote_winfsp { namespace repertory::remote_winfsp {
#define RAISE_REMOTE_WINFSP_CLIENT_EVENT(func, file, ret) \
if (config_.get_enable_drive_events() && \
(((config_.get_event_level() >= remote_winfsp_client_event::level) && \
((ret) != STATUS_SUCCESS)) || \
(config_.get_event_level() >= event_level::trace))) \
event_system::instance().raise<remote_winfsp_client_event>( \
std::string{func}, file, ret)
remote_client::remote_client(const app_config &config) remote_client::remote_client(const app_config &config)
: config_(config), packet_client_(config.get_remote_config()) {} : config_(config), packet_client_(config.get_remote_config()) {}
auto remote_client::winfsp_can_delete(PVOID file_desc, auto remote_client::winfsp_can_delete(PVOID file_desc, PWSTR file_name)
PWSTR file_name) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
packet request; packet request;
@ -56,14 +48,12 @@ auto remote_client::winfsp_can_delete(PVOID file_desc,
packet_client_.send(function_name, request, service_flags), packet_client_.send(function_name, request, service_flags),
}; };
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
function_name,
utils::path::create_api_path(utils::string::to_utf8(file_name)), ret);
return ret; return ret;
} }
auto remote_client::json_create_directory_snapshot( auto remote_client::json_create_directory_snapshot(const std::string &path,
const std::string &path, json &json_data) -> packet::error_type { json &json_data)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
packet request; packet request;
@ -78,7 +68,6 @@ auto remote_client::json_create_directory_snapshot(
ret = packet::decode_json(response, json_data); ret = packet::decode_json(response, json_data);
} }
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, path, ret);
return ret; return ret;
} }
@ -101,13 +90,12 @@ auto remote_client::json_read_directory_snapshot(
ret = packet::decode_json(response, json_data); ret = packet::decode_json(response, json_data);
} }
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, path, ret);
return ret; return ret;
} }
auto remote_client::json_release_directory_snapshot( auto remote_client::json_release_directory_snapshot(
const std::string &path, const std::string &path, const remote::file_handle &handle)
const remote::file_handle &handle) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
packet request; packet request;
@ -119,13 +107,12 @@ auto remote_client::json_release_directory_snapshot(
packet_client_.send(function_name, request, service_flags), packet_client_.send(function_name, request, service_flags),
}; };
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, path, ret);
return ret; return ret;
} }
auto remote_client::winfsp_cleanup(PVOID file_desc, PWSTR file_name, auto remote_client::winfsp_cleanup(PVOID file_desc, PWSTR file_name,
UINT32 flags, UINT32 flags, BOOLEAN &was_deleted)
BOOLEAN &was_deleted) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto handle{ auto handle{
@ -154,7 +141,6 @@ auto remote_client::winfsp_cleanup(PVOID file_desc, PWSTR file_name,
remove_all(file_path); remove_all(file_path);
} }
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, file_path, ret);
return ret; return ret;
} }
@ -179,7 +165,6 @@ auto remote_client::winfsp_close(PVOID file_desc) -> packet::error_type {
if ((ret == STATUS_SUCCESS) || if ((ret == STATUS_SUCCESS) ||
(ret == static_cast<packet::error_type>(STATUS_INVALID_HANDLE))) { (ret == static_cast<packet::error_type>(STATUS_INVALID_HANDLE))) {
remove_open_info(handle); remove_open_info(handle);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, file_path, ret);
} }
} }
@ -190,8 +175,8 @@ auto remote_client::winfsp_create(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, UINT32 attributes, UINT32 granted_access, UINT32 attributes,
UINT64 allocation_size, PVOID *file_desc, UINT64 allocation_size, PVOID *file_desc,
remote::file_info *file_info, remote::file_info *file_info,
std::string &normalized_name, std::string &normalized_name, BOOLEAN &exists)
BOOLEAN &exists) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
packet request; packet request;
@ -230,8 +215,6 @@ auto remote_client::winfsp_create(PWSTR file_name, UINT32 create_options,
} }
} }
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
function_name, get_open_file_path(to_handle(*file_desc)), ret);
return ret; return ret;
} }
@ -249,8 +232,6 @@ auto remote_client::winfsp_flush(PVOID file_desc, remote::file_info *file_info)
}; };
DECODE_OR_IGNORE(&response, *file_info); DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
function_name, get_open_file_path(to_handle(file_desc)), ret);
return ret; return ret;
} }
@ -265,8 +246,9 @@ auto remote_client::winfsp_get_dir_buffer([[maybe_unused]] PVOID file_desc,
return static_cast<packet::error_type>(STATUS_INVALID_HANDLE); return static_cast<packet::error_type>(STATUS_INVALID_HANDLE);
} }
auto remote_client::winfsp_get_file_info( auto remote_client::winfsp_get_file_info(PVOID file_desc,
PVOID file_desc, remote::file_info *file_info) -> packet::error_type { remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
packet request; packet request;
@ -279,14 +261,14 @@ auto remote_client::winfsp_get_file_info(
}; };
DECODE_OR_IGNORE(&response, *file_info); DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
function_name, get_open_file_path(to_handle(file_desc)), ret);
return ret; return ret;
} }
auto remote_client::winfsp_get_security_by_name( auto remote_client::winfsp_get_security_by_name(PWSTR file_name,
PWSTR file_name, PUINT32 attributes, std::uint64_t *descriptor_size, PUINT32 attributes,
std::wstring &string_descriptor) -> packet::error_type { std::uint64_t *descriptor_size,
std::wstring &string_descriptor)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
packet request; packet request;
@ -311,14 +293,13 @@ auto remote_client::winfsp_get_security_by_name(
DECODE_OR_IGNORE(&response, *attributes); DECODE_OR_IGNORE(&response, *attributes);
} }
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name,
utils::string::to_utf8(file_name), ret);
return ret; return ret;
} }
auto remote_client::winfsp_get_volume_info( auto remote_client::winfsp_get_volume_info(UINT64 &total_size,
UINT64 &total_size, UINT64 &free_size, UINT64 &free_size,
std::string &volume_label) -> packet::error_type { std::string &volume_label)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
packet request; packet request;
@ -352,14 +333,14 @@ auto remote_client::winfsp_mounted(const std::wstring &location)
}; };
event_system::instance().raise<drive_mounted>(function_name, mount_location); event_system::instance().raise<drive_mounted>(function_name, mount_location);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, mount_location, ret);
return ret; return ret;
} }
auto remote_client::winfsp_open( auto remote_client::winfsp_open(PWSTR file_name, UINT32 create_options,
PWSTR file_name, UINT32 create_options, UINT32 granted_access, UINT32 granted_access, PVOID *file_desc,
PVOID *file_desc, remote::file_info *file_info, remote::file_info *file_info,
std::string &normalized_name) -> packet::error_type { std::string &normalized_name)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
packet request; packet request;
@ -390,15 +371,14 @@ auto remote_client::winfsp_open(
} }
} }
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
function_name, get_open_file_path(to_handle(*file_desc)), ret);
return ret; return ret;
} }
auto remote_client::winfsp_overwrite( auto remote_client::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
PVOID file_desc, UINT32 attributes, BOOLEAN replace_attributes, BOOLEAN replace_attributes,
UINT64 allocation_size, UINT64 allocation_size,
remote::file_info *file_info) -> packet::error_type { remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
packet request; packet request;
@ -414,8 +394,6 @@ auto remote_client::winfsp_overwrite(
}; };
DECODE_OR_IGNORE(&response, *file_info); DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
function_name, get_open_file_path(to_handle(file_desc)), ret);
return ret; return ret;
} }
@ -439,17 +417,12 @@ auto remote_client::winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
ret = response.decode(buffer, *bytes_transferred); ret = response.decode(buffer, *bytes_transferred);
#if defined(_WIN32) #if defined(_WIN32)
if ((ret == STATUS_SUCCESS) && if ((ret == STATUS_SUCCESS) &&
(not *bytes_transferred || (*bytes_transferred != length))) { (not*bytes_transferred || (*bytes_transferred != length))) {
::SetLastError(ERROR_HANDLE_EOF); ::SetLastError(ERROR_HANDLE_EOF);
} }
#endif #endif
} }
if (ret != STATUS_SUCCESS) {
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
function_name, get_open_file_path(to_handle(file_desc)), ret);
}
return ret; return ret;
} }
@ -472,14 +445,13 @@ auto remote_client::winfsp_read_directory(PVOID file_desc, PWSTR pattern,
ret = packet::decode_json(response, item_list); ret = packet::decode_json(response, item_list);
} }
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
function_name, get_open_file_path(to_handle(file_desc)), ret);
return ret; return ret;
} }
auto remote_client::winfsp_rename( auto remote_client::winfsp_rename(PVOID file_desc, PWSTR file_name,
PVOID file_desc, PWSTR file_name, PWSTR new_file_name, PWSTR new_file_name,
BOOLEAN replace_if_exists) -> packet::error_type { BOOLEAN replace_if_exists)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
packet request; packet request;
@ -493,11 +465,6 @@ auto remote_client::winfsp_rename(
packet_client_.send(function_name, request, service_flags), packet_client_.send(function_name, request, service_flags),
}; };
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
function_name,
utils::path::create_api_path(utils::string::to_utf8(file_name)) + "|" +
utils::path::create_api_path(utils::string::to_utf8(new_file_name)),
ret);
return ret; return ret;
} }
@ -522,14 +489,13 @@ auto remote_client::winfsp_set_basic_info(
}; };
DECODE_OR_IGNORE(&response, *file_info); DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
function_name, get_open_file_path(to_handle(file_desc)), ret);
return ret; return ret;
} }
auto remote_client::winfsp_set_file_size( auto remote_client::winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
PVOID file_desc, UINT64 new_size, BOOLEAN set_allocation_size, BOOLEAN set_allocation_size,
remote::file_info *file_info) -> packet::error_type { remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
packet request; packet request;
@ -544,8 +510,6 @@ auto remote_client::winfsp_set_file_size(
}; };
DECODE_OR_IGNORE(&response, *file_info); DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
function_name, get_open_file_path(to_handle(file_desc)), ret);
return ret; return ret;
} }
@ -557,7 +521,7 @@ auto remote_client::winfsp_unmounted(const std::wstring &location)
utils::string::to_utf8(location), utils::string::to_utf8(location),
}; };
event_system::instance().raise<drive_unmount_pending>(function_name, event_system::instance().raise<drive_unmount_pending>(function_name,
mount_location); mount_location);
packet request; packet request;
request.encode(location); request.encode(location);
@ -566,16 +530,17 @@ auto remote_client::winfsp_unmounted(const std::wstring &location)
packet_client_.send(function_name, request, service_flags), packet_client_.send(function_name, request, service_flags),
}; };
event_system::instance().raise<drive_unmounted>(function_name, event_system::instance().raise<drive_unmounted>(function_name,
mount_location); mount_location);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, mount_location, ret);
return ret; return ret;
} }
auto remote_client::winfsp_write( auto remote_client::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length, UINT32 length, BOOLEAN write_to_end,
BOOLEAN write_to_end, BOOLEAN constrained_io, PUINT32 bytes_transferred, BOOLEAN constrained_io,
remote::file_info *file_info) -> packet::error_type { PUINT32 bytes_transferred,
remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
packet request; packet request;
@ -596,10 +561,6 @@ auto remote_client::winfsp_write(
DECODE_OR_IGNORE(&response, *bytes_transferred); DECODE_OR_IGNORE(&response, *bytes_transferred);
DECODE_OR_IGNORE(&response, *file_info); DECODE_OR_IGNORE(&response, *file_info);
if (ret != STATUS_SUCCESS) {
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
function_name, get_open_file_path(to_handle(file_desc)), ret);
}
return ret; return ret;
} }

View File

@ -33,6 +33,7 @@
#include "drives/remote/remote_open_file_table.hpp" #include "drives/remote/remote_open_file_table.hpp"
#include "drives/winfsp/remotewinfsp/i_remote_instance.hpp" #include "drives/winfsp/remotewinfsp/i_remote_instance.hpp"
#include "events/event_system.hpp" #include "events/event_system.hpp"
#include "events/types/remote_server_event.hpp"
#include "platform/platform.hpp" #include "platform/platform.hpp"
#include "types/remote.hpp" #include "types/remote.hpp"
#include "types/repertory.hpp" #include "types/repertory.hpp"
@ -41,15 +42,15 @@
#include "utils/file_utils.hpp" #include "utils/file_utils.hpp"
#include "utils/path.hpp" #include "utils/path.hpp"
#include "utils/time.hpp" #include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory::remote_winfsp { namespace repertory::remote_winfsp {
#define RAISE_REMOTE_WINFSP_SERVER_EVENT(func, file, ret) \ #define RAISE_REMOTE_WINFSP_SERVER_EVENT(func, file, ret) \
if (config_.get_enable_drive_events() && \ if (config_.get_enable_drive_events() && \
(((config_.get_event_level() >= remote_winfsp_server_event::level) && \ (((config_.get_event_level() >= remote_server_event::level) && \
((ret) != STATUS_SUCCESS)) || \ ((ret) != STATUS_SUCCESS)) || \
(config_.get_event_level() >= event_level::trace))) \ (config_.get_event_level() >= event_level::trace))) \
event_system::instance().raise<remote_winfsp_server_event>( \ event_system::instance().raise<remote_server_event>(file, ret, func)
std::string{func}, file, ret)
auto remote_server::get_next_handle() -> std::uint64_t { auto remote_server::get_next_handle() -> std::uint64_t {
if (++next_handle_ == 0U) { if (++next_handle_ == 0U) {
@ -141,9 +142,10 @@ auto remote_server::fuse_chmod(const char *path,
return ret; return ret;
} }
auto remote_server::fuse_chown( auto remote_server::fuse_chown(const char *path,
const char *path, const remote::user_id & /*uid*/, const remote::user_id & /*uid*/,
const remote::group_id & /*gid*/) -> packet::error_type { const remote::group_id & /*gid*/)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = construct_path(path); auto file_path = construct_path(path);
@ -171,9 +173,10 @@ construct_path(path); auto res = HasOpenFileCompatInfo(handle, EBADF); if (res
return ret; return ret;
}*/ }*/
auto remote_server::fuse_fgetattr( auto remote_server::fuse_fgetattr(const char *path, remote::stat &r_stat,
const char *path, remote::stat &r_stat, bool &directory, bool &directory,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
r_stat = {}; r_stat = {};
@ -185,7 +188,7 @@ auto remote_server::fuse_fgetattr(
}; };
if (res == 0) { if (res == 0) {
directory = utils::file::directory(file_path).exists(); directory = utils::file::directory(file_path).exists();
struct _stat64 unix_st {}; struct _stat64 unix_st{};
res = _fstat64(static_cast<int>(handle), &unix_st); res = _fstat64(static_cast<int>(handle), &unix_st);
if (res == 0) { if (res == 0) {
populate_stat(path, directory, r_stat, unix_st); populate_stat(path, directory, r_stat, unix_st);
@ -197,9 +200,10 @@ auto remote_server::fuse_fgetattr(
return ret; return ret;
} }
auto remote_server::fuse_fsetattr_x( auto remote_server::fuse_fsetattr_x(const char *path,
const char *path, const remote::setattr_x & /*attr*/, const remote::setattr_x & /*attr*/,
const remote::file_handle & /*handle*/) -> packet::error_type { const remote::file_handle & /*handle*/)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = construct_path(path); auto file_path = construct_path(path);
@ -208,9 +212,10 @@ auto remote_server::fuse_fsetattr_x(
return ret; return ret;
} }
auto remote_server::fuse_fsync( auto remote_server::fuse_fsync(const char *path,
const char *path, const std::int32_t & /*datasync*/, const std::int32_t & /*datasync*/,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = construct_path(path); auto file_path = construct_path(path);
@ -237,9 +242,10 @@ auto remote_server::fuse_fsync(
return ret; return ret;
} }
auto remote_server::fuse_ftruncate( auto remote_server::fuse_ftruncate(const char *path,
const char *path, const remote::file_offset &size, const remote::file_offset &size,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = construct_path(path); auto file_path = construct_path(path);
@ -279,7 +285,7 @@ auto remote_server::fuse_getattr(const char *path, remote::stat &r_st,
directory = utils::file::directory(file_path).exists(); directory = utils::file::directory(file_path).exists();
struct _stat64 st1 {}; struct _stat64 st1{};
auto res{ auto res{
_stat64(file_path.c_str(), &st1), _stat64(file_path.c_str(), &st1),
}; };
@ -305,9 +311,10 @@ STATUS_NOT_IMPLEMENTED; RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name,
file_path, ret); return ret; file_path, ret); return ret;
}*/ }*/
auto remote_server::fuse_getxtimes( auto remote_server::fuse_getxtimes(const char *path,
const char *path, remote::file_time & /*bkuptime*/, remote::file_time & /*bkuptime*/,
remote::file_time & /*crtime*/) -> packet::error_type { remote::file_time & /*crtime*/)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = construct_path(path); auto file_path = construct_path(path);
@ -438,10 +445,11 @@ auto remote_server::fuse_open(const char *path, const remote::open_flags &flags,
return ret; return ret;
} }
auto remote_server::fuse_read( auto remote_server::fuse_read(const char *path, char *buffer,
const char *path, char *buffer, const remote::file_size &read_size, const remote::file_size &read_size,
const remote::file_offset &read_offset, const remote::file_offset &read_offset,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = construct_path(path); auto file_path = construct_path(path);
@ -472,8 +480,8 @@ auto remote_server::fuse_read(
return ret; return ret;
} }
auto remote_server::fuse_rename(const char *from, auto remote_server::fuse_rename(const char *from, const char *to)
const char *to) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto from_path = utils::path::combine(mount_location_, {from}); auto from_path = utils::path::combine(mount_location_, {from});
@ -488,10 +496,11 @@ auto remote_server::fuse_rename(const char *from,
return ret; return ret;
} }
auto remote_server::fuse_write( auto remote_server::fuse_write(const char *path, const char *buffer,
const char *path, const char *buffer, const remote::file_size &write_size, const remote::file_size &write_size,
const remote::file_offset &write_offset, const remote::file_offset &write_offset,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = construct_path(path); auto file_path = construct_path(path);
@ -558,8 +567,9 @@ auto remote_server::fuse_readdir(const char *path,
return ret; return ret;
} }
auto remote_server::fuse_release( auto remote_server::fuse_release(const char *path,
const char *path, const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = construct_path(path); auto file_path = construct_path(path);
@ -603,8 +613,9 @@ auto remote_server::fuse_rmdir(const char *path) -> packet::error_type {
return ret; return ret;
} }
auto remote_server::fuse_setattr_x( auto remote_server::fuse_setattr_x(const char *path,
const char *path, remote::setattr_x & /*attr*/) -> packet::error_type { remote::setattr_x & /*attr*/)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = construct_path(path); auto file_path = construct_path(path);
@ -716,8 +727,9 @@ auto remote_server::fuse_statfs_x(const char *path, std::uint64_t bsize,
return 0; return 0;
} }
auto remote_server::fuse_truncate( auto remote_server::fuse_truncate(const char *path,
const char *path, const remote::file_offset &size) -> packet::error_type { const remote::file_offset &size)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = construct_path(path); auto file_path = construct_path(path);
@ -764,8 +776,8 @@ auto remote_server::fuse_unlink(const char *path) -> packet::error_type {
} }
auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv, auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
std::uint64_t op0, std::uint64_t op0, std::uint64_t op1)
std::uint64_t op1) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = construct_path(path); auto file_path = construct_path(path);
@ -824,8 +836,9 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
} }
// JSON Layer // JSON Layer
auto remote_server::json_create_directory_snapshot( auto remote_server::json_create_directory_snapshot(const std::string &path,
const std::string &path, json &json_data) -> packet::error_type { json &json_data)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = construct_path(path); auto file_path = construct_path(path);
@ -883,8 +896,8 @@ auto remote_server::json_read_directory_snapshot(
} }
auto remote_server::json_release_directory_snapshot( auto remote_server::json_release_directory_snapshot(
const std::string &path, const std::string &path, const remote::file_handle & /*handle*/)
const remote::file_handle & /*handle*/) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = construct_path(path); auto file_path = construct_path(path);
@ -915,8 +928,8 @@ auto remote_server::winfsp_can_delete(PVOID file_desc, PWSTR /*file_name*/)
} }
auto remote_server::winfsp_cleanup(PVOID file_desc, PWSTR /*file_name*/, auto remote_server::winfsp_cleanup(PVOID file_desc, PWSTR /*file_name*/,
UINT32 flags, UINT32 flags, BOOLEAN &was_deleted)
BOOLEAN &was_deleted) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = get_open_file_path(file_desc); auto file_path = get_open_file_path(file_desc);
@ -953,8 +966,8 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, UINT32 attributes, UINT32 granted_access, UINT32 attributes,
UINT64 /*allocation_size*/, PVOID *file_desc, UINT64 /*allocation_size*/, PVOID *file_desc,
remote::file_info *file_info, remote::file_info *file_info,
std::string &normalized_name, std::string &normalized_name, BOOLEAN &exists)
BOOLEAN &exists) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = utils::string::from_utf8(utils::path::combine( auto file_path = utils::string::from_utf8(utils::path::combine(
@ -1022,8 +1035,9 @@ auto remote_server::winfsp_flush(PVOID file_desc, remote::file_info *file_info)
return ret; return ret;
} }
auto remote_server::winfsp_get_file_info( auto remote_server::winfsp_get_file_info(PVOID file_desc,
PVOID file_desc, remote::file_info *file_info) -> packet::error_type { remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto *handle = reinterpret_cast<HANDLE>(file_desc); auto *handle = reinterpret_cast<HANDLE>(file_desc);
@ -1037,9 +1051,11 @@ auto remote_server::winfsp_get_file_info(
return ret; return ret;
} }
auto remote_server::winfsp_get_security_by_name( auto remote_server::winfsp_get_security_by_name(PWSTR file_name,
PWSTR file_name, PUINT32 attributes, std::uint64_t *descriptor_size, PUINT32 attributes,
std::wstring &string_descriptor) -> packet::error_type { std::uint64_t *descriptor_size,
std::wstring &string_descriptor)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = utils::string::from_utf8(utils::path::combine( auto file_path = utils::string::from_utf8(utils::path::combine(
@ -1078,9 +1094,10 @@ auto remote_server::winfsp_get_security_by_name(
return ret; return ret;
} }
auto remote_server::winfsp_get_volume_info( auto remote_server::winfsp_get_volume_info(UINT64 &total_size,
UINT64 &total_size, UINT64 &free_size, UINT64 &free_size,
std::string &volume_label) -> packet::error_type { std::string &volume_label)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
drive_.get_volume_info(total_size, free_size, volume_label); drive_.get_volume_info(total_size, free_size, volume_label);
@ -1097,10 +1114,11 @@ auto remote_server::winfsp_mounted(const std::wstring &location)
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
auto remote_server::winfsp_open( auto remote_server::winfsp_open(PWSTR file_name, UINT32 create_options,
PWSTR file_name, UINT32 create_options, UINT32 granted_access, UINT32 granted_access, PVOID *file_desc,
PVOID *file_desc, remote::file_info *file_info, remote::file_info *file_info,
std::string &normalized_name) -> packet::error_type { std::string &normalized_name)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto file_path = utils::string::from_utf8(utils::path::combine( auto file_path = utils::string::from_utf8(utils::path::combine(
@ -1136,10 +1154,11 @@ auto remote_server::winfsp_open(
return ret; return ret;
} }
auto remote_server::winfsp_overwrite( auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
PVOID file_desc, UINT32 attributes, BOOLEAN replace_attributes, BOOLEAN replace_attributes,
UINT64 /*allocation_size*/, UINT64 /*allocation_size*/,
remote::file_info *file_info) -> packet::error_type { remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto *handle = reinterpret_cast<HANDLE>(file_desc); auto *handle = reinterpret_cast<HANDLE>(file_desc);
@ -1240,9 +1259,10 @@ auto remote_server::winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/,
return ret; return ret;
} }
auto remote_server::winfsp_rename( auto remote_server::winfsp_rename(PVOID /*file_desc*/, PWSTR file_name,
PVOID /*file_desc*/, PWSTR file_name, PWSTR new_file_name, PWSTR new_file_name,
BOOLEAN replace_if_exists) -> packet::error_type { BOOLEAN replace_if_exists)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto from_path = utils::string::from_utf8(utils::path::combine( auto from_path = utils::string::from_utf8(utils::path::combine(
@ -1293,9 +1313,10 @@ auto remote_server::winfsp_set_basic_info(
return ret; return ret;
} }
auto remote_server::winfsp_set_file_size( auto remote_server::winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
PVOID file_desc, UINT64 new_size, BOOLEAN set_allocation_size, BOOLEAN set_allocation_size,
remote::file_info *file_info) -> packet::error_type { remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto *handle = reinterpret_cast<HANDLE>(file_desc); auto *handle = reinterpret_cast<HANDLE>(file_desc);
@ -1338,10 +1359,12 @@ auto remote_server::winfsp_unmounted(const std::wstring &location)
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
auto remote_server::winfsp_write( auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length, UINT32 length, BOOLEAN /*write_to_end*/,
BOOLEAN /*write_to_end*/, BOOLEAN constrained_io, PUINT32 bytes_transferred, BOOLEAN constrained_io,
remote::file_info *file_info) -> packet::error_type { PUINT32 bytes_transferred,
remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto *handle = reinterpret_cast<HANDLE>(file_desc); auto *handle = reinterpret_cast<HANDLE>(file_desc);

View File

@ -77,8 +77,8 @@ auto remote_winfsp_drive::winfsp_service::OnStart(ULONG, PWSTR *) -> NTSTATUS {
} }
if (ret != STATUS_SUCCESS) { if (ret != STATUS_SUCCESS) {
event_system::instance().raise<drive_mount_failed>(function_name, event_system::instance().raise<drive_mount_failed>(ret, function_name,
mount_location, ret); mount_location);
if (not lock_.set_mount_state(false, "", -1)) { if (not lock_.set_mount_state(false, "", -1)) {
utils::error::raise_error(function_name, "failed to set mount state"); utils::error::raise_error(function_name, "failed to set mount state");
} }
@ -105,7 +105,7 @@ remote_winfsp_drive::remote_winfsp_drive(app_config &config,
config_(config), config_(config),
lock_(lock), lock_(lock),
factory_(std::move(factory)) { factory_(std::move(factory)) {
E_SUBSCRIBE_EXACT(unmount_requested, [this](const unmount_requested &) { E_SUBSCRIBE(unmount_requested, [this](const unmount_requested &) {
std::thread([this]() { this->shutdown(); }).detach(); std::thread([this]() { this->shutdown(); }).detach();
}); });
} }
@ -129,8 +129,8 @@ auto remote_winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, UINT32 attributes, UINT32 granted_access, UINT32 attributes,
PSECURITY_DESCRIPTOR /*descriptor*/, PSECURITY_DESCRIPTOR /*descriptor*/,
UINT64 allocation_size, PVOID * /*file_node*/, UINT64 allocation_size, PVOID * /*file_node*/,
PVOID *file_desc, PVOID *file_desc, OpenFileInfo *ofi)
OpenFileInfo *ofi) -> NTSTATUS { -> NTSTATUS {
remote::file_info fi{}; remote::file_info fi{};
std::string normalized_name; std::string normalized_name;
BOOLEAN exists = 0; BOOLEAN exists = 0;
@ -164,9 +164,10 @@ auto remote_winfsp_drive::GetFileInfo(PVOID /*file_node*/, PVOID file_desc,
return ret; return ret;
} }
auto remote_winfsp_drive::GetSecurityByName( auto remote_winfsp_drive::GetSecurityByName(PWSTR file_name, PUINT32 attributes,
PWSTR file_name, PUINT32 attributes, PSECURITY_DESCRIPTOR descriptor, PSECURITY_DESCRIPTOR descriptor,
SIZE_T *descriptor_size) -> NTSTATUS { SIZE_T *descriptor_size)
-> NTSTATUS {
std::wstring string_descriptor; std::wstring string_descriptor;
std::uint64_t sds = (descriptor_size == nullptr) ? 0 : *descriptor_size; std::uint64_t sds = (descriptor_size == nullptr) ? 0 : *descriptor_size;
auto ret = remote_instance_->winfsp_get_security_by_name( auto ret = remote_instance_->winfsp_get_security_by_name(
@ -262,7 +263,7 @@ auto remote_winfsp_drive::mount(const std::vector<std::string> &drive_args)
auto ret = winfsp_service(lock_, *this, parsed_drive_args, config_).Run(); auto ret = winfsp_service(lock_, *this, parsed_drive_args, config_).Run();
event_system::instance().raise<drive_mount_result>(function_name, "", event_system::instance().raise<drive_mount_result>(function_name, "",
std::to_string(ret)); std::to_string(ret));
event_system::instance().stop(); event_system::instance().stop();
c.reset(); c.reset();
return static_cast<int>(ret); return static_cast<int>(ret);
@ -286,8 +287,8 @@ auto remote_winfsp_drive::Mounted(PVOID host) -> NTSTATUS {
auto remote_winfsp_drive::Open(PWSTR file_name, UINT32 create_options, auto remote_winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, PVOID * /*file_node*/, UINT32 granted_access, PVOID * /*file_node*/,
PVOID *file_desc, PVOID *file_desc, OpenFileInfo *ofi)
OpenFileInfo *ofi) -> NTSTATUS { -> NTSTATUS {
remote::file_info fi{}; remote::file_info fi{};
std::string normalize_name; std::string normalize_name;
auto ret = auto ret =
@ -307,8 +308,8 @@ auto remote_winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
auto remote_winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc, auto remote_winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc,
UINT32 attributes, UINT32 attributes,
BOOLEAN replace_attributes, BOOLEAN replace_attributes,
UINT64 allocation_size, UINT64 allocation_size, FileInfo *file_info)
FileInfo *file_info) -> NTSTATUS { -> NTSTATUS {
remote::file_info info{}; remote::file_info info{};
auto ret = remote_instance_->winfsp_overwrite( auto ret = remote_instance_->winfsp_overwrite(
file_desc, attributes, replace_attributes, allocation_size, &info); file_desc, attributes, replace_attributes, allocation_size, &info);
@ -425,8 +426,8 @@ auto remote_winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
UINT32 attributes, UINT64 creation_time, UINT32 attributes, UINT64 creation_time,
UINT64 last_access_time, UINT64 last_access_time,
UINT64 last_write_time, UINT64 last_write_time,
UINT64 change_time, UINT64 change_time, FileInfo *file_info)
FileInfo *file_info) -> NTSTATUS { -> NTSTATUS {
remote::file_info fi{}; remote::file_info fi{};
auto ret = remote_instance_->winfsp_set_basic_info( auto ret = remote_instance_->winfsp_set_basic_info(
file_desc, attributes, creation_time, last_access_time, last_write_time, file_desc, attributes, creation_time, last_access_time, last_write_time,
@ -478,8 +479,8 @@ VOID remote_winfsp_drive::Unmounted(PVOID host) {
auto remote_winfsp_drive::Write(PVOID /*file_node*/, PVOID file_desc, auto remote_winfsp_drive::Write(PVOID /*file_node*/, PVOID file_desc,
PVOID buffer, UINT64 offset, ULONG length, PVOID buffer, UINT64 offset, ULONG length,
BOOLEAN write_to_end, BOOLEAN constrained_io, BOOLEAN write_to_end, BOOLEAN constrained_io,
PULONG bytes_transferred, PULONG bytes_transferred, FileInfo *file_info)
FileInfo *file_info) -> NTSTATUS { -> NTSTATUS {
remote::file_info fi{}; remote::file_info fi{};
auto ret = remote_instance_->winfsp_write( auto ret = remote_instance_->winfsp_write(
file_desc, buffer, offset, length, write_to_end, constrained_io, file_desc, buffer, offset, length, write_to_end, constrained_io,

View File

@ -31,9 +31,11 @@
#include "events/types/drive_mount_failed.hpp" #include "events/types/drive_mount_failed.hpp"
#include "events/types/drive_mount_result.hpp" #include "events/types/drive_mount_result.hpp"
#include "events/types/drive_mounted.hpp" #include "events/types/drive_mounted.hpp"
#include "events/types/drive_stop_timed_out.hpp"
#include "events/types/drive_unmount_pending.hpp" #include "events/types/drive_unmount_pending.hpp"
#include "events/types/drive_unmounted.hpp" #include "events/types/drive_unmounted.hpp"
#include "events/types/unmount_requested.hpp" #include "events/types/unmount_requested.hpp"
#include "events/types/winfsp_event.hpp"
#include "platform/platform.hpp" #include "platform/platform.hpp"
#include "providers/i_provider.hpp" #include "providers/i_provider.hpp"
#include "types/repertory.hpp" #include "types/repertory.hpp"
@ -52,9 +54,9 @@ namespace repertory {
#define RAISE_WINFSP_EVENT(func, file, ret) \ #define RAISE_WINFSP_EVENT(func, file, ret) \
if (config_.get_enable_drive_events() && \ if (config_.get_enable_drive_events() && \
(((config_.get_event_level() >= winfsp_event::level) && \ (((config_.get_event_level() >= winfsp_event::level) && \
(ret != STATUS_SUCCESS)) || \ ((ret) != STATUS_SUCCESS)) || \
(config_.get_event_level() >= event_level::trace))) \ (config_.get_event_level() >= event_level::trace))) \
event_system::instance().raise<winfsp_event>(std::string{func}, file, ret) event_system::instance().raise<winfsp_event>(file, ret, func)
winfsp_drive::winfsp_service::winfsp_service( winfsp_drive::winfsp_service::winfsp_service(
lock_data &lock, winfsp_drive &drive, std::vector<std::string> drive_args, lock_data &lock, winfsp_drive &drive, std::vector<std::string> drive_args,
@ -88,8 +90,8 @@ auto winfsp_drive::handle_error(std::string_view function_name,
return ret; return ret;
} }
auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/, auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/, PWSTR * /*Argv*/)
PWSTR * /*Argv*/) -> NTSTATUS { -> NTSTATUS {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto mount_location = utils::string::to_lower( auto mount_location = utils::string::to_lower(
@ -125,8 +127,8 @@ auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/,
utils::error::raise_error(function_name, ret, "failed to set mount state"); utils::error::raise_error(function_name, ret, "failed to set mount state");
} }
event_system::instance().raise<drive_mount_failed>(function_name, event_system::instance().raise<drive_mount_failed>(ret, function_name,
mount_location, ret); mount_location);
return ret; return ret;
} }
@ -136,7 +138,7 @@ auto winfsp_drive::winfsp_service::OnStop() -> NTSTATUS {
timeout stop_timeout( timeout stop_timeout(
[]() { []() {
event_system::instance().raise<drive_stop_timed_out>(); event_system::instance().raise<drive_stop_timed_out>(function_name);
app_config::set_stop_requested(); app_config::set_stop_requested();
}, },
30s); 30s);
@ -154,7 +156,7 @@ auto winfsp_drive::winfsp_service::OnStop() -> NTSTATUS {
winfsp_drive::winfsp_drive(app_config &config, lock_data &lock, winfsp_drive::winfsp_drive(app_config &config, lock_data &lock,
i_provider &provider) i_provider &provider)
: provider_(provider), config_(config), lock_(lock) { : provider_(provider), config_(config), lock_(lock) {
E_SUBSCRIBE_EXACT(unmount_requested, [this](const unmount_requested &) { E_SUBSCRIBE(unmount_requested, [this](const unmount_requested &) {
std::thread([this]() { this->shutdown(); }).detach(); std::thread([this]() { this->shutdown(); }).detach();
}); });
} }
@ -468,9 +470,10 @@ auto winfsp_drive::get_item_meta(const std::string &api_path,
return ret; return ret;
} }
auto winfsp_drive::get_security_by_name( auto winfsp_drive::get_security_by_name(PWSTR file_name, PUINT32 attributes,
PWSTR file_name, PUINT32 attributes, PSECURITY_DESCRIPTOR descriptor, PSECURITY_DESCRIPTOR descriptor,
std::uint64_t *descriptor_size) -> NTSTATUS { std::uint64_t *descriptor_size)
-> NTSTATUS {
auto api_path = auto api_path =
utils::path::create_api_path(utils::string::to_utf8(file_name)); utils::path::create_api_path(utils::string::to_utf8(file_name));
@ -730,8 +733,8 @@ auto winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
auto winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc, auto winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc,
UINT32 attributes, BOOLEAN replace_attributes, UINT32 attributes, BOOLEAN replace_attributes,
UINT64 /*allocation_size*/, UINT64 /*allocation_size*/, FileInfo *file_info)
FileInfo *file_info) -> NTSTATUS { -> NTSTATUS {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
std::string api_path; std::string api_path;
@ -837,8 +840,8 @@ void winfsp_drive::populate_file_info(std::uint64_t file_size,
} }
auto winfsp_drive::Read(PVOID /*file_node*/, PVOID file_desc, PVOID buffer, auto winfsp_drive::Read(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
UINT64 offset, ULONG length, UINT64 offset, ULONG length, PULONG bytes_transferred)
PULONG bytes_transferred) -> NTSTATUS { -> NTSTATUS {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
*bytes_transferred = 0U; *bytes_transferred = 0U;
@ -893,8 +896,8 @@ auto winfsp_drive::Read(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc, auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
PWSTR /*pattern*/, PWSTR marker, PVOID buffer, PWSTR /*pattern*/, PWSTR marker, PVOID buffer,
ULONG buffer_length, ULONG buffer_length, PULONG bytes_transferred)
PULONG bytes_transferred) -> NTSTATUS { -> NTSTATUS {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
std::string api_path; std::string api_path;
@ -1050,8 +1053,8 @@ auto winfsp_drive::Rename(PVOID /*file_node*/, PVOID /*file_desc*/,
auto winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc, auto winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
UINT32 attributes, UINT64 creation_time, UINT32 attributes, UINT64 creation_time,
UINT64 last_access_time, UINT64 last_write_time, UINT64 last_access_time, UINT64 last_write_time,
UINT64 change_time, UINT64 change_time, FileInfo *file_info)
FileInfo *file_info) -> NTSTATUS { -> NTSTATUS {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
std::string api_path; std::string api_path;
@ -1195,6 +1198,7 @@ void winfsp_drive::stop_all() {
}); });
if (future.wait_for(30s) == std::future_status::timeout) { if (future.wait_for(30s) == std::future_status::timeout) {
event_system::instance().raise<drive_stop_timed_out>(function_name);
app_config::set_stop_requested(); app_config::set_stop_requested();
future.wait(); future.wait();
} }

View File

@ -62,14 +62,14 @@ console_consumer::console_consumer(event_level level) {
set_level(level); set_level(level);
E_SUBSCRIBE_ALL(process_event2); E_SUBSCRIBE_ALL(process_event);
E_SUBSCRIBE_EXACT(event_level_changed, E_SUBSCRIBE(event_level_changed,
[](auto &&event) { set_level(event.level); }); [](auto &&event) { set_level(event.new_level); });
} }
console_consumer::~console_consumer() { E_CONSUMER_RELEASE(); } console_consumer::~console_consumer() { E_CONSUMER_RELEASE(); }
void console_consumer::process_event2(const i_event &evt) { void console_consumer::process_event(const i_event &evt) {
switch (evt.get_event_level()) { switch (evt.get_event_level()) {
case event_level::critical: case event_level::critical:
spdlog::get("console")->critical(evt.get_single_line()); spdlog::get("console")->critical(evt.get_single_line());

View File

@ -66,14 +66,14 @@ logging_consumer::logging_consumer(event_level level,
set_level(level); set_level(level);
E_SUBSCRIBE_ALL(process_event2); E_SUBSCRIBE_ALL(process_event);
E_SUBSCRIBE_EXACT(event_level_changed, E_SUBSCRIBE(event_level_changed,
[](auto &&event) { set_level(event.level); }); [](auto &&event) { set_level(event.new_level); });
} }
logging_consumer::~logging_consumer() { E_CONSUMER_RELEASE(); } logging_consumer::~logging_consumer() { E_CONSUMER_RELEASE(); }
void logging_consumer::process_event2(const i_event &evt) { void logging_consumer::process_event(const i_event &evt) {
switch (evt.get_event_level()) { switch (evt.get_event_level()) {
case event_level::critical: case event_level::critical:
spdlog::get("file")->critical(evt.get_single_line()); spdlog::get("file")->critical(evt.get_single_line());

View File

@ -23,6 +23,8 @@
#include "app_config.hpp" #include "app_config.hpp"
#include "events/event_system.hpp" #include "events/event_system.hpp"
#include "events/types/invalid_cache_size.hpp"
#include "events/types/max_cache_size_reached.hpp"
#include "types/startup_exception.hpp" #include "types/startup_exception.hpp"
#include "utils/file_utils.hpp" #include "utils/file_utils.hpp"
@ -30,6 +32,8 @@ namespace repertory {
cache_size_mgr cache_size_mgr::instance_{}; cache_size_mgr cache_size_mgr::instance_{};
auto cache_size_mgr::expand(std::uint64_t size) -> api_error { auto cache_size_mgr::expand(std::uint64_t size) -> api_error {
REPERTORY_USES_FUNCTION_NAME();
unique_mutex_lock lock(mtx_); unique_mutex_lock lock(mtx_);
if (cfg_ == nullptr) { if (cfg_ == nullptr) {
@ -53,8 +57,8 @@ auto cache_size_mgr::expand(std::uint64_t size) -> api_error {
while (not get_stop_requested() && cache_size_ > max_cache_size && while (not get_stop_requested() && cache_size_ > max_cache_size &&
cache_dir.count() > 1U) { cache_dir.count() > 1U) {
if (last_cache_size != cache_size_) { if (last_cache_size != cache_size_) {
event_system::instance().raise<max_cache_size_reached>(cache_size_, event_system::instance().raise<max_cache_size_reached>(
max_cache_size); cache_size_, function_name, max_cache_size);
last_cache_size = cache_size_; last_cache_size = cache_size_;
} }
notify_.wait_for(lock, cache_wait_secs); notify_.wait_for(lock, cache_wait_secs);
@ -93,6 +97,8 @@ void cache_size_mgr::initialize(app_config *cfg) {
} }
auto cache_size_mgr::shrink(std::uint64_t size) -> api_error { auto cache_size_mgr::shrink(std::uint64_t size) -> api_error {
REPERTORY_USES_FUNCTION_NAME();
mutex_lock lock(mtx_); mutex_lock lock(mtx_);
if (size == 0U) { if (size == 0U) {
notify_.notify_all(); notify_.notify_all();
@ -102,7 +108,8 @@ auto cache_size_mgr::shrink(std::uint64_t size) -> api_error {
if (cache_size_ >= size) { if (cache_size_ >= size) {
cache_size_ -= size; cache_size_ -= size;
} else { } else {
event_system::instance().raise<invalid_cache_size>(cache_size_, size); event_system::instance().raise<invalid_cache_size>(cache_size_,
function_name, size);
cache_size_ = 0U; cache_size_ = 0U;
} }

View File

@ -23,12 +23,19 @@
#include "app_config.hpp" #include "app_config.hpp"
#include "db/file_mgr_db.hpp" #include "db/file_mgr_db.hpp"
#include "events/types/download_restore_failed.hpp"
#include "events/types/download_restored.hpp"
#include "events/types/download_resume_add_failed.hpp"
#include "events/types/download_resume_added.hpp"
#include "events/types/download_resume_removed.hpp"
#include "events/types/download_type_selected.hpp"
#include "events/types/file_upload_failed.hpp" #include "events/types/file_upload_failed.hpp"
#include "events/types/file_upload_not_found.hpp" #include "events/types/file_upload_not_found.hpp"
#include "events/types/file_upload_queued.hpp" #include "events/types/file_upload_queued.hpp"
#include "events/types/file_upload_removed.hpp" #include "events/types/file_upload_removed.hpp"
#include "events/types/file_upload_retry.hpp" #include "events/types/file_upload_retry.hpp"
#include "events/types/filesystem_item_evicted.hpp" #include "events/types/filesystem_item_evicted.hpp"
#include "events/types/item_timeout.hpp"
#include "events/types/service_start_begin.hpp" #include "events/types/service_start_begin.hpp"
#include "events/types/service_start_end.hpp" #include "events/types/service_start_end.hpp"
#include "events/types/service_stop_begin.hpp" #include "events/types/service_stop_begin.hpp"
@ -58,8 +65,8 @@ file_manager::file_manager(app_config &config, i_provider &provider)
return; return;
} }
E_SUBSCRIBE_EXACT(file_upload_completed, E_SUBSCRIBE(file_upload_completed,
[this](auto &&event) { this->upload_completed(event); }); [this](auto &&event) { this->upload_completed(event); });
} }
file_manager::~file_manager() { file_manager::~file_manager() {
@ -100,6 +107,8 @@ auto file_manager::close_all(const std::string &api_path) -> bool {
} }
void file_manager::close_timed_out_files() { void file_manager::close_timed_out_files() {
REPERTORY_USES_FUNCTION_NAME();
unique_recur_mutex_lock file_lock(open_file_mtx_); unique_recur_mutex_lock file_lock(open_file_mtx_);
auto closeable_list = auto closeable_list =
std::accumulate(open_file_lookup_.begin(), open_file_lookup_.end(), std::accumulate(open_file_lookup_.begin(), open_file_lookup_.end(),
@ -118,8 +127,8 @@ void file_manager::close_timed_out_files() {
for (auto &closeable_file : closeable_list) { for (auto &closeable_file : closeable_list) {
closeable_file->close(); closeable_file->close();
event_system::instance().raise<item_timeout>( event_system::instance().raise<item_timeout>(closeable_file->get_api_path(),
closeable_file->get_api_path()); function_name);
} }
closeable_list.clear(); closeable_list.clear();
} }
@ -225,10 +234,9 @@ auto file_manager::get_next_handle() -> std::uint64_t {
auto file_manager::get_open_file_by_handle(std::uint64_t handle) const auto file_manager::get_open_file_by_handle(std::uint64_t handle) const
-> std::shared_ptr<i_closeable_open_file> { -> std::shared_ptr<i_closeable_open_file> {
auto file_iter = auto file_iter =
std::find_if(open_file_lookup_.begin(), open_file_lookup_.end(), std::ranges::find_if(open_file_lookup_, [&handle](auto &&item) -> bool {
[&handle](auto &&item) -> bool { return item.second->has_handle(handle);
return item.second->has_handle(handle); });
});
return (file_iter == open_file_lookup_.end()) ? nullptr : file_iter->second; return (file_iter == open_file_lookup_.end()) ? nullptr : file_iter->second;
} }
@ -394,10 +402,11 @@ auto file_manager::open(const std::string &api_path, bool directory,
return open(api_path, directory, ofd, handle, file, nullptr); return open(api_path, directory, ofd, handle, file, nullptr);
} }
auto file_manager::open( auto file_manager::open(const std::string &api_path, bool directory,
const std::string &api_path, bool directory, const open_file_data &ofd, const open_file_data &ofd, std::uint64_t &handle,
std::uint64_t &handle, std::shared_ptr<i_open_file> &file, std::shared_ptr<i_open_file> &file,
std::shared_ptr<i_closeable_open_file> closeable_file) -> api_error { std::shared_ptr<i_closeable_open_file> closeable_file)
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto create_and_add_handle = const auto create_and_add_handle =
@ -497,7 +506,7 @@ auto file_manager::open(
: preferred_type); : preferred_type);
if (not directory) { if (not directory) {
event_system::instance().raise<download_type_selected>( event_system::instance().raise<download_type_selected>(
fsi.api_path, fsi.source_path, type); fsi.api_path, fsi.source_path, function_name, type);
} }
switch (type) { switch (type) {
@ -596,6 +605,8 @@ void file_manager::remove_resume(const std::string &api_path,
void file_manager::remove_resume(const std::string &api_path, void file_manager::remove_resume(const std::string &api_path,
const std::string &source_path, bool no_lock) { const std::string &source_path, bool no_lock) {
REPERTORY_USES_FUNCTION_NAME();
if (provider_.is_read_only()) { if (provider_.is_read_only()) {
return; return;
} }
@ -606,8 +617,8 @@ void file_manager::remove_resume(const std::string &api_path,
} }
if (mgr_db_->remove_resume(api_path)) { if (mgr_db_->remove_resume(api_path)) {
event_system::instance().raise<download_resume_removed>(api_path, event_system::instance().raise<download_resume_removed>(
source_path); api_path, source_path, function_name);
} }
if (not no_lock) { if (not no_lock) {
@ -769,8 +780,8 @@ auto file_manager::rename_directory(const std::string &from_api_path,
} }
auto file_manager::rename_file(const std::string &from_api_path, auto file_manager::rename_file(const std::string &from_api_path,
const std::string &to_api_path, const std::string &to_api_path, bool overwrite)
bool overwrite) -> api_error { -> api_error {
if (not provider_.is_rename_supported()) { if (not provider_.is_rename_supported()) {
return api_error::not_implemented; return api_error::not_implemented;
} }
@ -876,15 +887,18 @@ void file_manager::start() {
if (res != api_error::success) { if (res != api_error::success) {
event_system::instance().raise<download_restore_failed>( event_system::instance().raise<download_restore_failed>(
entry.api_path, entry.source_path, entry.api_path, entry.source_path,
"failed to get filesystem item|" + api_error_to_string(res)); fmt::format("failed to get filesystem item|{}",
api_error_to_string(res)),
function_name);
continue; continue;
} }
if (entry.source_path != fsi.source_path) { if (entry.source_path != fsi.source_path) {
event_system::instance().raise<download_restore_failed>( event_system::instance().raise<download_restore_failed>(
fsi.api_path, fsi.source_path, fsi.api_path, fsi.source_path,
"source path mismatch|expected|" + entry.source_path + "|actual|" + fmt::format("source path mismatch|expected|{}|actual|{}",
fsi.source_path); entry.source_path, fsi.source_path),
function_name);
continue; continue;
} }
@ -892,8 +906,9 @@ void file_manager::start() {
if (not opt_size.has_value()) { if (not opt_size.has_value()) {
event_system::instance().raise<download_restore_failed>( event_system::instance().raise<download_restore_failed>(
fsi.api_path, fsi.source_path, fsi.api_path, fsi.source_path,
"failed to get file size: " + fmt::format("failed to get file size|{}",
std::to_string(utils::get_last_error_code())); utils::get_last_error_code()),
function_name);
continue; continue;
} }
@ -901,8 +916,9 @@ void file_manager::start() {
if (file_size != fsi.size) { if (file_size != fsi.size) {
event_system::instance().raise<download_restore_failed>( event_system::instance().raise<download_restore_failed>(
fsi.api_path, fsi.source_path, fsi.api_path, fsi.source_path,
"file size mismatch|expected|" + std::to_string(fsi.size) + fmt::format("file size mismatch|expected|{}|actual|{}", fsi.size,
"|actual|" + std::to_string(file_size)); file_size),
function_name);
continue; continue;
} }
@ -913,8 +929,8 @@ void file_manager::start() {
: 0U, : 0U,
fsi, provider_, entry.read_state, *this); fsi, provider_, entry.read_state, *this);
open_file_lookup_[entry.api_path] = closeable_file; open_file_lookup_[entry.api_path] = closeable_file;
event_system::instance().raise<download_restored>(fsi.api_path, event_system::instance().raise<download_restored>(
fsi.source_path); fsi.api_path, fsi.source_path, function_name);
} catch (const std::exception &ex) { } catch (const std::exception &ex) {
utils::error::raise_error(function_name, ex, "query error"); utils::error::raise_error(function_name, ex, "query error");
} }
@ -972,6 +988,8 @@ void file_manager::stop() {
} }
void file_manager::store_resume(const i_open_file &file) { void file_manager::store_resume(const i_open_file &file) {
REPERTORY_USES_FUNCTION_NAME();
if (provider_.is_read_only()) { if (provider_.is_read_only()) {
return; return;
} }
@ -983,12 +1001,13 @@ void file_manager::store_resume(const i_open_file &file) {
file.get_source_path(), file.get_source_path(),
})) { })) {
event_system::instance().raise<download_resume_added>( event_system::instance().raise<download_resume_added>(
file.get_api_path(), file.get_source_path()); file.get_api_path(), file.get_source_path(), function_name);
return; return;
} }
event_system::instance().raise<download_resume_add_failed>( event_system::instance().raise<download_resume_add_failed>(
file.get_api_path(), file.get_source_path(), "failed to store resume"); file.get_api_path(), file.get_source_path(), "failed to store resume",
function_name);
} }
void file_manager::swap_renamed_items(std::string from_api_path, void file_manager::swap_renamed_items(std::string from_api_path,

View File

@ -32,6 +32,7 @@
#include "utils/error_utils.hpp" #include "utils/error_utils.hpp"
#include "utils/file_utils.hpp" #include "utils/file_utils.hpp"
#include "utils/path.hpp" #include "utils/path.hpp"
#include "utils/string.hpp"
#include "utils/unix.hpp" #include "utils/unix.hpp"
namespace repertory { namespace repertory {

View File

@ -27,6 +27,7 @@
#include "events/types/filesystem_item_added.hpp" #include "events/types/filesystem_item_added.hpp"
#include "providers/i_provider.hpp" #include "providers/i_provider.hpp"
#include "utils/error_utils.hpp" #include "utils/error_utils.hpp"
#include "utils/string.hpp"
namespace repertory { namespace repertory {
auto lock_data::get_mount_state(const provider_type & /*pt*/, json &mount_state) auto lock_data::get_mount_state(const provider_type & /*pt*/, json &mount_state)

View File

@ -69,8 +69,8 @@ void base_provider::add_all_items(stop_type &stop_requested) {
} }
auto base_provider::create_api_file(std::string path, std::string key, auto base_provider::create_api_file(std::string path, std::string key,
std::uint64_t size, std::uint64_t size, std::uint64_t file_time)
std::uint64_t file_time) -> api_file { -> api_file {
api_file file{}; api_file file{};
file.api_path = utils::path::create_api_path(path); file.api_path = utils::path::create_api_path(path);
file.api_parent = utils::path::get_parent_api_path(file.api_path); file.api_parent = utils::path::get_parent_api_path(file.api_path);
@ -102,8 +102,8 @@ auto base_provider::create_api_file(std::string path, std::uint64_t size,
} }
auto base_provider::create_directory_clone_source_meta( auto base_provider::create_directory_clone_source_meta(
const std::string &source_api_path, const std::string &source_api_path, const std::string &api_path)
const std::string &api_path) -> api_error { -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
bool exists{}; bool exists{};
@ -201,8 +201,8 @@ auto base_provider::create_directory(const std::string &api_path,
return api_error::error; return api_error::error;
} }
auto base_provider::create_file(const std::string &api_path, auto base_provider::create_file(const std::string &api_path, api_meta_map &meta)
api_meta_map &meta) -> api_error { -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -259,8 +259,9 @@ auto base_provider::create_file(const std::string &api_path,
return api_error::error; return api_error::error;
} }
auto base_provider::get_api_path_from_source( auto base_provider::get_api_path_from_source(const std::string &source_path,
const std::string &source_path, std::string &api_path) const -> api_error { std::string &api_path) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (source_path.empty()) { if (source_path.empty()) {
@ -273,8 +274,9 @@ auto base_provider::get_api_path_from_source(
return db3_->get_api_path(source_path, api_path); return db3_->get_api_path(source_path, api_path);
} }
auto base_provider::get_directory_items( auto base_provider::get_directory_items(const std::string &api_path,
const std::string &api_path, directory_item_list &list) const -> api_error { directory_item_list &list) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -308,11 +310,15 @@ auto base_provider::get_directory_items(
"..", "..",
"", "",
true, true,
0U,
{},
}); });
list.insert(list.begin(), directory_item{ list.insert(list.begin(), directory_item{
".", ".",
"", "",
true, true,
0U,
{},
}); });
return api_error::success; return api_error::success;
} }
@ -338,9 +344,10 @@ auto base_provider::get_file_size(const std::string &api_path,
return api_error::success; return api_error::success;
} }
auto base_provider::get_filesystem_item( auto base_provider::get_filesystem_item(const std::string &api_path,
const std::string &api_path, bool directory, bool directory,
filesystem_item &fsi) const -> api_error { filesystem_item &fsi) const
-> api_error {
bool exists{}; bool exists{};
auto res = is_directory(api_path, exists); auto res = is_directory(api_path, exists);
if (res != api_error::success) { if (res != api_error::success) {
@ -373,9 +380,10 @@ auto base_provider::get_filesystem_item(
return api_error::success; return api_error::success;
} }
auto base_provider::get_filesystem_item_and_file( auto base_provider::get_filesystem_item_and_file(const std::string &api_path,
const std::string &api_path, api_file &file, api_file &file,
filesystem_item &fsi) const -> api_error { filesystem_item &fsi) const
-> api_error {
auto res = get_file(api_path, file); auto res = get_file(api_path, file);
if (res != api_error::success) { if (res != api_error::success) {
return res; return res;
@ -510,7 +518,7 @@ void base_provider::process_removed_files(std::deque<removed_item> removed_list,
'_' + parts[parts.size() - 1U]}); '_' + parts[parts.size() - 1U]});
event_system::instance().raise<orphaned_file_detected>(function_name, event_system::instance().raise<orphaned_file_detected>(function_name,
item.source_path); item.source_path);
if (not utils::file::reset_modified_time(item.source_path)) { if (not utils::file::reset_modified_time(item.source_path)) {
event_system::instance().raise<orphaned_file_processing_failed>( event_system::instance().raise<orphaned_file_processing_failed>(
orphaned_file, orphaned_file,
@ -536,8 +544,8 @@ void base_provider::process_removed_files(std::deque<removed_item> removed_list,
} }
db3_->remove_api_path(item.api_path); db3_->remove_api_path(item.api_path);
event_system::instance().raise<file_removed_externally>(item.api_path, event_system::instance().raise<file_removed_externally>(
item.source_path); item.api_path, function_name, item.source_path);
} }
} }
@ -630,7 +638,7 @@ auto base_provider::remove_file(const std::string &api_path) -> api_error {
event_system::instance().raise<file_removed>(api_path, function_name); event_system::instance().raise<file_removed>(api_path, function_name);
} else { } else {
event_system::instance().raise<file_remove_failed>(api_path, error, event_system::instance().raise<file_remove_failed>(api_path, error,
function_name); function_name);
} }
return error; return error;
@ -677,10 +685,10 @@ auto base_provider::remove_directory(const std::string &api_path) -> api_error {
const auto notify_end = [&api_path](api_error error) -> api_error { const auto notify_end = [&api_path](api_error error) -> api_error {
if (error == api_error::success) { if (error == api_error::success) {
event_system::instance().raise<directory_removed>(api_path, event_system::instance().raise<directory_removed>(api_path,
function_name); function_name);
} else { } else {
event_system::instance().raise<directory_remove_failed>(api_path, error, event_system::instance().raise<directory_remove_failed>(api_path, error,
function_name); function_name);
} }
return error; return error;
}; };
@ -822,7 +830,7 @@ auto base_provider::start(api_item_added_callback api_item_added,
polling::instance().set_callback({ polling::instance().set_callback({
"check_deleted", "check_deleted",
polling::frequency::low, polling::frequency::low,
[this](auto &&stop_requested) { remove_deleted_items(stop_requested); }, [this](auto &&stop) { remove_deleted_items(stop); },
}); });
return true; return true;

View File

@ -45,9 +45,10 @@ namespace repertory {
encrypt_provider::encrypt_provider(app_config &config) encrypt_provider::encrypt_provider(app_config &config)
: config_(config), encrypt_config_(config.get_encrypt_config()) {} : config_(config), encrypt_config_(config.get_encrypt_config()) {}
auto encrypt_provider::create_api_file( auto encrypt_provider::create_api_file(const std::string &api_path,
const std::string &api_path, bool directory, bool directory,
const std::string &source_path) -> api_file { const std::string &source_path)
-> api_file {
auto times{utils::file::get_times(source_path)}; auto times{utils::file::get_times(source_path)};
if (not times.has_value()) { if (not times.has_value()) {
throw std::runtime_error("failed to get file times"); throw std::runtime_error("failed to get file times");
@ -73,10 +74,10 @@ auto encrypt_provider::create_api_file(
void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory, void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory,
const api_file &file) { const api_file &file) {
#if defined(_WIN32) #if defined(_WIN32)
struct _stat64 buf {}; struct _stat64 buf{};
_stat64(file.source_path.c_str(), &buf); _stat64(file.source_path.c_str(), &buf);
#else // !defined(_WIN32) #else // !defined(_WIN32)
struct stat buf {}; struct stat buf{};
stat(file.source_path.c_str(), &buf); stat(file.source_path.c_str(), &buf);
#endif // defined(_WIN32) #endif // defined(_WIN32)
@ -156,8 +157,9 @@ auto encrypt_provider::do_fs_operation(
return callback(cfg, source_path); return callback(cfg, source_path);
} }
auto encrypt_provider::get_api_path_from_source( auto encrypt_provider::get_api_path_from_source(const std::string &source_path,
const std::string &source_path, std::string &api_path) const -> api_error { std::string &api_path) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -197,8 +199,9 @@ auto encrypt_provider::get_directory_item_count(
return count; return count;
} }
auto encrypt_provider::get_directory_items( auto encrypt_provider::get_directory_items(const std::string &api_path,
const std::string &api_path, directory_item_list &list) const -> api_error { directory_item_list &list) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
return do_fs_operation( return do_fs_operation(
@ -331,8 +334,9 @@ auto encrypt_provider::get_file(const std::string &api_path,
return api_error::error; return api_error::error;
} }
auto encrypt_provider::get_file_list( auto encrypt_provider::get_file_list(api_file_list &list,
api_file_list &list, std::string & /* marker */) const -> api_error { std::string & /* marker */) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto &cfg{get_encrypt_config()}; const auto &cfg{get_encrypt_config()};
@ -355,8 +359,9 @@ auto encrypt_provider::get_file_list(
return api_error::error; return api_error::error;
} }
auto encrypt_provider::get_file_size( auto encrypt_provider::get_file_size(const std::string &api_path,
const std::string &api_path, std::uint64_t &file_size) const -> api_error { std::uint64_t &file_size) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -377,9 +382,10 @@ auto encrypt_provider::get_file_size(
return api_error::error; return api_error::error;
} }
auto encrypt_provider::get_filesystem_item( auto encrypt_provider::get_filesystem_item(const std::string &api_path,
const std::string &api_path, bool directory, bool directory,
filesystem_item &fsi) const -> api_error { filesystem_item &fsi) const
-> api_error {
std::string source_path; std::string source_path;
if (directory) { if (directory) {
auto result{db_->get_directory_source_path(api_path, source_path)}; auto result{db_->get_directory_source_path(api_path, source_path)};
@ -430,9 +436,10 @@ auto encrypt_provider::get_filesystem_item_from_source_path(
return get_filesystem_item(api_path, false, fsi); return get_filesystem_item(api_path, false, fsi);
} }
auto encrypt_provider::get_filesystem_item_and_file( auto encrypt_provider::get_filesystem_item_and_file(const std::string &api_path,
const std::string &api_path, api_file &file, api_file &file,
filesystem_item &fsi) const -> api_error { filesystem_item &fsi) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -558,8 +565,8 @@ auto encrypt_provider::is_directory(const std::string &api_path,
return api_error::error; return api_error::error;
} }
auto encrypt_provider::is_file(const std::string &api_path, auto encrypt_provider::is_file(const std::string &api_path, bool &exists) const
bool &exists) const -> api_error { -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -854,7 +861,7 @@ void encrypt_provider::remove_deleted_files(stop_type &stop_requested) {
} }
event_system::instance().raise<file_removed_externally>( event_system::instance().raise<file_removed_externally>(
item.api_path, item.source_path); item.api_path, function_name, item.source_path);
} }
}, },
get_stop_requested); get_stop_requested);

View File

@ -48,8 +48,8 @@ namespace {
return cfg.bucket; return cfg.bucket;
} }
[[nodiscard]] auto [[nodiscard]] auto get_last_modified(const nlohmann::json &obj)
get_last_modified(const nlohmann::json &obj) -> std::uint64_t { -> std::uint64_t {
try { try {
return repertory::s3_provider::convert_api_date( return repertory::s3_provider::convert_api_date(
obj["modTime"].get<std::string>()); obj["modTime"].get<std::string>());
@ -63,8 +63,9 @@ namespace repertory {
sia_provider::sia_provider(app_config &config, i_http_comm &comm) sia_provider::sia_provider(app_config &config, i_http_comm &comm)
: base_provider(config, comm) {} : base_provider(config, comm) {}
auto sia_provider::create_directory_impl( auto sia_provider::create_directory_impl(const std::string &api_path,
const std::string &api_path, api_meta_map & /* meta */) -> api_error { api_meta_map & /* meta */)
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
curl::requests::http_put_file put_file{}; curl::requests::http_put_file put_file{};
@ -138,8 +139,9 @@ auto sia_provider::get_directory_item_count(const std::string &api_path) const
return 0U; return 0U;
} }
auto sia_provider::get_directory_items_impl( auto sia_provider::get_directory_items_impl(const std::string &api_path,
const std::string &api_path, directory_item_list &list) const -> api_error { directory_item_list &list) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
json object_list{}; json object_list{};
@ -197,8 +199,8 @@ auto sia_provider::get_directory_items_impl(
return api_error::success; return api_error::success;
} }
auto sia_provider::get_file(const std::string &api_path, auto sia_provider::get_file(const std::string &api_path, api_file &file) const
api_file &file) const -> api_error { -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -235,8 +237,9 @@ auto sia_provider::get_file(const std::string &api_path,
return api_error::error; return api_error::error;
} }
auto sia_provider::get_file_list( auto sia_provider::get_file_list(api_file_list &list,
api_file_list &list, std::string & /* marker */) const -> api_error { std::string & /* marker */) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
using dir_func = std::function<api_error(std::string api_path)>; using dir_func = std::function<api_error(std::string api_path)>;
@ -440,8 +443,8 @@ auto sia_provider::get_total_drive_space() const -> std::uint64_t {
return 0U; return 0U;
} }
auto sia_provider::is_directory(const std::string &api_path, auto sia_provider::is_directory(const std::string &api_path, bool &exists) const
bool &exists) const -> api_error { -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {
@ -459,11 +462,10 @@ auto sia_provider::is_directory(const std::string &api_path,
} }
exists = object_list.contains("entries") && exists = object_list.contains("entries") &&
std::find_if(object_list.at("entries").begin(), std::ranges::find_if(object_list.at("entries"),
object_list.at("entries").end(), [&api_path](auto &&entry) -> bool {
[&api_path](const auto &entry) -> bool { return entry.at("name") == (api_path + "/");
return entry.at("name") == (api_path + "/"); }) != object_list.at("entries").end();
}) != object_list.at("entries").end();
return api_error::success; return api_error::success;
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
@ -473,8 +475,8 @@ auto sia_provider::is_directory(const std::string &api_path,
return api_error::error; return api_error::error;
} }
auto sia_provider::is_file(const std::string &api_path, auto sia_provider::is_file(const std::string &api_path, bool &exists) const
bool &exists) const -> api_error { -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
try { try {

View File

@ -26,12 +26,10 @@
#include "utils/utils.hpp" #include "utils/utils.hpp"
namespace repertory { namespace repertory {
client::client(rpc_host_info host_info) : host_info_(std::move(host_info)) { client::client(rpc_host_info host_info) : host_info_(std::move(host_info)) {}
request_id_ = 0u;
}
auto client::get_drive_information() -> rpc_response { auto client::get_drive_information() -> rpc_response {
const auto base_url = auto base_url =
"http://" + host_info_.host + ":" + std::to_string(host_info_.port); "http://" + host_info_.host + ":" + std::to_string(host_info_.port);
httplib::Client cli{base_url}; httplib::Client cli{base_url};
@ -39,19 +37,26 @@ auto client::get_drive_information() -> rpc_response {
auto resp = cli.Get("/api/v1/" + rpc_method::get_drive_information); auto resp = cli.Get("/api/v1/" + rpc_method::get_drive_information);
if (resp.error() != httplib::Error::Success) { if (resp.error() != httplib::Error::Success) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", httplib::to_string(resp.error())}}}; rpc_response_type::http_error,
{{"error", httplib::to_string(resp.error())}},
};
} }
if (resp->status != 200) { if (resp->status != http_error_codes::ok) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", std::to_string(resp->status)}}}; rpc_response_type::http_error,
{{"error", std::to_string(resp->status)}},
};
} }
return rpc_response{rpc_response_type::success, json::parse(resp->body)}; return rpc_response{
rpc_response_type::success,
json::parse(resp->body),
};
} }
auto client::get_config() -> rpc_response { auto client::get_config() -> rpc_response {
const auto base_url = auto base_url =
"http://" + host_info_.host + ":" + std::to_string(host_info_.port); "http://" + host_info_.host + ":" + std::to_string(host_info_.port);
httplib::Client cli{base_url}; httplib::Client cli{base_url};
@ -59,19 +64,26 @@ auto client::get_config() -> rpc_response {
auto resp = cli.Get("/api/v1/" + rpc_method::get_config); auto resp = cli.Get("/api/v1/" + rpc_method::get_config);
if (resp.error() != httplib::Error::Success) { if (resp.error() != httplib::Error::Success) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", httplib::to_string(resp.error())}}}; rpc_response_type::http_error,
{{"error", httplib::to_string(resp.error())}},
};
} }
if (resp->status != 200) { if (resp->status != http_error_codes::ok) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", std::to_string(resp->status)}}}; rpc_response_type::http_error,
{{"error", std::to_string(resp->status)}},
};
} }
return rpc_response{rpc_response_type::success, json::parse(resp->body)}; return rpc_response{
rpc_response_type::success,
json::parse(resp->body),
};
} }
auto client::get_config_value_by_name(const std::string &name) -> rpc_response { auto client::get_config_value_by_name(const std::string &name) -> rpc_response {
const auto base_url = auto base_url =
"http://" + host_info_.host + ":" + std::to_string(host_info_.port); "http://" + host_info_.host + ":" + std::to_string(host_info_.port);
httplib::Params params{{"name", name}}; httplib::Params params{{"name", name}};
@ -81,19 +93,26 @@ auto client::get_config_value_by_name(const std::string &name) -> rpc_response {
auto resp = auto resp =
cli.Get("/api/v1/" + rpc_method::get_config_value_by_name, params, {}); cli.Get("/api/v1/" + rpc_method::get_config_value_by_name, params, {});
if (resp.error() != httplib::Error::Success) { if (resp.error() != httplib::Error::Success) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", httplib::to_string(resp.error())}}}; rpc_response_type::http_error,
{{"error", httplib::to_string(resp.error())}},
};
} }
if (resp->status != 200) { if (resp->status != http_error_codes::ok) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", std::to_string(resp->status)}}}; rpc_response_type::http_error,
{{"error", std::to_string(resp->status)}},
};
} }
return rpc_response{rpc_response_type::success, json::parse(resp->body)}; return rpc_response{
rpc_response_type::success,
json::parse(resp->body),
};
} }
auto client::get_directory_items(const std::string &api_path) -> rpc_response { auto client::get_directory_items(const std::string &api_path) -> rpc_response {
const auto base_url = auto base_url =
"http://" + host_info_.host + ":" + std::to_string(host_info_.port); "http://" + host_info_.host + ":" + std::to_string(host_info_.port);
httplib::Params params{{"api_path", api_path}}; httplib::Params params{{"api_path", api_path}};
@ -102,19 +121,26 @@ auto client::get_directory_items(const std::string &api_path) -> rpc_response {
auto resp = cli.Get("/api/v1/" + rpc_method::get_directory_items, params, {}); auto resp = cli.Get("/api/v1/" + rpc_method::get_directory_items, params, {});
if (resp.error() != httplib::Error::Success) { if (resp.error() != httplib::Error::Success) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", httplib::to_string(resp.error())}}}; rpc_response_type::http_error,
{{"error", httplib::to_string(resp.error())}},
};
} }
if (resp->status != 200) { if (resp->status != http_error_codes::ok) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", std::to_string(resp->status)}}}; rpc_response_type::http_error,
{{"error", std::to_string(resp->status)}},
};
} }
return rpc_response{rpc_response_type::success, json::parse(resp->body)}; return rpc_response{
rpc_response_type::success,
json::parse(resp->body),
};
} }
auto client::get_open_files() -> rpc_response { auto client::get_open_files() -> rpc_response {
const auto base_url = auto base_url =
"http://" + host_info_.host + ":" + std::to_string(host_info_.port); "http://" + host_info_.host + ":" + std::to_string(host_info_.port);
httplib::Client cli{base_url}; httplib::Client cli{base_url};
@ -122,19 +148,26 @@ auto client::get_open_files() -> rpc_response {
auto resp = cli.Get("/api/v1/" + rpc_method::get_open_files); auto resp = cli.Get("/api/v1/" + rpc_method::get_open_files);
if (resp.error() != httplib::Error::Success) { if (resp.error() != httplib::Error::Success) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", httplib::to_string(resp.error())}}}; rpc_response_type::http_error,
{{"error", httplib::to_string(resp.error())}},
};
} }
if (resp->status != 200) { if (resp->status != http_error_codes::ok) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", std::to_string(resp->status)}}}; rpc_response_type::http_error,
{{"error", std::to_string(resp->status)}},
};
} }
return rpc_response{rpc_response_type::success, json::parse(resp->body)}; return rpc_response{
rpc_response_type::success,
json::parse(resp->body),
};
} }
auto client::get_pinned_files() -> rpc_response { auto client::get_pinned_files() -> rpc_response {
const auto base_url = auto base_url =
"http://" + host_info_.host + ":" + std::to_string(host_info_.port); "http://" + host_info_.host + ":" + std::to_string(host_info_.port);
httplib::Client cli{base_url}; httplib::Client cli{base_url};
@ -142,19 +175,26 @@ auto client::get_pinned_files() -> rpc_response {
auto resp = cli.Get("/api/v1/" + rpc_method::get_pinned_files); auto resp = cli.Get("/api/v1/" + rpc_method::get_pinned_files);
if (resp.error() != httplib::Error::Success) { if (resp.error() != httplib::Error::Success) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", httplib::to_string(resp.error())}}}; rpc_response_type::http_error,
{{"error", httplib::to_string(resp.error())}},
};
} }
if (resp->status != 200) { if (resp->status != http_error_codes::ok) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", std::to_string(resp->status)}}}; rpc_response_type::http_error,
{{"error", std::to_string(resp->status)}},
};
} }
return rpc_response{rpc_response_type::success, json::parse(resp->body)}; return rpc_response{
rpc_response_type::success,
json::parse(resp->body),
};
} }
auto client::pin_file(const std::string &api_path) -> rpc_response { auto client::pin_file(const std::string &api_path) -> rpc_response {
const auto base_url = auto base_url =
"http://" + host_info_.host + ":" + std::to_string(host_info_.port); "http://" + host_info_.host + ":" + std::to_string(host_info_.port);
httplib::Params params{{"api_path", api_path}}; httplib::Params params{{"api_path", api_path}};
@ -163,19 +203,26 @@ auto client::pin_file(const std::string &api_path) -> rpc_response {
auto resp = cli.Post("/api/v1/" + rpc_method::pin_file, params); auto resp = cli.Post("/api/v1/" + rpc_method::pin_file, params);
if (resp.error() != httplib::Error::Success) { if (resp.error() != httplib::Error::Success) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", httplib::to_string(resp.error())}}}; rpc_response_type::http_error,
{{"error", httplib::to_string(resp.error())}},
};
} }
if (resp->status != 200) { if (resp->status != http_error_codes::ok) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", std::to_string(resp->status)}}}; rpc_response_type::http_error,
{{"error", std::to_string(resp->status)}},
};
} }
return rpc_response{rpc_response_type::success, {}}; return rpc_response{
rpc_response_type::success,
{},
};
} }
auto client::pinned_status(const std::string &api_path) -> rpc_response { auto client::pinned_status(const std::string &api_path) -> rpc_response {
const auto base_url = auto base_url =
"http://" + host_info_.host + ":" + std::to_string(host_info_.port); "http://" + host_info_.host + ":" + std::to_string(host_info_.port);
httplib::Params params{{"api_path", api_path}}; httplib::Params params{{"api_path", api_path}};
@ -184,20 +231,28 @@ auto client::pinned_status(const std::string &api_path) -> rpc_response {
auto resp = cli.Get("/api/v1/" + rpc_method::pinned_status, params, {}); auto resp = cli.Get("/api/v1/" + rpc_method::pinned_status, params, {});
if (resp.error() != httplib::Error::Success) { if (resp.error() != httplib::Error::Success) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", httplib::to_string(resp.error())}}}; rpc_response_type::http_error,
{{"error", httplib::to_string(resp.error())}},
};
} }
if (resp->status != 200) { if (resp->status != http_error_codes::ok) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", std::to_string(resp->status)}}}; rpc_response_type::http_error,
{{"error", std::to_string(resp->status)}},
};
} }
return rpc_response{rpc_response_type::success, json::parse(resp->body)}; return rpc_response{
rpc_response_type::success,
json::parse(resp->body),
};
} }
auto client::set_config_value_by_name( auto client::set_config_value_by_name(const std::string &name,
const std::string &name, const std::string &value) -> rpc_response { const std::string &value)
const auto base_url = -> rpc_response {
auto base_url =
"http://" + host_info_.host + ":" + std::to_string(host_info_.port); "http://" + host_info_.host + ":" + std::to_string(host_info_.port);
httplib::Params params{ httplib::Params params{
@ -211,20 +266,26 @@ auto client::set_config_value_by_name(
auto resp = auto resp =
cli.Post("/api/v1/" + rpc_method::set_config_value_by_name, params); cli.Post("/api/v1/" + rpc_method::set_config_value_by_name, params);
if (resp.error() != httplib::Error::Success) { if (resp.error() != httplib::Error::Success) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", httplib::to_string(resp.error())}}}; rpc_response_type::http_error,
{{"error", httplib::to_string(resp.error())}},
};
} }
if (resp->status != 200) { if (resp->status != http_error_codes::ok) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", std::to_string(resp->status)}}}; rpc_response_type::http_error,
{{"error", std::to_string(resp->status)}},
};
}; };
return rpc_response{rpc_response_type::success, return rpc_response{
nlohmann::json::parse(resp->body)}; rpc_response_type::success,
nlohmann::json::parse(resp->body),
};
} }
auto client::unmount() -> rpc_response { auto client::unmount() -> rpc_response {
const auto base_url = auto base_url =
"http://" + host_info_.host + ":" + std::to_string(host_info_.port); "http://" + host_info_.host + ":" + std::to_string(host_info_.port);
httplib::Client cli{base_url}; httplib::Client cli{base_url};
@ -232,19 +293,26 @@ auto client::unmount() -> rpc_response {
auto resp = cli.Post("/api/v1/" + rpc_method::unmount); auto resp = cli.Post("/api/v1/" + rpc_method::unmount);
if (resp.error() != httplib::Error::Success) { if (resp.error() != httplib::Error::Success) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", httplib::to_string(resp.error())}}}; rpc_response_type::http_error,
{{"error", httplib::to_string(resp.error())}},
};
} }
if (resp->status != 200) { if (resp->status != http_error_codes::ok) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", std::to_string(resp->status)}}}; rpc_response_type::http_error,
{{"error", std::to_string(resp->status)}},
};
} }
return rpc_response{rpc_response_type::success, {}}; return rpc_response{
rpc_response_type::success,
{},
};
} }
auto client::unpin_file(const std::string &api_path) -> rpc_response { auto client::unpin_file(const std::string &api_path) -> rpc_response {
const auto base_url = auto base_url =
"http://" + host_info_.host + ":" + std::to_string(host_info_.port); "http://" + host_info_.host + ":" + std::to_string(host_info_.port);
httplib::Params params{{"api_path", api_path}}; httplib::Params params{{"api_path", api_path}};
@ -253,14 +321,21 @@ auto client::unpin_file(const std::string &api_path) -> rpc_response {
auto resp = cli.Post("/api/v1/" + rpc_method::unpin_file, params); auto resp = cli.Post("/api/v1/" + rpc_method::unpin_file, params);
if (resp.error() != httplib::Error::Success) { if (resp.error() != httplib::Error::Success) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", httplib::to_string(resp.error())}}}; rpc_response_type::http_error,
{{"error", httplib::to_string(resp.error())}},
};
} }
if (resp->status != 200) { if (resp->status != http_error_codes::ok) {
return rpc_response{rpc_response_type::http_error, return rpc_response{
{{"error", std::to_string(resp->status)}}}; rpc_response_type::http_error,
{{"error", std::to_string(resp->status)}},
};
} }
return rpc_response{rpc_response_type::success, {}}; return rpc_response{
rpc_response_type::success,
{},
};
} }
} // namespace repertory } // namespace repertory

View File

@ -164,7 +164,7 @@ void full_server::handle_unpin_file(const httplib::Request &req,
} }
if (exists) { if (exists) {
event_system::instance().raise<file_unpinned>(api_path); event_system::instance().raise<file_unpinned>(api_path, function_name);
} }
res.status = exists ? http_error_codes::ok : http_error_codes::not_found; res.status = exists ? http_error_codes::ok : http_error_codes::not_found;

View File

@ -179,11 +179,8 @@ auto api_error_from_string(std::string_view str) -> api_error {
throw startup_exception("undefined api_error strings"); throw startup_exception("undefined api_error strings");
} }
const auto iter = std::find_if( const auto iter = std::ranges::find_if(
LOOKUP.begin(), LOOKUP.end(), LOOKUP, [&str](auto &&item) -> bool { return item.second == str; });
[&str](const std::pair<api_error, std::string> &item) -> bool {
return item.second == str;
});
return iter == LOOKUP.end() ? api_error::error : iter->first; return iter == LOOKUP.end() ? api_error::error : iter->first;
} }

View File

@ -52,8 +52,8 @@ void get_api_authentication_data(std::string &user, std::string &password,
} }
} }
[[nodiscard]] auto [[nodiscard]] auto get_provider_type_from_args(std::vector<const char *> args)
get_provider_type_from_args(std::vector<const char *> args) -> provider_type { -> provider_type {
if (has_option(args, options::s3_option)) { if (has_option(args, options::s3_option)) {
return provider_type::s3; return provider_type::s3;
} }
@ -67,12 +67,11 @@ get_provider_type_from_args(std::vector<const char *> args) -> provider_type {
return provider_type::sia; return provider_type::sia;
} }
auto has_option(std::vector<const char *> args, auto has_option(std::vector<const char *> args, const std::string &option_name)
const std::string &option_name) -> bool { -> bool {
return std::find_if(args.begin(), args.end(), return std::ranges::find_if(args, [&option_name](auto &&value) -> bool {
[&option_name](const auto &value) -> bool { return option_name == value;
return option_name == value; }) != args.end();
}) != args.end();
} }
auto has_option(std::vector<const char *> args, const option &opt) -> bool { auto has_option(std::vector<const char *> args, const option &opt) -> bool {
@ -80,8 +79,8 @@ auto has_option(std::vector<const char *> args, const option &opt) -> bool {
} }
auto parse_option(std::vector<const char *> args, auto parse_option(std::vector<const char *> args,
const std::string &option_name, const std::string &option_name, std::uint8_t count)
std::uint8_t count) -> std::vector<std::string> { -> std::vector<std::string> {
std::vector<std::string> ret; std::vector<std::string> ret;
auto found{false}; auto found{false};
for (std::size_t i = 0U; not found && (i < args.size()); i++) { for (std::size_t i = 0U; not found && (i < args.size()); i++) {
@ -119,18 +118,18 @@ auto parse_string_option(std::vector<const char *> args, const option &opt,
return ret; return ret;
} }
auto parse_drive_options( auto parse_drive_options(std::vector<const char *> args,
std::vector<const char *> args, [[maybe_unused]] provider_type &prov, [[maybe_unused]] provider_type &prov,
[[maybe_unused]] std::string &data_directory) -> std::vector<std::string> { [[maybe_unused]] std::string &data_directory)
-> std::vector<std::string> {
// Strip out options from command line // Strip out options from command line
const auto &option_list = options::option_list; const auto &option_list = options::option_list;
std::vector<std::string> drive_args; std::vector<std::string> drive_args;
for (std::size_t i = 0U; i < args.size(); i++) { for (std::size_t i = 0U; i < args.size(); i++) {
const auto &arg = args.at(i); const auto &arg = args.at(i);
if (std::find_if(option_list.begin(), option_list.end(), if (std::ranges::find_if(option_list, [&arg](auto &&pair) -> bool {
[&arg](const auto &pair) -> bool { return ((pair.at(0U) == arg) || (pair.at(1U) == arg));
return ((pair.at(0U) == arg) || (pair.at(1U) == arg)); }) == option_list.end()) {
}) == option_list.end()) {
drive_args.emplace_back(args.at(i)); drive_args.emplace_back(args.at(i));
continue; continue;
} }

View File

@ -21,11 +21,9 @@
*/ */
#include "utils/timeout.hpp" #include "utils/timeout.hpp"
#include "types/repertory.hpp"
namespace repertory { namespace repertory {
timeout::timeout(std::function<void()> timeout_callback, timeout::timeout(std::function<void()> timeout_callback,
const std::chrono::system_clock::duration &duration) std::chrono::system_clock::duration duration)
: timeout_killed_(duration == 0s) { : timeout_killed_(duration == 0s) {
if (timeout_killed_) { if (timeout_killed_) {
return; return;

View File

@ -22,11 +22,16 @@
#include "test_common.hpp" #include "test_common.hpp"
#include "app_config.hpp" #include "app_config.hpp"
#include "events/types/download_restored.hpp"
#include "events/types/download_resume_added.hpp"
#include "events/types/download_resume_removed.hpp"
#include "events/types/file_upload_completed.hpp" #include "events/types/file_upload_completed.hpp"
#include "events/types/file_upload_queued.hpp"
#include "events/types/filesystem_item_closed.hpp" #include "events/types/filesystem_item_closed.hpp"
#include "events/types/filesystem_item_handle_closed.hpp" #include "events/types/filesystem_item_handle_closed.hpp"
#include "events/types/filesystem_item_handle_opened.hpp" #include "events/types/filesystem_item_handle_opened.hpp"
#include "events/types/filesystem_item_opened.hpp" #include "events/types/filesystem_item_opened.hpp"
#include "events/types/item_timeout.hpp"
#include "events/types/service_start_begin.hpp" #include "events/types/service_start_begin.hpp"
#include "events/types/service_start_end.hpp" #include "events/types/service_start_end.hpp"
#include "events/types/service_stop_begin.hpp" #include "events/types/service_stop_begin.hpp"
@ -130,7 +135,7 @@ TEST_F(file_manager_test, can_create_and_close_file) {
mgr.start(); mgr.start();
event_capture capture({ event_capture capture({
"item_timeout", item_timeout::name,
filesystem_item_opened::name, filesystem_item_opened::name,
filesystem_item_handle_opened::name, filesystem_item_handle_opened::name,
filesystem_item_handle_closed::name, filesystem_item_handle_closed::name,
@ -196,23 +201,19 @@ TEST_F(file_manager_test, can_create_and_close_file) {
event_consumer ec3(filesystem_item_closed::name, [&](const i_event &evt) { event_consumer ec3(filesystem_item_closed::name, [&](const i_event &evt) {
const auto &evt2 = dynamic_cast<const filesystem_item_closed &>(evt); const auto &evt2 = dynamic_cast<const filesystem_item_closed &>(evt);
EXPECT_STREQ("/test_create.txt", EXPECT_STREQ("/test_create.txt", evt2.api_path.c_str());
evt2.get_api_path().get<std::string>().c_str()); EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
EXPECT_STREQ(source_path.c_str(), EXPECT_FALSE(evt2.directory);
evt2.get_source().get<std::string>().c_str());
EXPECT_STREQ("0", evt2.get_directory().get<std::string>().c_str());
}); });
event_consumer ec4( event_consumer ec4(
filesystem_item_handle_closed::name, [&](const i_event &evt) { filesystem_item_handle_closed::name, [&](const i_event &evt) {
const auto &evt2 = const auto &evt2 =
dynamic_cast<const filesystem_item_handle_closed &>(evt); dynamic_cast<const filesystem_item_handle_closed &>(evt);
EXPECT_STREQ("/test_create.txt", EXPECT_STREQ("/test_create.txt", evt2.api_path.c_str());
evt2.get_api_path().get<std::string>().c_str()); EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
EXPECT_STREQ(source_path.c_str(), EXPECT_FALSE(evt2.directory);
evt2.get_source().get<std::string>().c_str()); EXPECT_EQ(std::uint64_t(1U), evt2.handle);
EXPECT_STREQ("0", evt2.get_directory().get<std::string>().c_str());
EXPECT_STREQ("1", evt2.get_handle().get<std::string>().c_str());
}); });
mgr.close(handle); mgr.close(handle);
@ -239,7 +240,7 @@ TEST_F(file_manager_test, can_open_and_close_file) {
mgr.start(); mgr.start();
event_capture capture({ event_capture capture({
"item_timeout", item_timeout::name,
filesystem_item_opened::name, filesystem_item_opened::name,
filesystem_item_handle_opened::name, filesystem_item_handle_opened::name,
filesystem_item_handle_closed::name, filesystem_item_handle_closed::name,
@ -274,23 +275,19 @@ TEST_F(file_manager_test, can_open_and_close_file) {
event_consumer consumer( event_consumer consumer(
filesystem_item_opened::name, [&](const i_event &evt) { filesystem_item_opened::name, [&](const i_event &evt) {
const auto &evt2 = dynamic_cast<const filesystem_item_opened &>(evt); const auto &evt2 = dynamic_cast<const filesystem_item_opened &>(evt);
EXPECT_STREQ("/test_open.txt", EXPECT_STREQ("/test_open.txt", evt2.api_path.c_str());
evt2.get_api_path().get<std::string>().c_str()); EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
EXPECT_STREQ(source_path.c_str(), EXPECT_FALSE(evt2.directory);
evt2.get_source().get<std::string>().c_str());
EXPECT_STREQ("0", evt2.get_directory().get<std::string>().c_str());
}); });
event_consumer ec2( event_consumer ec2(
filesystem_item_handle_opened::name, [&](const i_event &evt) { filesystem_item_handle_opened::name, [&](const i_event &evt) {
const auto &evt2 = const auto &evt2 =
dynamic_cast<const filesystem_item_handle_opened &>(evt); dynamic_cast<const filesystem_item_handle_opened &>(evt);
EXPECT_STREQ("/test_open.txt", EXPECT_STREQ("/test_open.txt", evt2.api_path.c_str());
evt2.get_api_path().get<std::string>().c_str()); EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
EXPECT_STREQ(source_path.c_str(), EXPECT_FALSE(evt2.directory);
evt2.get_source().get<std::string>().c_str()); EXPECT_EQ(std::uint64_t(1U), evt2.handle);
EXPECT_STREQ("0", evt2.get_directory().get<std::string>().c_str());
EXPECT_STREQ("1", evt2.get_handle().get<std::string>().c_str());
}); });
std::shared_ptr<i_open_file> open_file; std::shared_ptr<i_open_file> open_file;
@ -308,23 +305,19 @@ TEST_F(file_manager_test, can_open_and_close_file) {
event_consumer ec3(filesystem_item_closed::name, [&](const i_event &evt) { event_consumer ec3(filesystem_item_closed::name, [&](const i_event &evt) {
const auto &evt2 = dynamic_cast<const filesystem_item_closed &>(evt); const auto &evt2 = dynamic_cast<const filesystem_item_closed &>(evt);
EXPECT_STREQ("/test_open.txt", EXPECT_STREQ("/test_open.txt", evt2.api_path.c_str());
evt2.get_api_path().get<std::string>().c_str()); EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
EXPECT_STREQ(source_path.c_str(), EXPECT_FALSE(evt2.directory);
evt2.get_source().get<std::string>().c_str());
EXPECT_STREQ("0", evt2.get_directory().get<std::string>().c_str());
}); });
event_consumer ec4( event_consumer ec4(
filesystem_item_handle_closed::name, [&](const i_event &evt) { filesystem_item_handle_closed::name, [&](const i_event &evt) {
const auto &evt2 = const auto &evt2 =
dynamic_cast<const filesystem_item_handle_closed &>(evt); dynamic_cast<const filesystem_item_handle_closed &>(evt);
EXPECT_STREQ("/test_open.txt", EXPECT_STREQ("/test_open.txt", evt2.api_path.c_str());
evt2.get_api_path().get<std::string>().c_str()); EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
EXPECT_STREQ(source_path.c_str(), EXPECT_FALSE(evt2.directory);
evt2.get_source().get<std::string>().c_str()); EXPECT_EQ(std::uint64_t(1U), evt2.handle);
EXPECT_STREQ("0", evt2.get_directory().get<std::string>().c_str());
EXPECT_STREQ("1", evt2.get_handle().get<std::string>().c_str());
}); });
mgr.close(handle); mgr.close(handle);
@ -413,15 +406,13 @@ TEST_F(file_manager_test,
{utils::create_uuid_string()}); {utils::create_uuid_string()});
event_consumer consumer( event_consumer consumer(
"download_resume_added", [&source_path](const i_event &evt) { download_resume_added::name, [&source_path](const i_event &evt) {
const auto &evt2 = dynamic_cast<const download_resume_added &>(evt); const auto &evt2 = dynamic_cast<const download_resume_added &>(evt);
EXPECT_STREQ("/test_write_partial_download.txt", EXPECT_STREQ("/test_write_partial_download.txt", evt2.api_path.c_str());
evt2.get_api_path().get<std::string>().c_str()); EXPECT_STREQ(source_path.c_str(), evt2.dest_path.c_str());
EXPECT_STREQ(source_path.c_str(),
evt2.get_dest_path().get<std::string>().c_str());
}); });
event_capture capture({"download_resume_added"}, event_capture capture({download_resume_added::name},
{ {
file_upload_completed::name, file_upload_completed::name,
file_upload_queued::name, file_upload_queued::name,
@ -512,7 +503,7 @@ TEST_F(file_manager_test,
mgr.stop(); mgr.stop();
capture.wait_for_empty(); capture.wait_for_empty();
event_capture ec2({"download_restored", "download_resume_added"}, event_capture ec2({download_restored::name, download_resume_added::name},
{ {
file_upload_completed::name, file_upload_completed::name,
file_upload_queued::name, file_upload_queued::name,
@ -536,13 +527,12 @@ TEST_F(file_manager_test,
mgr.start(); mgr.start();
event_consumer es2("download_restored", [&source_path](const i_event &evt) { event_consumer es2(
const auto &evt2 = dynamic_cast<const download_restored &>(evt); download_restored::name, [&source_path](const i_event &evt) {
EXPECT_STREQ("/test_write_partial_download.txt", const auto &evt2 = dynamic_cast<const download_restored &>(evt);
evt2.get_api_path().get<std::string>().c_str()); EXPECT_STREQ("/test_write_partial_download.txt", evt2.api_path.c_str());
EXPECT_STREQ(source_path.c_str(), EXPECT_STREQ(source_path.c_str(), evt2.dest_path.c_str());
evt2.get_dest_path().get<std::string>().c_str()); });
});
EXPECT_EQ(std::size_t(1u), mgr.get_open_file_count()); EXPECT_EQ(std::size_t(1u), mgr.get_open_file_count());
EXPECT_EQ(std::size_t(0u), mgr.get_open_handle_count()); EXPECT_EQ(std::size_t(0u), mgr.get_open_handle_count());
@ -571,18 +561,14 @@ TEST_F(file_manager_test, upload_occurs_after_write_if_fully_downloaded) {
event_consumer consumer( event_consumer consumer(
"file_upload_queued", [&source_path](const i_event &evt) { "file_upload_queued", [&source_path](const i_event &evt) {
const auto &evt2 = dynamic_cast<const file_upload_queued &>(evt); const auto &evt2 = dynamic_cast<const file_upload_queued &>(evt);
EXPECT_STREQ("/test_write_full_download.txt", EXPECT_STREQ("/test_write_full_download.txt", evt2.api_path.c_str());
evt2.get_api_path().get<std::string>().c_str()); EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
EXPECT_STREQ(source_path.c_str(),
evt2.get_source().get<std::string>().c_str());
}); });
event_consumer es2( event_consumer es2(
file_upload_completed::name, [&source_path](const i_event &evt) { file_upload_completed::name, [&source_path](const i_event &evt) {
const auto &evt2 = dynamic_cast<const file_upload_completed &>(evt); const auto &evt2 = dynamic_cast<const file_upload_completed &>(evt);
EXPECT_STREQ("/test_write_full_download.txt", EXPECT_STREQ("/test_write_full_download.txt", evt2.api_path.c_str());
evt2.get_api_path().get<std::string>().c_str()); EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
EXPECT_STREQ(source_path.c_str(),
evt2.get_source().get<std::string>().c_str());
}); });
auto now = utils::time::get_time_now(); auto now = utils::time::get_time_now();
@ -644,7 +630,7 @@ TEST_F(file_manager_test, upload_occurs_after_write_if_fully_downloaded) {
} }
event_capture capture({ event_capture capture({
"item_timeout", item_timeout::name,
file_upload_queued::name, file_upload_queued::name,
file_upload_completed::name, file_upload_completed::name,
}); });
@ -1060,11 +1046,15 @@ TEST_F(file_manager_test, can_get_directory_items) {
"..", "..",
"", "",
true, true,
0U,
{},
}); });
list.insert(list.begin(), directory_item{ list.insert(list.begin(), directory_item{
".", ".",
"", "",
true, true,
0U,
{},
}); });
return api_error::success; return api_error::success;
}); });
@ -1425,7 +1415,7 @@ TEST_F(file_manager_test, can_remove_file) {
TEST_F(file_manager_test, can_queue_and_remove_upload) { TEST_F(file_manager_test, can_queue_and_remove_upload) {
event_capture capture({ event_capture capture({
file_upload_queued::name, file_upload_queued::name,
"download_resume_removed", download_resume_removed::name,
}); });
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false)); EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
@ -1460,10 +1450,9 @@ TEST_F(file_manager_test, file_is_closed_after_download_timeout) {
auto source_path = utils::path::combine(cfg->get_cache_directory(), auto source_path = utils::path::combine(cfg->get_cache_directory(),
{utils::create_uuid_string()}); {utils::create_uuid_string()});
event_consumer consumer("item_timeout", [](const i_event &evt) { event_consumer consumer(item_timeout::name, [](const i_event &evt) {
const auto &evt2 = dynamic_cast<const item_timeout &>(evt); const auto &evt2 = dynamic_cast<const item_timeout &>(evt);
EXPECT_STREQ("/test_download_timeout.txt", EXPECT_STREQ("/test_download_timeout.txt", evt2.api_path.c_str());
evt2.get_api_path().get<std::string>().c_str());
}); });
auto now = utils::time::get_time_now(); auto now = utils::time::get_time_now();
@ -1486,7 +1475,7 @@ TEST_F(file_manager_test, file_is_closed_after_download_timeout) {
return api_error::success; return api_error::success;
}); });
event_capture capture({"item_timeout"}); event_capture capture({item_timeout::name});
EXPECT_CALL(mp, read_file_bytes) EXPECT_CALL(mp, read_file_bytes)
.WillRepeatedly([](const std::string & /* api_path */, std::size_t size, .WillRepeatedly([](const std::string & /* api_path */, std::size_t size,
@ -1587,7 +1576,7 @@ TEST_F(file_manager_test,
mgr.start(); mgr.start();
event_capture capture({ event_capture capture({
"item_timeout", item_timeout::name,
filesystem_item_opened::name, filesystem_item_opened::name,
filesystem_item_handle_opened::name, filesystem_item_handle_opened::name,
filesystem_item_handle_closed::name, filesystem_item_handle_closed::name,

View File

@ -421,19 +421,19 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) {
decrypt_parts(cfg, dir_item.api_path); decrypt_parts(cfg, dir_item.api_path);
} }
auto dir = std::find_if(list_decrypted.begin(), list_decrypted.end(), auto dir =
[](const directory_item &dir_item) -> bool { std::ranges::find_if(list_decrypted, [](auto &&dir_item) -> bool {
return dir_item.directory; return dir_item.directory;
}); });
EXPECT_LT(dir, list_decrypted.end()); EXPECT_LT(dir, list_decrypted.end());
EXPECT_STREQ("/sub10", dir->api_path.c_str()); EXPECT_STREQ("/sub10", dir->api_path.c_str());
EXPECT_STREQ("/", dir->api_parent.c_str()); EXPECT_STREQ("/", dir->api_parent.c_str());
EXPECT_EQ(std::size_t(0U), dir->size); EXPECT_EQ(std::size_t(0U), dir->size);
auto file = std::find_if(list_decrypted.begin(), list_decrypted.end(), auto file =
[](const directory_item &dir_item) -> bool { std::ranges::find_if(list_decrypted, [](auto &&dir_item) -> bool {
return not dir_item.directory; return not dir_item.directory;
}); });
EXPECT_LT(file, list_decrypted.end()); EXPECT_LT(file, list_decrypted.end());
EXPECT_STREQ("/test.txt", file->api_path.c_str()); EXPECT_STREQ("/test.txt", file->api_path.c_str());
EXPECT_STREQ("/", file->api_parent.c_str()); EXPECT_STREQ("/", file->api_parent.c_str());
@ -460,10 +460,10 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) {
decrypt_parts(cfg, dir_item.api_path); decrypt_parts(cfg, dir_item.api_path);
} }
auto file2 = std::find_if(list_decrypted2.begin(), list_decrypted2.end(), auto file2 =
[](const directory_item &dir_item) -> bool { std::ranges::find_if(list_decrypted2, [](auto &&dir_item) -> bool {
return not dir_item.directory; return not dir_item.directory;
}); });
EXPECT_LT(file2, list_decrypted2.end()); EXPECT_LT(file2, list_decrypted2.end());
EXPECT_STREQ("/sub10/moose.txt", file2->api_path.c_str()); EXPECT_STREQ("/sub10/moose.txt", file2->api_path.c_str());
EXPECT_STREQ("/sub10", file2->api_parent.c_str()); EXPECT_STREQ("/sub10", file2->api_parent.c_str());