refactoring
Some checks failed
BlockStorage/repertory_osx_builds/pipeline/head This commit looks good
BlockStorage/repertory_linux_builds/pipeline/head There was a failure building this commit

This commit is contained in:
Scott E. Graves 2023-12-15 17:58:49 -06:00
parent 34c4a9c508
commit 71686405e0
41 changed files with 1436 additions and 709 deletions

View File

@ -112,6 +112,9 @@ private:
template <typename dest>
auto get_value(const json &json_document, const std::string &name, dest &dst,
bool &success_flag) -> bool {
constexpr const auto *function_name =
static_cast<const char *>(__FUNCTION__);
auto ret = false;
try {
if (json_document.find(name) != json_document.end()) {
@ -121,7 +124,7 @@ private:
success_flag = false;
}
} catch (const json::exception &ex) {
utils::error::raise_error(__FUNCTION__, ex, "exception occurred");
utils::error::raise_error(function_name, ex, "exception occurred");
success_flag = false;
ret = false;
}

View File

@ -30,8 +30,7 @@ namespace repertory {
class packet_client final {
private:
struct client final {
explicit client(boost::asio::io_context &ctx) : nonce(""), socket(ctx) {}
explicit client(boost::asio::io_context &ctx) : socket(ctx) {}
std::string nonce;
tcp::socket socket;
};
@ -43,34 +42,40 @@ public:
~packet_client();
packet_client(const packet_client &) = delete;
packet_client(packet_client &&) = delete;
auto operator=(const packet_client &) -> packet_client & = delete;
auto operator=(packet_client &&) -> packet_client & = delete;
private:
boost::asio::io_context io_context_;
const std::string host_name_or_ip_;
const std::uint8_t max_connections_;
const std::uint16_t port_;
const std::uint16_t receive_timeout_;
const std::uint16_t send_timeout_;
const std::string encryption_token_;
std::string host_name_or_ip_;
std::uint8_t max_connections_;
std::uint16_t port_;
std::uint16_t receive_timeout_;
std::uint16_t send_timeout_;
std::string encryption_token_;
std::string unique_id_;
bool allow_connections_ = true;
private:
bool allow_connections_{true};
boost::asio::ip::basic_resolver<boost::asio::ip::tcp>::results_type
resolve_results_;
std::mutex clients_mutex_;
std::vector<std::shared_ptr<client>> clients_;
private:
void close(client &c) const;
static void close(client &cli);
void close_all();
void connect(client &c);
void connect(client &cli);
[[nodiscard]] auto get_client() -> std::shared_ptr<client>;
void put_client(std::shared_ptr<client> &c);
void put_client(std::shared_ptr<client> &cli);
[[nodiscard]] auto read_packet(client &c, packet &response)
[[nodiscard]] auto read_packet(client &cli, packet &response)
-> packet::error_type;
void resolve();

View File

@ -45,6 +45,12 @@ public:
~packet_server();
public:
packet_server(const packet_server &) = delete;
packet_server(packet_server &&) = delete;
auto operator=(const packet_server &) -> packet_server & = delete;
auto operator=(packet_server &&) -> packet_server & = delete;
private:
struct connection {
connection(boost::asio::io_service &io_service, tcp::acceptor &acceptor_)
@ -56,11 +62,11 @@ private:
std::string client_id;
std::string nonce;
void generate_nonce() { nonce = utils::generate_random_string(256u); }
void generate_nonce() { nonce = utils::generate_random_string(256U); }
};
private:
const std::string encryption_token_;
std::string encryption_token_;
closed_callback closed_;
message_handler_callback message_handler_;
boost::asio::io_context io_context_;
@ -70,21 +76,22 @@ private:
std::unordered_map<std::string, std::uint32_t> connection_lookup_;
private:
void add_client(connection &c, const std::string &client_id);
void add_client(connection &conn, const std::string &client_id);
void initialize(const uint16_t &port, uint8_t pool_size);
void listen_for_connection(tcp::acceptor &acceptor);
void on_accept(std::shared_ptr<connection> c, boost::system::error_code ec);
void on_accept(std::shared_ptr<connection> conn,
boost::system::error_code err);
void read_header(std::shared_ptr<connection> c);
void read_header(std::shared_ptr<connection> conn);
void read_packet(std::shared_ptr<connection> c, std::uint32_t data_size);
void read_packet(std::shared_ptr<connection> conn, std::uint32_t data_size);
void remove_client(connection &c);
void remove_client(connection &conn);
void send_response(std::shared_ptr<connection> c,
void send_response(std::shared_ptr<connection> conn,
const packet::error_type &result, packet &response);
};
} // namespace repertory

View File

@ -161,8 +161,11 @@ public:
template <typename context_t> struct db_result final {
db_result(std::shared_ptr<context_t> context, std::int32_t res)
: context_(std::move(context)), res_(res) {
constexpr const auto *function_name =
static_cast<const char *>(__FUNCTION__);
if (res == SQLITE_OK) {
set_res(sqlite3_step(context_->stmt.get()), __FUNCTION__);
set_res(sqlite3_step(context_->stmt.get()), function_name);
}
}
@ -193,10 +196,13 @@ public:
[[nodiscard]] auto get_row(std::optional<db_row<context_t>> &row) const
-> bool {
constexpr const auto *function_name =
static_cast<const char *>(__FUNCTION__);
row.reset();
if (has_row()) {
row = db_row{context_};
set_res(sqlite3_step(context_->stmt.get()), __FUNCTION__);
set_res(sqlite3_step(context_->stmt.get()), function_name);
return true;
}
return false;
@ -205,8 +211,11 @@ public:
[[nodiscard]] auto has_row() const -> bool { return res_ == SQLITE_ROW; }
void next_row() const {
constexpr const auto *function_name =
static_cast<const char *>(__FUNCTION__);
if (has_row()) {
set_res(sqlite3_step(context_->stmt.get()), __FUNCTION__);
set_res(sqlite3_step(context_->stmt.get()), function_name);
}
}
};

View File

@ -54,7 +54,7 @@ private:
const UINT32 &attributes,
remote::file_info &file_info);
static void populate_stat(const struct stat64 &st1, remote::stat &st);
static void populate_stat(const struct stat64 &unix_st, remote::stat &r_stat);
[[nodiscard]] auto update_to_windows_format(json &item) -> json &;
@ -88,7 +88,7 @@ public:
remote::file_offset &length, const remote::file_handle &handle) override
;*/
[[nodiscard]] auto fuse_fgetattr(const char *path, remote::stat &st,
[[nodiscard]] auto fuse_fgetattr(const char *path, remote::stat &r_stat,
bool &directory,
const remote::file_handle &handle)
-> packet::error_type override;
@ -107,7 +107,7 @@ public:
const remote::file_handle &handle)
-> packet::error_type override;
[[nodiscard]] auto fuse_getattr(const char *path, remote::stat &st,
[[nodiscard]] auto fuse_getattr(const char *path, remote::stat &r_stat,
bool &directory)
-> packet::error_type override;
@ -196,11 +196,11 @@ public:
std::int32_t &flags, std::uint32_t position) override ;*/
[[nodiscard]] auto fuse_statfs(const char *path, std::uint64_t frsize,
remote::statfs &st)
remote::statfs &r_stat)
-> packet::error_type override;
[[nodiscard]] auto fuse_statfs_x(const char *path, std::uint64_t bsize,
remote::statfs_x &st)
remote::statfs_x &r_stat)
-> packet::error_type override;
[[nodiscard]] auto fuse_truncate(const char *path,

View File

@ -23,6 +23,8 @@
#define INCLUDE_TYPES_REPERTORY_HPP_
namespace repertory {
constexpr const auto max_time = 0xFFFFFFFFFFFFFFFFULL;
const std::string META_ACCESSED = "accessed";
const std::string META_ATTRIBUTES = "attributes";
const std::string META_BACKUP = "backup";

View File

@ -361,6 +361,8 @@ auto app_config::get_provider_name(const provider_type &prov) -> std::string {
}
auto app_config::get_value_by_name(const std::string &name) -> std::string {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
if (name == "ApiAuth") {
return api_auth_;
@ -510,12 +512,14 @@ auto app_config::get_value_by_name(const std::string &name) -> std::string {
return std::to_string(s3_config_.timeout_ms);
}
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
utils::error::raise_error(function_name, e, "exception occurred");
}
return "";
}
auto app_config::load() -> bool {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto ret = false;
const auto config_file_path = get_config_file_path();
@ -671,7 +675,7 @@ auto app_config::load() -> bool {
config_changed_ = true;
}
} catch (const std::exception &ex) {
utils::error::raise_error(__FUNCTION__, ex, "exception occurred");
utils::error::raise_error(function_name, ex, "exception occurred");
ret = false;
}
}
@ -680,15 +684,17 @@ auto app_config::load() -> bool {
}
void app_config::save() {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = get_config_file_path();
recur_mutex_lock lock(read_write_mutex_);
if (config_changed_ || not utils::file::is_file(file_path)) {
if (not utils::file::is_directory(data_directory_)) {
if (not utils::file::create_full_directory_path(data_directory_)) {
utils::error::raise_error(
__FUNCTION__, "failed to create directory|sp|" + data_directory_ +
"|err|" +
std::to_string(utils::get_last_error_code()));
function_name, "failed to create directory|sp|" + data_directory_ +
"|err|" +
std::to_string(utils::get_last_error_code()));
}
}
config_changed_ = false;
@ -725,6 +731,8 @@ void app_config::set_is_remote_mount(bool is_remote_mount) {
auto app_config::set_value_by_name(const std::string &name,
const std::string &value) -> std::string {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
if (name == "ApiAuth") {
set_api_auth(value);
@ -924,8 +932,9 @@ auto app_config::set_value_by_name(const std::string &name,
return s3_config_.encryption_token;
}
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
utils::error::raise_error(function_name, e, "exception occurred");
}
return "";
}
} // namespace repertory

View File

@ -40,6 +40,8 @@ void client_pool::pool::execute(
}
client_pool::pool::pool(std::uint8_t pool_size) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
event_system::instance().raise<service_started>("client_pool");
for (std::uint8_t i = 0U; i < pool_size; i++) {
@ -75,7 +77,7 @@ client_pool::pool::pool(std::uint8_t pool_size) {
item->work_complete(result);
} catch (const std::exception &e) {
item->work_complete(utils::from_api_error(api_error::error));
utils::error::raise_error(__FUNCTION__, e,
utils::error::raise_error(function_name, e,
"exception occurred in work item");
}

View File

@ -219,13 +219,16 @@ auto packet::decode(remote::file_info &val) -> packet::error_type {
}
auto packet::decode_json(packet &response, json &json_data) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::string data;
auto ret = response.decode(data);
if (ret == 0) {
try {
json_data = json::parse(data);
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "failed to parse json string");
utils::error::raise_error(function_name, e,
"failed to parse json string");
ret = -EIO;
}
}
@ -234,6 +237,8 @@ auto packet::decode_json(packet &response, json &json_data) -> int {
}
auto packet::decrypt(const std::string &token) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto ret = utils::from_api_error(api_error::success);
try {
data_buffer result;
@ -245,7 +250,7 @@ auto packet::decrypt(const std::string &token) -> packet::error_type {
buffer_ = std::move(result);
decode_offset_ = 0;
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
utils::error::raise_error(function_name, e, "exception occurred");
ret = utils::from_api_error(api_error::error);
}
@ -514,13 +519,15 @@ void packet::encode_top(remote::file_info val) {
}
void packet::encrypt(const std::string &token) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
data_buffer result;
utils::encryption::encrypt_data(token, buffer_, result);
buffer_ = std::move(result);
encode_top(static_cast<std::uint32_t>(buffer_.size()));
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
utils::error::raise_error(function_name, e, "exception occurred");
}
}

View File

@ -39,9 +39,8 @@ packet_client::packet_client(std::string host_name_or_ip,
std::uint16_t receive_timeout,
std::uint16_t send_timeout,
std::string encryption_token)
: io_context_(),
host_name_or_ip_(std::move(host_name_or_ip)),
max_connections_(max_connections ? max_connections : 20u),
: host_name_or_ip_(std::move(host_name_or_ip)),
max_connections_(max_connections == 0U ? 20U : max_connections),
port_(port),
receive_timeout_(receive_timeout),
send_timeout_(send_timeout),
@ -54,38 +53,40 @@ packet_client::~packet_client() {
io_context_.stop();
}
void packet_client::close(client &cli) const {
void packet_client::close(client &cli) {
try {
boost::system::error_code ec;
cli.socket.close(ec);
boost::system::error_code err;
cli.socket.close(err);
} catch (...) {
}
}
void packet_client::close_all() {
unique_mutex_lock clients_lock(clients_mutex_);
for (auto &c : clients_) {
close(*c.get());
for (auto &cli : clients_) {
close(*cli);
}
clients_.clear();
unique_id_ = utils::create_uuid_string();
}
void packet_client::connect(client &c) {
void packet_client::connect(client &cli) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
resolve();
boost::asio::connect(c.socket, resolve_results_);
c.socket.set_option(boost::asio::ip::tcp::no_delay(true));
c.socket.set_option(boost::asio::socket_base::linger(false, 0));
boost::asio::connect(cli.socket, resolve_results_);
cli.socket.set_option(boost::asio::ip::tcp::no_delay(true));
cli.socket.set_option(boost::asio::socket_base::linger(false, 0));
packet response;
const auto res = read_packet(c, response);
const auto res = read_packet(cli, response);
if (res != 0) {
throw std::runtime_error(std::to_string(res));
}
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "connection handshake failed");
utils::error::raise_error(function_name, e, "connection handshake failed");
}
}
@ -99,7 +100,7 @@ auto packet_client::get_client() -> std::shared_ptr<packet_client::client> {
ret = std::make_shared<client>(io_context_);
connect(*ret);
} else {
ret = clients_[0u];
ret = clients_[0U];
utils::remove_element_from(clients_, ret);
clients_lock.unlock();
}
@ -108,21 +109,21 @@ auto packet_client::get_client() -> std::shared_ptr<packet_client::client> {
return ret;
}
void packet_client::put_client(std::shared_ptr<client> &c) {
void packet_client::put_client(std::shared_ptr<client> &cli) {
mutex_lock clientsLock(clients_mutex_);
if (clients_.size() < max_connections_) {
clients_.emplace_back(c);
clients_.emplace_back(cli);
}
}
auto packet_client::read_packet(client &c, packet &response)
auto packet_client::read_packet(client &cli, packet &response)
-> packet::error_type {
data_buffer buffer(sizeof(std::uint32_t));
const auto read_buffer = [&]() {
std::uint32_t offset = 0u;
std::uint32_t offset{};
while (offset < buffer.size()) {
const auto bytes_read = boost::asio::read(
c.socket,
cli.socket,
boost::asio::buffer(&buffer[offset], buffer.size() - offset));
if (bytes_read <= 0) {
throw std::runtime_error("read failed|" + std::to_string(bytes_read));
@ -133,7 +134,7 @@ auto packet_client::read_packet(client &c, packet &response)
read_buffer();
const auto size = boost::endian::big_to_native(
*reinterpret_cast<std::uint32_t *>(&buffer[0u]));
*reinterpret_cast<std::uint32_t *>(buffer.data()));
buffer.resize(size);
read_buffer();
@ -141,7 +142,7 @@ auto packet_client::read_packet(client &c, packet &response)
auto ret = response.decrypt(encryption_token_);
if (ret == 0) {
ret = response.decode(c.nonce);
ret = response.decode(cli.nonce);
}
return ret;
@ -169,6 +170,8 @@ auto packet_client::send(const std::string &method, packet &request,
auto packet_client::send(const std::string &method, packet &request,
packet &response, std::uint32_t &service_flags)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto success = false;
packet::error_type ret = utils::from_api_error(api_error::error);
request.encode_top(method);
@ -177,28 +180,29 @@ auto packet_client::send(const std::string &method, packet &request,
request.encode_top(PACKET_SERVICE_FLAGS);
request.encode_top(get_repertory_version());
static const std::uint8_t max_attempts = 5u;
for (std::uint8_t i = 1u;
static const std::uint8_t max_attempts{5U};
for (std::uint8_t i = 1U;
allow_connections_ && not success && (i <= max_attempts); i++) {
auto c = get_client();
if (c) {
auto current_client = get_client();
if (current_client) {
try {
request.encode_top(c->nonce);
request.encode_top(current_client->nonce);
request.encrypt(encryption_token_);
timeout request_timeout(
[this, method, c]() {
[method, current_client]() {
event_system::instance().raise<packet_client_timeout>("request",
method);
close(*c.get());
packet_client::close(*current_client);
},
std::chrono::seconds(send_timeout_));
std::uint32_t offset = 0u;
std::uint32_t offset{};
while (offset < request.get_size()) {
const auto bytes_written = boost::asio::write(
c->socket, boost::asio::buffer(&request[offset],
request.get_size() - offset));
current_client->socket,
boost::asio::buffer(&request[offset],
request.get_size() - offset));
if (bytes_written <= 0) {
throw std::runtime_error("write failed|" +
std::to_string(bytes_written));
@ -208,27 +212,29 @@ auto packet_client::send(const std::string &method, packet &request,
request_timeout.disable();
timeout response_timeout(
[this, method, c]() {
[method, current_client]() {
event_system::instance().raise<packet_client_timeout>("response",
method);
close(*c.get());
packet_client::close(*current_client);
},
std::chrono::seconds(receive_timeout_));
ret = read_packet(*c, response);
ret = read_packet(*current_client, response);
response_timeout.disable();
if (ret == 0) {
if ((ret = response.decode(service_flags)) == 0) {
ret = response.decode(service_flags);
if (ret == 0) {
packet::error_type res{};
if ((ret = response.decode(res)) == 0) {
ret = response.decode(res);
if (ret == 0) {
ret = res;
success = true;
put_client(c);
put_client(current_client);
}
}
}
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "send failed");
utils::error::raise_error(function_name, e, "send failed");
close_all();
if (allow_connections_ && (i < max_attempts)) {
std::this_thread::sleep_for(1s);

View File

@ -45,7 +45,7 @@ packet_server::packet_server(std::uint16_t port, std::string token,
packet_server::~packet_server() {
event_system::instance().raise<service_shutdown_begin>("packet_server");
std::thread([this]() {
for (std::size_t i = 0u; i < service_threads_.size(); i++) {
for (std::size_t i = 0U; i < service_threads_.size(); i++) {
io_context_.stop();
}
}).detach();
@ -55,19 +55,21 @@ packet_server::~packet_server() {
event_system::instance().raise<service_shutdown_end>("packet_server");
}
void packet_server::add_client(connection &c, const std::string &client_id) {
c.client_id = client_id;
void packet_server::add_client(connection &conn, const std::string &client_id) {
conn.client_id = client_id;
recur_mutex_lock connection_lock(connection_mutex_);
if (connection_lookup_.find(client_id) == connection_lookup_.end()) {
connection_lookup_[client_id] = 1u;
connection_lookup_[client_id] = 1U;
} else {
connection_lookup_[client_id]++;
connection_lookup_.at(client_id)++;
}
}
void packet_server::initialize(const uint16_t &port, uint8_t pool_size) {
pool_size = std::max(uint8_t(1u), pool_size);
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
pool_size = std::max(uint8_t(1U), pool_size);
server_thread_ = std::make_unique<std::thread>([this, port, pool_size]() {
tcp::acceptor acceptor(io_context_);
try {
@ -77,72 +79,79 @@ void packet_server::initialize(const uint16_t &port, uint8_t pool_size) {
acceptor.bind(endpoint);
acceptor.listen();
} catch (const std::exception &e) {
repertory::utils::error::raise_error(__FUNCTION__, e,
repertory::utils::error::raise_error(function_name, e,
"exception occurred");
}
listen_for_connection(acceptor);
for (std::uint8_t i = 0u; i < pool_size; i++) {
for (std::uint8_t i = 0U; i < pool_size; i++) {
service_threads_.emplace_back([this]() { io_context_.run(); });
}
for (auto &th : service_threads_) {
th.join();
for (auto &thread : service_threads_) {
thread.join();
}
});
}
void packet_server::listen_for_connection(tcp::acceptor &acceptor) {
auto c = std::make_shared<packet_server::connection>(io_context_, acceptor);
acceptor.async_accept(c->socket,
boost::bind(&packet_server::on_accept, this, c,
boost::asio::placeholders::error));
auto conn =
std::make_shared<packet_server::connection>(io_context_, acceptor);
acceptor.async_accept(conn->socket, [this, conn](auto &&err) {
on_accept(conn, std::forward<decltype(err)>(err));
});
}
void packet_server::on_accept(std::shared_ptr<connection> c,
boost::system::error_code ec) {
listen_for_connection(c->acceptor);
if (ec) {
utils::error::raise_error(__FUNCTION__, ec.message());
void packet_server::on_accept(std::shared_ptr<connection> conn,
boost::system::error_code err) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
listen_for_connection(conn->acceptor);
if (err) {
utils::error::raise_error(function_name, err.message());
std::this_thread::sleep_for(1s);
} else {
c->socket.set_option(boost::asio::ip::tcp::no_delay(true));
c->socket.set_option(boost::asio::socket_base::linger(false, 0));
conn->socket.set_option(boost::asio::ip::tcp::no_delay(true));
conn->socket.set_option(boost::asio::socket_base::linger(false, 0));
c->generate_nonce();
conn->generate_nonce();
packet response;
send_response(c, 0, response);
send_response(conn, 0, response);
}
}
void packet_server::read_header(std::shared_ptr<connection> c) {
static const std::string function_name = __FUNCTION__;
void packet_server::read_header(std::shared_ptr<connection> conn) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
c->buffer.resize(sizeof(std::uint32_t));
conn->buffer.resize(sizeof(std::uint32_t));
boost::asio::async_read(
c->socket, boost::asio::buffer(&c->buffer[0u], c->buffer.size()),
[this, c](boost::system::error_code ec, std::size_t) {
if (ec) {
remove_client(*c);
repertory::utils::error::raise_error(function_name, ec.message());
conn->socket,
boost::asio::buffer(conn->buffer.data(), conn->buffer.size()),
[this, conn](boost::system::error_code err, std::size_t) {
if (err) {
remove_client(*conn);
repertory::utils::error::raise_error(function_name, err.message());
} else {
auto to_read = *reinterpret_cast<std::uint32_t *>(&c->buffer[0u]);
auto to_read =
*reinterpret_cast<std::uint32_t *>(conn->buffer.data());
boost::endian::big_to_native_inplace(to_read);
read_packet(c, to_read);
read_packet(conn, to_read);
}
});
}
void packet_server::read_packet(std::shared_ptr<connection> c,
void packet_server::read_packet(std::shared_ptr<connection> conn,
std::uint32_t data_size) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
const auto read_buffer = [&]() {
std::uint32_t offset = 0u;
while (offset < c->buffer.size()) {
std::uint32_t offset{};
while (offset < conn->buffer.size()) {
const auto bytes_read = boost::asio::read(
c->socket,
boost::asio::buffer(&c->buffer[offset], c->buffer.size() - offset));
conn->socket, boost::asio::buffer(&conn->buffer[offset],
conn->buffer.size() - offset));
if (bytes_read <= 0) {
throw std::runtime_error("read failed|" + std::to_string(bytes_read));
}
@ -152,46 +161,48 @@ void packet_server::read_packet(std::shared_ptr<connection> c,
auto should_send_response = true;
auto response = std::make_shared<packet>();
c->buffer.resize(data_size);
conn->buffer.resize(data_size);
read_buffer();
packet::error_type ret;
auto request = std::make_shared<packet>(c->buffer);
packet::error_type ret{};
auto request = std::make_shared<packet>(conn->buffer);
if (request->decrypt(encryption_token_) == 0) {
std::string nonce;
if ((ret = request->decode(nonce)) == 0) {
if (nonce != c->nonce) {
ret = request->decode(nonce);
if (ret == 0) {
if (nonce != conn->nonce) {
throw std::runtime_error("invalid nonce");
}
c->generate_nonce();
conn->generate_nonce();
std::string version;
if ((ret = request->decode(version)) == 0) {
ret = request->decode(version);
if (ret == 0) {
if (utils::compare_version_strings(
version, REPERTORY_MIN_REMOTE_VERSION) >= 0) {
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
DECODE_OR_IGNORE(request, service_flags);
std::string client_id;
DECODE_OR_IGNORE(request, client_id);
std::uint64_t thread_id = 0u;
std::uint64_t thread_id{};
DECODE_OR_IGNORE(request, thread_id);
std::string method;
DECODE_OR_IGNORE(request, method);
if (ret == 0) {
if (c->client_id.empty()) {
add_client(*c, client_id);
if (conn->client_id.empty()) {
add_client(*conn, client_id);
}
should_send_response = false;
message_handler_(service_flags, client_id, thread_id, method,
request.get(), *response,
[this, c, request,
[this, conn, request,
response](const packet::error_type &result) {
this->send_response(c, result, *response);
this->send_response(conn, result, *response);
});
}
} else {
@ -207,43 +218,43 @@ void packet_server::read_packet(std::shared_ptr<connection> c,
throw std::runtime_error("decryption failed");
}
if (should_send_response) {
send_response(c, ret, *response);
send_response(conn, ret, *response);
}
} catch (const std::exception &e) {
remove_client(*c);
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
remove_client(*conn);
utils::error::raise_error(function_name, e, "exception occurred");
}
}
void packet_server::remove_client(connection &c) {
if (not c.client_id.empty()) {
void packet_server::remove_client(connection &conn) {
if (not conn.client_id.empty()) {
recur_mutex_lock connection_lock(connection_mutex_);
if (not --connection_lookup_[c.client_id]) {
connection_lookup_.erase(c.client_id);
closed_(c.client_id);
if (--connection_lookup_[conn.client_id] == 0U) {
connection_lookup_.erase(conn.client_id);
closed_(conn.client_id);
}
}
}
void packet_server::send_response(std::shared_ptr<connection> c,
void packet_server::send_response(std::shared_ptr<connection> conn,
const packet::error_type &result,
packet &response) {
static const std::string function_name = __FUNCTION__;
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
response.encode_top(result);
response.encode_top(PACKET_SERVICE_FLAGS);
response.encode_top(c->nonce);
response.encode_top(conn->nonce);
response.encrypt(encryption_token_);
response.transfer_into(c->buffer);
response.transfer_into(conn->buffer);
boost::asio::async_write(
c->socket, boost::asio::buffer(c->buffer),
[this, c](boost::system::error_code ec, std::size_t /*length*/) {
if (ec) {
remove_client(*c);
utils::error::raise_error(function_name, ec.message());
conn->socket, boost::asio::buffer(conn->buffer),
[this, conn](boost::system::error_code err, std::size_t /*length*/) {
if (err) {
remove_client(*conn);
utils::error::raise_error(function_name, err.message());
} else {
read_header(c);
read_header(conn);
}
});
}

View File

@ -58,14 +58,16 @@ auto db_insert::dump() const -> std::string {
}
auto db_insert::go() const -> db_result<context> {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
sqlite3_stmt *stmt_ptr{nullptr};
auto query_str = dump();
auto res = sqlite3_prepare_v2(&context_->db3, query_str.c_str(), -1,
&stmt_ptr, nullptr);
if (res != SQLITE_OK) {
utils::error::raise_error(__FUNCTION__, "failed to prepare|" +
std::to_string(res) + '|' +
sqlite3_errstr(res));
utils::error::raise_error(function_name, "failed to prepare|" +
std::to_string(res) + '|' +
sqlite3_errstr(res));
return {context_, res};
}
context_->stmt.reset(stmt_ptr);
@ -84,9 +86,9 @@ auto db_insert::go() const -> db_result<context> {
},
std::next(context_->values.begin(), idx)->second);
if (res != SQLITE_OK) {
utils::error::raise_error(__FUNCTION__, "failed to bind|" +
std::to_string(res) + '|' +
sqlite3_errstr(res));
utils::error::raise_error(function_name, "failed to bind|" +
std::to_string(res) + '|' +
sqlite3_errstr(res));
return {context_, res};
}
}

View File

@ -112,12 +112,14 @@ auto db_select::dump() const -> std::string {
}
auto db_select::go() const -> db_result<context> {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
sqlite3_stmt *stmt_ptr{nullptr};
auto query_str = dump();
auto res = sqlite3_prepare_v2(&context_->db3, query_str.c_str(), -1,
&stmt_ptr, nullptr);
if (res != SQLITE_OK) {
utils::error::raise_error(__FUNCTION__,
utils::error::raise_error(function_name,
"failed to prepare|" + std::to_string(res) + '|' +
sqlite3_errstr(res) + '|' + query_str);
return {context_, res};
@ -138,7 +140,7 @@ auto db_select::go() const -> db_result<context> {
},
context_->ands.at(static_cast<std::size_t>(idx)).value);
if (res != SQLITE_OK) {
utils::error::raise_error(__FUNCTION__,
utils::error::raise_error(function_name,
"failed to bind|" + std::to_string(res) + '|' +
sqlite3_errstr(res) + '|' + query_str);
return {context_, res};

View File

@ -31,6 +31,8 @@ auto directory_iterator::fill_buffer(const remote::file_offset &offset,
void *buffer,
populate_stat_callback populate_stat)
-> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (offset < items_.size()) {
try {
std::string item_name;
@ -65,7 +67,7 @@ auto directory_iterator::fill_buffer(const remote::file_offset &offset,
return -1;
}
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e,
utils::error::raise_error(function_name, e,
"failed to fill fuse directory buffer");
}

View File

@ -33,9 +33,11 @@
namespace repertory {
auto eviction::check_minimum_requirements(const std::string &file_path)
-> bool {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::uint64_t file_size{};
if (not utils::file::get_file_size(file_path, file_size)) {
utils::error::raise_error(__FUNCTION__, utils::get_last_error_code(),
utils::error::raise_error(function_name, utils::get_last_error_code(),
file_path, "failed to get file size");
return false;
}
@ -77,6 +79,8 @@ auto eviction::get_filtered_cached_files() -> std::deque<std::string> {
}
void eviction::service_function() {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto should_evict = true;
// Handle maximum cache size eviction
@ -116,13 +120,13 @@ void eviction::service_function() {
}
} else {
utils::error::raise_api_path_error(
__FUNCTION__, file.api_path, file.source_path,
function_name, file.api_path, file.source_path,
utils::get_last_error_code(), "failed to get file size");
}
}
}
} catch (const std::exception &ex) {
utils::error::raise_error(__FUNCTION__, ex,
utils::error::raise_error(function_name, ex,
"failed to process cached file|sp|" +
cached_files_list.front());
}

View File

@ -101,16 +101,20 @@ fuse_base::fuse_base(app_config &config) : config_(config) {
fuse_base::~fuse_base() { E_CONSUMER_RELEASE(); }
auto fuse_base::access_(const char *path, int mask) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().access_impl(api_path, mask);
});
}
#ifdef __APPLE__
auto fuse_base::chflags_(const char *path, uint32_t flags) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().chflags_impl(api_path, flags);
});
}
@ -119,15 +123,19 @@ auto fuse_base::chflags_(const char *path, uint32_t flags) -> int {
#if FUSE_USE_VERSION >= 30
auto fuse_base::chmod_(const char *path, mode_t mode, struct fuse_file_info *fi)
-> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().chmod_impl(api_path, mode, fi);
});
}
#else
auto fuse_base::chmod_(const char *path, mode_t mode) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().chmod_impl(api_path, mode);
});
}
@ -136,15 +144,19 @@ auto fuse_base::chmod_(const char *path, mode_t mode) -> int {
#if FUSE_USE_VERSION >= 30
auto fuse_base::chown_(const char *path, uid_t uid, gid_t gid,
struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().chown_impl(api_path, uid, gid, fi);
});
}
#else
auto fuse_base::chown_(const char *path, uid_t uid, gid_t gid) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().chown_impl(api_path, uid, gid);
});
}
@ -152,14 +164,18 @@ auto fuse_base::chown_(const char *path, uid_t uid, gid_t gid) -> int {
auto fuse_base::create_(const char *path, mode_t mode,
struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().create_impl(api_path, mode, fi);
});
}
void fuse_base::destroy_(void *ptr) {
execute_void_callback(__FUNCTION__, [&]() { instance().destroy_impl(ptr); });
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
execute_void_callback(function_name, [&]() { instance().destroy_impl(ptr); });
}
void fuse_base::destroy_impl(void * /* ptr */) { repertory_shutdown(); }
@ -228,8 +244,10 @@ auto fuse_base::execute_void_pointer_callback(const std::string &function_name,
auto fuse_base::fallocate_(const char *path, int mode, off_t offset,
off_t length, struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().fallocate_impl(api_path, mode, offset, length, fi);
});
}
@ -237,8 +255,10 @@ auto fuse_base::fallocate_(const char *path, int mode, off_t offset,
#if FUSE_USE_VERSION < 30
auto fuse_base::fgetattr_(const char *path, struct stat *st,
struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().fgetattr_impl(api_path, st, fi);
});
}
@ -247,8 +267,10 @@ auto fuse_base::fgetattr_(const char *path, struct stat *st,
#ifdef __APPLE__
auto fuse_base::fsetattr_x_(const char *path, struct setattr_x *attr,
struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().fsetattr_x_impl(api_path, attr, fi);
});
}
@ -256,8 +278,10 @@ auto fuse_base::fsetattr_x_(const char *path, struct setattr_x *attr,
auto fuse_base::fsync_(const char *path, int datasync,
struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().fsync_impl(api_path, datasync, fi);
});
}
@ -265,8 +289,10 @@ auto fuse_base::fsync_(const char *path, int datasync,
#if FUSE_USE_VERSION < 30
auto fuse_base::ftruncate_(const char *path, off_t size,
struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().ftruncate_impl(api_path, size, fi);
});
}
@ -275,15 +301,19 @@ auto fuse_base::ftruncate_(const char *path, off_t size,
#if FUSE_USE_VERSION >= 30
auto fuse_base::getattr_(const char *path, struct stat *st,
struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().getattr_impl(api_path, st, fi);
});
}
#else
auto fuse_base::getattr_(const char *path, struct stat *st) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().getattr_impl(api_path, st);
});
}
@ -292,8 +322,10 @@ auto fuse_base::getattr_(const char *path, struct stat *st) -> int {
#ifdef __APPLE__
auto fuse_base::getxtimes_(const char *path, struct timespec *bkuptime,
struct timespec *crtime) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().getxtimes_impl(api_path, bkuptime, crtime);
});
}
@ -302,14 +334,18 @@ auto fuse_base::getxtimes_(const char *path, struct timespec *bkuptime,
#if FUSE_USE_VERSION >= 30
auto fuse_base::init_(struct fuse_conn_info *conn, struct fuse_config *cfg)
-> void * {
return execute_void_pointer_callback(__FUNCTION__, [&]() -> void * {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return execute_void_pointer_callback(function_name, [&]() -> void * {
return instance().init_impl(conn, cfg);
});
}
#else
auto fuse_base::init_(struct fuse_conn_info *conn) -> void * {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return execute_void_pointer_callback(
__FUNCTION__, [&]() -> void * { return instance().init_impl(conn); });
function_name, [&]() -> void * { return instance().init_impl(conn); });
}
#endif
@ -346,8 +382,10 @@ auto fuse_base::init_impl(struct fuse_conn_info *conn) -> void * {
#endif
auto fuse_base::mkdir_(const char *path, mode_t mode) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().mkdir_impl(api_path, mode);
});
}
@ -396,24 +434,30 @@ auto fuse_base::mount(std::vector<std::string> args) -> int {
}
auto fuse_base::open_(const char *path, struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().open_impl(api_path, fi);
});
}
auto fuse_base::opendir_(const char *path, struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().opendir_impl(api_path, fi);
});
}
auto fuse_base::read_(const char *path, char *buffer, size_t read_size,
off_t read_offset, struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::size_t bytes_read{};
const auto res = instance().execute_callback(
__FUNCTION__, path,
function_name, path,
[&](const std::string &api_path) -> api_error {
return instance().read_impl(api_path, buffer, read_size, read_offset,
fi, bytes_read);
@ -427,8 +471,10 @@ auto fuse_base::readdir_(const char *path, void *buf,
fuse_fill_dir_t fuse_fill_dir, off_t offset,
struct fuse_file_info *fi, fuse_readdir_flags flags)
-> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().readdir_impl(api_path, buf, fuse_fill_dir, offset, fi,
flags);
});
@ -437,8 +483,10 @@ 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,
struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().readdir_impl(api_path, buf, fuse_fill_dir, offset,
fi);
});
@ -446,16 +494,20 @@ auto fuse_base::readdir_(const char *path, void *buf,
#endif
auto fuse_base::release_(const char *path, struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().release_impl(api_path, fi);
});
}
auto fuse_base::releasedir_(const char *path, struct fuse_file_info *fi)
-> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().releasedir_impl(api_path, fi);
});
}
@ -463,8 +515,10 @@ auto fuse_base::releasedir_(const char *path, struct fuse_file_info *fi)
#if FUSE_USE_VERSION >= 30
auto fuse_base::rename_(const char *from, const char *to, unsigned int flags)
-> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, from, to,
function_name, from, to,
[&](const std::string &from_api_file,
const std::string &to_api_path) -> api_error {
return instance().rename_impl(from_api_file, to_api_path, flags);
@ -472,8 +526,10 @@ auto fuse_base::rename_(const char *from, const char *to, unsigned int flags)
}
#else
auto fuse_base::rename_(const char *from, const char *to) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, from, to,
function_name, from, to,
[&](const std::string &from_api_file,
const std::string &to_api_path) -> api_error {
return instance().rename_impl(from_api_file, to_api_path);
@ -482,8 +538,10 @@ auto fuse_base::rename_(const char *from, const char *to) -> int {
#endif
auto fuse_base::rmdir_(const char *path) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().rmdir_impl(api_path);
});
}
@ -492,9 +550,11 @@ auto fuse_base::rmdir_(const char *path) -> int {
#ifdef __APPLE__
auto fuse_base::getxattr_(const char *path, const char *name, char *value,
size_t size, uint32_t position) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
int attribute_size = 0;
const auto res = instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().getxattr_impl(api_path, name, value, size, position,
attribute_size);
});
@ -504,9 +564,11 @@ auto fuse_base::getxattr_(const char *path, const char *name, char *value,
#else // __APPLE__
auto fuse_base::getxattr_(const char *path, const char *name, char *value,
size_t size) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
int attribute_size = 0;
const auto res = instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().getxattr_impl(api_path, name, value, size,
attribute_size);
});
@ -516,11 +578,13 @@ auto fuse_base::getxattr_(const char *path, const char *name, char *value,
#endif // __APPLE__
auto fuse_base::listxattr_(const char *path, char *buffer, size_t size) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
int required_size = 0;
bool return_size = false;
const auto res = instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().listxattr_impl(api_path, buffer, size, required_size,
return_size);
});
@ -633,8 +697,10 @@ void fuse_base::raise_fuse_event(std::string function_name,
}
auto fuse_base::removexattr_(const char *path, const char *name) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().removexattr_impl(api_path, name);
});
}
@ -642,8 +708,10 @@ auto fuse_base::removexattr_(const char *path, const char *name) -> int {
#ifdef __APPLE__
auto fuse_base::setxattr_(const char *path, const char *name, const char *value,
size_t size, int flags, uint32_t position) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto res = instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().setxattr_impl(api_path, name, value, size, flags,
position);
});
@ -656,8 +724,10 @@ auto fuse_base::setxattr_(const char *path, const char *name, const char *value,
#else // __APPLE__
auto fuse_base::setxattr_(const char *path, const char *name, const char *value,
size_t size, int flags) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto res = instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().setxattr_impl(api_path, name, value, size, flags);
});
if (res != 0) {
@ -677,53 +747,67 @@ void fuse_base::shutdown() {
#ifdef __APPLE__
auto fuse_base::setattr_x_(const char *path, struct setattr_x *attr) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().setattr_x_impl(api_path, attr);
});
}
auto fuse_base::setbkuptime_(const char *path, const struct timespec *bkuptime)
-> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().setbkuptime_impl(api_path, bkuptime);
});
}
auto fuse_base::setchgtime_(const char *path, const struct timespec *chgtime)
-> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().setchgtime_impl(api_path, chgtime);
});
}
auto fuse_base::setcrtime_(const char *path, const struct timespec *crtime)
-> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().setcrtime_impl(api_path, crtime);
});
}
auto fuse_base::setvolname_(const char *volname) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, volname, [&](const std::string &api_path) -> api_error {
function_name, volname, [&](const std::string &api_path) -> api_error {
return instance().setvolname_impl(volname);
});
}
auto fuse_base::statfs_x_(const char *path, struct statfs *stbuf) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().statfs_x_impl(api_path, stbuf);
});
}
#else // __APPLE__
auto fuse_base::statfs_(const char *path, struct statvfs *stbuf) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().statfs_impl(api_path, stbuf);
});
}
@ -732,23 +816,29 @@ auto fuse_base::statfs_(const char *path, struct statvfs *stbuf) -> int {
#if FUSE_USE_VERSION >= 30
auto fuse_base::truncate_(const char *path, off_t size,
struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().truncate_impl(api_path, size, fi);
});
}
#else
auto fuse_base::truncate_(const char *path, off_t size) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().truncate_impl(api_path, size);
});
}
#endif
auto fuse_base::unlink_(const char *path) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().unlink_impl(api_path);
});
}
@ -770,15 +860,19 @@ auto fuse_base::unmount(const std::string &mount_location) -> int {
#if FUSE_USE_VERSION >= 30
auto fuse_base::utimens_(const char *path, const struct timespec tv[2],
struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().utimens_impl(api_path, tv, fi);
});
}
#else
auto fuse_base::utimens_(const char *path, const struct timespec tv[2]) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return instance().execute_callback(
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
function_name, path, [&](const std::string &api_path) -> api_error {
return instance().utimens_impl(api_path, tv);
});
}
@ -786,10 +880,12 @@ auto fuse_base::utimens_(const char *path, const struct timespec tv[2]) -> int {
auto fuse_base::write_(const char *path, const char *buffer, size_t write_size,
off_t write_offset, struct fuse_file_info *fi) -> int {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::size_t bytes_written{};
const auto res = instance().execute_callback(
__FUNCTION__, path,
function_name, path,
[&](const std::string &api_path) -> api_error {
return instance().write_impl(api_path, buffer, write_size, write_offset,
fi, bytes_written);

View File

@ -205,6 +205,8 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
}
void fuse_drive::destroy_impl(void *ptr) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
event_system::instance().raise<drive_unmount_pending>(get_mount_location());
remote_server_.reset();
@ -240,7 +242,7 @@ void fuse_drive::destroy_impl(void *ptr) {
config_.save();
if (not lock_data_.set_mount_state(false, "", -1)) {
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
utils::error::raise_error(function_name, "failed to set mount state");
}
fuse_base::destroy_impl(ptr);
@ -389,10 +391,12 @@ auto fuse_drive::get_directory_item_count(const std::string &api_path) const
auto fuse_drive::get_directory_items(const std::string &api_path) const
-> directory_item_list {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
directory_item_list list{};
auto res = provider_.get_directory_items(api_path, list);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to get directory items");
}
@ -401,10 +405,12 @@ auto fuse_drive::get_directory_items(const std::string &api_path) const
auto fuse_drive::get_file_size(const std::string &api_path) const
-> std::uint64_t {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::uint64_t file_size{};
auto res = provider_.get_file_size(api_path, file_size);
if (res == api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to get file size from provider");
}
@ -521,6 +527,8 @@ auto fuse_drive::init_impl(struct fuse_conn_info *conn, struct fuse_config *cfg)
#else
void *fuse_drive::init_impl(struct fuse_conn_info *conn) {
#endif
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
#if FUSE_USE_VERSION >= 30
auto *ret = fuse_drive_base::init_impl(conn, cfg);
#else
@ -568,11 +576,11 @@ void *fuse_drive::init_impl(struct fuse_conn_info *conn) {
}
if (not lock_data_.set_mount_state(true, get_mount_location(), getpid())) {
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
utils::error::raise_error(function_name, "failed to set mount state");
}
event_system::instance().raise<drive_mounted>(get_mount_location());
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception during fuse init");
utils::error::raise_error(function_name, e, "exception during fuse init");
destroy_impl(this);
@ -587,6 +595,8 @@ auto fuse_drive::is_processing(const std::string &api_path) const -> bool {
}
auto fuse_drive::mkdir_impl(std::string api_path, mode_t mode) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto res = check_parent_access(api_path, W_OK | X_OK);
if (res != api_error::success) {
return res;
@ -596,17 +606,18 @@ auto fuse_drive::mkdir_impl(std::string api_path, mode_t mode) -> api_error {
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_DIRECTORY, now, now,
true, get_effective_gid(), "", mode, now,
0U, 0U, 0U, "", get_effective_uid(), now);
if ((res = provider_.create_directory(api_path, meta)) !=
api_error::success) {
res = provider_.create_directory(api_path, meta);
if (res != api_error::success) {
return res;
}
if (api_path != "/") {
if ((res = provider_.set_item_meta(
utils::path::get_parent_api_path(api_path), META_MODIFIED,
std::to_string(now))) != api_error::success) {
res = provider_.set_item_meta(utils::path::get_parent_api_path(api_path),
META_MODIFIED, std::to_string(now));
if (res != api_error::success) {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, res, "failed to set directory modified time");
function_name, api_path, res,
"failed to set directory modified time");
}
}
@ -1019,9 +1030,11 @@ auto fuse_drive::setxattr_impl(std::string api_path, const char *name,
void fuse_drive::set_item_meta(const std::string &api_path,
const std::string &key,
const std::string &value) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto res = provider_.set_item_meta(api_path, key, value);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"key|" + key + "|value|" + value);
}
}
@ -1340,11 +1353,13 @@ auto fuse_drive::write_impl(std::string /*api_path*/
}
void fuse_drive::update_accessed_time(const std::string &api_path) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (atime_enabled_) {
auto res = provider_.set_item_meta(
api_path, META_ACCESSED, std::to_string(utils::get_file_time_now()));
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to set accessed time");
}
}

View File

@ -36,49 +36,59 @@ remote_client::remote_client(const app_config &config)
auto remote_client::fuse_access(const char *path, const std::int32_t &mask)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(mask);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_chflags(const char *path, std::uint32_t flags)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(flags);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_chmod(const char *path, const remote::file_mode &mode)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(mode);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_chown(const char *path, const remote::user_id &uid,
const remote::group_id &gid)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(uid);
request.encode(gid);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_destroy() -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, service_flags);
return packet_client_.send(function_name, service_flags);
}
/*packet::error_type remote_client::fuse_fallocate(const char *path, const
@ -91,13 +101,15 @@ std::int32_t &mode, const remote::file_offset &offset, const remote::file_offset
request.encode(handle);
std::uint32_t service_flags {};
return packetClient_.send(__FUNCTION__, request, service_flags);
return packetClient_.send(function_name, request, service_flags);
}*/
auto remote_client::fuse_fgetattr(const char *path, remote::stat &st,
bool &directory,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(handle);
@ -107,7 +119,7 @@ auto remote_client::fuse_fgetattr(const char *path, remote::stat &st,
packet response;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == 0) {
if ((ret = response.decode(st)) == 0) {
std::uint8_t d{};
@ -124,42 +136,50 @@ auto remote_client::fuse_fsetattr_x(const char *path,
const remote::setattr_x &attr,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(attr);
request.encode(handle);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_fsync(const char *path, const std::int32_t &datasync,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(datasync);
request.encode(handle);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_ftruncate(const char *path,
const remote::file_offset &size,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(size);
request.encode(handle);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_getattr(const char *path, remote::stat &st,
bool &directory) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(uid_);
@ -168,7 +188,7 @@ auto remote_client::fuse_getattr(const char *path, remote::stat &st,
packet response;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == 0) {
if ((ret = response.decode(st)) == 0) {
std::uint8_t d = 0;
@ -189,7 +209,7 @@ packet request; request.encode(path); request.encode(name);
packet response;
std::uint32_t service_flags {};
if ((ret = packetClient_.send(__FUNCTION__, request, response,
if ((ret = packetClient_.send(function_name, request, response,
service_flags)) == 0) { remote::file_size size2; if ((ret =
response.decode(size2)) == 0) { if (size2 >
std::numeric_limits<std::size_t>::max()) { ret = -ERANGE; } else { memcpy(value,
@ -212,7 +232,7 @@ packet::error_type ret = 0; if (size > std::numeric_limits<std::size_t>::max())
packet response;
std::uint32_t service_flags {};
if ((ret = packetClient_.send(__FUNCTION__, request, response,
if ((ret = packetClient_.send(function_name, request, response,
service_flags)) == 0) { remote::file_size size2; if ((ret =
response.decode(size2)) == 0) { if (size2 >
std::numeric_limits<std::size_t>::max()) { ret = -ERANGE; } else { memcpy(value,
@ -229,13 +249,15 @@ auto remote_client::fuse_getxtimes(const char *path,
remote::file_time &bkuptime,
remote::file_time &crtime)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
packet response;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == 0) {
DECODE_OR_RETURN(&response, bkuptime);
DECODE_OR_RETURN(&response, crtime);
@ -245,8 +267,10 @@ auto remote_client::fuse_getxtimes(const char *path,
}
auto remote_client::fuse_init() -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, service_flags);
return packet_client_.send(function_name, service_flags);
}
/*packet::error_type remote_client::fuse_listxattr(const char *path, char
@ -256,7 +280,7 @@ request; request.encode(path); request.encode(size);
packet response;
std::uint32_t service_flags {};
if ((ret = packetClient_.send(__FUNCTION__, request, response,
if ((ret = packetClient_.send(function_name, request, response,
service_flags)) == 0) { remote::file_size size2; if ((ret =
response.decode(size2)) == 0) { if (size2 >
std::numeric_limits<std::size_t>::max()) { ret = -ERANGE; } else {
@ -272,23 +296,27 @@ static_cast<std::size_t>(size2));
auto remote_client::fuse_mkdir(const char *path, const remote::file_mode &mode)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(mode);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_opendir(const char *path, remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
packet response;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == 0) {
ret = response.decode(handle);
}
@ -300,6 +328,8 @@ auto remote_client::fuse_create(const char *path, const remote::file_mode &mode,
const remote::open_flags &flags,
remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(mode);
@ -308,7 +338,7 @@ auto remote_client::fuse_create(const char *path, const remote::file_mode &mode,
packet response;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == 0) {
ret = response.decode(handle);
}
@ -319,6 +349,8 @@ auto remote_client::fuse_create(const char *path, const remote::file_mode &mode,
auto remote_client::fuse_open(const char *path, const remote::open_flags &flags,
remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(flags);
@ -326,7 +358,7 @@ auto remote_client::fuse_open(const char *path, const remote::open_flags &flags,
packet response;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == 0) {
ret = response.decode(handle);
}
@ -339,6 +371,8 @@ auto remote_client::fuse_read(const char *path, char *buffer,
const remote::file_offset &read_offset,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(read_size);
@ -348,7 +382,7 @@ auto remote_client::fuse_read(const char *path, char *buffer,
packet response;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret > 0) {
memcpy(buffer, response.current_pointer(), static_cast<std::size_t>(ret));
}
@ -358,12 +392,14 @@ auto remote_client::fuse_read(const char *path, char *buffer,
auto remote_client::fuse_rename(const char *from, const char *to)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(from);
request.encode(to);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_write(const char *path, const char *buffer,
@ -371,6 +407,8 @@ auto remote_client::fuse_write(const char *path, const char *buffer,
const remote::file_offset &write_offset,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (write_size > std::numeric_limits<std::size_t>::max()) {
return -ERANGE;
}
@ -383,7 +421,7 @@ auto remote_client::fuse_write(const char *path, const char *buffer,
request.encode(handle);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_write_base64(const char *path, const char *buffer,
@ -391,6 +429,8 @@ auto remote_client::fuse_write_base64(const char *path, const char *buffer,
const remote::file_offset &write_offset,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (write_size > std::numeric_limits<std::size_t>::max()) {
return -ERANGE;
}
@ -403,13 +443,15 @@ auto remote_client::fuse_write_base64(const char *path, const char *buffer,
request.encode(handle);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_readdir(const char *path,
const remote::file_offset &offset,
const remote::file_handle &handle,
std::string &item_path) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(offset);
@ -418,7 +460,7 @@ auto remote_client::fuse_readdir(const char *path,
packet response;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == 0) {
DECODE_OR_IGNORE(&response, item_path);
}
@ -429,23 +471,27 @@ auto remote_client::fuse_readdir(const char *path,
auto remote_client::fuse_release(const char *path,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(handle);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_releasedir(const char *path,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(handle);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
/*packet::error_type remote_client::fuse_removexattr(const char *path, const
@ -453,66 +499,78 @@ char *name) override { packet request; request.encode(path);
request.Encode(name);
std::uint32_t service_flags {};
return packetClient_.send(__FUNCTION__, request, service_flags);
return packetClient_.send(function_name, request, service_flags);
}*/
auto remote_client::fuse_rmdir(const char *path) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_setattr_x(const char *path, remote::setattr_x &attr)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(attr);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_setbkuptime(const char *path,
const remote::file_time &bkuptime)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(bkuptime);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_setchgtime(const char *path,
const remote::file_time &chgtime)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(chgtime);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_setcrtime(const char *path,
const remote::file_time &crtime)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(crtime);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_setvolname(const char *volname) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(volname);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
/*packet::error_type remote_client::fuse_setxattr(const char *path, const char
@ -524,7 +582,7 @@ request; request.encode(path); request.encode(name); request.encode(size);
request.encode(flags);
std::uint32_t service_flags {};
ret = packetClient_.send(__FUNCTION__, request, service_flags);
ret = packetClient_.send(function_name, request, service_flags);
}
return ret;
@ -539,7 +597,7 @@ request.Encode(size); request.encode(value, static_cast<std::size_t>(size));
request.encode(flags); request.encode(position);
std::uint32_t service_flags {};
ret = packetClient_.send(__FUNCTION__, request, service_flags);
ret = packetClient_.send(function_name, request, service_flags);
}
return ret;
@ -547,6 +605,8 @@ request.encode(flags); request.encode(position);
auto remote_client::fuse_statfs(const char *path, std::uint64_t frsize,
remote::statfs &st) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(frsize);
@ -554,7 +614,7 @@ auto remote_client::fuse_statfs(const char *path, std::uint64_t frsize,
packet response;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == 0) {
ret = response.decode(st);
}
@ -564,6 +624,8 @@ auto remote_client::fuse_statfs(const char *path, std::uint64_t frsize,
auto remote_client::fuse_statfs_x(const char *path, std::uint64_t bsize,
remote::statfs_x &st) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(bsize);
@ -571,7 +633,7 @@ auto remote_client::fuse_statfs_x(const char *path, std::uint64_t bsize,
packet response;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == 0) {
ret = response.decode(st);
}
@ -582,25 +644,31 @@ auto remote_client::fuse_statfs_x(const char *path, std::uint64_t bsize,
auto remote_client::fuse_truncate(const char *path,
const remote::file_offset &size)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(size);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_unlink(const char *path) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::fuse_utimens(const char *path, const remote::file_time *tv,
std::uint64_t op0, std::uint64_t op1)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(&tv[0], sizeof(remote::file_time) * 2);
@ -608,19 +676,21 @@ auto remote_client::fuse_utimens(const char *path, const remote::file_time *tv,
request.encode(op1);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
auto remote_client::json_create_directory_snapshot(const std::string &path,
json &json_data)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
packet response;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == 0) {
ret = packet::decode_json(response, json_data);
}
@ -631,6 +701,8 @@ auto remote_client::json_create_directory_snapshot(const std::string &path,
auto remote_client::json_read_directory_snapshot(
const std::string &path, const remote::file_handle &handle,
std::uint32_t page, json &json_data) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(handle);
@ -639,7 +711,7 @@ auto remote_client::json_read_directory_snapshot(
packet response;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == 0) {
ret = packet::decode_json(response, json_data);
}
@ -650,12 +722,14 @@ auto remote_client::json_read_directory_snapshot(
auto remote_client::json_release_directory_snapshot(
const std::string &path, const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(handle);
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
return packet_client_.send(function_name, request, service_flags);
}
void remote_client::set_fuse_uid_gid(const remote::user_id &uid,

View File

@ -86,6 +86,8 @@ auto remote_fuse_drive::create_impl(std::string api_path, mode_t mode,
}
void remote_fuse_drive::destroy_impl(void *ptr) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
event_system::instance().raise<drive_unmount_pending>(get_mount_location());
if (server_) {
@ -96,7 +98,7 @@ void remote_fuse_drive::destroy_impl(void *ptr) {
if (remote_instance_) {
const auto res = remote_instance_->fuse_destroy();
if (res != 0) {
utils::error::raise_error(__FUNCTION__,
utils::error::raise_error(function_name,
"remote fuse_destroy() failed|err|" +
std::to_string(res));
}
@ -104,7 +106,7 @@ void remote_fuse_drive::destroy_impl(void *ptr) {
}
if (not lock_data_.set_mount_state(false, "", -1)) {
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
utils::error::raise_error(function_name, "failed to set mount state");
}
event_system::instance().raise<drive_unmounted>(get_mount_location());
@ -220,6 +222,8 @@ auto remote_fuse_drive::init_impl(struct fuse_conn_info *conn,
#else
auto remote_fuse_drive::init_impl(struct fuse_conn_info *conn) -> void * {
#endif
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
#if FUSE_USE_VERSION >= 30
auto *ret = fuse_base::init_impl(conn, cfg);
#else
@ -236,14 +240,14 @@ auto remote_fuse_drive::init_impl(struct fuse_conn_info *conn) -> void * {
event_system::instance().start();
if (not lock_data_.set_mount_state(true, get_mount_location(), getpid())) {
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
utils::error::raise_error(function_name, "failed to set mount state");
}
remote_instance_ = factory_();
remote_instance_->set_fuse_uid_gid(getuid(), getgid());
if (remote_instance_->fuse_init() != 0) {
utils::error::raise_error(__FUNCTION__,
utils::error::raise_error(function_name,
"failed to connect to remote server");
event_system::instance().raise<unmount_requested>();
} else {

File diff suppressed because it is too large Load Diff

View File

@ -54,14 +54,16 @@ remote_client::remote_client(const app_config &config)
auto remote_client::winfsp_can_delete(PVOID file_desc, PWSTR file_name)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(file_desc);
request.encode(file_name);
std::uint32_t service_flags = 0u;
const auto ret = packet_client_.send(__FUNCTION__, request, service_flags);
std::uint32_t service_flags{};
const auto ret = packet_client_.send(function_name, request, service_flags);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
__FUNCTION__,
function_name,
utils::path::create_api_path(utils::string::to_utf8(file_name)), ret);
return ret;
}
@ -69,58 +71,66 @@ auto remote_client::winfsp_can_delete(PVOID file_desc, PWSTR file_name)
auto remote_client::json_create_directory_snapshot(const std::string &path,
json &json_data)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == 0) {
ret = packet::decode_json(response, json_data);
}
RAISE_REMOTE_WINFSP_CLIENT_EVENT(__FUNCTION__, path, ret);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, path, ret);
return ret;
}
auto remote_client::json_read_directory_snapshot(
const std::string &path, const remote::file_handle &handle,
std::uint32_t page, json &json_data) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(handle);
request.encode(page);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == 0) {
ret = packet::decode_json(response, json_data);
}
RAISE_REMOTE_WINFSP_CLIENT_EVENT(__FUNCTION__, path, ret);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, path, ret);
return ret;
}
auto remote_client::json_release_directory_snapshot(
const std::string &path, const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(path);
request.encode(handle);
std::uint32_t service_flags = 0u;
const auto ret = packet_client_.send(__FUNCTION__, request, service_flags);
std::uint32_t service_flags{};
const auto ret = packet_client_.send(function_name, request, service_flags);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(__FUNCTION__, path, ret);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, path, ret);
return ret;
}
auto remote_client::winfsp_cleanup(PVOID file_desc, PWSTR file_name,
UINT32 flags, BOOLEAN &was_closed)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto handle = to_handle(file_desc);
const auto file_path = get_open_file_path(handle);
was_closed = 0;
@ -131,18 +141,20 @@ auto remote_client::winfsp_cleanup(PVOID file_desc, PWSTR file_name,
request.encode(flags);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
DECODE_OR_IGNORE(&response, was_closed);
if (was_closed) {
if (was_closed != 0U) {
remove_all(file_path);
}
RAISE_REMOTE_WINFSP_CLIENT_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_client::winfsp_close(PVOID file_desc) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto handle = to_handle(file_desc);
if (has_open_info(handle, STATUS_INVALID_HANDLE) == STATUS_SUCCESS) {
const auto file_path = get_open_file_path(handle);
@ -150,11 +162,11 @@ auto remote_client::winfsp_close(PVOID file_desc) -> packet::error_type {
packet request;
request.encode(file_desc);
std::uint32_t service_flags = 0u;
const auto ret = packet_client_.send(__FUNCTION__, request, service_flags);
std::uint32_t service_flags{};
const auto ret = packet_client_.send(function_name, request, service_flags);
if ((ret == STATUS_SUCCESS) || (ret == STATUS_INVALID_HANDLE)) {
remove_open_info(handle);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, file_path, ret);
}
}
@ -167,6 +179,8 @@ auto remote_client::winfsp_create(PWSTR file_name, UINT32 create_options,
remote::file_info *file_info,
std::string &normalized_name, BOOLEAN &exists)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(file_name);
request.encode(create_options);
@ -175,11 +189,11 @@ auto remote_client::winfsp_create(PWSTR file_name, UINT32 create_options,
request.encode(allocation_size);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == STATUS_SUCCESS) {
HANDLE handle;
HANDLE handle{};
DECODE_OR_IGNORE(&response, handle);
DECODE_OR_IGNORE(&response, *file_info);
DECODE_OR_IGNORE(&response, normalized_name);
@ -198,23 +212,25 @@ auto remote_client::winfsp_create(PWSTR file_name, UINT32 create_options,
}
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
__FUNCTION__, get_open_file_path(to_handle(*file_desc)), ret);
function_name, get_open_file_path(to_handle(*file_desc)), ret);
return ret;
}
auto remote_client::winfsp_flush(PVOID file_desc, remote::file_info *file_info)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(file_desc);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
__FUNCTION__, get_open_file_path(to_handle(file_desc)), ret);
function_name, get_open_file_path(to_handle(file_desc)), ret);
return ret;
}
@ -232,17 +248,19 @@ auto remote_client::winfsp_get_dir_buffer([[maybe_unused]] PVOID file_desc,
auto remote_client::winfsp_get_file_info(PVOID file_desc,
remote::file_info *file_info)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(file_desc);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
__FUNCTION__, get_open_file_path(to_handle(file_desc)), ret);
function_name, get_open_file_path(to_handle(file_desc)), ret);
return ret;
}
@ -251,16 +269,18 @@ auto remote_client::winfsp_get_security_by_name(PWSTR file_name,
std::uint64_t *descriptor_size,
std::wstring &string_descriptor)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(file_name);
request.encode(
static_cast<std::uint64_t>(descriptor_size ? *descriptor_size : 0));
request.encode(static_cast<std::uint64_t>(
descriptor_size == nullptr ? 0 : *descriptor_size));
request.encode(static_cast<std::uint8_t>(attributes != nullptr));
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
string_descriptor.clear();
DECODE_OR_IGNORE(&response, string_descriptor);
@ -268,11 +288,11 @@ auto remote_client::winfsp_get_security_by_name(PWSTR file_name,
string_descriptor = L"O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;WD)";
}
if (attributes) {
if (attributes != nullptr) {
DECODE_OR_IGNORE(&response, *attributes);
}
RAISE_REMOTE_WINFSP_CLIENT_EVENT(__FUNCTION__,
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name,
utils::string::to_utf8(file_name), ret);
return ret;
}
@ -281,11 +301,13 @@ auto remote_client::winfsp_get_volume_info(UINT64 &total_size,
UINT64 &free_size,
std::string &volume_label)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
DECODE_OR_IGNORE(&response, total_size);
DECODE_OR_IGNORE(&response, free_size);
DECODE_OR_IGNORE(&response, volume_label);
@ -295,16 +317,18 @@ auto remote_client::winfsp_get_volume_info(UINT64 &total_size,
auto remote_client::winfsp_mounted(const std::wstring &location)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(get_repertory_version());
request.encode(location);
std::uint32_t service_flags = 0u;
const auto ret = packet_client_.send(__FUNCTION__, request, service_flags);
std::uint32_t service_flags{};
const auto ret = packet_client_.send(function_name, request, service_flags);
const auto mount_location = utils::string::to_utf8(location);
event_system::instance().raise<drive_mounted>(mount_location);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(__FUNCTION__, mount_location, ret);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, mount_location, ret);
return ret;
}
@ -313,17 +337,19 @@ auto remote_client::winfsp_open(PWSTR file_name, UINT32 create_options,
remote::file_info *file_info,
std::string &normalized_name)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(file_name);
request.encode(create_options);
request.encode(granted_access);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == STATUS_SUCCESS) {
HANDLE handle;
HANDLE handle{};
DECODE_OR_IGNORE(&response, handle);
DECODE_OR_IGNORE(&response, *file_info);
DECODE_OR_IGNORE(&response, normalized_name);
@ -337,7 +363,7 @@ auto remote_client::winfsp_open(PWSTR file_name, UINT32 create_options,
}
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
__FUNCTION__, get_open_file_path(to_handle(*file_desc)), ret);
function_name, get_open_file_path(to_handle(*file_desc)), ret);
return ret;
}
@ -346,6 +372,8 @@ auto remote_client::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
UINT64 allocation_size,
remote::file_info *file_info)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(file_desc);
request.encode(attributes);
@ -353,28 +381,30 @@ auto remote_client::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
request.encode(allocation_size);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
__FUNCTION__, get_open_file_path(to_handle(file_desc)), ret);
function_name, get_open_file_path(to_handle(file_desc)), ret);
return ret;
}
auto remote_client::winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
UINT32 length, PUINT32 bytes_transferred)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(file_desc);
request.encode(offset);
request.encode(length);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
DECODE_OR_IGNORE(&response, *bytes_transferred);
if (ret == STATUS_SUCCESS) {
ret = response.decode(buffer, *bytes_transferred);
@ -388,7 +418,7 @@ auto remote_client::winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
if (ret != STATUS_SUCCESS) {
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
__FUNCTION__, get_open_file_path(to_handle(file_desc)), ret);
function_name, get_open_file_path(to_handle(file_desc)), ret);
}
return ret;
@ -397,21 +427,23 @@ auto remote_client::winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
auto remote_client::winfsp_read_directory(PVOID file_desc, PWSTR pattern,
PWSTR marker, json &item_list)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(file_desc);
request.encode(pattern);
request.encode(marker);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
if (ret == STATUS_SUCCESS) {
ret = packet::decode_json(response, item_list);
}
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
__FUNCTION__, get_open_file_path(to_handle(file_desc)), ret);
function_name, get_open_file_path(to_handle(file_desc)), ret);
return ret;
}
@ -419,16 +451,18 @@ auto remote_client::winfsp_rename(PVOID file_desc, PWSTR file_name,
PWSTR new_file_name,
BOOLEAN replace_if_exists)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(file_desc);
request.encode(file_name);
request.encode(new_file_name);
request.encode(replace_if_exists);
std::uint32_t service_flags = 0u;
const auto ret = packet_client_.send(__FUNCTION__, request, service_flags);
std::uint32_t service_flags{};
const auto ret = packet_client_.send(function_name, request, service_flags);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
__FUNCTION__,
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);
@ -439,6 +473,8 @@ auto remote_client::winfsp_set_basic_info(
PVOID file_desc, UINT32 attributes, UINT64 creation_time,
UINT64 last_access_time, UINT64 last_write_time, UINT64 change_time,
remote::file_info *file_info) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(file_desc);
request.encode(attributes);
@ -448,13 +484,13 @@ auto remote_client::winfsp_set_basic_info(
request.encode(change_time);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
__FUNCTION__, get_open_file_path(to_handle(file_desc)), ret);
function_name, get_open_file_path(to_handle(file_desc)), ret);
return ret;
}
@ -462,34 +498,38 @@ auto remote_client::winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
BOOLEAN set_allocation_size,
remote::file_info *file_info)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(file_desc);
request.encode(new_size);
request.encode(set_allocation_size);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
__FUNCTION__, get_open_file_path(to_handle(file_desc)), ret);
function_name, get_open_file_path(to_handle(file_desc)), ret);
return ret;
}
auto remote_client::winfsp_unmounted(const std::wstring &location)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto mount_location = utils::string::to_utf8(location);
event_system::instance().raise<drive_unmount_pending>(mount_location);
packet request;
request.encode(location);
std::uint32_t service_flags = 0u;
const auto ret = packet_client_.send(__FUNCTION__, request, service_flags);
std::uint32_t service_flags{};
const auto ret = packet_client_.send(function_name, request, service_flags);
event_system::instance().raise<drive_unmounted>(mount_location);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(__FUNCTION__, mount_location, ret);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, mount_location, ret);
return ret;
}
@ -499,32 +539,34 @@ auto remote_client::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
PUINT32 bytes_transferred,
remote::file_info *file_info)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
packet request;
request.encode(file_desc);
request.encode(length);
request.encode(offset);
request.encode(write_to_end);
request.encode(constrained_io);
if (length) {
if (length != 0U) {
request.encode(buffer, length);
}
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
packet_client_.send(function_name, request, response, service_flags);
DECODE_OR_IGNORE(&response, *bytes_transferred);
DECODE_OR_IGNORE(&response, *file_info);
if (ret != STATUS_SUCCESS) {
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
__FUNCTION__, get_open_file_path(to_handle(file_desc)), ret);
function_name, get_open_file_path(to_handle(file_desc)), ret);
}
return ret;
}
#ifndef _WIN32
native_handle remote_client::to_handle(PVOID file_desc) {
auto remote_client::to_handle(PVOID file_desc) -> native_handle {
return static_cast<native_handle>(reinterpret_cast<std::uint64_t>(file_desc));
}
#endif

View File

@ -98,28 +98,34 @@ void remote_server::populate_stat(const char *path, bool directory,
// FUSE Layer
auto remote_server::fuse_access(const char *path, const std::int32_t &mask)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto windows_mask = utils::unix_access_mask_to_windows(mask);
const auto res = _access(file_path.c_str(), windows_mask);
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_chflags(const char *path, std::uint32_t /*flags*/)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto ret = STATUS_NOT_IMPLEMENTED;
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_chmod(const char *path,
const remote::file_mode & /*mode*/)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto ret = STATUS_NOT_IMPLEMENTED;
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
@ -127,14 +133,18 @@ auto remote_server::fuse_chown(const char *path,
const remote::user_id & /*uid*/,
const remote::group_id & /*gid*/)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto ret = STATUS_NOT_IMPLEMENTED;
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_destroy() -> packet::error_type {
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, "", 0);
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, "", 0);
return 0;
}
@ -146,7 +156,7 @@ construct_path(path); auto res = HasOpenFileCompatInfo(handle, EBADF); if (res
}
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}*/
@ -154,6 +164,8 @@ auto remote_server::fuse_fgetattr(const char *path, remote::stat &r_stat,
bool &directory,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
memset(&r_stat, 0, sizeof(remote::stat));
@ -168,7 +180,7 @@ auto remote_server::fuse_fgetattr(const char *path, remote::stat &r_stat,
}
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
@ -176,9 +188,11 @@ auto remote_server::fuse_fsetattr_x(const char *path,
const remote::setattr_x & /*attr*/,
const remote::file_handle & /*handle*/)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto ret = STATUS_NOT_IMPLEMENTED;
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
@ -186,6 +200,8 @@ auto remote_server::fuse_fsync(const char *path,
const std::int32_t & /*datasync*/,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
auto res = has_compat_open_info(handle, EBADF);
@ -204,7 +220,7 @@ auto remote_server::fuse_fsync(const char *path,
}
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
@ -212,6 +228,8 @@ auto remote_server::fuse_ftruncate(const char *path,
const remote::file_offset &size,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
auto res = has_compat_open_info(handle, EBADF);
@ -233,12 +251,14 @@ auto remote_server::fuse_ftruncate(const char *path,
}
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_getattr(const char *path, remote::stat &r_st,
bool &directory) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
memset(&r_st, 0, sizeof(remote::stat));
@ -251,20 +271,20 @@ auto remote_server::fuse_getattr(const char *path, remote::stat &r_st,
}
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
/*packet::error_type remote_server::fuse_getxattr(const char *path, const char
*name, char *value, const remote::file_size &size) { const auto file_path =
construct_path(path); const auto ret = STATUS_NOT_IMPLEMENTED;
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret); return ret;
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret); return ret;
}
packet::error_type remote_server::fuse_getxattr_osx(const char *path, const char
*name, char *value, const remote::file_size &size, std::uint32_t position) {
const auto file_path = construct_path(path); const auto ret =
STATUS_NOT_IMPLEMENTED; RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__,
STATUS_NOT_IMPLEMENTED; RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name,
file_path, ret); return ret;
}*/
@ -272,36 +292,44 @@ auto remote_server::fuse_getxtimes(const char *path,
remote::file_time & /*bkuptime*/,
remote::file_time & /*crtime*/)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto ret = STATUS_NOT_IMPLEMENTED;
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_init() -> packet::error_type {
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, "", 0);
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, "", 0);
return 0;
}
/*packet::error_type remote_server::fuse_listxattr(const char *path, char
*buffer, const remote::file_size &size) { const auto file_path =
construct_path(path); const auto ret = STATUS_NOT_IMPLEMENTED;
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}*/
auto remote_server::fuse_mkdir(const char *path,
const remote::file_mode & /*mode*/)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto res = _mkdir(file_path.c_str());
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_opendir(const char *path, remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto unicode_file_path = utils::string::from_utf8(file_path);
auto res = -1;
@ -316,7 +344,7 @@ auto remote_server::fuse_opendir(const char *path, remote::file_handle &handle)
}
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
@ -324,6 +352,8 @@ auto remote_server::fuse_create(const char *path, const remote::file_mode &mode,
const remote::open_flags &flags,
remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto ret = -1;
const auto file_path = construct_path(path);
@ -351,13 +381,15 @@ auto remote_server::fuse_create(const char *path, const remote::file_mode &mode,
}
}
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_open(const char *path, const remote::open_flags &flags,
remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
auto res = -1;
@ -380,7 +412,7 @@ auto remote_server::fuse_open(const char *path, const remote::open_flags &flags,
}
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
@ -389,6 +421,8 @@ auto remote_server::fuse_read(const char *path, char *buffer,
const remote::file_offset &read_offset,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
auto &data = *reinterpret_cast<data_buffer *>(buffer);
auto res = 0;
@ -425,19 +459,21 @@ auto remote_server::fuse_read(const char *path, char *buffer,
const auto ret = ((res < 0) ? -errno : static_cast<int>(data.size()));
if (ret < 0) {
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
}
return ret;
}
auto remote_server::fuse_rename(const char *from, const char *to)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto from_path = utils::path::combine(mount_location_, {from});
const auto to_path = utils::path::combine(mount_location_, {to});
const auto res = rename(from_path.c_str(), to_path.c_str());
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, from + std::string("|") + to,
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, from + std::string("|") + to,
ret);
return ret;
}
@ -447,6 +483,8 @@ auto remote_server::fuse_write(const char *path, const char *buffer,
const remote::file_offset &write_offset,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
std::size_t bytes_written{};
auto res = 0;
@ -475,7 +513,7 @@ auto remote_server::fuse_write(const char *path, const char *buffer,
const auto ret = ((res < 0) ? -errno : static_cast<int>(bytes_written));
if (ret < 0) {
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
}
return ret;
}
@ -493,6 +531,8 @@ auto remote_server::fuse_readdir(const char *path,
const remote::file_offset &offset,
const remote::file_handle &handle,
std::string &item_path) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
auto res = 0;
if (offset > std::numeric_limits<std::size_t>::max()) {
@ -509,91 +549,107 @@ auto remote_server::fuse_readdir(const char *path,
}
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_release(const char *path,
const remote::file_handle &handle)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
remove_compat_open_info(handle);
const auto res = _close(static_cast<int>(handle));
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_releasedir(const char *path,
const remote::file_handle & /*handle*/)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, 0);
return 0;
}
/*packet::error_type remote_server::fuse_removexattr(const char *path, const
char *name) { const auto file_path = construct_path(path); const auto ret =
STATUS_NOT_IMPLEMENTED; RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__,
STATUS_NOT_IMPLEMENTED; RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name,
file_path, ret); return ret;
}*/
auto remote_server::fuse_rmdir(const char *path) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto res = _rmdir(file_path.c_str());
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_setattr_x(const char *path,
remote::setattr_x & /*attr*/)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto ret = STATUS_NOT_IMPLEMENTED;
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_setbkuptime(const char *path,
const remote::file_time & /*bkuptime*/)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto ret = STATUS_NOT_IMPLEMENTED;
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_setchgtime(const char *path,
const remote::file_time & /*chgtime*/)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto ret = STATUS_NOT_IMPLEMENTED;
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_setcrtime(const char *path,
const remote::file_time & /*crtime*/)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto ret = STATUS_NOT_IMPLEMENTED;
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_setvolname(const char *volname) -> packet::error_type {
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, volname, 0);
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, volname, 0);
return 0;
}
/*packet::error_type remote_server::fuse_setxattr(const char *path, const char
*name, const char *value, const remote::file_size &size, const std::int32_t
&flags) { const auto file_path = construct_path(path); const auto ret =
STATUS_NOT_IMPLEMENTED; RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__,
STATUS_NOT_IMPLEMENTED; RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name,
file_path, ret); return ret;
}
@ -601,12 +657,14 @@ packet::error_type remote_server::fuse_setxattr_osx(const char *path, const char
*name, const char *value, const remote::file_size &size, const std::int32_t
&flags, const std::uint32_t &position) { const auto file_path =
construct_path(path); const auto ret = STATUS_NOT_IMPLEMENTED;
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}*/
auto remote_server::fuse_statfs(const char *path, std::uint64_t frsize,
remote::statfs &r_stat) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto total_bytes = drive_.get_total_drive_space();
@ -621,13 +679,15 @@ auto remote_server::fuse_statfs(const char *path, std::uint64_t frsize,
r_stat.f_ffree = r_stat.f_favail =
r_stat.f_files - drive_.get_total_item_count();
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, 0);
return 0;
}
auto remote_server::fuse_statfs_x(const char *path, std::uint64_t bsize,
remote::statfs_x &r_stat)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto total_bytes = drive_.get_total_drive_space();
@ -645,13 +705,15 @@ auto remote_server::fuse_statfs_x(const char *path, std::uint64_t bsize,
(utils::create_volume_label(config_.get_provider_type())).c_str(),
sizeof(r_stat.f_mntfromname) - 1U);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, 0);
return 0;
}
auto remote_server::fuse_truncate(const char *path,
const remote::file_offset &size)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto unicode_file_path = utils::string::from_utf8(file_path);
auto res = -1;
@ -679,21 +741,25 @@ auto remote_server::fuse_truncate(const char *path,
}
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_unlink(const char *path) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto res = _unlink(file_path.c_str());
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
std::uint64_t op0, std::uint64_t op1)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
const auto unicode_file_path = utils::string::from_utf8(file_path);
@ -746,7 +812,7 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
}
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
@ -754,6 +820,8 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
auto remote_server::json_create_directory_snapshot(const std::string &path,
json &json_data)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
auto res = -1;
@ -772,13 +840,15 @@ auto remote_server::json_create_directory_snapshot(const std::string &path,
}
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::json_read_directory_snapshot(
const std::string &path, const remote::file_handle &handle,
std::uint32_t page, json &json_data) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
auto *iterator = reinterpret_cast<directory_iterator *>(handle);
std::size_t offset{};
@ -797,15 +867,17 @@ auto remote_server::json_read_directory_snapshot(
json_data["page_count"] = utils::divide_with_ceiling(
iterator->get_count(), REPERTORY_DIRECTORY_PAGE_SIZE);
const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::json_release_directory_snapshot(
const std::string &path, const remote::file_handle & /*handle*/)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = construct_path(path);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, 0);
return 0;
}
@ -813,6 +885,8 @@ auto remote_server::json_release_directory_snapshot(
// WinFSP Layer
auto remote_server::winfsp_can_delete(PVOID file_desc, PWSTR /*file_name*/)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto *handle = reinterpret_cast<HANDLE>(file_desc);
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
@ -824,7 +898,7 @@ auto remote_server::winfsp_can_delete(PVOID file_desc, PWSTR /*file_name*/)
? STATUS_SUCCESS
: FspNtStatusFromWin32(::GetLastError());
}
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, get_open_file_path(file_desc),
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, get_open_file_path(file_desc),
ret);
return ret;
}
@ -832,6 +906,8 @@ auto remote_server::winfsp_can_delete(PVOID file_desc, PWSTR /*file_name*/)
auto remote_server::winfsp_cleanup(PVOID file_desc, PWSTR /*file_name*/,
UINT32 flags, BOOLEAN &was_closed)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = get_open_file_path(file_desc);
was_closed = FALSE;
auto *handle = reinterpret_cast<HANDLE>(file_desc);
@ -843,11 +919,13 @@ auto remote_server::winfsp_cleanup(PVOID file_desc, PWSTR /*file_name*/,
was_closed = TRUE;
}
}
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, ret);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret;
}
auto remote_server::winfsp_close(PVOID file_desc) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = get_open_file_path(file_desc);
auto *handle = reinterpret_cast<HANDLE>(file_desc);
@ -856,7 +934,7 @@ auto remote_server::winfsp_close(PVOID file_desc) -> packet::error_type {
remove_open_info(file_desc);
}
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, file_path, STATUS_SUCCESS);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, STATUS_SUCCESS);
return STATUS_SUCCESS;
}
@ -866,6 +944,8 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
remote::file_info *file_info,
std::string &normalized_name, BOOLEAN &exists)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = utils::string::from_utf8(utils::path::combine(
mount_location_, {utils::string::to_utf8(file_name)}));
exists = static_cast<BOOLEAN>(utils::file::is_file(utils::path::combine(
@ -899,13 +979,15 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
? FspNtStatusFromWin32(::GetLastError())
: populate_file_info(construct_api_path(get_open_file_path(handle)),
*file_info);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__,
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name,
utils::string::to_utf8(file_path), ret);
return ret;
}
auto remote_server::winfsp_flush(PVOID file_desc, remote::file_info *file_info)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto *handle = reinterpret_cast<HANDLE>(file_desc);
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) {
@ -917,7 +999,7 @@ auto remote_server::winfsp_flush(PVOID file_desc, remote::file_info *file_info)
}
}
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, get_open_file_path(file_desc),
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, get_open_file_path(file_desc),
ret);
return ret;
}
@ -925,13 +1007,15 @@ auto remote_server::winfsp_flush(PVOID file_desc, remote::file_info *file_info)
auto remote_server::winfsp_get_file_info(PVOID file_desc,
remote::file_info *file_info)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto *handle = reinterpret_cast<HANDLE>(file_desc);
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) {
ret = populate_file_info(construct_api_path(get_open_file_path(handle)),
*file_info);
}
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, get_open_file_path(file_desc),
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, get_open_file_path(file_desc),
ret);
return ret;
}
@ -941,6 +1025,8 @@ auto remote_server::winfsp_get_security_by_name(PWSTR file_name,
std::uint64_t *descriptor_size,
std::wstring &string_descriptor)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = utils::string::from_utf8(utils::path::combine(
mount_location_, {utils::string::to_utf8(file_name)}));
@ -971,7 +1057,7 @@ auto remote_server::winfsp_get_security_by_name(PWSTR file_name,
::LocalFree(descriptor);
}
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__,
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name,
utils::string::to_utf8(file_path), ret);
return ret;
}
@ -980,15 +1066,19 @@ auto remote_server::winfsp_get_volume_info(UINT64 &total_size,
UINT64 &free_size,
std::string &volume_label)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
drive_.get_volume_info(total_size, free_size, volume_label);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, volume_label, STATUS_SUCCESS);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, volume_label, STATUS_SUCCESS);
return STATUS_SUCCESS;
}
auto remote_server::winfsp_mounted(const std::wstring &location)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
RAISE_REMOTE_WINFSP_SERVER_EVENT(
__FUNCTION__, utils::string::to_utf8(location), STATUS_SUCCESS);
function_name, utils::string::to_utf8(location), STATUS_SUCCESS);
return STATUS_SUCCESS;
}
@ -997,6 +1087,8 @@ auto remote_server::winfsp_open(PWSTR file_name, UINT32 create_options,
remote::file_info *file_info,
std::string &normalized_name)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto file_path = utils::string::from_utf8(utils::path::combine(
mount_location_, {utils::string::to_utf8(file_name)}));
@ -1021,7 +1113,7 @@ auto remote_server::winfsp_open(PWSTR file_name, UINT32 create_options,
? FspNtStatusFromWin32(::GetLastError())
: populate_file_info(construct_api_path(get_open_file_path(handle)),
*file_info);
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__,
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name,
utils::string::to_utf8(file_path), ret);
return ret;
}
@ -1031,6 +1123,8 @@ auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
UINT64 /*allocation_size*/,
remote::file_info *file_info)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto *handle = reinterpret_cast<HANDLE>(file_desc);
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) {
@ -1076,7 +1170,7 @@ auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
}
}
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, get_open_file_path(file_desc),
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, get_open_file_path(file_desc),
ret);
return ret;
}
@ -1084,6 +1178,8 @@ auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
auto remote_server::winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
UINT32 length, PUINT32 bytes_transferred)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
*bytes_transferred = 0U;
auto *handle = reinterpret_cast<HANDLE>(file_desc);
@ -1100,7 +1196,7 @@ auto remote_server::winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
: FspNtStatusFromWin32(::GetLastError());
}
if (ret != STATUS_SUCCESS) {
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__,
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name,
get_open_file_path(file_desc), ret);
}
@ -1110,6 +1206,8 @@ auto remote_server::winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
auto remote_server::winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/,
PWSTR marker, json &item_list)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto ret = STATUS_INVALID_HANDLE;
item_list.clear();
@ -1131,7 +1229,7 @@ auto remote_server::winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/,
ret = STATUS_SUCCESS;
}
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, get_open_file_path(file_desc),
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, get_open_file_path(file_desc),
ret);
return ret;
}
@ -1140,6 +1238,8 @@ auto remote_server::winfsp_rename(PVOID /*file_desc*/, PWSTR file_name,
PWSTR new_file_name,
BOOLEAN replace_if_exists)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto from_path = utils::string::from_utf8(utils::path::combine(
mount_location_, {utils::string::to_utf8(file_name)}));
const auto to_path = utils::string::from_utf8(utils::path::combine(
@ -1152,7 +1252,7 @@ auto remote_server::winfsp_rename(PVOID /*file_desc*/, PWSTR file_name,
: FspNtStatusFromWin32(::GetLastError());
RAISE_REMOTE_WINFSP_SERVER_EVENT(
__FUNCTION__, utils::string::to_utf8(from_path + L"|" + to_path), ret);
function_name, utils::string::to_utf8(from_path + L"|" + to_path), ret);
return ret;
}
@ -1160,6 +1260,8 @@ auto remote_server::winfsp_set_basic_info(
PVOID file_desc, UINT32 attributes, UINT64 creation_time,
UINT64 last_access_time, UINT64 last_write_time, UINT64 change_time,
remote::file_info *file_info) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto *handle = reinterpret_cast<HANDLE>(file_desc);
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) {
@ -1182,7 +1284,7 @@ auto remote_server::winfsp_set_basic_info(
construct_api_path(get_open_file_path(handle)), *file_info)
: FspNtStatusFromWin32(::GetLastError());
}
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, get_open_file_path(file_desc),
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, get_open_file_path(file_desc),
ret);
return ret;
}
@ -1191,6 +1293,8 @@ auto remote_server::winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
BOOLEAN set_allocation_size,
remote::file_info *file_info)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto *handle = reinterpret_cast<HANDLE>(file_desc);
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) {
@ -1217,15 +1321,17 @@ auto remote_server::winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
: ret;
}
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__, get_open_file_path(file_desc),
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, get_open_file_path(file_desc),
ret);
return ret;
}
auto remote_server::winfsp_unmounted(const std::wstring &location)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
RAISE_REMOTE_WINFSP_SERVER_EVENT(
__FUNCTION__, utils::string::to_utf8(location), STATUS_SUCCESS);
function_name, utils::string::to_utf8(location), STATUS_SUCCESS);
return STATUS_SUCCESS;
}
@ -1235,6 +1341,8 @@ auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
PUINT32 bytes_transferred,
remote::file_info *file_info)
-> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto *handle = reinterpret_cast<HANDLE>(file_desc);
*bytes_transferred = 0U;
auto ret = has_open_info(handle, STATUS_INVALID_HANDLE);
@ -1274,7 +1382,7 @@ auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
}
if (ret != STATUS_SUCCESS) {
RAISE_REMOTE_WINFSP_SERVER_EVENT(__FUNCTION__,
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name,
get_open_file_path(file_desc), ret);
}
return ret;

View File

@ -49,6 +49,8 @@ remote_winfsp_drive::winfsp_service::winfsp_service(
host_(drive) {}
auto remote_winfsp_drive::winfsp_service::OnStart(ULONG, PWSTR *) -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto mount_location = utils::string::to_lower(
utils::path::absolute((drive_args_.size() > 1u) ? drive_args_[1u] : ""));
const auto drive_letter =
@ -75,7 +77,7 @@ auto remote_winfsp_drive::winfsp_service::OnStart(ULONG, PWSTR *) -> NTSTATUS {
event_system::instance().raise<drive_mount_failed>(mount_location,
std::to_string(ret));
if (not lock_.set_mount_state(false, "", -1)) {
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
utils::error::raise_error(function_name, "failed to set mount state");
}
}
@ -83,9 +85,11 @@ auto remote_winfsp_drive::winfsp_service::OnStart(ULONG, PWSTR *) -> NTSTATUS {
}
auto remote_winfsp_drive::winfsp_service::OnStop() -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
host_.Unmount();
if (not lock_.set_mount_state(false, "", -1)) {
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
utils::error::raise_error(function_name, "failed to set mount state");
}
return STATUS_SUCCESS;
@ -258,6 +262,8 @@ auto remote_winfsp_drive::mount(const std::vector<std::string> &drive_args)
}
auto remote_winfsp_drive::Mounted(PVOID host) -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto *file_system_host = reinterpret_cast<FileSystemHost *>(host);
remote_instance_ = factory_();
server_ = std::make_unique<server>(config_);
@ -265,7 +271,7 @@ auto remote_winfsp_drive::Mounted(PVOID host) -> NTSTATUS {
mount_location_ = utils::string::to_utf8(file_system_host->MountPoint());
if (not lock_.set_mount_state(true, mount_location_,
::GetCurrentProcessId())) {
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
utils::error::raise_error(function_name, "failed to set mount state");
}
return remote_instance_->winfsp_mounted(file_system_host->MountPoint());
@ -445,11 +451,13 @@ auto remote_winfsp_drive::SetFileSize(PVOID /*file_node*/, PVOID file_desc,
}
VOID remote_winfsp_drive::Unmounted(PVOID host) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
server_->stop();
server_.reset();
auto *file_system_host = reinterpret_cast<FileSystemHost *>(host);
if (not lock_.set_mount_state(false, "", -1)) {
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
utils::error::raise_error(function_name, "failed to set mount state");
}
remote_instance_->winfsp_unmounted(file_system_host->MountPoint());
remote_instance_.reset();

View File

@ -66,6 +66,8 @@ winfsp_drive::winfsp_service::winfsp_service(
auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/, PWSTR * /*Argv*/)
-> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto mount_location = utils::string::to_lower(
utils::path::absolute((drive_args_.size() > 1U) ? drive_args_[1U] : ""));
const auto drive_letter =
@ -90,7 +92,8 @@ auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/, PWSTR * /*Argv*/)
if (ret != STATUS_SUCCESS) {
if (not lock_.set_mount_state(false, "", -1)) {
utils::error::raise_error(__FUNCTION__, 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>(mount_location,
std::to_string(ret));
@ -100,10 +103,12 @@ auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/, PWSTR * /*Argv*/)
}
auto winfsp_drive::winfsp_service::OnStop() -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
host_.Unmount();
if (not lock_.set_mount_state(false, "", -1)) {
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
utils::error::raise_error(function_name, "failed to set mount state");
}
return STATUS_SUCCESS;
@ -121,6 +126,8 @@ void winfsp_drive::shutdown() { ::GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0); }
auto winfsp_drive::CanDelete(PVOID /*file_node*/, PVOID file_desc,
PWSTR /*file_name*/) -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::string api_path;
auto error = api_error::invalid_handle;
auto handle =
@ -141,12 +148,14 @@ auto winfsp_drive::CanDelete(PVOID /*file_node*/, PVOID file_desc,
}
auto ret = utils::from_api_error(error);
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, ret);
RAISE_WINFSP_EVENT(function_name, api_path, ret);
return ret;
}
VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
PWSTR /*file_name*/, ULONG flags) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::string api_path;
auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
@ -167,13 +176,13 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
if (directory) {
auto res = provider_.remove_directory(api_path);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to remove directory");
}
} else {
auto res = fm_->remove_file(api_path);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to remove file");
}
}
@ -187,7 +196,8 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
FILE_ATTRIBUTE_ARCHIVE));
if (res != api_error::success) {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, res, "failed to set meta attributes");
function_name, api_path, res,
"failed to set meta attributes");
}
}
}
@ -200,7 +210,7 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
std::to_string(now));
if (res != api_error::success) {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, res,
function_name, api_path, res,
"failed to set meta accessed time");
}
}
@ -210,7 +220,7 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
std::to_string(now));
if (res != api_error::success) {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, res,
function_name, api_path, res,
"failed to set meta written time");
}
}
@ -221,7 +231,7 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
{META_MODIFIED, std::to_string(now)}});
if (res != api_error::success) {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, res,
function_name, api_path, res,
"failed to set meta modified time");
}
}
@ -237,10 +247,13 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
}
}
}
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, 0);
RAISE_WINFSP_EVENT(function_name, api_path, 0);
}
VOID winfsp_drive::Close(PVOID /*file_node*/, PVOID file_desc) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::string api_path;
auto handle =
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(file_desc));
@ -258,7 +271,7 @@ VOID winfsp_drive::Close(PVOID /*file_node*/, PVOID file_desc) {
FspFileSystemDeleteDirectoryBuffer(&directory_buffer);
}
}
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, 0);
RAISE_WINFSP_EVENT(function_name, api_path, 0);
}
auto winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
@ -266,6 +279,8 @@ auto winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
PSECURITY_DESCRIPTOR /*descriptor*/,
UINT64 /*allocation_size*/, PVOID * /*file_node*/,
PVOID *file_desc, OpenFileInfo *ofi) -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
// TODO Need to revisit this
// (ConvertSecurityDescriptorToStringSecurityDescriptor/ConvertStringSecurityDescriptorToSecurityDescriptor)
auto error = api_error::error;
@ -311,12 +326,14 @@ auto winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
}
auto ret = utils::from_api_error(error);
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, ret);
RAISE_WINFSP_EVENT(function_name, api_path, ret);
return ret;
}
auto winfsp_drive::Flush(PVOID /*file_node*/, PVOID file_desc,
FileInfo *file_info) -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::string api_path;
auto error = api_error::success;
auto handle =
@ -343,7 +360,7 @@ auto winfsp_drive::Flush(PVOID /*file_node*/, PVOID file_desc,
}
auto ret = utils::from_api_error(error);
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, ret);
RAISE_WINFSP_EVENT(function_name, api_path, ret);
return ret;
}
@ -354,10 +371,12 @@ auto winfsp_drive::get_directory_item_count(const std::string &api_path) const
auto winfsp_drive::get_directory_items(const std::string &api_path) const
-> directory_item_list {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
directory_item_list list;
auto res = provider_.get_directory_items(api_path, list);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to get directory list");
}
return list;
@ -365,6 +384,8 @@ auto winfsp_drive::get_directory_items(const std::string &api_path) const
auto winfsp_drive::GetFileInfo(PVOID /*file_node*/, PVOID file_desc,
FileInfo *file_info) -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::string api_path;
auto error = api_error::invalid_handle;
auto handle =
@ -382,16 +403,18 @@ auto winfsp_drive::GetFileInfo(PVOID /*file_node*/, PVOID file_desc,
}
auto ret = utils::from_api_error(error);
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, ret);
RAISE_WINFSP_EVENT(function_name, api_path, ret);
return ret;
}
auto winfsp_drive::get_file_size(const std::string &api_path) const
-> std::uint64_t {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::uint64_t file_size{};
auto res = provider_.get_file_size(api_path, file_size);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to get file size");
}
@ -455,6 +478,8 @@ auto winfsp_drive::get_security_by_name(PWSTR file_name, PUINT32 attributes,
auto winfsp_drive::GetSecurityByName(PWSTR file_name, PUINT32 attributes,
PSECURITY_DESCRIPTOR descriptor,
SIZE_T *descriptor_size) -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto api_path =
utils::path::create_api_path(utils::string::to_utf8(file_name));
std::uint64_t sds = descriptor_size == nullptr ? 0U : *descriptor_size;
@ -463,7 +488,7 @@ auto winfsp_drive::GetSecurityByName(PWSTR file_name, PUINT32 attributes,
if (sds != 0U) {
*descriptor_size = static_cast<SIZE_T>(sds);
}
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, ret);
RAISE_WINFSP_EVENT(function_name, api_path, ret);
return ret;
}
@ -489,6 +514,8 @@ void winfsp_drive::get_volume_info(UINT64 &total_size, UINT64 &free_size,
}
auto winfsp_drive::GetVolumeInfo(VolumeInfo *volume_info) -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const std::wstring volume_label = utils::string::from_utf8(
utils::create_volume_label(config_.get_provider_type()));
const auto total_bytes = provider_.get_total_drive_space();
@ -500,7 +527,7 @@ auto winfsp_drive::GetVolumeInfo(VolumeInfo *volume_info) -> NTSTATUS {
std::min(static_cast<UINT16>(64),
static_cast<UINT16>(volume_label.size() * sizeof(WCHAR)));
RAISE_WINFSP_EVENT(__FUNCTION__, utils::string::to_utf8(volume_label), 0);
RAISE_WINFSP_EVENT(function_name, utils::string::to_utf8(volume_label), 0);
return STATUS_SUCCESS;
}
@ -563,6 +590,8 @@ auto winfsp_drive::mount(const std::vector<std::string> &drive_args) -> int {
}
auto winfsp_drive::Mounted(PVOID host) -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto ret = STATUS_SUCCESS;
utils::file::change_to_process_directory();
@ -598,12 +627,12 @@ auto winfsp_drive::Mounted(PVOID host) -> NTSTATUS {
if (not lock_.set_mount_state(true, mount_location,
::GetCurrentProcessId())) {
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
utils::error::raise_error(function_name, "failed to set mount state");
}
event_system::instance().raise<drive_mounted>(mount_location);
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
utils::error::raise_error(function_name, e, "exception occurred");
if (remote_server_) {
remote_server_.reset();
}
@ -623,6 +652,8 @@ auto winfsp_drive::Mounted(PVOID host) -> NTSTATUS {
auto winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, PVOID * /*file_node*/,
PVOID *file_desc, OpenFileInfo *ofi) -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto api_path =
utils::path::create_api_path(utils::string::to_utf8(file_name));
@ -660,7 +691,7 @@ auto winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
}
auto ret = utils::from_api_error(error);
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, ret);
RAISE_WINFSP_EVENT(function_name, api_path, ret);
return ret;
}
@ -668,6 +699,8 @@ auto winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc,
UINT32 attributes, BOOLEAN replace_attributes,
UINT64 /*allocation_size*/, FileInfo *file_info)
-> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::string api_path;
auto error = api_error::invalid_handle;
auto handle =
@ -714,7 +747,7 @@ auto winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc,
}
auto ret = utils::from_api_error(error);
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, ret);
RAISE_WINFSP_EVENT(function_name, api_path, ret);
return ret;
}
@ -776,6 +809,8 @@ void winfsp_drive::populate_file_info(std::uint64_t file_size,
auto winfsp_drive::Read(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
UINT64 offset, ULONG length, PULONG bytes_transferred)
-> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
*bytes_transferred = 0U;
std::string api_path;
@ -803,7 +838,7 @@ auto winfsp_drive::Read(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
std::to_string(utils::get_file_time_now()));
if (res != api_error::success) {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, res,
function_name, api_path, res,
"failed to set meta accessed time");
}
}
@ -816,8 +851,9 @@ auto winfsp_drive::Read(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
auto ret = utils::from_api_error(error);
if (ret != STATUS_SUCCESS) {
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, ret);
RAISE_WINFSP_EVENT(function_name, api_path, ret);
}
return ret;
}
@ -825,6 +861,8 @@ auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
PWSTR /*pattern*/, PWSTR marker, PVOID buffer,
ULONG buffer_length, PULONG bytes_transferred)
-> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::string api_path;
auto error = api_error::invalid_handle;
auto handle =
@ -863,7 +901,7 @@ auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
if (dir_item.meta.empty()) {
utils::error::raise_api_path_error(
__FUNCTION__, dir_item.api_path, api_error::error,
function_name, dir_item.api_path, api_error::error,
"item meta is empty");
continue;
}
@ -904,7 +942,7 @@ auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
error = api_error::success;
}
} else {
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, status_result);
RAISE_WINFSP_EVENT(function_name, api_path, status_result);
return status_result;
}
}
@ -916,13 +954,15 @@ auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
}
auto ret = utils::from_api_error(error);
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, ret);
RAISE_WINFSP_EVENT(function_name, api_path, ret);
return ret;
}
auto winfsp_drive::Rename(PVOID /*file_node*/, PVOID /*file_desc*/,
PWSTR file_name, PWSTR new_file_name,
BOOLEAN replace_if_exists) -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto from_api_path =
utils::path::create_api_path(utils::string::to_utf8(file_name));
const auto to_api_path =
@ -944,7 +984,7 @@ auto winfsp_drive::Rename(PVOID /*file_node*/, PVOID /*file_desc*/,
}
auto ret = utils::from_api_error(error);
RAISE_WINFSP_EVENT(__FUNCTION__, from_api_path + "|" + to_api_path, ret);
RAISE_WINFSP_EVENT(function_name, from_api_path + "|" + to_api_path, ret);
return ret;
}
@ -953,6 +993,8 @@ auto winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
UINT64 last_access_time, UINT64 last_write_time,
UINT64 change_time, FileInfo *file_info)
-> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::string api_path;
auto error = api_error::invalid_handle;
auto handle =
@ -976,17 +1018,17 @@ auto winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
}
meta[META_ATTRIBUTES] = std::to_string(attributes);
}
if ((creation_time != 0U) && (creation_time != 0xFFFFFFFFFFFFFFFF)) {
if ((creation_time != 0U) && (creation_time != max_time) {
meta[META_CREATION] = std::to_string(creation_time);
}
if ((last_access_time != 0U) &&
(last_access_time != 0xFFFFFFFFFFFFFFFF)) {
(last_access_time != max_time) {
meta[META_ACCESSED] = std::to_string(last_access_time);
}
if ((last_write_time != 0U) && (last_write_time != 0xFFFFFFFFFFFFFFFF)) {
if ((last_write_time != 0U) && (last_write_time != max_time) {
meta[META_WRITTEN] = std::to_string(last_write_time);
}
if ((change_time != 0U) && (change_time != 0xFFFFFFFFFFFFFFFF)) {
if ((change_time != 0U) && (change_time != max_time) {
meta[META_CHANGED] = std::to_string(change_time);
meta[META_MODIFIED] = std::to_string(change_time);
}
@ -1002,7 +1044,7 @@ auto winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
}
auto ret = utils::from_api_error(error);
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, ret);
RAISE_WINFSP_EVENT(function_name, api_path, ret);
return ret;
}
@ -1024,6 +1066,8 @@ void winfsp_drive::set_file_info(remote::file_info &dest,
auto winfsp_drive::SetFileSize(PVOID /*file_node*/, PVOID file_desc,
UINT64 new_size, BOOLEAN set_allocation_size,
FileInfo *file_info) -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::string api_path;
auto error = api_error::invalid_handle;
auto handle =
@ -1072,11 +1116,13 @@ auto winfsp_drive::SetFileSize(PVOID /*file_node*/, PVOID file_desc,
}
auto ret = utils::from_api_error(error);
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, ret);
RAISE_WINFSP_EVENT(function_name, api_path, ret);
return ret;
}
VOID winfsp_drive::Unmounted(PVOID host) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto *file_system_host = reinterpret_cast<FileSystemHost *>(host);
const auto mount_location =
parse_mount_location(file_system_host->MountPoint());
@ -1096,7 +1142,7 @@ VOID winfsp_drive::Unmounted(PVOID host) {
eviction_.reset();
if (not lock_.set_mount_state(false, "", -1)) {
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
utils::error::raise_error(function_name, "failed to set mount state");
}
event_system::instance().raise<drive_unmounted>(mount_location);
@ -1107,6 +1153,8 @@ auto winfsp_drive::Write(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
UINT64 offset, ULONG length, BOOLEAN write_to_end,
BOOLEAN constrained_io, PULONG bytes_transferred,
FileInfo *file_info) -> NTSTATUS {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
*bytes_transferred = 0;
std::string api_path;
@ -1155,8 +1203,9 @@ auto winfsp_drive::Write(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
auto ret = utils::from_api_error(error);
if (ret != STATUS_SUCCESS) {
RAISE_WINFSP_EVENT(__FUNCTION__, api_path, ret);
RAISE_WINFSP_EVENT(function_name, api_path, ret);
}
return ret;
}
} // namespace repertory

View File

@ -69,6 +69,8 @@ logging_consumer::~logging_consumer() {
}
void logging_consumer::check_log_roll(std::size_t count) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::uint64_t file_size{};
const auto success = utils::file::get_file_size(log_path_, file_size);
if (success && (file_size + count) >= MAX_LOG_FILE_SIZE) {
@ -85,7 +87,7 @@ void logging_consumer::check_log_roll(std::size_t count) {
log_directory_,
{"repertory." + std::to_string(i + std::uint8_t(1)) + ".log"});
if (not utils::file::move_file(temp_log_path, next_file_path)) {
utils::error::raise_error(__FUNCTION__,
utils::error::raise_error(function_name,
utils::get_last_error_code(),
temp_log_path + "|dest|" + next_file_path,
"failed to move file");
@ -97,7 +99,7 @@ void logging_consumer::check_log_roll(std::size_t count) {
auto backup_log_path =
utils::path::combine(log_directory_, {"repertory.1.log"});
if (not utils::file::move_file(log_path_, backup_log_path)) {
utils::error::raise_error(__FUNCTION__, utils::get_last_error_code(),
utils::error::raise_error(function_name, utils::get_last_error_code(),
log_path_ + "|dest|" + backup_log_path,
"failed to move file");
}

View File

@ -200,6 +200,8 @@ auto file_manager::create(const std::string &api_path, api_meta_map &meta,
}
auto file_manager::evict_file(const std::string &api_path) -> bool {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (provider_.is_direct_only()) {
return false;
}
@ -216,7 +218,7 @@ auto file_manager::evict_file(const std::string &api_path) -> bool {
std::string pinned;
auto res = provider_.get_item_meta(api_path, META_PINNED, pinned);
if (res != api_error::success && res != api_error::item_not_found) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to get pinned status");
return false;
}
@ -228,7 +230,7 @@ auto file_manager::evict_file(const std::string &api_path) -> bool {
std::string source_path{};
res = provider_.get_item_meta(api_path, META_SOURCE, source_path);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to get source path");
return false;
}
@ -249,10 +251,12 @@ auto file_manager::evict_file(const std::string &api_path) -> bool {
auto file_manager::get_directory_items(const std::string &api_path) const
-> directory_item_list {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
directory_item_list list{};
auto res = provider_.get_directory_items(api_path, list);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to get directory list");
}
return list;
@ -336,6 +340,8 @@ auto file_manager::get_open_handle_count() const -> std::size_t {
}
auto file_manager::get_stored_downloads() const -> std::vector<json> {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::vector<json> ret;
if (not provider_.is_direct_only()) {
auto result = db::db_select{*db_.get(), resume_table}.go();
@ -355,7 +361,7 @@ auto file_manager::get_stored_downloads() const -> std::vector<json> {
ret.push_back(row.value().get_column("data").get_value_as_json());
} catch (const std::exception &ex) {
utils::error::raise_error(__FUNCTION__, ex, "query error");
utils::error::raise_error(function_name, ex, "query error");
}
}
}
@ -519,6 +525,8 @@ void file_manager::queue_upload(const std::string &api_path,
}
auto file_manager::remove_file(const std::string &api_path) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
recur_mutex_lock open_lock(open_file_mtx_);
auto file_iter = open_file_lookup_.find(api_path);
if (file_iter != open_file_lookup_.end() &&
@ -542,7 +550,7 @@ auto file_manager::remove_file(const std::string &api_path) -> api_error {
if (not utils::file::retry_delete_file(fsi.source_path)) {
utils::error::raise_api_path_error(
__FUNCTION__, fsi.api_path, fsi.source_path,
function_name, fsi.api_path, fsi.source_path,
utils::get_last_error_code(), "failed to delete source");
return api_error::success;
}
@ -690,6 +698,8 @@ auto file_manager::rename_directory(const std::string &from_api_path,
auto file_manager::rename_file(const std::string &from_api_path,
const std::string &to_api_path, bool overwrite)
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (not provider_.is_rename_supported()) {
return api_error::not_implemented;
}
@ -766,7 +776,7 @@ auto file_manager::rename_file(const std::string &from_api_path,
if ((res == api_error::success) || (res == api_error::item_not_found)) {
if (not utils::file::retry_delete_file(fsi.source_path)) {
utils::error::raise_api_path_error(
__FUNCTION__, fsi.api_path, fsi.source_path,
function_name, fsi.api_path, fsi.source_path,
utils::get_last_error_code(), "failed to delete source path");
}
return handle_file_rename(from_api_path, to_api_path);
@ -789,6 +799,8 @@ auto file_manager::rename_file(const std::string &from_api_path,
}
void file_manager::start() {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
polling::instance().set_callback(
{"timed_out_close", polling::frequency::second,
[this]() { this->close_timed_out_files(); }});
@ -819,7 +831,7 @@ void file_manager::start() {
});
}
} catch (const std::exception &ex) {
utils::error::raise_error(__FUNCTION__, ex, "query error");
utils::error::raise_error(function_name, ex, "query error");
}
}
@ -889,7 +901,7 @@ void file_manager::start() {
"failed to get filesystem item|" + api_error_to_string(res));
}
} catch (const std::exception &ex) {
utils::error::raise_error(__FUNCTION__, ex, "query error");
utils::error::raise_error(function_name, ex, "query error");
}
}
}
@ -968,6 +980,8 @@ void file_manager::swap_renamed_items(std::string from_api_path,
}
void file_manager::upload_completed(const file_upload_completed &evt) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
unique_mutex_lock upload_lock(upload_mtx_);
if (not utils::string::to_bool(evt.get_cancelled().get<std::string>())) {
@ -981,7 +995,7 @@ void file_manager::upload_completed(const file_upload_completed &evt) {
.go();
if (not result.ok()) {
utils::error::raise_api_path_error(
__FUNCTION__, evt.get_api_path().get<std::string>(),
function_name, evt.get_api_path().get<std::string>(),
evt.get_source().get<std::string>(),
"failed to remove from to upload_active table");
}
@ -1020,6 +1034,8 @@ void file_manager::upload_completed(const file_upload_completed &evt) {
}
void file_manager::upload_handler() {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
while (not stop_requested_) {
unique_mutex_lock upload_lock(upload_mtx_);
if (not stop_requested_) {
@ -1060,7 +1076,7 @@ void file_manager::upload_handler() {
.go();
if (not ins_res.ok()) {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, source_path,
function_name, api_path, source_path,
"failed to add to upload_active table");
}
}
@ -1075,7 +1091,7 @@ void file_manager::upload_handler() {
}
}
} catch (const std::exception &ex) {
utils::error::raise_error(__FUNCTION__, ex, "query error");
utils::error::raise_error(function_name, ex, "query error");
}
}
}

View File

@ -250,6 +250,8 @@ auto file_manager::open_file::native_operation(
auto file_manager::open_file::native_operation(
std::uint64_t new_file_size,
i_open_file::native_operation_callback callback) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (fsi_.directory) {
return api_error::invalid_operation;
}
@ -283,7 +285,7 @@ auto file_manager::open_file::native_operation(
auto res = do_io([&]() -> api_error { return callback(nf_->get_handle()); });
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, get_api_path(),
utils::error::raise_api_path_error(function_name, get_api_path(),
utils::get_last_error_code(),
"failed to allocate file");
return res;
@ -292,7 +294,7 @@ auto file_manager::open_file::native_operation(
{
std::uint64_t file_size{};
if (not nf_->get_file_size(file_size)) {
utils::error::raise_api_path_error(__FUNCTION__, get_api_path(),
utils::error::raise_api_path_error(function_name, get_api_path(),
utils::get_last_error_code(),
"failed to get file size");
return set_api_error(api_error::os_error);
@ -300,7 +302,7 @@ auto file_manager::open_file::native_operation(
if (file_size != new_file_size) {
utils::error::raise_api_path_error(
__FUNCTION__, get_api_path(), api_error::file_size_mismatch,
function_name, get_api_path(), api_error::file_size_mismatch,
"allocated file size mismatch|expected|" +
std::to_string(new_file_size) + "|actual|" +
std::to_string(file_size));
@ -334,7 +336,7 @@ auto file_manager::open_file::native_operation(
{META_WRITTEN, now},
});
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, get_api_path(), res,
utils::error::raise_api_path_error(function_name, get_api_path(), res,
"failed to set file meta");
return set_api_error(res);
}
@ -423,6 +425,8 @@ auto file_manager::open_file::resize(std::uint64_t new_file_size) -> api_error {
}
auto file_manager::open_file::close() -> bool {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (not fsi_.directory && not stop_requested_) {
stop_requested_ = true;
@ -462,7 +466,7 @@ auto file_manager::open_file::close() -> bool {
mgr_.remove_resume(get_api_path(), get_source_path());
if (not utils::file::retry_delete_file(fsi_.source_path)) {
utils::error::raise_api_path_error(
__FUNCTION__, get_api_path(), fsi_.source_path,
function_name, get_api_path(), fsi_.source_path,
utils::get_last_error_code(), "failed to delete file");
}
@ -472,7 +476,7 @@ auto file_manager::open_file::close() -> bool {
const auto res = provider_.set_item_meta(fsi_.api_path, META_SOURCE,
fsi_.source_path);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, get_api_path(),
utils::error::raise_api_path_error(function_name, get_api_path(),
fsi_.source_path, res,
"failed to set file meta");
}
@ -535,6 +539,8 @@ void file_manager::open_file::update_background_reader(std::size_t read_chunk) {
auto file_manager::open_file::write(std::uint64_t write_offset,
const data_buffer &data,
std::size_t &bytes_written) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
bytes_written = 0U;
if (fsi_.directory || provider_.is_direct_only()) {
@ -592,7 +598,7 @@ auto file_manager::open_file::write(std::uint64_t write_offset,
{META_WRITTEN, now},
});
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, get_api_path(), res,
utils::error::raise_api_path_error(function_name, get_api_path(), res,
"failed to set file meta");
return set_api_error(res);
}

View File

@ -85,12 +85,14 @@ file_manager::ring_buffer_open_file::ring_buffer_open_file(
}
file_manager::ring_buffer_open_file::~ring_buffer_open_file() {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
close();
nf_->close();
if (not utils::file::retry_delete_file(fsi_.source_path)) {
utils::error::raise_api_path_error(
__FUNCTION__, fsi_.api_path, fsi_.source_path,
function_name, fsi_.api_path, fsi_.source_path,
utils::get_last_error_code(), "failed to delete file");
}
}

View File

@ -49,11 +49,13 @@ void file_manager::upload::cancel() {
void file_manager::upload::stop() { stop_requested_ = true; }
void file_manager::upload::upload_thread() {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
error_ =
provider_.upload_file(fsi_.api_path, fsi_.source_path, stop_requested_);
if (not utils::file::reset_modified_time(fsi_.source_path)) {
utils::error::raise_api_path_error(
__FUNCTION__, fsi_.api_path, fsi_.source_path,
function_name, fsi_.api_path, fsi_.source_path,
utils::get_last_error_code(), "failed to reset modified time");
}

View File

@ -101,6 +101,8 @@ auto lock_data::get_state_directory() -> std::string {
}
auto lock_data::grab_lock(std::uint8_t retry_count) -> lock_result {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (lock_fd_ == -1) {
return lock_result::failure;
}
@ -109,7 +111,7 @@ auto lock_data::grab_lock(std::uint8_t retry_count) -> lock_result {
switch (lock_status_) {
case 0:
if (not set_mount_state(false, "", -1)) {
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
utils::error::raise_error(function_name, "failed to set mount state");
}
return lock_result::success;
case EWOULDBLOCK:
@ -121,16 +123,18 @@ auto lock_data::grab_lock(std::uint8_t retry_count) -> lock_result {
auto lock_data::set_mount_state(bool active, const std::string &mount_location,
int pid) -> bool {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto ret = false;
auto fd =
auto handle =
open(get_lock_data_file().c_str(), O_CREAT | O_RDWR, S_IWUSR | S_IRUSR);
if (fd != -1) {
if (wait_for_lock(fd) == 0) {
if (handle != -1) {
if (wait_for_lock(handle) == 0) {
const auto mount_id =
app_config::get_provider_display_name(pt_) + unique_id_;
json mount_state;
if (not utils::file::read_json_file(get_lock_data_file(), mount_state)) {
utils::error::raise_error(__FUNCTION__,
utils::error::raise_error(function_name,
"failed to read mount state file|sp|" +
get_lock_file());
}
@ -157,10 +161,10 @@ auto lock_data::set_mount_state(bool active, const std::string &mount_location,
ret = true;
}
flock(fd, LOCK_UN);
flock(handle, LOCK_UN);
}
close(fd);
close(handle);
}
return ret;
}

View File

@ -73,6 +73,8 @@ auto lock_data::get_mount_state(json &mount_state) -> bool {
}
auto lock_data::grab_lock(std::uint8_t retry_count) -> lock_result {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto ret = lock_result::success;
if (mutex_handle_ == INVALID_HANDLE_VALUE) {
ret = lock_result::failure;
@ -97,7 +99,7 @@ auto lock_data::grab_lock(std::uint8_t retry_count) -> lock_result {
if (should_reset) {
if (not set_mount_state(false, "", -1)) {
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
utils::error::raise_error(function_name, "failed to set mount state");
}
}
} break;

View File

@ -68,13 +68,15 @@ auto base_provider::create_api_file(std::string path, std::uint64_t size,
auto base_provider::create_directory_clone_source_meta(
const std::string &source_api_path, const std::string &api_path)
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
bool exists{};
auto res = is_file(source_api_path, exists);
if (res != api_error::success) {
return res;
}
if (exists) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
utils::error::raise_api_path_error(function_name, api_path,
api_error::item_exists,
"failed to create directory");
return api_error::item_exists;
@ -85,7 +87,7 @@ auto base_provider::create_directory_clone_source_meta(
return res;
}
if (exists) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
utils::error::raise_api_path_error(function_name, api_path,
api_error::directory_exists,
"failed to create directory");
return api_error::directory_exists;
@ -96,7 +98,7 @@ auto base_provider::create_directory_clone_source_meta(
return res;
}
if (exists) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
utils::error::raise_api_path_error(function_name, api_path,
api_error::item_exists,
"failed to create directory");
return api_error::item_exists;
@ -108,7 +110,7 @@ auto base_provider::create_directory_clone_source_meta(
if (res == api_error::item_not_found) {
res = api_error::directory_not_found;
}
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to create directory");
return res;
}
@ -118,13 +120,15 @@ auto base_provider::create_directory_clone_source_meta(
auto base_provider::create_directory(const std::string &api_path,
api_meta_map &meta) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
bool exists{};
auto res = is_directory(api_path, exists);
if (res != api_error::success) {
return res;
}
if (exists) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
utils::error::raise_api_path_error(function_name, api_path,
api_error::directory_exists,
"failed to create directory");
return api_error::directory_exists;
@ -132,12 +136,12 @@ auto base_provider::create_directory(const std::string &api_path,
res = is_file(api_path, exists);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to create directory");
return res;
}
if (exists) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
utils::error::raise_api_path_error(function_name, api_path,
api_error::item_exists,
"failed to create directory");
return api_error::item_exists;
@ -146,12 +150,12 @@ auto base_provider::create_directory(const std::string &api_path,
try {
res = create_directory_impl(api_path, meta);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to create directory");
return res;
}
} catch (const std::exception &e) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to create directory");
return api_error::error;
}
@ -162,13 +166,15 @@ auto base_provider::create_directory(const std::string &api_path,
auto base_provider::create_file(const std::string &api_path, api_meta_map &meta)
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
bool exists{};
auto res = is_directory(api_path, exists);
if (res != api_error::success && res != api_error::item_not_found) {
return res;
}
if (exists) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
utils::error::raise_api_path_error(function_name, api_path,
api_error::directory_exists,
"failed to create file");
return api_error::directory_exists;
@ -179,7 +185,7 @@ auto base_provider::create_file(const std::string &api_path, api_meta_map &meta)
return res;
}
if (exists) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
utils::error::raise_api_path_error(function_name, api_path,
api_error::item_exists,
"failed to create file");
return api_error::item_exists;
@ -188,7 +194,7 @@ auto base_provider::create_file(const std::string &api_path, api_meta_map &meta)
try {
res = create_file_extra(api_path, meta);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to create file");
return res;
}
@ -196,7 +202,7 @@ auto base_provider::create_file(const std::string &api_path, api_meta_map &meta)
meta[META_DIRECTORY] = utils::string::from_bool(false);
res = set_item_meta(api_path, meta);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to create file");
return res;
}
@ -209,7 +215,7 @@ auto base_provider::create_file(const std::string &api_path, api_meta_map &meta)
return res;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to create file");
}
@ -219,8 +225,10 @@ auto base_provider::create_file(const std::string &api_path, api_meta_map &meta)
auto base_provider::get_api_path_from_source(const std::string &source_path,
std::string &api_path) const
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (source_path.empty()) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
utils::error::raise_api_path_error(function_name, api_path,
api_error::item_not_found,
"failed to source path from api path");
return api_error::item_not_found;
@ -232,6 +240,8 @@ auto base_provider::get_api_path_from_source(const std::string &source_path,
auto base_provider::get_directory_items(const std::string &api_path,
directory_item_list &list) const
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
bool exists{};
auto res = is_directory(api_path, exists);
if (res != api_error::success) {
@ -247,7 +257,7 @@ auto base_provider::get_directory_items(const std::string &api_path,
return res;
}
} catch (const std::exception &e) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to get directory items");
return api_error::error;
}
@ -393,12 +403,14 @@ auto base_provider::get_total_item_count() const -> std::uint64_t {
}
auto base_provider::get_used_drive_space() const -> std::uint64_t {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
auto used_space = get_used_drive_space_impl();
get_file_mgr()->update_used_space(used_space);
return used_space;
} catch (const std::exception &ex) {
utils::error::raise_error(__FUNCTION__, ex,
utils::error::raise_error(function_name, ex,
"failed to get used drive space");
}
@ -417,6 +429,8 @@ auto base_provider::is_file_writeable(const std::string &api_path) const
}
void base_provider::remove_deleted_files() {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
struct removed_item {
std::string api_path{};
bool directory{};
@ -426,7 +440,7 @@ void base_provider::remove_deleted_files() {
api_file_list list{};
auto res = get_file_list(list);
if (res != api_error::success) {
utils::error::raise_error(__FUNCTION__, res, "failed to get file list");
utils::error::raise_error(function_name, res, "failed to get file list");
return;
}
@ -482,7 +496,7 @@ void base_provider::remove_deleted_files() {
}
} else {
utils::error::raise_error(
__FUNCTION__, std::to_string(utils::get_last_error_code()),
function_name, std::to_string(utils::get_last_error_code()),
"failed to create orphaned director|sp|" + orphaned_directory);
continue;
}
@ -517,10 +531,7 @@ auto base_provider::remove_file(const std::string &api_path) -> api_error {
return error;
};
const auto *const function_name = __FUNCTION__;
const auto remove_file_meta = [this, &api_path, &function_name,
&notify_end]() -> api_error {
const auto remove_file_meta = [this, &api_path, &notify_end]() -> api_error {
api_meta_map meta{};
auto res = get_item_meta(api_path, meta);
db3_->remove_api_path(api_path);
@ -650,6 +661,8 @@ void base_provider::stop() {
auto base_provider::upload_file(const std::string &api_path,
const std::string &source_path,
stop_type &stop_requested) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
event_system::instance().raise<provider_upload_begin>(api_path, source_path);
const auto notify_end = [&api_path,
@ -661,7 +674,7 @@ auto base_provider::upload_file(const std::string &api_path,
try {
return notify_end(upload_file_impl(api_path, source_path, stop_requested));
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
utils::error::raise_error(function_name, e, "exception occurred");
}
return notify_end(api_error::error);

View File

@ -217,6 +217,8 @@ auto encrypt_provider::do_fs_operation(
auto encrypt_provider::get_api_path_from_source(const std::string &source_path,
std::string &api_path) const
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
auto result = db::db_select{*db_, file_table}
.column("data")
@ -246,7 +248,7 @@ auto encrypt_provider::get_api_path_from_source(const std::string &source_path,
return api_error::item_not_found;
} catch (const std::exception &ex) {
utils::error::raise_error(__FUNCTION__, ex, source_path,
utils::error::raise_error(function_name, ex, source_path,
"failed to get api path from source path");
}
@ -255,7 +257,7 @@ auto encrypt_provider::get_api_path_from_source(const std::string &source_path,
auto encrypt_provider::get_directory_item_count(
const std::string &api_path) const -> std::uint64_t {
static const auto *function_name = __FUNCTION__;
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::uint64_t count{};
auto res = do_fs_operation(
@ -285,7 +287,7 @@ auto encrypt_provider::get_directory_item_count(
auto encrypt_provider::get_directory_items(const std::string &api_path,
directory_item_list &list) const
-> api_error {
static const auto *function_name = __FUNCTION__;
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
return do_fs_operation(
api_path, true,
@ -421,6 +423,8 @@ auto encrypt_provider::get_file(const std::string &api_path,
}
auto encrypt_provider::get_file_list(api_file_list &list) const -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto cfg = config_.get_encrypt_config();
try {
@ -435,7 +439,7 @@ auto encrypt_provider::get_file_list(api_file_list &list) const -> api_error {
return api_error::success;
} catch (const std::exception &ex) {
utils::error::raise_error(__FUNCTION__, ex, cfg.path,
utils::error::raise_error(function_name, ex, cfg.path,
"failed to get file list");
}
@ -445,6 +449,8 @@ auto encrypt_provider::get_file_list(api_file_list &list) const -> api_error {
auto encrypt_provider::get_file_size(const std::string &api_path,
std::uint64_t &file_size) const
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
auto result = db::db_select{*db_, source_table}
.column("source_path")
@ -461,7 +467,7 @@ auto encrypt_provider::get_file_size(const std::string &api_path,
source_path);
return api_error::success;
} catch (const std::exception &ex) {
utils::error::raise_error(__FUNCTION__, ex, api_path,
utils::error::raise_error(function_name, ex, api_path,
"failed to get file size");
}
@ -828,6 +834,8 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
std::size_t size, std::uint64_t offset,
data_buffer &data,
stop_type &stop_requested) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto result = db::db_select{*db_, source_table}
.column("source_path")
.where("api_path")
@ -886,7 +894,7 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
.column_value("data", file_data.dump())
.go();
if (not ins_res.ok()) {
utils::error::raise_error(__FUNCTION__, ins_res.get_error(), source_path,
utils::error::raise_error(function_name, ins_res.get_error(), source_path,
"failed to update meta db");
return api_error::error;
}
@ -999,6 +1007,8 @@ void encrypt_provider::remove_deleted_files() {
auto encrypt_provider::start(api_item_added_callback /*api_item_added*/,
i_file_manager * /*mgr*/) -> bool {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (not is_online()) {
return false;
}
@ -1011,9 +1021,9 @@ auto encrypt_provider::start(api_item_added_callback /*api_item_added*/,
sqlite3_open_v2(db_path.c_str(), &db3,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr);
if (res != SQLITE_OK) {
utils::error::raise_error(__FUNCTION__, "failed to open db|" + db_path +
'|' + std::to_string(res) +
'|' + sqlite3_errstr(res));
utils::error::raise_error(function_name, "failed to open db|" + db_path +
'|' + std::to_string(res) +
'|' + sqlite3_errstr(res));
return false;
}
db_.reset(db3);
@ -1021,8 +1031,8 @@ auto encrypt_provider::start(api_item_added_callback /*api_item_added*/,
for (const auto &create : sql_create_tables) {
std::string err;
if (not db::execute_sql(*db_, create.second, err)) {
utils::error::raise_error(__FUNCTION__, "failed to create table|" +
create.first + '|' + err);
utils::error::raise_error(function_name, "failed to create table|" +
create.first + '|' + err);
db_.reset();
return false;
}

View File

@ -31,6 +31,8 @@
namespace repertory {
meta_db::meta_db(const app_config &cfg) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto db_path = utils::path::combine(cfg.get_data_directory(), {"meta.db3"});
sqlite3 *db3{nullptr};
@ -38,9 +40,9 @@ meta_db::meta_db(const app_config &cfg) {
sqlite3_open_v2(db_path.c_str(), &db3,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr);
if (res != SQLITE_OK) {
utils::error::raise_error(__FUNCTION__, "failed to open db|" + db_path +
'|' + std::to_string(res) +
'|' + sqlite3_errstr(res));
utils::error::raise_error(function_name, "failed to open db|" + db_path +
'|' + std::to_string(res) +
'|' + sqlite3_errstr(res));
return;
}
db_.reset(db3);
@ -56,7 +58,7 @@ meta_db::meta_db(const app_config &cfg) {
");";
std::string err;
if (not db::execute_sql(*db_, create, err)) {
utils::error::raise_error(__FUNCTION__,
utils::error::raise_error(function_name,
"failed to create db|" + db_path + '|' + err);
db_.reset();
return;
@ -101,6 +103,8 @@ auto meta_db::get_api_path_list() -> std::vector<std::string> {
auto meta_db::get_item_meta(const std::string &api_path, api_meta_map &meta)
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto result = db::db_select{*db_, table_name}
.column("*")
.where("api_path")
@ -128,7 +132,7 @@ auto meta_db::get_item_meta(const std::string &api_path, api_meta_map &meta)
return api_error::item_not_found;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to get item meta");
}
@ -137,6 +141,8 @@ auto meta_db::get_item_meta(const std::string &api_path, api_meta_map &meta)
auto meta_db::get_item_meta(const std::string &api_path, const std::string &key,
std::string &value) const -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto result = db::db_select{*db_, table_name}
.column("*")
.where("api_path")
@ -167,7 +173,7 @@ auto meta_db::get_item_meta(const std::string &api_path, const std::string &key,
return api_error::item_not_found;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to get item meta");
}
@ -175,6 +181,8 @@ auto meta_db::get_item_meta(const std::string &api_path, const std::string &key,
}
auto meta_db::get_pinned_files() const -> std::vector<std::string> {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::vector<std::string> ret{};
try {
@ -190,13 +198,15 @@ auto meta_db::get_pinned_files() const -> std::vector<std::string> {
}
}
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "failed to get pinned files");
utils::error::raise_error(function_name, e, "failed to get pinned files");
}
return ret;
}
auto meta_db::get_total_item_count() const -> std::uint64_t {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
std::uint64_t ret{};
try {
@ -209,7 +219,7 @@ auto meta_db::get_total_item_count() const -> std::uint64_t {
row->get_column("count").get_value<std::int64_t>());
}
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e,
utils::error::raise_error(function_name, e,
"failed to get total item count");
}
@ -217,6 +227,8 @@ auto meta_db::get_total_item_count() const -> std::uint64_t {
}
void meta_db::remove_api_path(const std::string &api_path) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto result = db::db_select{*db_, table_name}
.delete_query()
.where("api_path")
@ -224,7 +236,7 @@ void meta_db::remove_api_path(const std::string &api_path) {
.go();
if (not result.ok()) {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, result.get_error(), "failed to remove meta");
function_name, api_path, result.get_error(), "failed to remove meta");
}
}
@ -273,6 +285,8 @@ auto meta_db::set_item_meta(const std::string &api_path,
auto meta_db::update_item_meta(const std::string &api_path, api_meta_map meta)
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto directory = utils::string::to_bool(meta[META_DIRECTORY]);
auto pinned = utils::string::to_bool(meta[META_PINNED]);
auto source_path = meta[META_SOURCE];
@ -290,7 +304,7 @@ auto meta_db::update_item_meta(const std::string &api_path, api_meta_map meta)
.column_value("source_path", source_path)
.go();
if (not result.ok()) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
utils::error::raise_api_path_error(function_name, api_path,
result.get_error(),
"failed to update item meta");
return api_error::error;

View File

@ -63,6 +63,8 @@ auto s3_provider::add_if_not_found(api_file &file,
auto s3_provider::create_directory_impl(const std::string &api_path,
api_meta_map &meta) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto cfg = get_config().get_s3_config();
const auto is_encrypted = not cfg.encryption_token.empty();
stop_type stop_requested{false};
@ -72,7 +74,7 @@ auto s3_provider::create_directory_impl(const std::string &api_path,
auto res = get_item_meta(utils::path::get_parent_api_path(api_path),
META_KEY, encrypted_file_path);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to create file");
return res;
}
@ -97,14 +99,14 @@ auto s3_provider::create_directory_impl(const std::string &api_path,
long response_code{};
if (not get_comm().make_request(put_file, response_code, stop_requested)) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
utils::error::raise_api_path_error(function_name, api_path,
api_error::comm_error,
"failed to create directory");
return api_error::comm_error;
}
if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, response_code,
utils::error::raise_api_path_error(function_name, api_path, response_code,
"failed to create directory");
return api_error::comm_error;
}
@ -114,12 +116,14 @@ auto s3_provider::create_directory_impl(const std::string &api_path,
auto s3_provider::create_file_extra(const std::string &api_path,
api_meta_map &meta) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (not get_config().get_s3_config().encryption_token.empty()) {
std::string encrypted_file_path;
auto res = get_item_meta(utils::path::get_parent_api_path(api_path),
META_KEY, encrypted_file_path);
if (res != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to create file");
return res;
}
@ -197,6 +201,8 @@ auto s3_provider::decrypt_object_name(std::string &object_name) const
auto s3_provider::get_directory_item_count(const std::string &api_path) const
-> std::uint64_t {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
const auto cfg = get_config().get_s3_config();
const auto is_encrypted = not cfg.encryption_token.empty();
@ -247,7 +253,7 @@ auto s3_provider::get_directory_item_count(const std::string &api_path) const
return ret;
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
utils::error::raise_error(function_name, e, "exception occurred");
}
return 0U;
@ -371,6 +377,8 @@ auto s3_provider::get_directory_items_impl(const std::string &api_path,
auto s3_provider::get_file(const std::string &api_path, api_file &file) const
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
bool is_encrypted{};
std::string object_name;
@ -394,7 +402,7 @@ auto s3_provider::get_file(const std::string &api_path, api_file &file) const
file.modified_date = utils::aws::format_time(result.last_modified);
return add_if_not_found(file, object_name);
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
utils::error::raise_error(function_name, e, "exception occurred");
}
return api_error::error;
@ -464,6 +472,8 @@ auto s3_provider::get_object_info(bool directory, const std::string &api_path,
bool &is_encrypted, std::string &object_name,
head_object_result &result) const
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
const auto cfg = get_config().get_s3_config();
is_encrypted = not cfg.encryption_token.empty();
@ -502,7 +512,7 @@ auto s3_provider::get_object_info(bool directory, const std::string &api_path,
return api_error::success;
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
utils::error::raise_error(function_name, e, "exception occurred");
}
return api_error::error;
@ -571,6 +581,8 @@ auto s3_provider::get_used_drive_space_impl() const -> std::uint64_t {
auto s3_provider::is_directory(const std::string &api_path, bool &exists) const
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
exists = false;
if (api_path == "/") {
exists = true;
@ -589,7 +601,7 @@ auto s3_provider::is_directory(const std::string &api_path, bool &exists) const
exists = res != api_error::item_not_found;
return api_error::success;
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
utils::error::raise_error(function_name, e, "exception occurred");
}
return api_error::error;
@ -597,6 +609,8 @@ auto s3_provider::is_directory(const std::string &api_path, bool &exists) const
auto s3_provider::is_file(const std::string &api_path, bool &exists) const
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
exists = false;
if (api_path == "/") {
return api_error::success;
@ -614,7 +628,7 @@ auto s3_provider::is_file(const std::string &api_path, bool &exists) const
exists = res != api_error::item_not_found;
return api_error::success;
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
utils::error::raise_error(function_name, e, "exception occurred");
}
return api_error::error;
@ -628,6 +642,8 @@ auto s3_provider::is_online() const -> bool {
auto s3_provider::read_file_bytes(const std::string &api_path, std::size_t size,
std::uint64_t offset, data_buffer &data,
stop_type &stop_requested) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
const auto cfg = get_config().get_s3_config();
const auto is_encrypted = not cfg.encryption_token.empty();
@ -668,13 +684,13 @@ auto s3_provider::read_file_bytes(const std::string &api_path, std::size_t size,
const auto notify_retry = [&]() {
if (response_code == 0) {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, api_error::comm_error,
function_name, api_path, api_error::comm_error,
"read file bytes failed|offset|" + std::to_string(read_offset) +
"|size|" + std::to_string(read_size) + "|retry|" +
std::to_string(i + 1U));
} else {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, response_code,
function_name, api_path, response_code,
"read file bytes failed|offset|" + std::to_string(read_offset) +
"|size|" + std::to_string(read_size) + "|retry|" +
std::to_string(i + 1U));
@ -720,7 +736,7 @@ auto s3_provider::read_file_bytes(const std::string &api_path, std::size_t size,
return read_bytes(size, offset, data);
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
utils::error::raise_error(function_name, e, "exception occurred");
}
return api_error::error;
@ -728,6 +744,8 @@ auto s3_provider::read_file_bytes(const std::string &api_path, std::size_t size,
auto s3_provider::remove_directory_impl(const std::string &api_path)
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto cfg = get_config().get_s3_config();
const auto is_encrypted = not cfg.encryption_token.empty();
@ -750,7 +768,7 @@ auto s3_provider::remove_directory_impl(const std::string &api_path)
long response_code{};
stop_type stop_requested{};
if (not get_comm().make_request(del, response_code, stop_requested)) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
utils::error::raise_api_path_error(function_name, api_path,
api_error::comm_error,
"failed to remove directory");
return api_error::comm_error;
@ -759,7 +777,7 @@ auto s3_provider::remove_directory_impl(const std::string &api_path)
if ((response_code < http_error_codes::ok ||
response_code >= http_error_codes::multiple_choices) &&
response_code != http_error_codes::not_found) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, response_code,
utils::error::raise_api_path_error(function_name, api_path, response_code,
"failed to remove directory");
return api_error::comm_error;
}
@ -768,6 +786,8 @@ auto s3_provider::remove_directory_impl(const std::string &api_path)
}
auto s3_provider::remove_file_impl(const std::string &api_path) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto cfg = get_config().get_s3_config();
const auto is_encrypted = not cfg.encryption_token.empty();
@ -790,15 +810,16 @@ auto s3_provider::remove_file_impl(const std::string &api_path) -> api_error {
long response_code{};
stop_type stop_requested{};
if (not get_comm().make_request(del, response_code, stop_requested)) {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, api_error::comm_error, "failed to remove file");
utils::error::raise_api_path_error(function_name, api_path,
api_error::comm_error,
"failed to remove file");
return api_error::comm_error;
}
if ((response_code < http_error_codes::ok ||
response_code >= http_error_codes::multiple_choices) &&
response_code != http_error_codes::not_found) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, response_code,
utils::error::raise_api_path_error(function_name, api_path, response_code,
"failed to remove file");
return api_error::comm_error;
}

View File

@ -41,6 +41,8 @@ sia_provider::sia_provider(app_config &config, i_http_comm &comm)
auto sia_provider::create_directory_impl(const std::string &api_path,
api_meta_map & /* meta */)
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
curl::requests::http_put_file put_file{};
put_file.allow_timeout = true;
put_file.path = "/api/worker/objects" + api_path + "/";
@ -48,14 +50,14 @@ auto sia_provider::create_directory_impl(const std::string &api_path,
long response_code{};
stop_type stop_requested{};
if (not get_comm().make_request(put_file, response_code, stop_requested)) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
utils::error::raise_api_path_error(function_name, api_path,
api_error::comm_error,
"failed to create directory");
return api_error::comm_error;
}
if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, response_code,
utils::error::raise_api_path_error(function_name, api_path, response_code,
"failed to create directory");
return api_error::comm_error;
}
@ -65,6 +67,8 @@ auto sia_provider::create_directory_impl(const std::string &api_path,
auto sia_provider::get_directory_item_count(const std::string &api_path) const
-> std::uint64_t {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
json object_list{};
if (not get_object_list(api_path, object_list)) {
@ -83,7 +87,7 @@ auto sia_provider::get_directory_item_count(const std::string &api_path) const
}
++item_count;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to process entry|" +
entry.dump());
}
@ -92,7 +96,7 @@ auto sia_provider::get_directory_item_count(const std::string &api_path) const
return item_count;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to get directory item count");
}
@ -102,6 +106,8 @@ auto sia_provider::get_directory_item_count(const std::string &api_path) const
auto sia_provider::get_directory_items_impl(const std::string &api_path,
directory_item_list &list) const
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
json object_list{};
if (not get_object_list(api_path, object_list)) {
return api_error::comm_error;
@ -128,7 +134,7 @@ auto sia_provider::get_directory_items_impl(const std::string &api_path,
get_api_item_added()(directory, file);
auto res = get_item_meta(entry_api_path, meta);
if (res != api_error::success) {
utils::error::raise_error(__FUNCTION__, res,
utils::error::raise_error(function_name, res,
"failed to get item meta");
continue;
}
@ -147,7 +153,7 @@ auto sia_provider::get_directory_items_impl(const std::string &api_path,
dir_item.size = file.file_size;
list.emplace_back(std::move(dir_item));
} catch (const std::exception &e) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to process entry|" +
entry.dump());
}
@ -185,6 +191,8 @@ auto sia_provider::get_file(const std::string &api_path, api_file &file) const
}
auto sia_provider::get_file_list(api_file_list &list) const -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
using dir_func = std::function<api_error(std::string api_path)>;
const dir_func get_files_in_dir = [&](std::string api_path) -> api_error {
try {
@ -235,7 +243,7 @@ auto sia_provider::get_file_list(api_file_list &list) const -> api_error {
return api_error::success;
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e,
utils::error::raise_error(function_name, e,
"failed to process directory|" + api_path);
}
@ -247,6 +255,8 @@ auto sia_provider::get_file_list(api_file_list &list) const -> api_error {
auto sia_provider::get_object_info(const std::string &api_path,
json &object_info) const -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
curl::requests::http_get get{};
get.allow_timeout = true;
@ -270,14 +280,14 @@ auto sia_provider::get_object_info(const std::string &api_path,
}
if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, response_code,
utils::error::raise_api_path_error(function_name, api_path, response_code,
"failed to get object info");
return api_error::comm_error;
}
return api_error::success;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to get object info");
}
@ -286,6 +296,8 @@ auto sia_provider::get_object_info(const std::string &api_path,
auto sia_provider::get_object_list(const std::string &api_path,
nlohmann::json &object_list) const -> bool {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
curl::requests::http_get get{};
get.allow_timeout = true;
get.path = "/api/bus/objects" + api_path + "/";
@ -300,14 +312,14 @@ auto sia_provider::get_object_list(const std::string &api_path,
long response_code{};
stop_type stop_requested{};
if (not get_comm().make_request(get, response_code, stop_requested)) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
utils::error::raise_api_path_error(function_name, api_path,
api_error::comm_error,
"failed to get object list");
return false;
}
if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, response_code,
utils::error::raise_api_path_error(function_name, api_path, response_code,
"failed to get object list");
return false;
}
@ -316,6 +328,8 @@ auto sia_provider::get_object_list(const std::string &api_path,
}
auto sia_provider::get_total_drive_space() const -> std::uint64_t {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
curl::requests::http_get get{};
get.allow_timeout = true;
@ -336,14 +350,14 @@ auto sia_provider::get_total_drive_space() const -> std::uint64_t {
}
if (response_code != http_error_codes::ok) {
utils::error::raise_error(__FUNCTION__, response_code,
utils::error::raise_error(function_name, response_code,
"failed to get total drive space");
return 0U;
}
return config_data["contracts"]["storage"].get<std::uint64_t>();
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e,
utils::error::raise_error(function_name, e,
"failed to get total drive space");
}
@ -351,6 +365,8 @@ auto sia_provider::get_total_drive_space() const -> std::uint64_t {
}
auto sia_provider::get_used_drive_space_impl() const -> std::uint64_t {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
curl::requests::http_get get{};
get.allow_timeout = true;
get.path = "/api/bus/stats/objects";
@ -370,7 +386,7 @@ auto sia_provider::get_used_drive_space_impl() const -> std::uint64_t {
}
if (response_code != http_error_codes::ok) {
utils::error::raise_error(__FUNCTION__, response_code,
utils::error::raise_error(function_name, response_code,
"failed to get used drive space");
return 0U;
}
@ -380,6 +396,8 @@ auto sia_provider::get_used_drive_space_impl() const -> std::uint64_t {
auto sia_provider::is_directory(const std::string &api_path, bool &exists) const
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (api_path == "/") {
exists = true;
return api_error::success;
@ -402,7 +420,7 @@ auto sia_provider::is_directory(const std::string &api_path, bool &exists) const
}) != object_list.at("entries").end();
return api_error::success;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to determine path is directory");
}
@ -411,6 +429,8 @@ auto sia_provider::is_directory(const std::string &api_path, bool &exists) const
auto sia_provider::is_file(const std::string &api_path, bool &exists) const
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
exists = false;
if (api_path == "/") {
return api_error::success;
@ -430,7 +450,7 @@ auto sia_provider::is_file(const std::string &api_path, bool &exists) const
exists = not file_data.contains("entries");
return api_error::success;
} catch (const std::exception &e) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
utils::error::raise_api_path_error(function_name, api_path, e,
"failed to determine path is directory");
}
@ -438,6 +458,8 @@ auto sia_provider::is_file(const std::string &api_path, bool &exists) const
}
auto sia_provider::is_online() const -> bool {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {
curl::requests::http_get get{};
get.allow_timeout = true;
@ -454,22 +476,22 @@ auto sia_provider::is_online() const -> bool {
long response_code{};
stop_type stop_requested{};
if (not get_comm().make_request(get, response_code, stop_requested)) {
utils::error::raise_error(__FUNCTION__, api_error::comm_error,
utils::error::raise_error(function_name, api_error::comm_error,
"failed to determine if provider is online");
return false;
}
if (response_code != http_error_codes::ok) {
utils::error::raise_error(__FUNCTION__, response_code,
utils::error::raise_error(function_name, response_code,
"failed to determine if provider is online");
return false;
}
event_system::instance().raise<debug_log>(__FUNCTION__, "",
event_system::instance().raise<debug_log>(function_name, "",
state_data.dump());
return true;
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e,
utils::error::raise_error(function_name, e,
"failed to determine if provider is online");
}
@ -480,6 +502,8 @@ auto sia_provider::read_file_bytes(const std::string &api_path,
std::size_t size, std::uint64_t offset,
data_buffer &buffer,
stop_type &stop_requested) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
curl::requests::http_get get{};
get.path = "/api/worker/objects" + api_path;
get.range = {{
@ -497,13 +521,13 @@ auto sia_provider::read_file_bytes(const std::string &api_path,
const auto notify_retry = [&]() {
if (response_code == 0) {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, api_error::comm_error,
function_name, api_path, api_error::comm_error,
"read file bytes failed|offset|" + std::to_string(offset) +
"|size|" + std::to_string(size) + "|retry|" +
std::to_string(i + 1U));
} else {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, response_code,
function_name, api_path, response_code,
"read file bytes failed|offset|" + std::to_string(offset) +
"|size|" + std::to_string(size) + "|retry|" +
std::to_string(i + 1U));
@ -530,6 +554,8 @@ auto sia_provider::read_file_bytes(const std::string &api_path,
auto sia_provider::remove_directory_impl(const std::string &api_path)
-> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
curl::requests::http_delete del{};
del.allow_timeout = true;
del.path = "/api/bus/objects" + api_path + "/";
@ -537,14 +563,14 @@ auto sia_provider::remove_directory_impl(const std::string &api_path)
long response_code{};
stop_type stop_requested{};
if (not get_comm().make_request(del, response_code, stop_requested)) {
utils::error::raise_api_path_error(__FUNCTION__, api_path,
utils::error::raise_api_path_error(function_name, api_path,
api_error::comm_error,
"failed to remove directory");
return api_error::comm_error;
}
if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, response_code,
utils::error::raise_api_path_error(function_name, api_path, response_code,
"failed to remove directory");
return api_error::comm_error;
}
@ -553,6 +579,8 @@ auto sia_provider::remove_directory_impl(const std::string &api_path)
}
auto sia_provider::remove_file_impl(const std::string &api_path) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
curl::requests::http_delete del{};
del.allow_timeout = true;
del.path = "/api/bus/objects" + api_path;
@ -560,14 +588,15 @@ auto sia_provider::remove_file_impl(const std::string &api_path) -> api_error {
long response_code{};
stop_type stop_requested{};
if (not get_comm().make_request(del, response_code, stop_requested)) {
utils::error::raise_api_path_error(
__FUNCTION__, api_path, api_error::comm_error, "failed to remove file");
utils::error::raise_api_path_error(function_name, api_path,
api_error::comm_error,
"failed to remove file");
return api_error::comm_error;
}
if (response_code != http_error_codes::ok &&
response_code != http_error_codes::not_found) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, response_code,
utils::error::raise_api_path_error(function_name, api_path, response_code,
"failed to remove file");
return api_error::comm_error;
}
@ -577,6 +606,8 @@ auto sia_provider::remove_file_impl(const std::string &api_path) -> api_error {
auto sia_provider::rename_file(const std::string &from_api_path,
const std::string &to_api_path) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
curl::requests::http_post post{};
post.path = "/api/bus/objects/rename";
post.json = nlohmann::json({
@ -589,7 +620,7 @@ auto sia_provider::rename_file(const std::string &from_api_path,
stop_type stop_requested{};
if (not get_comm().make_request(post, response_code, stop_requested)) {
utils::error::raise_api_path_error(
__FUNCTION__, from_api_path + '|' + to_api_path, api_error::comm_error,
function_name, from_api_path + '|' + to_api_path, api_error::comm_error,
"failed to rename file");
return api_error::comm_error;
}
@ -597,7 +628,7 @@ auto sia_provider::rename_file(const std::string &from_api_path,
if (response_code < http_error_codes::ok ||
response_code >= http_error_codes::multiple_choices) {
utils::error::raise_api_path_error(
__FUNCTION__, from_api_path + '|' + to_api_path, response_code,
function_name, from_api_path + '|' + to_api_path, response_code,
"failed to rename file file");
return api_error::comm_error;
}
@ -620,20 +651,22 @@ void sia_provider::stop() {
auto sia_provider::upload_file_impl(const std::string &api_path,
const std::string &source_path,
stop_type &stop_requested) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
curl::requests::http_put_file put_file{};
put_file.path = "/api/worker/objects" + api_path;
put_file.source_path = source_path;
long response_code{};
if (not get_comm().make_request(put_file, response_code, stop_requested)) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, source_path,
utils::error::raise_api_path_error(function_name, api_path, source_path,
api_error::comm_error,
"failed to upload file");
return api_error::comm_error;
}
if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, source_path,
utils::error::raise_api_path_error(function_name, api_path, source_path,
response_code, "failed to upload file");
return api_error::comm_error;
}

View File

@ -89,13 +89,15 @@ void full_server::handle_get_pinned_files(const httplib::Request & /*req*/,
void full_server::handle_get_pinned_status(const httplib::Request &req,
httplib::Response &res) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto api_path =
utils::path::create_api_path(req.get_param_value("api_path"));
std::string pinned;
const auto result = provider_.get_item_meta(api_path, META_PINNED, pinned);
if (result != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, result,
utils::error::raise_api_path_error(function_name, api_path, result,
"failed to get pinned status");
res.status = 500;
return;
@ -111,13 +113,15 @@ void full_server::handle_get_pinned_status(const httplib::Request &req,
void full_server::handle_pin_file(const httplib::Request &req,
httplib::Response &res) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto api_path =
utils::path::create_api_path(req.get_param_value("api_path"));
bool exists{};
auto result = provider_.is_file(api_path, exists);
if (result != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, result,
utils::error::raise_api_path_error(function_name, api_path, result,
"failed to pin file");
res.status = 500;
return;
@ -138,13 +142,15 @@ void full_server::handle_pin_file(const httplib::Request &req,
void full_server::handle_unpin_file(const httplib::Request &req,
httplib::Response &res) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto api_path =
utils::path::create_api_path(req.get_param_value("api_path"));
bool exists{};
auto result = provider_.is_file(api_path, exists);
if (result != api_error::success) {
utils::error::raise_api_path_error(__FUNCTION__, api_path, result,
utils::error::raise_api_path_error(function_name, api_path, result,
"failed to unpin file");
res.status = 500;
return;

View File

@ -29,8 +29,10 @@ namespace repertory {
server::server(app_config &config) : config_(config) {}
auto server::check_authorization(const httplib::Request &req) -> bool {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (config_.get_api_auth().empty() || config_.get_api_user().empty()) {
utils::error::raise_error(__FUNCTION__,
utils::error::raise_error(function_name,
"authorization user or password is not set");
return false;
}
@ -118,7 +120,9 @@ void server::initialize(httplib::Server &inst) {
}
void server::start() {
mutex_lock l(start_stop_mutex_);
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
mutex_lock lock(start_stop_mutex_);
if (not started_) {
event_system::instance().raise<service_started>("server");
server_ = std::make_unique<httplib::Server>();
@ -132,11 +136,11 @@ void server::start() {
std::rethrow_exception(ep);
} catch (std::exception &e) {
data["error"] = e.what() ? e.what() : "unknown error";
utils::error::raise_error(__FUNCTION__, e,
utils::error::raise_error(function_name, e,
"failed request: " + req.path);
} catch (...) {
data["error"] = "unknown error";
utils::error::raise_error(__FUNCTION__, "unknown error",
utils::error::raise_error(function_name, "unknown error",
"failed request: " + req.path);
}

View File

@ -340,19 +340,21 @@ auto encrypting_reader::create_iostream() const
auto encrypting_reader::reader_function(char *buffer, size_t size,
size_t nitems) -> size_t {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
const auto read_size = static_cast<std::size_t>(std::min(
static_cast<std::uint64_t>(size * nitems), total_size_ - read_offset_));
auto chunk = read_offset_ / encrypted_chunk_size_;
auto chunk_offset = read_offset_ % encrypted_chunk_size_;
std::size_t total_read = 0u;
std::size_t total_read{};
auto ret = false;
if (read_offset_ < total_size_) {
try {
ret = true;
auto remain = read_size;
while (not stop_requested_ && ret && remain) {
while (not stop_requested_ && ret && (remain != 0U)) {
if (chunk_buffers_.find(chunk) == chunk_buffers_.end()) {
auto &chunk_buffer = chunk_buffers_[chunk];
data_buffer file_data(chunk == last_data_chunk_
@ -383,7 +385,7 @@ auto encrypting_reader::reader_function(char *buffer, size_t size,
read_offset_ += to_read;
}
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
utils::error::raise_error(function_name, e, "exception occurred");
ret = false;
}
}

View File

@ -581,6 +581,8 @@ auto read_file_lines(const std::string &path) -> std::vector<std::string> {
}
auto read_json_file(const std::string &path, json &data) -> bool {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (not utils::file::is_file(path)) {
return true;
}
@ -605,7 +607,7 @@ auto read_json_file(const std::string &path, json &data) -> bool {
}
}
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, path,
utils::error::raise_error(function_name, e, path,
"failed to read json file");
}

View File

@ -240,11 +240,13 @@ auto unix_time_to_windows_time(const remote::file_time &file_time) -> UINT64 {
void use_getpwuid(uid_t uid,
std::function<void(struct passwd *pass)> callback) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
static std::mutex mtx{};
mutex_lock lock{mtx};
auto *temp_pw = getpwuid(uid);
if (temp_pw == nullptr) {
utils::error::raise_error(__FUNCTION__, "'getpwuid' returned nullptr");
utils::error::raise_error(function_name, "'getpwuid' returned nullptr");
return;
}