1 Commits

Author SHA1 Message Date
1b8de3b097 v2.0.1-rc (#13)
All checks were successful
BlockStorage/repertory_osx_builds/pipeline/head This commit looks good
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good
Reviewed-on: #13
2023-12-10 18:11:20 +00:00
380 changed files with 409949 additions and 143205 deletions

View File

@ -70,6 +70,7 @@ duse_libidn2
dwith_gflags
dwith_liburing
dwith_tools
dxxh_no_inline_hints
dylib
endfunction
endmacro
@ -243,6 +244,7 @@ wcast
wconversion
wdouble
wduplicated
wfloat
wformat
windres
winfsp

1
.gitignore vendored
View File

@ -15,3 +15,4 @@ tags
src/common.cpp
cspell.json
dviml
*.log

View File

@ -86,9 +86,9 @@ pipeline {
agent any
steps {
sh 'scripts/make_package.sh alpine /home/sgraves/cert build/alpine_arm64 . /mnt/filebase 1'
sh 'scripts/make_package.sh alpine /home/sgraves/cert build/alpine . /mnt/filebase'
sh 'scripts/make_package.sh mingw64 /home/sgraves/cert build/mingw64 . /mnt/filebase'
sh 'scripts/make_package.sh alpine /home/sgraves/cert build/alpine_arm64 . /mnt/storj 1'
sh 'scripts/make_package.sh alpine /home/sgraves/cert build/alpine . /mnt/storj'
sh 'scripts/make_package.sh mingw64 /home/sgraves/cert build/mingw64 . /mnt/storj'
}
}
}

View File

@ -47,7 +47,7 @@ pipeline {
}
steps {
sh 'scripts/make_package.sh darwin /Users/sgraves/cert build . /Users/sgraves/mnt/filebase'
sh 'scripts/make_package.sh darwin /Users/sgraves/cert build . /Users/sgraves/mnt/storj'
}
}
}

View File

@ -8,7 +8,7 @@
#ifndef CPPHTTPLIB_HTTPLIB_H
#define CPPHTTPLIB_HTTPLIB_H
#define CPPHTTPLIB_VERSION "0.14.0"
#define CPPHTTPLIB_VERSION "0.14.2"
/*
* Configuration
@ -247,7 +247,6 @@ using socket_t = int;
#ifdef _MSC_VER
#pragma comment(lib, "crypt32.lib")
#pragma comment(lib, "cryptui.lib")
#endif
#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && defined(__APPLE__)
#include <TargetConditionals.h>
@ -331,7 +330,7 @@ struct scope_exit {
explicit scope_exit(std::function<void(void)> &&f)
: exit_function(std::move(f)), execute_on_destruction{true} {}
scope_exit(scope_exit &&rhs)
scope_exit(scope_exit &&rhs) noexcept
: exit_function(std::move(rhs.exit_function)),
execute_on_destruction{rhs.execute_on_destruction} {
rhs.release();
@ -385,6 +384,7 @@ public:
DataSink &operator=(DataSink &&) = delete;
std::function<bool(const char *data, size_t data_len)> write;
std::function<bool()> is_writable;
std::function<void()> done;
std::function<void(const Headers &trailer)> done_with_trailer;
std::ostream os;
@ -395,7 +395,7 @@ private:
explicit data_sink_streambuf(DataSink &sink) : sink_(sink) {}
protected:
std::streamsize xsputn(const char *s, std::streamsize n) {
std::streamsize xsputn(const char *s, std::streamsize n) override {
sink_.write(s, static_cast<size_t>(n));
return n;
}
@ -873,15 +873,15 @@ private:
bool routing(Request &req, Response &res, Stream &strm);
bool handle_file_request(const Request &req, Response &res,
bool head = false);
bool dispatch_request(Request &req, Response &res, const Handlers &handlers);
bool
dispatch_request_for_content_reader(Request &req, Response &res,
ContentReader content_reader,
const HandlersForContentReader &handlers);
bool dispatch_request(Request &req, Response &res,
const Handlers &handlers) const;
bool dispatch_request_for_content_reader(
Request &req, Response &res, ContentReader content_reader,
const HandlersForContentReader &handlers) const;
bool parse_request_line(const char *s, Request &req);
bool parse_request_line(const char *s, Request &req) const;
void apply_ranges(const Request &req, Response &res,
std::string &content_type, std::string &boundary);
std::string &content_type, std::string &boundary) const;
bool write_response(Stream &strm, bool close_connection, const Request &req,
Response &res);
bool write_response_with_content(Stream &strm, bool close_connection,
@ -901,7 +901,7 @@ private:
bool read_content_core(Stream &strm, Request &req, Response &res,
ContentReceiver receiver,
MultipartContentHeader multipart_header,
ContentReceiver multipart_receiver);
ContentReceiver multipart_receiver) const;
virtual bool process_and_close_socket(socket_t sock);
@ -967,7 +967,7 @@ enum class Error {
SSLPeerCouldBeClosed_,
};
std::string to_string(const Error error);
std::string to_string(Error error);
std::ostream &operator<<(std::ostream &os, const Error &obj);
@ -1226,7 +1226,7 @@ public:
void set_ca_cert_path(const std::string &ca_cert_file_path,
const std::string &ca_cert_dir_path = std::string());
void set_ca_cert_store(X509_STORE *ca_cert_store);
X509_STORE *create_ca_cert_store(const char *ca_cert, std::size_t size);
X509_STORE *create_ca_cert_store(const char *ca_cert, std::size_t size) const;
#endif
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
@ -1255,14 +1255,14 @@ protected:
// Also, shutdown_ssl and close_socket should also NOT be called concurrently
// with a DIFFERENT thread sending requests using that socket.
virtual void shutdown_ssl(Socket &socket, bool shutdown_gracefully);
void shutdown_socket(Socket &socket);
void shutdown_socket(Socket &socket) const;
void close_socket(Socket &socket);
bool process_request(Stream &strm, Request &req, Response &res,
bool close_connection, Error &error);
bool write_content_with_provider(Stream &strm, const Request &req,
Error &error);
Error &error) const;
void copy_settings(const ClientImpl &rhs);
@ -1353,7 +1353,8 @@ private:
Result send_(Request &&req);
socket_t create_client_socket(Error &error) const;
bool read_response_line(Stream &strm, const Request &req, Response &res);
bool read_response_line(Stream &strm, const Request &req,
Response &res) const;
bool write_request(Stream &strm, Request &req, bool close_connection,
Error &error);
bool redirect(Request &req, Response &res, Error &error);
@ -1372,7 +1373,7 @@ private:
const std::string &content_type);
ContentProviderWithoutLength get_multipart_content_provider(
const std::string &boundary, const MultipartFormDataItems &items,
const MultipartFormDataProviderItems &provider_items);
const MultipartFormDataProviderItems &provider_items) const;
std::string adjust_host_string(const std::string &host) const;
@ -1685,7 +1686,7 @@ public:
private:
bool create_and_connect_socket(Socket &socket, Error &error) override;
void shutdown_ssl(Socket &socket, bool shutdown_gracefully) override;
void shutdown_ssl_impl(Socket &socket, bool shutdown_socket);
void shutdown_ssl_impl(Socket &socket, bool shutdown_gracefully);
bool process_socket(const Socket &socket,
std::function<bool(Stream &strm)> callback) override;
@ -2075,6 +2076,9 @@ std::string trim_copy(const std::string &s);
void split(const char *b, const char *e, char d,
std::function<void(const char *, const char *)> fn);
void split(const char *b, const char *e, char d, size_t m,
std::function<void(const char *, const char *)> fn);
bool process_client_socket(socket_t sock, time_t read_timeout_sec,
time_t read_timeout_usec, time_t write_timeout_sec,
time_t write_timeout_usec,
@ -2151,7 +2155,7 @@ public:
class nocompressor : public compressor {
public:
virtual ~nocompressor() = default;
~nocompressor() override = default;
bool compress(const char *data, size_t data_length, bool /*last*/,
Callback callback) override;
@ -2161,7 +2165,7 @@ public:
class gzip_compressor : public compressor {
public:
gzip_compressor();
~gzip_compressor();
~gzip_compressor() override;
bool compress(const char *data, size_t data_length, bool last,
Callback callback) override;
@ -2174,7 +2178,7 @@ private:
class gzip_decompressor : public decompressor {
public:
gzip_decompressor();
~gzip_decompressor();
~gzip_decompressor() override;
bool is_valid() const override;
@ -2317,7 +2321,7 @@ inline std::string from_i_to_hex(size_t n) {
inline size_t to_utf8(int code, char *buff) {
if (code < 0x0080) {
buff[0] = (code & 0x7F);
buff[0] = static_cast<char>(code & 0x7F);
return 1;
} else if (code < 0x0800) {
buff[0] = static_cast<char>(0xC0 | ((code >> 6) & 0x1F));
@ -2583,16 +2587,23 @@ inline std::string trim_double_quotes_copy(const std::string &s) {
inline void split(const char *b, const char *e, char d,
std::function<void(const char *, const char *)> fn) {
return split(b, e, d, std::numeric_limits<size_t>::max(), fn);
}
inline void split(const char *b, const char *e, char d, size_t m,
std::function<void(const char *, const char *)> fn) {
size_t i = 0;
size_t beg = 0;
size_t count = 1;
while (e ? (b + i < e) : (b[i] != '\0')) {
if (b[i] == d) {
if (b[i] == d && count < m) {
auto r = trim(b, e, beg, i);
if (r.first < r.second) {
fn(&b[r.first], &b[r.second]);
}
beg = i + 1;
count++;
}
i++;
}
@ -2683,9 +2694,7 @@ inline mmap::mmap(const char *path)
,
size_(0),
addr_(nullptr) {
if (!open(path)) {
std::runtime_error("");
}
open(path);
}
inline mmap::~mmap() { close(); }
@ -2974,7 +2983,7 @@ private:
size_t read_buff_off_ = 0;
size_t read_buff_content_size_ = 0;
static const size_t read_buff_size_ = 1024 * 4;
static const size_t read_buff_size_ = 1024l * 4;
};
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
@ -3109,8 +3118,9 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
#ifndef _WIN32
if (hints.ai_family == AF_UNIX) {
const auto addrlen = host.length();
if (addrlen > sizeof(sockaddr_un::sun_path))
if (addrlen > sizeof(sockaddr_un::sun_path)) {
return INVALID_SOCKET;
}
auto sock = socket(hints.ai_family, hints.ai_socktype, hints.ai_protocol);
if (sock != INVALID_SOCKET) {
@ -3324,7 +3334,7 @@ inline socket_t create_client_socket(
if (ip_from_if.empty()) {
ip_from_if = intf;
}
if (!bind_ip_address(sock2, ip_from_if.c_str())) {
if (!bind_ip_address(sock2, ip_from_if)) {
error = Error::BindIPAddress;
return false;
}
@ -3486,7 +3496,7 @@ find_content_type(const std::string &path,
auto it = user_data.find(ext);
if (it != user_data.end()) {
return it->second.c_str();
return it->second;
}
using udl::operator""_t;
@ -3752,8 +3762,9 @@ inline bool gzip_decompressor::decompress(const char *data, size_t data_length,
}
}
if (ret != Z_OK && ret != Z_STREAM_END)
if (ret != Z_OK && ret != Z_STREAM_END) {
return false;
}
} while (data_length > 0);
@ -4069,7 +4080,7 @@ inline bool read_content_chunked(Stream &strm, T &x,
return false;
}
if (strcmp(line_reader.ptr(), "\r\n")) {
if (strcmp(line_reader.ptr(), "\r\n") != 0) {
return false;
}
@ -4085,7 +4096,7 @@ inline bool read_content_chunked(Stream &strm, T &x,
return false;
}
while (strcmp(line_reader.ptr(), "\r\n")) {
while (strcmp(line_reader.ptr(), "\r\n") != 0) {
if (line_reader.size() > CPPHTTPLIB_HEADER_MAX_LENGTH) {
return false;
}
@ -4241,6 +4252,8 @@ inline bool write_content(Stream &strm, const ContentProvider &content_provider,
return ok;
};
data_sink.is_writable = [&]() -> bool { return strm.is_writable(); };
while (offset < end_offset && !is_shutting_down()) {
if (!strm.is_writable()) {
error = Error::Write;
@ -4287,6 +4300,8 @@ write_content_without_length(Stream &strm,
return ok;
};
data_sink.is_writable = [&]() -> bool { return strm.is_writable(); };
data_sink.done = [&](void) { data_available = false; };
while (data_available && !is_shutting_down()) {
@ -4337,6 +4352,8 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider,
return ok;
};
data_sink.is_writable = [&]() -> bool { return strm.is_writable(); };
auto done_with_trailer = [&](const Headers *trailer) {
if (!ok) {
return;
@ -4438,8 +4455,9 @@ inline bool redirect(T &cli, Request &req, Response &res,
req = new_req;
res = new_res;
if (res.location.empty())
if (res.location.empty()) {
res.location = location;
}
}
return ret;
}
@ -4534,8 +4552,9 @@ inline bool parse_range_header(const std::string &s, Ranges &ranges) try {
auto len = static_cast<size_t>(m.length(1));
auto all_valid_ranges = true;
split(&s[pos], &s[pos + len], ',', [&](const char *b, const char *e) {
if (!all_valid_ranges)
if (!all_valid_ranges) {
return;
}
static auto re_another_range = std::regex(R"(\s*(\d*)-(\d*))");
std::cmatch cm;
if (std::regex_match(b, e, cm, re_another_range)) {
@ -4922,8 +4941,9 @@ serialize_multipart_formdata(const MultipartFormDataItems &items,
body += item.content + serialize_multipart_formdata_item_end();
}
if (finish)
if (finish) {
body += serialize_multipart_formdata_finish(boundary);
}
return body;
}
@ -5376,7 +5396,7 @@ inline std::string random_string(size_t length) {
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[repertory_rand<size_t>() % max_index];
return charset[static_cast<size_t>(std::rand()) % max_index];
};
std::string str(length, 0);
std::generate_n(str.begin(), length, randchar);
@ -5671,7 +5691,7 @@ inline SocketStream::SocketStream(socket_t sock, time_t read_timeout_sec,
write_timeout_usec_(write_timeout_usec),
read_buff_(read_buff_size_, 0) {}
inline SocketStream::~SocketStream() {}
inline SocketStream::~SocketStream() = default;
inline bool SocketStream::is_readable() const {
return select_read(sock_, read_timeout_sec_, read_timeout_usec_) > 0;
@ -5897,7 +5917,7 @@ inline Server::Server()
#endif
}
inline Server::~Server() {}
inline Server::~Server() = default;
inline std::unique_ptr<detail::MatcherBase>
Server::make_matcher(const std::string &pattern) {
@ -5909,66 +5929,60 @@ Server::make_matcher(const std::string &pattern) {
}
inline Server &Server::Get(const std::string &pattern, Handler handler) {
get_handlers_.push_back(
std::make_pair(make_matcher(pattern), std::move(handler)));
get_handlers_.emplace_back(make_matcher(pattern), std::move(handler));
return *this;
}
inline Server &Server::Post(const std::string &pattern, Handler handler) {
post_handlers_.push_back(
std::make_pair(make_matcher(pattern), std::move(handler)));
post_handlers_.emplace_back(make_matcher(pattern), std::move(handler));
return *this;
}
inline Server &Server::Post(const std::string &pattern,
HandlerWithContentReader handler) {
post_handlers_for_content_reader_.push_back(
std::make_pair(make_matcher(pattern), std::move(handler)));
post_handlers_for_content_reader_.emplace_back(make_matcher(pattern),
std::move(handler));
return *this;
}
inline Server &Server::Put(const std::string &pattern, Handler handler) {
put_handlers_.push_back(
std::make_pair(make_matcher(pattern), std::move(handler)));
put_handlers_.emplace_back(make_matcher(pattern), std::move(handler));
return *this;
}
inline Server &Server::Put(const std::string &pattern,
HandlerWithContentReader handler) {
put_handlers_for_content_reader_.push_back(
std::make_pair(make_matcher(pattern), std::move(handler)));
put_handlers_for_content_reader_.emplace_back(make_matcher(pattern),
std::move(handler));
return *this;
}
inline Server &Server::Patch(const std::string &pattern, Handler handler) {
patch_handlers_.push_back(
std::make_pair(make_matcher(pattern), std::move(handler)));
patch_handlers_.emplace_back(make_matcher(pattern), std::move(handler));
return *this;
}
inline Server &Server::Patch(const std::string &pattern,
HandlerWithContentReader handler) {
patch_handlers_for_content_reader_.push_back(
std::make_pair(make_matcher(pattern), std::move(handler)));
patch_handlers_for_content_reader_.emplace_back(make_matcher(pattern),
std::move(handler));
return *this;
}
inline Server &Server::Delete(const std::string &pattern, Handler handler) {
delete_handlers_.push_back(
std::make_pair(make_matcher(pattern), std::move(handler)));
delete_handlers_.emplace_back(make_matcher(pattern), std::move(handler));
return *this;
}
inline Server &Server::Delete(const std::string &pattern,
HandlerWithContentReader handler) {
delete_handlers_for_content_reader_.push_back(
std::make_pair(make_matcher(pattern), std::move(handler)));
delete_handlers_for_content_reader_.emplace_back(make_matcher(pattern),
std::move(handler));
return *this;
}
inline Server &Server::Options(const std::string &pattern, Handler handler) {
options_handlers_.push_back(
std::make_pair(make_matcher(pattern), std::move(handler)));
options_handlers_.emplace_back(make_matcher(pattern), std::move(handler));
return *this;
}
@ -6116,9 +6130,7 @@ inline Server &Server::set_payload_max_length(size_t length) {
inline bool Server::bind_to_port(const std::string &host, int port,
int socket_flags) {
if (bind_internal(host, port, socket_flags) < 0)
return false;
return true;
return bind_internal(host, port, socket_flags) >= 0;
}
inline int Server::bind_to_any_port(const std::string &host, int socket_flags) {
return bind_internal(host, 0, socket_flags);
@ -6152,7 +6164,7 @@ inline void Server::stop() {
}
}
inline bool Server::parse_request_line(const char *s, Request &req) {
inline bool Server::parse_request_line(const char *s, Request &req) const {
auto len = strlen(s);
if (len < 2 || s[len - 2] != '\r' || s[len - 1] != '\n') {
return false;
@ -6208,7 +6220,7 @@ inline bool Server::parse_request_line(const char *s, Request &req) {
size_t count = 0;
detail::split(req.target.data(), req.target.data() + req.target.size(), '?',
[&](const char *b, const char *e) {
2, [&](const char *b, const char *e) {
switch (count) {
case 0:
req.path = detail::decode_url(std::string(b, e), false);
@ -6433,10 +6445,11 @@ inline bool Server::read_content_with_content_receiver(
std::move(multipart_receiver));
}
inline bool Server::read_content_core(Stream &strm, Request &req, Response &res,
ContentReceiver receiver,
MultipartContentHeader multipart_header,
ContentReceiver multipart_receiver) {
inline bool
Server::read_content_core(Stream &strm, Request &req, Response &res,
ContentReceiver receiver,
MultipartContentHeader multipart_header,
ContentReceiver multipart_receiver) const {
detail::MultipartFormDataParser multipart_form_data_parser;
ContentReceiverWithProgress out;
@ -6502,7 +6515,7 @@ inline bool Server::handle_file_request(const Request &req, Response &res,
if (detail::is_file(path)) {
for (const auto &kv : entry.headers) {
res.set_header(kv.first.c_str(), kv.second);
res.set_header(kv.first, kv.second);
}
auto mm = std::make_shared<detail::mmap>(path.c_str());
@ -6739,7 +6752,7 @@ inline bool Server::routing(Request &req, Response &res, Stream &strm) {
}
inline bool Server::dispatch_request(Request &req, Response &res,
const Handlers &handlers) {
const Handlers &handlers) const {
for (const auto &x : handlers) {
const auto &matcher = x.first;
const auto &handler = x.second;
@ -6754,7 +6767,7 @@ inline bool Server::dispatch_request(Request &req, Response &res,
inline void Server::apply_ranges(const Request &req, Response &res,
std::string &content_type,
std::string &boundary) {
std::string &boundary) const {
if (req.ranges.size() > 1) {
boundary = detail::make_multipart_data_boundary();
@ -6866,7 +6879,7 @@ inline void Server::apply_ranges(const Request &req, Response &res,
inline bool Server::dispatch_request_for_content_reader(
Request &req, Response &res, ContentReader content_reader,
const HandlersForContentReader &handlers) {
const HandlersForContentReader &handlers) const {
for (const auto &x : handlers) {
const auto &matcher = x.first;
const auto &handler = x.second;
@ -7125,8 +7138,9 @@ inline socket_t ClientImpl::create_client_socket(Error &error) const {
// Check is custom IP specified for host_
std::string ip;
auto it = addr_map_.find(host_);
if (it != addr_map_.end())
if (it != addr_map_.end()) {
ip = it->second;
}
return detail::create_client_socket(
host_, ip, port_, address_family_, tcp_nodelay_, socket_options_,
@ -7153,7 +7167,7 @@ inline void ClientImpl::shutdown_ssl(Socket & /*socket*/,
socket_requests_are_from_thread_ == std::this_thread::get_id());
}
inline void ClientImpl::shutdown_socket(Socket &socket) {
inline void ClientImpl::shutdown_socket(Socket &socket) const {
if (socket.sock == INVALID_SOCKET) {
return;
}
@ -7182,7 +7196,7 @@ inline void ClientImpl::close_socket(Socket &socket) {
}
inline bool ClientImpl::read_response_line(Stream &strm, const Request &req,
Response &res) {
Response &res) const {
std::array<char, 2048> buf{};
detail::stream_line_reader line_reader(strm, buf.data(), buf.size());
@ -7476,7 +7490,7 @@ inline bool ClientImpl::redirect(Request &req, Response &res, Error &error) {
} else {
if (next_scheme == "https") {
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
SSLClient cli(next_host.c_str(), next_port);
SSLClient cli(next_host, next_port);
cli.copy_settings(*this);
if (ca_cert_store_) {
cli.set_ca_cert_store(ca_cert_store_);
@ -7486,7 +7500,7 @@ inline bool ClientImpl::redirect(Request &req, Response &res, Error &error) {
return false;
#endif
} else {
ClientImpl cli(next_host.c_str(), next_port);
ClientImpl cli(next_host, next_port);
cli.copy_settings(*this);
return detail::redirect(cli, req, res, path, location, error);
}
@ -7495,7 +7509,7 @@ inline bool ClientImpl::redirect(Request &req, Response &res, Error &error) {
inline bool ClientImpl::write_content_with_provider(Stream &strm,
const Request &req,
Error &error) {
Error &error) const {
auto is_shutting_down = []() { return false; };
if (req.is_chunked_content_provider_) {
@ -7843,13 +7857,14 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,
inline ContentProviderWithoutLength ClientImpl::get_multipart_content_provider(
const std::string &boundary, const MultipartFormDataItems &items,
const MultipartFormDataProviderItems &provider_items) {
size_t cur_item = 0, cur_start = 0;
const MultipartFormDataProviderItems &provider_items) const {
size_t cur_item = 0;
size_t cur_start = 0;
// cur_item and cur_start are copied to within the std::function and maintain
// state between successive calls
return [&, cur_item, cur_start](size_t offset,
DataSink &sink) mutable -> bool {
if (!offset && items.size()) {
if (!offset && !items.empty()) {
sink.os << detail::serialize_multipart_formdata(items, boundary, false);
return true;
} else if (cur_item < provider_items.size()) {
@ -7866,8 +7881,9 @@ inline ContentProviderWithoutLength ClientImpl::get_multipart_content_provider(
cur_sink.write = sink.write;
cur_sink.done = [&]() { has_data = false; };
if (!provider_items[cur_item].provider(offset - cur_start, cur_sink))
if (!provider_items[cur_item].provider(offset - cur_start, cur_sink)) {
return false;
}
if (!has_data) {
sink.os << detail::serialize_multipart_formdata_item_end();
@ -7988,7 +8004,7 @@ inline Result ClientImpl::Get(const std::string &path, const Params &params,
}
std::string path_with_query = append_query_params(path, params);
return Get(path_with_query.c_str(), headers, progress);
return Get(path_with_query, headers, progress);
}
inline Result ClientImpl::Get(const std::string &path, const Params &params,
@ -8008,8 +8024,8 @@ inline Result ClientImpl::Get(const std::string &path, const Params &params,
}
std::string path_with_query = append_query_params(path, params);
return Get(path_with_query.c_str(), headers, response_handler,
content_receiver, progress);
return Get(path_with_query, headers, response_handler, content_receiver,
progress);
}
inline Result ClientImpl::Head(const std::string &path) {
@ -8111,7 +8127,7 @@ inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
const auto &content_type =
detail::serialize_multipart_formdata_get_content_type(boundary);
const auto &body = detail::serialize_multipart_formdata(items, boundary);
return Post(path, headers, body, content_type.c_str());
return Post(path, headers, body, content_type);
}
inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
@ -8124,7 +8140,7 @@ inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
const auto &content_type =
detail::serialize_multipart_formdata_get_content_type(boundary);
const auto &body = detail::serialize_multipart_formdata(items, boundary);
return Post(path, headers, body, content_type.c_str());
return Post(path, headers, body, content_type);
}
inline Result
@ -8508,10 +8524,11 @@ inline void ClientImpl::set_ca_cert_store(X509_STORE *ca_cert_store) {
}
inline X509_STORE *ClientImpl::create_ca_cert_store(const char *ca_cert,
std::size_t size) {
std::size_t size) const {
auto mem = BIO_new_mem_buf(ca_cert, static_cast<int>(size));
if (!mem)
if (!mem) {
return nullptr;
}
auto inf = PEM_X509_INFO_read_bio(mem, nullptr, nullptr, nullptr);
if (!inf) {
@ -8676,7 +8693,7 @@ inline SSLSocketStream::SSLSocketStream(socket_t sock, SSL *ssl,
SSL_clear_mode(ssl, SSL_MODE_AUTO_RETRY);
}
inline SSLSocketStream::~SSLSocketStream() {}
inline SSLSocketStream::~SSLSocketStream() = default;
inline bool SSLSocketStream::is_readable() const {
return detail::select_read(sock_, read_timeout_sec_, read_timeout_usec_) > 0;
@ -8898,7 +8915,7 @@ inline SSLClient::SSLClient(const std::string &host, int port,
detail::split(&host_[0], &host_[host_.size()], '.',
[&](const char *b, const char *e) {
host_components_.emplace_back(std::string(b, e));
host_components_.emplace_back(b, e);
});
if (!client_cert_path.empty() && !client_key_path.empty()) {
@ -8919,7 +8936,7 @@ inline SSLClient::SSLClient(const std::string &host, int port,
detail::split(&host_[0], &host_[host_.size()], '.',
[&](const char *b, const char *e) {
host_components_.emplace_back(std::string(b, e));
host_components_.emplace_back(b, e);
});
if (client_cert != nullptr && client_key != nullptr) {
@ -9197,8 +9214,8 @@ SSLClient::verify_host_with_subject_alt_name(X509 *server_cert) const {
auto type = GEN_DNS;
struct in6_addr addr6;
struct in_addr addr;
struct in6_addr addr6 {};
struct in_addr addr {};
size_t addr_len = 0;
#ifndef __MINGW32__
@ -9279,7 +9296,7 @@ inline bool SSLClient::check_host_name(const char *pattern,
std::vector<std::string> pattern_components;
detail::split(&pattern[0], &pattern[pattern_len], '.',
[&](const char *b, const char *e) {
pattern_components.emplace_back(std::string(b, e));
pattern_components.emplace_back(b, e);
});
if (host_components_.size() != pattern_components.size()) {
@ -9364,7 +9381,7 @@ inline Client::Client(const std::string &host, int port,
: cli_(detail::make_unique<ClientImpl>(host, port, client_cert_path,
client_key_path)) {}
inline Client::~Client() {}
inline Client::~Client() = default;
inline bool Client::is_valid() const {
return cli_ != nullptr && cli_->is_valid();

File diff suppressed because it is too large Load Diff

13300
3rd_party/sqlite/include/sqlite3.h vendored Normal file

File diff suppressed because it is too large Load Diff

252720
3rd_party/sqlite/src/sqlite3.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -5,16 +5,20 @@
### Issues
* \#10 Address compiler warnings
* \#11 Switch to SQLite over RocksDB
### Changes from v2.0.0-rc
* Refactored S3 provider
* Require `c++20`
* Refactored Sia, S3 and base provider
* Fixed intermittent deadlock on file close
* Removed MSVC compilation support (MinGW-64 should be used)
* Upgraded `boost` to v1.83.0
* Upgraded `curl` to v8.4.0
* Upgraded `libsodium` to v1.0.19
* Upgraded `rocksdb` to v8.6.7
* Require `c++20`
* Switched to Storj over Filebase for hosting binaries
* Updated `boost` to v1.83.0
* Updated `cpp-httplib` to v0.14.2
* Updated `curl` to v8.4.0
* Updated `libsodium` to v1.0.19
* Updated `OpenSSL` to v3.2.0
## 2.0.0-rc

View File

@ -50,7 +50,7 @@ if (LINUX OR MINGW)
endif()
set(ENV{PKG_CONFIG_PATH}
"${EXTERNAL_BUILD_ROOT}/lib/pkgconfig:${EXTERNAL_BUILD_ROOT}/lib64/pkgconfig:$ENV{PKG_CONFIG_PATH}"
"${EXTERNAL_BUILD_ROOT}/lib/pkgconfig:${EXTERNAL_BUILD_ROOT}/share/pkgconfig:$ENV{PKG_CONFIG_PATH}"
)
find_package(PkgConfig REQUIRED)
@ -83,12 +83,12 @@ if (LINUX OR MINGW)
if (LIBFUSE3 AND NOT MINGW)
pkg_check_modules(LIBFUSE3 REQUIRED fuse3>=3.0.0)
set(LIBFUSE3_LIBRARIES ${LIBFUSE3})
add_definitions(-DFUSE_USE_VERSION=30)
set(REPERTORY_DEFINITIONS ${REPERTORY_DEFINITIONS} -DFUSE_USE_VERSION=30)
endif()
if(NOT LIBFUSE3_LIBRARIES AND NOT MINGW)
pkg_check_modules(LIBFUSE2 REQUIRED fuse>=2.9.0)
add_definitions(-DFUSE_USE_VERSION=29)
set(REPERTORY_DEFINITIONS ${REPERTORY_DEFINITIONS} -DFUSE_USE_VERSION=29)
endif()
if (NOT LIBPTHREAD_LIBRARY)
@ -132,8 +132,7 @@ elseif (MACOS)
message(FATAL_ERROR "'libpthread' not found")
endif()
set(REPERTORY_DEFINITIONS ${REPERTORY_DEFINITIONS} -DBOOST_ASIO_HAS_STD_STRING_VIEW)
add_definitions(-DFUSE_USE_VERSION=29)
set(REPERTORY_DEFINITIONS ${REPERTORY_DEFINITIONS} -DFUSE_USE_VERSION=29 -DBOOST_ASIO_HAS_STD_STRING_VIEW)
include_directories(/usr/local/include)
find_library(OSXFUSE NO_CACHE NAMES OSXFUSE)
@ -210,14 +209,12 @@ include_directories(SYSTEM
link_directories(
${EXTERNAL_BUILD_ROOT}/lib
${EXTERNAL_BUILD_ROOT}/lib64
)
include(cmake/zlib.cmake)
include(cmake/openssl.cmake)
include(cmake/curl.cmake)
include(cmake/boost.cmake)
include(cmake/rocksdb.cmake)
include(cmake/libsodium.cmake)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/common.cpp.in ${CMAKE_CURRENT_SOURCE_DIR}/src/common.cpp @ONLY)
@ -229,15 +226,14 @@ include_directories(SYSTEM
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/stduuid
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/json
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/pugixml/src
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/sqlite/include
${CURL_INCLUDE_DIRS}
${LIBFUSE2_INCLUDE_DIRS}
${LIBFUSE3_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIR}
${ROCKSDB_INCLUDE_DIRS}
)
set(REPERTORY_LINK_LIBRARIES
${ROCKSDB_LIBRARIES}
${LIBFUSE2_LIBRARIES}
${LIBFUSE3_LIBRARIES}
${Boost_LIBRARIES}
@ -256,12 +252,14 @@ file(GLOB_RECURSE REPERTORY_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/**/*.hh
${CMAKE_CURRENT_SOURCE_DIR}/include/**/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/pugixml/src/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/sqlite/include/*.h
)
file(GLOB_RECURSE REPERTORY_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/**/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/pugixml/src/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/sqlite/src/*.c
)
list(REMOVE_ITEM REPERTORY_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)

View File

@ -16,13 +16,11 @@ on Windows.
* [Sia renterd](https://github.com/SiaFoundation/renterd/releases) v0.4.0+ for Sia support
* Only 64-bit operating systems are supported
* Linux requires the following dependencies:
* `libfuse3`
* Linux requires `fusermount3` or `repertory` must be manually compiled with `libfuse2` support
* OS X requires the following dependency to be installed:
* [FUSE for macOS v4.5.0](https://github.com/osxfuse/osxfuse/releases/download/macfuse-4.5.0/macfuse-4.5.0.dmg)
* Windows requires the following dependencies to be installed:
* [WinFSP 2023](https://github.com/winfsp/winfsp/releases/download/v2.0/winfsp-2.0.23075.msi)
* [Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019](https://aka.ms/vs/16/release/vc_redist.x64.exe)
## Supported Operating Systems
@ -36,18 +34,17 @@ on Windows.
* [boost c++ libraries](https://www.boost.org/)
* [cpp-httplib](https://github.com/yhirose/cpp-httplib)
* [curl](https://curl.haxx.se/)
* [Filebase](https://filebase.com/)
* [FUSE for macOS](https://osxfuse.github.io/)
* [Google Test](https://github.com/google/googletest)
* [JSON for Modern C++](https://github.com/nlohmann/json)
* [libfuse](https://github.com/libfuse/libfuse)
* [libsodium](https://doc.libsodium.org/)
* [OpenSSL](https://www.openssl.org/)
* [OSSP uuid](http://www.ossp.org/pkg/lib/uuid/)
* [RocksDB](https://rocksdb.org/)
* [ScPrime](https://scpri.me/)
* [Sia Decentralized Cloud Storage](https://sia.tech/)
* [SQLite](https://www.sqlite.org)
* [stduuid](https://github.com/mariusbancila/stduuid)
* [Storj](https://storj.io/)
* [WinFSP - FUSE for Windows](https://github.com/billziss-gh/winfsp)
* [zlib](https://zlib.net/)
@ -80,4 +77,3 @@ mMH3segHBkRj0xJcfOxceRLj1a+ULIIR3xL/3f8s5Id25TDo/nqBoCvu5PeCpo6L
9wIDAQAB
-----END PUBLIC KEY-----
```

View File

@ -1,9 +1,10 @@
set(BOOST_VERSION ${BOOST_MAJOR_VERSION}.${BOOST_MINOR_VERSION}.${BOOST_REVISION})
set(BOOST_VERSION2 ${BOOST_MAJOR_VERSION}_${BOOST_MINOR_VERSION}_${BOOST_REVISION})
set(BOOST_PROJECT_NAME boost_${BOOST_VERSION})
set(BOOST_BUILD_ROOT ${EXTERNAL_BUILD_ROOT}/builds/${BOOST_PROJECT_NAME})
set(BOOST_ADDRESS_MODEL 64)
set(BOOST_VERSION ${BOOST_MAJOR_VERSION}.${BOOST_MINOR_VERSION}.${BOOST_REVISION})
set(BOOST_VERSION2 ${BOOST_MAJOR_VERSION}_${BOOST_MINOR_VERSION}_${BOOST_REVISION})
set(BOOST_DOWNLOAD_URL https://boostorg.jfrog.io/artifactory/main/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION2}.tar.gz)
@ -38,10 +39,12 @@ set (BOOST_COMMON_ARGS
)
if (MINGW)
set(BOOST_COMMON_ARGS
${BOOST_COMMON_ARGS}
--user-config=./user-config.jam
)
if (NOT CMAKE_HOST_WIN32)
set(BOOST_COMMON_ARGS
${BOOST_COMMON_ARGS}
--user-config=./user-config.jam
)
endif()
set(BOOST_TARGET_OS target-os=windows)
endif()
@ -69,12 +72,11 @@ ExternalProject_Add(boost_project
add_dependencies(boost_project openssl_project)
set(BOOST_ROOT ${BOOST_BUILD_ROOT}/src/boost_project)
if (MINGW)
if (MINGW AND CMAKE_HOST_WIN32)
set(BOOST_GCC_VERSION ${CMAKE_CXX_COMPILER_VERSION})
string(REPLACE "." ";" BOOST_GCC_VERSION_LIST ${BOOST_GCC_VERSION})
list(GET BOOST_GCC_VERSION_LIST 0 BOOST_GCC_MAJOR_VERSION)
# set(BOOST_LIB_EXTRA "-mgw${BOOST_GCC_MAJOR_VERSION}-mt-x64-${BOOST_MAJOR_VERSION}_${BOOST_MINOR_VERSION}")
set(BOOST_LIB_EXTRA "-mgw${BOOST_GCC_MAJOR_VERSION}-mt${DEBUG_EXTRA2}-x64-${BOOST_MAJOR_VERSION}_${BOOST_MINOR_VERSION}")
endif()
set(Boost_LIBRARIES
@ -90,3 +92,6 @@ set(Boost_LIBRARIES
)
add_dependencies(boost_project zlib_project)
if (CMAKE_HOST_WIN32)
include_directories(SYSTEM ${EXTERNAL_BUILD_ROOT}/include/boost-${BOOST_MAJOR_VERSION}_${BOOST_MINOR_VERSION})
endif()

View File

@ -18,23 +18,21 @@ if (UNIX OR MINGW)
)
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(REPERTORY_COMMON_FLAG_LIST
${REPERTORY_COMMON_FLAG_LIST}
-DDEBUG
-D_DEBUG
-Og
-fno-omit-frame-pointer
-g
-gdwarf-4
)
else()
set(REPERTORY_COMMON_FLAG_LIST
${REPERTORY_COMMON_FLAG_LIST}
-O3
-DNDEBUG
)
endif()
set(REPERTORY_COMMON_FLAG_LIST_DEBUG
${REPERTORY_COMMON_FLAG_LIST_DEBUG}
-DDEBUG
-D_DEBUG
-Og
-fno-omit-frame-pointer
-g
-gdwarf-4
)
set(REPERTORY_COMMON_FLAG_LIST_RELEASE
${REPERTORY_COMMON_FLAG_LIST_RELEASE}
-O3
-DNDEBUG
)
if (NOT IS_CLANG_COMPILER)
set(REPERTORY_GCC_FLAGS
@ -59,7 +57,7 @@ if (UNIX OR MINGW)
-Wnon-virtual-dtor
-Wold-style-cast
-Woverloaded-virtual
-Wuseless-cast
-Wno-useless-cast
)
endif()
@ -75,12 +73,30 @@ if (UNIX OR MINGW)
)
endif()
list(JOIN REPERTORY_COMMON_FLAG_LIST_DEBUG " " REPERTORY_COMMON_FLAG_LIST_DEBUG)
list(JOIN REPERTORY_COMMON_FLAG_LIST_RELEASE " " REPERTORY_COMMON_FLAG_LIST_RELEASE)
list(JOIN REPERTORY_CXX_FLAGS_LIST " " REPERTORY_CXX_FLAGS_LIST)
list(JOIN REPERTORY_C_FLAGS_LIST " " REPERTORY_C_FLAGS_LIST)
list(JOIN REPERTORY_SHARED_LINKER_FLAGS_LIST " " REPERTORY_SHARED_LINKER_FLAGS_LIST)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${REPERTORY_C_FLAGS_LIST}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${REPERTORY_CXX_FLAGS_LIST}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${REPERTORY_C_FLAGS_LIST}")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${REPERTORY_COMMON_FLAG_LIST_DEBUG}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${REPERTORY_COMMON_FLAG_LIST_DEBUG}")
else()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${REPERTORY_COMMON_FLAG_LIST_RELEASE}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${REPERTORY_COMMON_FLAG_LIST_RELEASE}")
endif()
set (REPERTORY_CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} ${REPERTORY_COMMON_FLAG_LIST_DEBUG}")
set (REPERTORY_CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} ${REPERTORY_COMMON_FLAG_LIST_DEBUG}")
set (REPERTORY_CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} ${REPERTORY_COMMON_FLAG_LIST_RELEASE}")
set (REPERTORY_CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${REPERTORY_COMMON_FLAG_LIST_RELEASE}")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${REPERTORY_SHARED_LINKER_FLAGS_LIST}")
if (ALPINE_FOUND OR MINGW)
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")

View File

@ -17,6 +17,5 @@ add_dependencies(librepertory
curl_project
libsodium_project
openssl_project
rocksdb_project
zlib_project
)

View File

@ -20,7 +20,7 @@ set(OPENSSL_PROJECT_NAME openssl_${OPENSSL_VERSION})
set(OPENSSL_BUILD_ROOT ${EXTERNAL_BUILD_ROOT}/builds/${OPENSSL_PROJECT_NAME})
ExternalProject_Add(openssl_project
DOWNLOAD_NO_PROGRESS 1
URL https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_${OPENSSL_VERSION}.tar.gz
URL https://github.com/openssl/openssl/releases/download/openssl-${OPENSSL_VERSION}/openssl-${OPENSSL_VERSION}.tar.gz
PREFIX ${OPENSSL_BUILD_ROOT}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ./Configure no-shared ${OPENSSL_COMPILE_TYPE} --openssldir=${EXTERNAL_BUILD_ROOT}/ssl --prefix=${EXTERNAL_BUILD_ROOT}

View File

@ -1,66 +0,0 @@
set(ROCKSDB_PROJECT_NAME rocksdb_${ROCKSDB_VERSION})
set(ROCKSDB_BUILD_ROOT ${EXTERNAL_BUILD_ROOT}/builds/${ROCKSDB_PROJECT_NAME})
if (MACOS)
set(ROCKSDB_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
else()
set(ROCKSDB_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
set(ROCKSDB_CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${EXTERNAL_BUILD_TYPE}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_FLAGS=${ROCKSDB_CMAKE_CXX_FLAGS}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_GENERATOR=${CMAKE_GENERATOR}
-DCMAKE_INSTALL_PREFIX=${EXTERNAL_BUILD_ROOT}
-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}
-DCMAKE_SHARED_LINKER_FLAGS=${CMAKE_SHARED_LINKER_FLAGS}
-DFAIL_ON_WARNINGS=OFF
-DPORTABLE=1
-DROCKSDB_BUILD_SHARED=OFF
-DWITH_BENCHMARK_TOOLS=OFF
-DWITH_LIBURING=OFF
-DWITH_TESTS=OFF
-DWITH_TOOLS=OFF
)
if (MINGW)
if (CMAKE_TOOLCHAIN_FILE)
set(ROCKSDB_CMAKE_ARGS
${ROCKSDB_CMAKE_ARGS}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
)
endif()
ExternalProject_Add(rocksdb_project
DOWNLOAD_NO_PROGRESS 1
URL https://github.com/facebook/rocksdb/archive/v${ROCKSDB_VERSION}.tar.gz
PREFIX ${ROCKSDB_BUILD_ROOT}
CMAKE_ARGS ${ROCKSDB_CMAKE_ARGS} -DWITH_GFLAGS=OFF
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping install step."
)
set(ROCKSDB_LIBRARIES ${ROCKSDB_BUILD_ROOT}/src/rocksdb_project-build/librocksdb.a)
include_directories(SYSTEM ${ROCKSDB_BUILD_ROOT}/src/rocksdb_project/include)
else()
ExternalProject_Add(rocksdb_project
DOWNLOAD_NO_PROGRESS 1
URL https://github.com/facebook/rocksdb/archive/v${ROCKSDB_VERSION}.tar.gz
PREFIX ${ROCKSDB_BUILD_ROOT}
CMAKE_ARGS ${ROCKSDB_CMAKE_ARGS} -DWITH_GFLAGS=OFF
)
if (MACOS)
set(ROCKSDB_LIBRARIES ${EXTERNAL_BUILD_ROOT}/lib/librocksdb.a)
else()
set(ROCKSDB_LIBRARIES librocksdb.a)
endif()
endif()
if (LINUX OR MINGW)
add_dependencies(rocksdb_project curl_project)
endif()
add_dependencies(rocksdb_project zlib_project)

View File

@ -32,3 +32,8 @@ set(REPERTORY_OUTPUT_DIR ${CMAKE_BINARY_DIR})
set(EXTERNAL_BUILD_ROOT ${CMAKE_BINARY_DIR}/external)
set(EXTERNAL_BUILD_TYPE ${CMAKE_BUILD_TYPE})
if (UNIX OR MINGW)
file(MAKE_DIRECTORY ${EXTERNAL_BUILD_ROOT}/lib)
file(CREATE_LINK ${EXTERNAL_BUILD_ROOT}/lib ${EXTERNAL_BUILD_ROOT}/lib64 SYMBOLIC)
endif()

View File

@ -1,11 +1,9 @@
set(BOOST_MAJOR_VERSION 1)
set(BOOST_MINOR_VERSION 83)
set(BOOST_REVISION 0)
set(CURL_VERSION 8_4_0)
set(CURL_VERSION 8_5_0)
set(GTEST_VERSION v1.14.0)
set(LIBSODIUM_VERSION 1.0.19)
set(LIBUUID_VERSION 1.6.2)
set(OPENSSL_VERSION 1_1_1w)
set(ROCKSDB_VERSION 8.6.7)
set(OPENSSL_VERSION 3.2.0)
set(WINFSP_VERSION 2.0)
set(ZLIB_VERSION v1.3)

View File

@ -5,13 +5,13 @@ WORKDIR /mnt
ENV MINGW=/mingw
ARG PKG_CONFIG_VERSION=0.29.2
ARG CMAKE_VERSION=3.27.1
ARG BINUTILS_VERSION=2.41
ARG MINGW_VERSION=11.0.1
ARG CMAKE_VERSION=3.27.1
ARG GCC_VERSION=13.2.0
ARG MINGW_VERSION=11.0.1
ARG NASM_VERSION=2.16.01
ARG NVCC_VERSION=12.2.1
ARG PKG_CONFIG_VERSION=0.29.2
SHELL [ "/bin/bash", "-c" ]
@ -49,14 +49,18 @@ RUN set -ex \
yasm \
wget \
zip \
git \
git
RUN set -ex \
\
&& wget -q https://pkg-config.freedesktop.org/releases/pkg-config-${PKG_CONFIG_VERSION}.tar.gz -O - | tar -xz \
&& wget -q https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}.tar.gz -O - | tar -xz \
&& wget -q https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.xz -O - | tar -xJ \
&& wget -q https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/mingw-w64-v${MINGW_VERSION}.tar.bz2 -O - | tar -xj \
&& wget -q https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz -O - | tar -xJ \
&& wget -q https://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.xz -O - | tar -xJ \
&& wget -q https://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.xz -O - | tar -xJ
RUN set -ex \
\
&& mkdir -p ${MINGW}/include ${MINGW}/lib/pkgconfig \
&& chmod 0777 -R /mnt ${MINGW} \
@ -69,16 +73,18 @@ RUN set -ex \
--disable-shared \
--disable-nls \
&& make -j`nproc` \
&& make install \
&& cd .. \
&& make install
RUN set -ex \
\
&& cd cmake-${CMAKE_VERSION} \
&& ./configure \
--prefix=/usr/local \
--parallel=`nproc` \
&& make -j`nproc` \
&& make install \
&& cd .. \
&& make install
RUN set -ex \
\
&& cd binutils-${BINUTILS_VERSION} \
&& ./configure \
@ -93,8 +99,9 @@ RUN set -ex \
--disable-werror \
--with-system-zlib \
&& make -j`nproc` \
&& make install \
&& cd .. \
&& make install
RUN set -ex \
\
&& mkdir mingw-w64 \
&& cd mingw-w64 \
@ -102,8 +109,9 @@ RUN set -ex \
--prefix=/usr/local/x86_64-w64-mingw32 \
--host=x86_64-w64-mingw32 \
--enable-sdk=all \
&& make install \
&& cd .. \
&& make install
RUN set -ex \
\
&& mkdir gcc \
&& cd gcc \
@ -125,8 +133,9 @@ RUN set -ex \
--disable-nls \
--disable-werror \
&& make -j`nproc` all-gcc \
&& make install-gcc \
&& cd .. \
&& make install-gcc
RUN set -ex \
\
&& cd mingw-w64 \
&& ../mingw-w64-v${MINGW_VERSION}/mingw-w64-crt/configure \
@ -136,8 +145,9 @@ RUN set -ex \
--disable-lib32 \
--enable-lib64 \
&& (make || make || make || make) \
&& make install \
&& cd .. \
&& make install
RUN set -ex \
\
&& cd mingw-w64 \
&& ../mingw-w64-v${MINGW_VERSION}/mingw-w64-libraries/winpthreads/configure \
@ -146,38 +156,45 @@ RUN set -ex \
--enable-static \
--disable-shared \
&& make -j`nproc` \
&& make install \
&& cd .. \
&& make install
RUN set -ex \
\
&& cd gcc \
&& make -j`nproc` \
&& make install \
&& cd .. \
&& make install
RUN set -ex \
\
&& cd nasm-${NASM_VERSION} \
&& ./configure --prefix=/usr/local \
&& make -j`nproc` \
&& make install \
&& cd .. \
&& make install
RUN set -ex \
\
&& rm -r pkg-config-${PKG_CONFIG_VERSION} \
&& rm -r cmake-${CMAKE_VERSION} \
&& rm -r binutils-${BINUTILS_VERSION} \
&& rm -r mingw-w64 mingw-w64-v${MINGW_VERSION} \
&& rm -r gcc gcc-${GCC_VERSION} \
&& rm -r nasm-${NASM_VERSION} \
&& rm -r nasm-${NASM_VERSION}
RUN set -ex \
\
&& apt-get remove --purge -y file gcc g++ zlib1g-dev libssl-dev libgmp-dev libmpfr-dev libmpc-dev libisl-dev \
\
&& apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/3bf863cc.pub \
&& echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/ /" > /etc/apt/sources.list.d/cuda.list \
&& apt-get update \
\
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
cuda-nvcc-${NVCC_VERSION:0:2}-${NVCC_VERSION:3:1} \
cuda-nvcc-${NVCC_VERSION:0:2}-${NVCC_VERSION:3:1}
RUN set -ex \
\
&& ln -s /usr/bin/gcc /usr/local/cuda/bin/gcc \
&& ln -s /usr/bin/g++ /usr/local/cuda/bin/g++ \
&& ln -s /usr/bin/g++ /usr/local/cuda/bin/g++
RUN set -ex \
\
&& apt-get remove --purge -y gnupg \
&& apt-get autoremove --purge -y \

View File

@ -39,6 +39,9 @@ public:
[[nodiscard]] static auto default_data_directory(const provider_type &prov)
-> std::string;
[[nodiscard]] static auto default_remote_port(const provider_type &prov)
-> std::uint16_t;
[[nodiscard]] static auto default_rpc_port(const provider_type &prov)
-> std::uint16_t;
@ -100,8 +103,8 @@ private:
s3_config s3_config_;
std::uint64_t version_ = REPERTORY_CONFIG_VERSION;
std::string log_directory_;
std::recursive_mutex read_write_mutex_;
std::recursive_mutex remote_mount_mutex_;
mutable std::recursive_mutex read_write_mutex_;
mutable std::recursive_mutex remote_mount_mutex_;
private:
[[nodiscard]] auto load() -> bool;
@ -360,9 +363,17 @@ public:
}
#ifdef REPERTORY_TESTING
void set_host_config(host_config hc) { hc_ = std::move(hc); }
void set_host_config(host_config hc) {
config_changed_ = true;
hc_ = std::move(hc);
save();
}
void set_s3_config(s3_config s3) { s3_config_ = std::move(s3); }
void set_s3_config(s3_config s3) {
config_changed_ = true;
s3_config_ = std::move(s3);
save();
}
#endif
void set_is_remote_mount(bool is_remote_mount);

View File

@ -42,12 +42,12 @@
namespace repertory::cli::actions {
using action = std::function<exit_code(
int, char **, const std::string &, const provider_type &,
std::vector<const char *>, const std::string &, const provider_type &,
const std::string &, std::string, std::string)>;
struct option_hasher {
auto operator()(const utils::cli::option &opt) const -> std::size_t {
return std::hash<std::string>()(opt[0u] + '|' + opt[1u]);
return std::hash<std::string>()(opt[0U] + '|' + opt[1U]);
}
};
@ -75,14 +75,14 @@ static const std::unordered_map<utils::cli::option, action, option_hasher>
};
[[nodiscard]] inline auto
perform_action(const utils::cli::option &opt, int argc, char *argv[],
const std::string &data_directory, const provider_type &pt,
perform_action(const utils::cli::option &opt, std::vector<const char *> args,
const std::string &data_directory, const provider_type &prov,
const std::string &unique_id, std::string user,
std::string password) -> exit_code {
if (utils::cli::has_option(argc, argv, opt)) {
if (utils::cli::has_option(args, opt)) {
if (option_actions.find(opt) != option_actions.end()) {
return option_actions.at(opt)(argc, argv, data_directory, pt, unique_id,
user, password);
return option_actions.at(opt)(args, data_directory, prov, unique_id, user,
password);
}
}

View File

@ -27,9 +27,10 @@
namespace repertory::cli::actions {
[[nodiscard]] inline auto
check_version(int, char *[], const std::string & /* data_directory */,
const provider_type & /* pt */, const std::string &, std::string,
std::string) -> exit_code {
check_version(std::vector<const char *> /* args */,
const std::string & /* data_directory */,
const provider_type & /* pt */, const std::string & /*unique_id*/,
std::string /*user*/, std::string /*password*/) -> exit_code {
auto ret = exit_code::success;
// TODO need to updated way to check version

View File

@ -30,20 +30,22 @@
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
[[nodiscard]] inline auto
display_config(int, char *[], const std::string &data_directory,
const provider_type &pt, const std::string &unique_id,
std::string user, std::string password) -> exit_code {
lock_data lock(pt, unique_id);
const auto res = lock.grab_lock(1u);
[[nodiscard]] inline auto display_config(std::vector<const char *> /* args */,
const std::string &data_directory,
const provider_type &prov,
const std::string &unique_id,
std::string user, std::string password)
-> exit_code {
lock_data lock(prov, unique_id);
const auto res = lock.grab_lock(1U);
if (res == lock_result::success) {
app_config config(pt, data_directory);
app_config config(prov, data_directory);
const auto cfg = config.get_json();
std::cout << 0 << std::endl;
std::cout << cfg.dump(2) << std::endl;
} else if (res == lock_result::locked) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt,
auto port = app_config::default_api_port(prov);
utils::cli::get_api_authentication_data(user, password, port, prov,
data_directory);
const auto response =
client({"localhost", password, port, user}).get_config();

View File

@ -31,24 +31,25 @@
namespace repertory::cli::actions {
[[nodiscard]] inline auto
drive_information(int, char *[], const std::string &data_directory,
const provider_type &pt, const std::string &unique_id,
std::string user, std::string password) -> exit_code {
drive_information(std::vector<const char *> /* args */,
const std::string &data_directory, const provider_type &prov,
const std::string &unique_id, std::string user,
std::string password) -> exit_code {
auto ret = exit_code::success;
lock_data lock(pt, unique_id);
const auto res = lock.grab_lock(1u);
lock_data lock(prov, unique_id);
const auto res = lock.grab_lock(1U);
if (res == lock_result::locked) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt,
auto port = app_config::default_api_port(prov);
utils::cli::get_api_authentication_data(user, password, port, prov,
data_directory);
const auto response =
client({"localhost", password, port, user}).get_drive_information();
std::cout << static_cast<int>(response.response_type) << std::endl;
std::cout << response.data.dump(2) << std::endl;
} else {
std::cerr << app_config::get_provider_display_name(pt) << " is not mounted."
<< std::endl;
std::cerr << app_config::get_provider_display_name(prov)
<< " is not mounted." << std::endl;
ret = exit_code::not_mounted;
}

View File

@ -30,19 +30,19 @@
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
[[nodiscard]] inline auto get(int argc, char *argv[],
[[nodiscard]] inline auto get(std::vector<const char *> args,
const std::string &data_directory,
const provider_type &pt,
const provider_type &prov,
const std::string &unique_id, std::string user,
std::string password) -> exit_code {
std::string data;
auto ret = utils::cli::parse_string_option(
argc, argv, repertory::utils::cli::options::get_option, data);
args, repertory::utils::cli::options::get_option, data);
if (ret == exit_code::success) {
lock_data lock(pt, unique_id);
lock_data lock(prov, unique_id);
const auto res = lock.grab_lock(1);
if (res == lock_result::success) {
app_config config(pt, data_directory);
app_config config(prov, data_directory);
const auto value = config.get_value_by_name(data);
std::cout << (value.empty()
? static_cast<int>(
@ -51,8 +51,8 @@ namespace repertory::cli::actions {
<< std::endl;
std::cout << json({{"value", value}}).dump(2) << std::endl;
} else if (res == lock_result::locked) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt,
auto port = app_config::default_api_port(prov);
utils::cli::get_api_authentication_data(user, password, port, prov,
data_directory);
const auto response = client({"localhost", password, port, user})
.get_config_value_by_name(data);

View File

@ -29,17 +29,16 @@
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
[[nodiscard]] inline auto
get_directory_items(int argc, char *argv[], const std::string &data_directory,
const provider_type &pt, const std::string &,
std::string user, std::string password) -> exit_code {
[[nodiscard]] inline auto get_directory_items(
std::vector<const char *> args, const std::string &data_directory,
const provider_type &prov, const std::string & /* unique_id */,
std::string user, std::string password) -> exit_code {
std::string data;
auto ret = utils::cli::parse_string_option(
argc, argv, repertory::utils::cli::options::get_directory_items_option,
data);
args, repertory::utils::cli::options::get_directory_items_option, data);
if (ret == exit_code::success) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt,
auto port = app_config::default_api_port(prov);
utils::cli::get_api_authentication_data(user, password, port, prov,
data_directory);
const auto response =
client({"localhost", password, port, user}).get_directory_items(data);

View File

@ -29,13 +29,15 @@
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
[[nodiscard]] inline auto
get_pinned_files(int, char *[], const std::string &data_directory,
const provider_type &pt, const std::string &, std::string user,
std::string password) -> exit_code {
[[nodiscard]] inline auto get_pinned_files(std::vector<const char *> /* args */,
const std::string &data_directory,
const provider_type &prov,
const std::string & /* unique_id */,
std::string user,
std::string password) -> exit_code {
auto ret = exit_code::success;
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt,
auto port = app_config::default_api_port(prov);
utils::cli::get_api_authentication_data(user, password, port, prov,
data_directory);
const auto response =
client({"localhost", password, port, user}).get_pinned_files();

View File

@ -23,8 +23,8 @@
#define INCLUDE_CLI_HELP_HPP_
namespace repertory::cli::actions {
template <typename drive> inline void help(int argc, char *argv[]) {
drive::display_options(argc, argv);
template <typename drive> inline void help(std::vector<const char *> args) {
drive::display_options(args);
std::cout << "Repertory options:" << std::endl;
std::cout << " -cv,--check_version Check daemon version "
"compatibility"

View File

@ -54,30 +54,30 @@ using remote_instance = repertory::remote_fuse::i_remote_instance;
namespace repertory::cli::actions {
[[nodiscard]] inline auto
mount(int argc, char *argv[], std::string data_directory, int &mount_result,
provider_type pt, const std::string &remote_host,
mount(std::vector<const char *> args, std::string data_directory,
int &mount_result, provider_type prov, const std::string &remote_host,
std::uint16_t remote_port, const std::string &unique_id) -> exit_code {
auto ret = exit_code::success;
lock_data lock(pt, unique_id);
lock_data lock(prov, unique_id);
const auto res = lock.grab_lock();
if (res == lock_result::locked) {
ret = exit_code::mount_active;
std::cerr << app_config::get_provider_display_name(pt)
std::cerr << app_config::get_provider_display_name(prov)
<< " mount is already active" << std::endl;
} else if (res == lock_result::success) {
const auto generate_config = utils::cli::has_option(
argc, argv, utils::cli::options::generate_config_option);
args, utils::cli::options::generate_config_option);
if (generate_config) {
app_config config(pt, data_directory);
if (pt == provider_type::remote) {
app_config config(prov, data_directory);
if (prov == provider_type::remote) {
config.set_enable_remote_mount(false);
config.set_is_remote_mount(true);
config.set_remote_host_name_or_ip(remote_host);
config.set_remote_port(remote_port);
config.save();
}
std::cout << "Generated " << app_config::get_provider_display_name(pt)
std::cout << "Generated " << app_config::get_provider_display_name(prov)
<< " Configuration" << std::endl;
std::cout << config.get_config_file_path() << std::endl;
ret = utils::file::is_file(config.get_config_file_path())
@ -85,14 +85,13 @@ mount(int argc, char *argv[], std::string data_directory, int &mount_result,
: exit_code::file_creation_failed;
} else {
#ifdef _WIN32
if (utils::cli::has_option(argc, argv,
utils::cli::options::hidden_option)) {
if (utils::cli::has_option(args, utils::cli::options::hidden_option)) {
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
}
#endif
const auto drive_args =
utils::cli::parse_drive_options(argc, argv, pt, data_directory);
app_config config(pt, data_directory);
utils::cli::parse_drive_options(args, prov, data_directory);
app_config config(prov, data_directory);
#ifdef _WIN32
if (config.get_enable_mount_manager() &&
not utils::is_process_elevated()) {
@ -102,8 +101,8 @@ mount(int argc, char *argv[], std::string data_directory, int &mount_result,
}
lock.release();
mount_result = utils::run_process_elevated(argc, argv);
lock_data lock2(pt, unique_id);
mount_result = utils::run_process_elevated(args);
lock_data lock2(prov, unique_id);
if (lock2.grab_lock() == lock_result::success) {
if (not lock2.set_mount_state(false, "", -1)) {
std::cerr << "failed to set mount state" << std::endl;
@ -114,15 +113,16 @@ mount(int argc, char *argv[], std::string data_directory, int &mount_result,
return exit_code::mount_result;
}
#endif
std::cout << "Initializing " << app_config::get_provider_display_name(pt)
std::cout << "Initializing "
<< app_config::get_provider_display_name(prov)
<< (unique_id.empty() ? ""
: (pt == provider_type::s3)
: (prov == provider_type::s3)
? " [" + unique_id + ']'
: " [" + remote_host + ':' +
std::to_string(remote_port) + ']')
<< " Drive" << std::endl;
if (pt == provider_type::remote) {
std::uint16_t port = 0u;
if (prov == provider_type::remote) {
std::uint16_t port{0U};
if (utils::get_next_available_port(config.get_api_port(), port)) {
config.set_remote_host_name_or_ip(remote_host);
config.set_remote_port(remote_port);
@ -155,7 +155,7 @@ mount(int argc, char *argv[], std::string data_directory, int &mount_result,
config.set_is_remote_mount(false);
try {
auto provider = create_provider(pt, config);
auto provider = create_provider(prov, config);
repertory_drive drive(config, lock, *provider);
if (not lock.set_mount_state(true, "", -1)) {
std::cerr << "failed to set mount state" << std::endl;

View File

@ -31,23 +31,24 @@
namespace repertory::cli::actions {
[[nodiscard]] inline auto
open_files(int, char *[], const std::string &data_directory,
const provider_type &pt, const std::string &unique_id,
std::string user, std::string password) -> exit_code {
open_files(std::vector<const char *> /* args */,
const std::string &data_directory, const provider_type &prov,
const std::string &unique_id, std::string user, std::string password)
-> exit_code {
auto ret = exit_code::success;
lock_data lock(pt, unique_id);
const auto res = lock.grab_lock(1u);
lock_data lock(prov, unique_id);
const auto res = lock.grab_lock(1U);
if (res == lock_result::locked) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt,
auto port = app_config::default_api_port(prov);
utils::cli::get_api_authentication_data(user, password, port, prov,
data_directory);
const auto response =
client({"localhost", password, port, user}).get_open_files();
std::cout << static_cast<int>(response.response_type) << std::endl;
std::cout << response.data.dump(2) << std::endl;
} else {
std::cerr << app_config::get_provider_display_name(pt) << " is not mounted."
<< std::endl;
std::cerr << app_config::get_provider_display_name(prov)
<< " is not mounted." << std::endl;
ret = exit_code::not_mounted;
}

View File

@ -29,17 +29,16 @@
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
[[nodiscard]] inline auto pin_file(int argc, char *argv[],
const std::string &data_directory,
const provider_type &pt, const std::string &,
std::string user, std::string password)
-> exit_code {
[[nodiscard]] inline auto
pin_file(std::vector<const char *> args, const std::string &data_directory,
const provider_type &prov, const std::string & /* unique_id */,
std::string user, std::string password) -> exit_code {
std::string data;
auto ret = utils::cli::parse_string_option(
argc, argv, repertory::utils::cli::options::pin_file_option, data);
args, repertory::utils::cli::options::pin_file_option, data);
if (ret == exit_code::success) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt,
auto port = app_config::default_api_port(prov);
utils::cli::get_api_authentication_data(user, password, port, prov,
data_directory);
const auto response =
client({"localhost", password, port, user}).pin_file(data);

View File

@ -29,17 +29,16 @@
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
[[nodiscard]] inline auto pinned_status(int argc, char *argv[],
const std::string &data_directory,
const provider_type &pt,
const std::string &, std::string user,
std::string password) -> exit_code {
[[nodiscard]] inline auto
pinned_status(std::vector<const char *> args, const std::string &data_directory,
const provider_type &prov, const std::string & /*unique_id*/,
std::string user, std::string password) -> exit_code {
std::string data;
auto ret = utils::cli::parse_string_option(
argc, argv, repertory::utils::cli::options::pinned_status_option, data);
args, repertory::utils::cli::options::pinned_status_option, data);
if (ret == exit_code::success) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt,
auto port = app_config::default_api_port(prov);
utils::cli::get_api_authentication_data(user, password, port, prov,
data_directory);
const auto response =
client({"localhost", password, port, user}).pinned_status(data);

View File

@ -30,27 +30,27 @@
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
[[nodiscard]] inline auto set(int argc, char *argv[],
[[nodiscard]] inline auto set(std::vector<const char *> args,
const std::string &data_directory,
const provider_type &pt,
const provider_type &prov,
const std::string &unique_id, std::string user,
std::string password) -> exit_code {
auto ret = exit_code::success;
auto data = utils::cli::parse_option(argc, argv, "-set", 2u);
auto data = utils::cli::parse_option(args, "-set", 2U);
if (data.empty()) {
data = utils::cli::parse_option(argc, argv, "--set", 2u);
data = utils::cli::parse_option(args, "--set", 2U);
if (data.empty()) {
ret = exit_code::invalid_syntax;
std::cerr << "Invalid syntax for '-set'" << std::endl;
}
}
if (ret == exit_code::success) {
lock_data lock(pt, unique_id);
const auto res = lock.grab_lock(1u);
lock_data lock(prov, unique_id);
const auto res = lock.grab_lock(1U);
if (res == lock_result::success) {
app_config config(pt, data_directory);
const auto value = config.set_value_by_name(data[0u], data[1u]);
const auto notFound = value.empty() && not data[1u].empty();
app_config config(prov, data_directory);
const auto value = config.set_value_by_name(data[0U], data[1U]);
const auto notFound = value.empty() && not data[1U].empty();
ret = notFound ? exit_code::set_option_not_found : exit_code::success;
std::cout << (notFound ? static_cast<int>(
rpc_response_type::config_value_not_found)
@ -58,11 +58,11 @@ namespace repertory::cli::actions {
<< std::endl;
std::cout << json({{"value", value}}).dump(2) << std::endl;
} else if (res == lock_result::locked) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt,
auto port = app_config::default_api_port(prov);
utils::cli::get_api_authentication_data(user, password, port, prov,
data_directory);
const auto response = client({"localhost", password, port, user})
.set_config_value_by_name(data[0u], data[1u]);
.set_config_value_by_name(data[0U], data[1U]);
std::cout << static_cast<int>(response.response_type) << std::endl;
std::cout << response.data.dump(2) << std::endl;
ret = response.response_type == rpc_response_type::config_value_not_found

View File

@ -26,13 +26,15 @@
#include "types/repertory.hpp"
namespace repertory::cli::actions {
[[nodiscard]] inline auto status(int, char *[], const std::string &,
const provider_type &pt,
const std::string &unique_id, std::string,
std::string) -> exit_code {
[[nodiscard]] inline auto status(std::vector<const char *> /* args */,
const std::string & /*data_directory*/,
const provider_type &prov,
const std::string &unique_id,
std::string /* user */,
std::string /* password */) -> exit_code {
auto ret = exit_code::success;
lock_data lock(pt, unique_id);
[[maybe_unused]] auto status = lock.grab_lock(10u);
lock_data lock(prov, unique_id);
[[maybe_unused]] auto status = lock.grab_lock(10U);
json mount_state;
if (lock.get_mount_state(mount_state)) {
std::cout << mount_state.dump(2) << std::endl;

View File

@ -29,14 +29,13 @@
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
[[nodiscard]] inline auto unmount(int, char *[],
const std::string &data_directory,
const provider_type &pt, const std::string &,
std::string user, std::string password)
-> exit_code {
[[nodiscard]] inline auto
unmount(std::vector<const char *> /* args */, const std::string &data_directory,
const provider_type &prov, const std::string & /*unique_id*/,
std::string user, std::string password) -> exit_code {
auto ret = exit_code::success;
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt,
auto port = app_config::default_api_port(prov);
utils::cli::get_api_authentication_data(user, password, port, prov,
data_directory);
const auto response = client({"localhost", password, port, user}).unmount();
std::cout << static_cast<int>(response.response_type) << std::endl;

View File

@ -29,17 +29,16 @@
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
[[nodiscard]] inline auto unpin_file(int argc, char *argv[],
const std::string &data_directory,
const provider_type &pt,
const std::string &, std::string user,
std::string password) -> exit_code {
[[nodiscard]] inline auto
unpin_file(std::vector<const char *> args, const std::string &data_directory,
const provider_type &prov, const std::string & /*unique_id*/,
std::string user, std::string password) -> exit_code {
std::string data;
auto ret = utils::cli::parse_string_option(
argc, argv, repertory::utils::cli::options::unpin_file_option, data);
args, repertory::utils::cli::options::unpin_file_option, data);
if (ret == exit_code::success) {
auto port = app_config::default_api_port(pt);
utils::cli::get_api_authentication_data(user, password, port, pt,
auto port = app_config::default_api_port(prov);
utils::cli::get_api_authentication_data(user, password, port, prov,
data_directory);
const auto response =
client({"localhost", password, port, user}).unpin_file(data);

View File

@ -23,12 +23,12 @@
#define INCLUDE_CLI_VERSION_HPP_
namespace repertory::cli::actions {
template <typename drive> inline void version(int argc, char *argv[]) {
template <typename drive> inline void version(std::vector<const char *> args) {
std::cout << "Repertory core version: " << get_repertory_version()
<< std::endl;
std::cout << "Repertory Git revision: " << get_repertory_git_revision()
<< std::endl;
drive::display_version_information(argc, argv);
drive::display_version_information(args);
}
} // namespace repertory::cli::actions

View File

@ -24,6 +24,8 @@
#include "comm/curl/multi_request.hpp"
#include "comm/i_http_comm.hpp"
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "utils/encryption.hpp"
#include "utils/utils.hpp"
@ -196,7 +198,7 @@ public:
CURLcode curl_code{};
curl_request.get_result(curl_code, response_code);
if (curl_code != CURLE_OK) {
std::cout << curl_easy_strerror(curl_code) << std::endl;
event_system::instance().raise<curl_error>(url, curl_code);
return false;
}
@ -225,6 +227,11 @@ public:
stop_type &stop_requested) const
-> bool override;
[[nodiscard]] auto make_request(const curl::requests::http_post &post_file,
long &response_code,
stop_type &stop_requested) const
-> bool override;
[[nodiscard]] auto make_request(const curl::requests::http_put_file &put_file,
long &response_code,
stop_type &stop_requested) const

View File

@ -0,0 +1,49 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_POST_HPP_
#define INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_POST_HPP_
#include "comm/curl/requests/http_request_base.hpp"
namespace repertory::curl::requests {
struct http_post final : http_request_base {
http_post() = default;
http_post(const http_post &) = default;
http_post(http_post &&) = default;
auto operator=(const http_post &) -> http_post & = default;
auto operator=(http_post &&) -> http_post & = default;
~http_post() override;
std::optional<nlohmann::json> json;
[[nodiscard]] auto set_method(CURL *curl,
stop_type & /*stop_requested*/) const
-> bool override;
private:
mutable curl_slist *headers{nullptr};
mutable std::optional<std::string> json_str;
};
} // namespace repertory::curl::requests
#endif // INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_POST_HPP_

View File

@ -25,6 +25,7 @@
#include "comm/curl/requests/http_delete.hpp"
#include "comm/curl/requests/http_get.hpp"
#include "comm/curl/requests/http_head.hpp"
#include "comm/curl/requests/http_post.hpp"
#include "comm/curl/requests/http_put_file.hpp"
#include "types/repertory.hpp"
@ -49,6 +50,11 @@ public:
stop_type &stop_requested) const
-> bool = 0;
[[nodiscard]] virtual auto make_request(const curl::requests::http_post &post,
long &response_code,
stop_type &stop_requested) const
-> bool = 0;
[[nodiscard]] virtual auto
make_request(const curl::requests::http_put_file &put_file,
long &response_code, stop_type &stop_requested) const

View File

@ -1,117 +0,0 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef INCLUDE_COMM_S3_S3_REQUESTS_HPP_
#define INCLUDE_COMM_S3_S3_REQUESTS_HPP_
#if defined(REPERTORY_ENABLE_S3)
#include "comm/s3/s3_requests_curl.hpp"
#include "types/repertory.hpp"
#include "types/s3.hpp"
#include "utils/string_utils.hpp"
namespace repertory {
template <typename client_type>
[[nodiscard]] inline auto
create_directory_object_request(client_type &client, const s3_config &config,
const std::string &object_name,
long &response_code) -> bool {
return create_directory_object_request_impl(client, config, object_name,
response_code);
}
template <typename client_type>
[[nodiscard]] inline auto delete_object_request(client_type &client,
const s3_config &config,
const std::string &object_name,
long &response_code) -> bool {
return delete_object_request_impl(client, config, object_name, response_code);
}
template <typename client_type>
[[nodiscard]] inline auto
head_object_request(client_type &client, const s3_config &config,
const std::string &object_name, head_object_result &result,
long &response_code) -> bool {
return head_object_request_impl(client, config, object_name, result,
response_code);
}
template <typename client_type>
[[nodiscard]] inline auto
list_directories_request(client_type &client, const s3_config &config,
list_directories_result &result, long &response_code)
-> bool {
return list_directories_request_impl(client, config, result, response_code);
}
template <typename client_type>
[[nodiscard]] inline auto
list_files_request(client_type &client, const s3_config &config,
const get_api_file_token_callback &get_api_file_token,
const get_name_callback &get_name, list_files_result &result,
long &response_code) -> bool {
return list_files_request_impl(client, config, get_api_file_token, get_name,
result, response_code);
}
template <typename client_type>
[[nodiscard]] inline auto list_objects_in_directory_request(
client_type &client, const s3_config &config,
const std::string &object_name, meta_provider_callback meta_provider,
list_objects_result &result, long &response_code) -> bool {
return list_objects_in_directory_request_impl(
client, config, object_name, meta_provider, result, response_code);
}
template <typename client_type>
[[nodiscard]] inline auto
list_objects_request(client_type &client, const s3_config &config,
list_objects_result &result, long &response_code) -> bool {
return list_objects_request_impl(client, config, result, response_code);
}
template <typename client_type>
[[nodiscard]] inline auto
put_object_request(client_type &client, const s3_config &config,
std::string object_name, const std::string &source_path,
const std::string &encryption_token,
get_key_callback get_key, set_key_callback set_key,
long &response_code, stop_type &stop_requested) -> bool {
return put_object_request_impl(client, config, object_name, source_path,
encryption_token, get_key, set_key,
response_code, stop_requested);
}
template <typename client_type>
[[nodiscard]] inline auto
read_object_request(client_type &client, const s3_config &config,
const std::string &object_name, std::size_t size,
std::uint64_t offset, data_buffer &data,
long &response_code, stop_type &stop_requested) -> bool {
return read_object_request_impl(client, config, object_name, size, offset,
data, response_code, stop_requested);
}
} // namespace repertory
#endif
#endif // INCLUDE_COMM_S3_S3_REQUESTS_HPP_

View File

@ -1,83 +0,0 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef INCLUDE_COMM_S3_S3_REQUESTS_CURL_HPP_
#define INCLUDE_COMM_S3_S3_REQUESTS_CURL_HPP_
#if defined(REPERTORY_ENABLE_S3)
#include "comm/i_http_comm.hpp"
#include "types/repertory.hpp"
#include "types/s3.hpp"
#include "utils/string_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
[[nodiscard]] auto create_directory_object_request_impl(
i_http_comm &client, const s3_config &config,
const std::string &object_name, long &response_code) -> bool;
[[nodiscard]] auto delete_object_request_impl(i_http_comm &client,
const s3_config &config,
const std::string &object_name,
long &response_code) -> bool;
[[nodiscard]] auto head_object_request_impl(i_http_comm &client,
const s3_config &config,
const std::string &object_name,
head_object_result &result,
long &response_code) -> bool;
[[nodiscard]] auto
list_directories_request_impl(i_http_comm &client, const s3_config &config,
list_directories_result &result,
long &response_code) -> bool;
[[nodiscard]] auto
list_files_request_impl(i_http_comm &client, const s3_config &config,
const get_api_file_token_callback &get_api_file_token,
const get_name_callback &get_name,
list_files_result &result, long &response_code) -> bool;
[[nodiscard]] auto list_objects_in_directory_request_impl(
i_http_comm &client, const s3_config &config,
const std::string &object_name, meta_provider_callback meta_provider,
list_objects_result &result, long &response_code) -> bool;
[[nodiscard]] auto list_objects_request_impl(i_http_comm &client,
const s3_config &config,
list_objects_result &result,
long &response_code) -> bool;
[[nodiscard]] auto
put_object_request_impl(i_http_comm &client, const s3_config &config,
std::string object_name, const std::string &source_path,
const std::string &encryption_token,
get_key_callback get_key, set_key_callback set_key,
long &response_code, stop_type &stop_requested) -> bool;
[[nodiscard]] auto read_object_request_impl(
i_http_comm &client, const s3_config &config,
const std::string &object_name, std::size_t size, std::uint64_t offset,
data_buffer &data, long &response_code, stop_type &stop_requested) -> bool;
} // namespace repertory
#endif // REPERTORY_ENABLE_S3
#endif // INCLUDE_COMM_S3_S3_REQUESTS_CURL_HPP_

View File

@ -22,6 +22,32 @@
#ifndef INCLUDE_COMMON_HPP_
#define INCLUDE_COMMON_HPP_
#if defined(__GNUC__)
// clang-format off
#define REPERTORY_IGNORE_WARNINGS_ENABLE() \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wconversion\"") \
_Pragma("GCC diagnostic ignored \"-Wdouble-promotion\"") \
_Pragma("GCC diagnostic ignored \"-Wduplicated-branches\"") \
_Pragma("GCC diagnostic ignored \"-Wfloat-conversion\"") \
_Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"") \
_Pragma("GCC diagnostic ignored \"-Wnull-dereference\"") \
_Pragma("GCC diagnostic ignored \"-Wsign-conversion\"") \
_Pragma("GCC diagnostic ignored \"-Wunused-but-set-variable\"") \
_Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") \
_Pragma("GCC diagnostic ignored \"-Wuseless-cast\"")
#define REPERTORY_IGNORE_WARNINGS_DISABLE() \
_Pragma("GCC diagnostic pop")
#else
#define REPERTORY_IGNORE_WARNINGS_ENABLE()
#define REPERTORY_IGNORE_WARNINGS_DISABLE()
#endif // defined(__GNUC__)
// clang-format on
#ifdef __cplusplus
REPERTORY_IGNORE_WARNINGS_ENABLE()
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
@ -103,7 +129,7 @@ template <typename data_type>
#include <curl/curl.h>
#include <curl/multi.h>
#include <json.hpp>
#include <rocksdb/db.h>
#include <sqlite3.h>
#include <stduuid.h>
#ifdef _WIN32
@ -124,6 +150,28 @@ template <typename data_type>
#define CPPHTTPLIB_OPENSSL_SUPPORT
#include <httplib.h>
REPERTORY_IGNORE_WARNINGS_DISABLE()
struct sqlite3_deleter {
void operator()(sqlite3 *db3) {
if (db3 != nullptr) {
sqlite3_close_v2(db3);
}
}
};
using db3_t = std::unique_ptr<sqlite3, sqlite3_deleter>;
struct sqlite3_statement_deleter {
void operator()(sqlite3_stmt *stmt) {
if (stmt != nullptr) {
sqlite3_finalize(stmt);
}
}
};
using db3_stmt_t = std::unique_ptr<sqlite3_stmt, sqlite3_statement_deleter>;
using namespace std::chrono_literals;
using json = nlohmann::json;
@ -356,17 +404,17 @@ enum {
};
struct FSP_FSCTL_FILE_INFO {
UINT32 FileAttributes;
UINT32 ReparseTag;
UINT64 AllocationSize;
UINT64 FileSize;
UINT64 CreationTime;
UINT64 LastAccessTime;
UINT64 LastWriteTime;
UINT64 ChangeTime;
UINT64 IndexNumber;
UINT32 HardLinks;
UINT32 EaSize;
UINT32 FileAttributes{};
UINT32 ReparseTag{};
UINT64 AllocationSize{};
UINT64 FileSize{};
UINT64 CreationTime{};
UINT64 LastAccessTime{};
UINT64 LastWriteTime{};
UINT64 ChangeTime{};
UINT64 IndexNumber{};
UINT32 HardLinks{};
UINT32 EaSize{};
};
using FileInfo = FSP_FSCTL_FILE_INFO;
@ -382,6 +430,13 @@ void repertory_init();
void repertory_shutdown();
} // namespace repertory
namespace {
template <class... Ts> struct overloaded : Ts... {
using Ts::operator()...;
};
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
} // namespace
#define INTERFACE_SETUP(name) \
public: \
name(const name &) noexcept = delete; \
@ -395,4 +450,5 @@ protected: \
public: \
virtual ~name() = default
#endif // __cplusplus
#endif // INCLUDE_COMMON_HPP_

View File

@ -0,0 +1,217 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef INCLUDE_DATABASE_DB_COMMON_HPP_
#define INCLUDE_DATABASE_DB_COMMON_HPP_
#include "utils/error_utils.hpp"
namespace repertory::db {
using db_types_t = std::variant<std::int64_t, std::string>;
struct comp_data_t final {
std::string column_name;
std::string op_type;
db_types_t value;
};
class db_column final {
public:
db_column() noexcept = default;
db_column(const db_column &) = default;
db_column(db_column &&column) noexcept = default;
~db_column() = default;
auto operator=(const db_column &) -> db_column & = default;
auto operator=(db_column &&) -> db_column & = default;
db_column(std::int32_t index, std::string name, db_types_t value) noexcept
: index_(index), name_(std::move(name)), value_(std::move(value)) {}
private:
std::int32_t index_{};
std::string name_;
db_types_t value_;
public:
[[nodiscard]] auto get_index() const -> std::int32_t { return index_; }
[[nodiscard]] auto get_name() const -> std::string { return name_; }
template <typename data_type>
[[nodiscard]] auto get_value() const -> data_type {
return std::visit(
overloaded{
[](const data_type &value) -> data_type { return value; },
[](auto &&) -> data_type {
throw std::runtime_error("data type not supported");
},
},
value_);
}
[[nodiscard]] auto get_value_as_json() const -> nlohmann::json {
return std::visit(
overloaded{
[this](std::int64_t value) -> auto {
return nlohmann::json({{name_, value}});
},
[](auto &&value) -> auto { return nlohmann::json::parse(value); },
},
value_);
}
};
template <typename context_t> class db_row final {
public:
db_row(std::shared_ptr<context_t> context) {
auto column_count = sqlite3_column_count(context->stmt.get());
for (std::int32_t col = 0; col < column_count; col++) {
std::string name{sqlite3_column_name(context->stmt.get(), col)};
auto column_type = sqlite3_column_type(context->stmt.get(), col);
db_types_t value;
switch (column_type) {
case SQLITE_INTEGER: {
value = sqlite3_column_int64(context->stmt.get(), col);
} break;
case SQLITE_TEXT: {
const auto *text = reinterpret_cast<const char *>(
sqlite3_column_text(context->stmt.get(), col));
value = std::string(text == nullptr ? "" : text);
} break;
default:
throw std::runtime_error("column type not implemented|" + name + '|' +
std::to_string(column_type));
}
columns_[name] = db_column{col, name, value};
}
}
private:
std::map<std::string, db_column> columns_;
public:
[[nodiscard]] auto get_columns() const -> std::vector<db_column> {
std::vector<db_column> ret;
for (const auto &item : columns_) {
ret.push_back(item.second);
}
return ret;
}
[[nodiscard]] auto get_column(std::int32_t index) const -> db_column {
auto iter = std::find_if(columns_.begin(), columns_.end(),
[&index](auto &&col) -> bool {
return col.second.get_index() == index;
});
if (iter == columns_.end()) {
throw std::out_of_range("");
}
return iter->second;
}
[[nodiscard]] auto get_column(std::string name) const -> db_column {
return columns_.at(name);
}
};
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) {
if (res == SQLITE_OK) {
set_res(sqlite3_step(context_->stmt.get()), __FUNCTION__);
}
}
private:
std::shared_ptr<context_t> context_;
mutable std::int32_t res_;
private:
void set_res(std::int32_t res, std::string function) const {
if (res != SQLITE_OK && res != SQLITE_DONE && res != SQLITE_ROW) {
utils::error::raise_error(function, "failed to step|" +
std::to_string(res) + '|' +
sqlite3_errstr(res));
}
res_ = res;
}
public:
[[nodiscard]] auto ok() const -> bool {
return res_ == SQLITE_DONE || res_ == SQLITE_ROW;
}
[[nodiscard]] auto get_error() const -> std::int32_t { return res_; }
[[nodiscard]] auto get_error_str() const -> std::string {
return sqlite3_errstr(res_);
}
[[nodiscard]] auto get_row(std::optional<db_row<context_t>> &row) const
-> bool {
row.reset();
if (has_row()) {
row = db_row{context_};
set_res(sqlite3_step(context_->stmt.get()), __FUNCTION__);
return true;
}
return false;
}
[[nodiscard]] auto has_row() const -> bool { return res_ == SQLITE_ROW; }
void next_row() const {
if (has_row()) {
set_res(sqlite3_step(context_->stmt.get()), __FUNCTION__);
}
}
};
inline void set_journal_mode(sqlite3 &db3) {
sqlite3_exec(&db3, "PRAGMA journal_mode = WAL;", nullptr, nullptr, nullptr);
}
[[nodiscard]] inline auto execute_sql(sqlite3 &db3, const std::string &sql,
std::string &err) -> bool {
char *err_msg{nullptr};
auto res = sqlite3_exec(&db3, sql.c_str(), nullptr, nullptr, &err_msg);
if (err_msg != nullptr) {
err = err_msg;
sqlite3_free(err_msg);
err_msg = nullptr;
}
if (res != SQLITE_OK) {
err = "failed to execute sql|" + sql + "|" + std::to_string(res) + '|' +
(err.empty() ? sqlite3_errstr(res) : err);
return false;
}
return true;
}
} // namespace repertory::db
#endif // INCLUDE_DATABASE_DB_COMMON_HPP_

View File

@ -0,0 +1,69 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef INCLUDE_DATABASE_DB_INSERT_HPP_
#define INCLUDE_DATABASE_DB_INSERT_HPP_
#include "database/db_common.hpp"
#include "utils/error_utils.hpp"
namespace repertory::db {
class db_insert final {
public:
struct context final {
context(sqlite3 &db3_, std::string table_name_)
: db3(db3_), table_name(std::move(table_name_)) {}
sqlite3 &db3;
std::string table_name;
bool or_replace{false};
std::map<std::string, db_types_t> values{};
db3_stmt_t stmt{nullptr};
};
using row = db_row<context>;
public:
db_insert(sqlite3 &db3, std::string table_name)
: context_(std::make_shared<context>(db3, table_name)) {}
db_insert(std::shared_ptr<context> ctx) : context_(std::move(ctx)) {}
private:
std::shared_ptr<context> context_;
public:
[[nodiscard]] auto or_replace() -> db_insert & {
context_->or_replace = true;
return *this;
}
[[nodiscard]] auto column_value(std::string column_name, db_types_t value)
-> db_insert &;
[[nodiscard]] auto dump() const -> std::string;
[[nodiscard]] auto go() const -> db_result<context>;
};
} // namespace repertory::db
#endif // INCLUDE_DATABASE_DB_INSERT_HPP_

View File

@ -0,0 +1,125 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef INCLUDE_DATABASE_DB_SELECT_HPP_
#define INCLUDE_DATABASE_DB_SELECT_HPP_
#include "database/db_common.hpp"
#include "utils/error_utils.hpp"
namespace repertory::db {
class db_select final {
public:
struct context final {
context(sqlite3 &db3_, std::string table_name_)
: db3(db3_), table_name(std::move(table_name_)) {}
sqlite3 &db3;
std::string table_name;
std::vector<comp_data_t> ands{};
std::vector<std::string> columns{};
std::map<std::string, std::string> count_columns{};
bool delete_query{false};
std::optional<std::int32_t> limit;
std::optional<std::pair<std::string, bool>> order_by;
db3_stmt_t stmt{nullptr};
};
using row = db_row<context>;
public:
db_select(sqlite3 &db3, std::string table_name)
: context_(std::make_shared<context>(db3, table_name)) {}
db_select(std::shared_ptr<context> ctx) : context_(std::move(ctx)) {}
public:
struct db_where final {
db_where(std::shared_ptr<context> ctx, std::string column_name)
: context_(std::move(ctx)), column_name_(std::move(column_name)) {}
public:
struct db_where_next final {
db_where_next(std::shared_ptr<context> ctx) : context_(std::move(ctx)) {}
private:
std::shared_ptr<context> context_;
public:
[[nodiscard]] auto and_where(std::string column_name) const -> db_where {
return db_where{context_, column_name};
}
[[nodiscard]] auto dump() const -> std::string {
return db_select{context_}.dump();
}
[[nodiscard]] auto go() const -> db_result<context> {
return db_select{context_}.go();
}
[[nodiscard]] auto limit(std::int32_t value) const -> db_select {
return db_select{context_}.limit(value);
}
[[nodiscard]] auto order_by(std::string column_name, bool ascending) const
-> db_select {
return db_select{context_}.order_by(column_name, ascending);
}
};
private:
std::shared_ptr<context> context_;
std::string column_name_;
public:
[[nodiscard]] auto equals(db_types_t value) const -> db_where_next {
context_->ands.emplace_back(comp_data_t{column_name_, "=", value});
return db_where_next{context_};
}
};
private:
std::shared_ptr<context> context_;
public:
[[nodiscard]] auto column(std::string column_name) -> db_select &;
[[nodiscard]] auto count(std::string column_name, std::string as_column_name)
-> db_select &;
[[nodiscard]] auto delete_query() -> db_select &;
[[nodiscard]] auto dump() const -> std::string;
[[nodiscard]] auto go() const -> db_result<context>;
[[nodiscard]] auto limit(std::int32_t value) -> db_select &;
[[nodiscard]] auto order_by(std::string column_name, bool ascending)
-> db_select &;
[[nodiscard]] auto where(std::string column_name) const -> db_where;
};
} // namespace repertory::db
#endif // INCLUDE_DATABASE_DB_SELECT_HPP_

View File

@ -33,16 +33,20 @@ public:
private:
struct open_directory {
directory_iterator *iterator;
std::chrono::system_clock::time_point last_update =
std::chrono::system_clock::now();
directory_iterator *iterator{nullptr};
std::chrono::system_clock::time_point last_update{
std::chrono::system_clock::now()};
};
public:
directory_cache() : single_thread_service_base("directory_cache") {}
~directory_cache() override = default;
directory_cache(const directory_cache &) = delete;
directory_cache(directory_cache &&) = delete;
auto operator=(const directory_cache &) -> directory_cache & = delete;
auto operator=(directory_cache &&) -> directory_cache & = delete;
private:
std::unordered_map<std::string, open_directory> directory_lookup_;
std::recursive_mutex directory_mutex_;

View File

@ -38,6 +38,12 @@ public:
virtual ~fuse_base();
public:
fuse_base(const fuse_base &) = delete;
fuse_base(fuse_base &&) = delete;
auto operator=(const fuse_base &) -> fuse_base & = delete;
auto operator=(fuse_base &&) -> fuse_base & = delete;
protected:
app_config &config_;
@ -309,7 +315,7 @@ protected:
return api_error::not_implemented;
}
virtual void destroy_impl(void * /*ptr*/) { return; }
virtual void destroy_impl(void * /*ptr*/);
[[nodiscard]] virtual auto
fallocate_impl(std::string /*api_path*/, int /*mode*/, off_t /*offset*/,
@ -593,9 +599,9 @@ protected:
virtual void shutdown();
public:
static void display_options(int argc, char *argv[]);
static void display_options(std::vector<const char *> args);
static void display_version_information(int argc, char *argv[]);
static void display_version_information(std::vector<const char *> args);
static auto unmount(const std::string &mount_location) -> int;

View File

@ -316,9 +316,6 @@ public:
[[nodiscard]] auto is_processing(const std::string &api_path) const
-> bool override;
void populate_stat(const directory_item &dir_item,
struct stat &st) const override;
[[nodiscard]] auto rename_directory(const std::string &from_api_path,
const std::string &to_api_path)
-> int override;

View File

@ -36,6 +36,12 @@ public:
~fuse_drive_base() override = default;
public:
fuse_drive_base(const fuse_drive_base &) = delete;
fuse_drive_base(fuse_drive_base &&) = delete;
auto operator=(const fuse_drive_base &) -> fuse_drive_base & = delete;
auto operator=(fuse_drive_base &&) -> fuse_drive_base & = delete;
protected:
[[nodiscard]] auto access_impl(std::string api_path, int mask)
-> api_error override;

View File

@ -69,9 +69,6 @@ public:
[[nodiscard]] virtual auto is_processing(const std::string &api_path) const
-> bool = 0;
virtual void populate_stat(const directory_item &dir_item,
struct stat &st) const = 0;
[[nodiscard]] virtual auto rename_directory(const std::string &from_api_path,
const std::string &to_api_path)
-> int = 0;

View File

@ -112,14 +112,14 @@ public:
-> packet::error_type = 0;
[[nodiscard]] virtual auto fuse_read(const char *path, char *buffer,
const remote::file_size &readSize,
const remote::file_offset &readOffset,
const remote::file_size &read_size,
const remote::file_offset &read_offset,
const remote::file_handle &handle)
-> packet::error_type = 0;
[[nodiscard]] virtual auto
fuse_readdir(const char *path, const remote::file_offset &offset,
const remote::file_handle &handle, std::string &itemPath)
const remote::file_handle &handle, std::string &item_path)
-> packet::error_type = 0;
[[nodiscard]] virtual auto fuse_release(const char *path,

View File

@ -53,7 +53,8 @@ private:
bool was_mounted_ = false;
private:
void populate_stat(const remote::stat &r, bool directory, struct stat &st);
void populate_stat(const remote::stat &r_stat, bool directory,
struct stat &unix_st);
protected:
[[nodiscard]] auto access_impl(std::string api_path, int mask)
@ -66,7 +67,7 @@ protected:
#if FUSE_USE_VERSION >= 30
[[nodiscard]] auto chmod_impl(std::string api_path, mode_t mode,
struct fuse_file_info *fi)
struct fuse_file_info *f_info)
-> api_error override;
#else
[[nodiscard]] auto chmod_impl(std::string api_path, mode_t mode)
@ -75,7 +76,7 @@ protected:
#if FUSE_USE_VERSION >= 30
[[nodiscard]] auto chown_impl(std::string api_path, uid_t uid, gid_t gid,
struct fuse_file_info *fi)
struct fuse_file_info *f_info)
-> api_error override;
#else
[[nodiscard]] auto chown_impl(std::string api_path, uid_t uid, gid_t gid)
@ -83,37 +84,38 @@ protected:
#endif
[[nodiscard]] auto create_impl(std::string api_path, mode_t mode,
struct fuse_file_info *fi)
struct fuse_file_info *f_info)
-> api_error override;
void destroy_impl(void * /*ptr*/) override;
[[nodiscard]] auto fgetattr_impl(std::string api_path, struct stat *st,
struct fuse_file_info *fi)
[[nodiscard]] auto fgetattr_impl(std::string api_path, struct stat *unix_st,
struct fuse_file_info *f_info)
-> api_error override;
#ifdef __APPLE__
[[nodiscard]] auto fsetattr_x_impl(std::string api_path,
struct setattr_x *attr,
struct fuse_file_info *fi)
struct fuse_file_info *f_info)
-> api_error override;
#endif // __APPLE__
[[nodiscard]] auto fsync_impl(std::string api_path, int datasync,
struct fuse_file_info *fi)
struct fuse_file_info *f_info)
-> api_error override;
#if FUSE_USE_VERSION < 30
[[nodiscard]] auto ftruncate_impl(std::string api_path, off_t size,
struct fuse_file_info *fi)
struct fuse_file_info *f_info)
-> api_error override;
#endif
#if FUSE_USE_VERSION >= 30
[[nodiscard]] auto getattr_impl(std::string api_path, struct stat *st,
struct fuse_file_info *fi)
[[nodiscard]] auto getattr_impl(std::string api_path, struct stat *unix_st,
struct fuse_file_info *f_info)
-> api_error override;
#else
[[nodiscard]] auto getattr_impl(std::string api_path, struct stat *st)
[[nodiscard]] auto getattr_impl(std::string api_path, struct stat *unix_st)
-> api_error override;
#endif
@ -136,37 +138,38 @@ protected:
void notify_fuse_main_exit(int &ret) override;
[[nodiscard]] auto open_impl(std::string api_path, struct fuse_file_info *fi)
[[nodiscard]] auto open_impl(std::string api_path,
struct fuse_file_info *f_info)
-> api_error override;
[[nodiscard]] auto opendir_impl(std::string api_path,
struct fuse_file_info *fi)
struct fuse_file_info *f_info)
-> api_error override;
[[nodiscard]] auto read_impl(std::string api_path, char *buffer,
size_t read_size, off_t read_offset,
struct fuse_file_info *fi,
struct fuse_file_info *f_info,
std::size_t &bytes_read) -> api_error override;
#if FUSE_USE_VERSION >= 30
[[nodiscard]] auto readdir_impl(std::string api_path, void *buf,
fuse_fill_dir_t fuse_fill_dir, off_t offset,
struct fuse_file_info *fi,
struct fuse_file_info *f_info,
fuse_readdir_flags flags)
-> api_error override;
#else
[[nodiscard]] auto readdir_impl(std::string api_path, void *buf,
fuse_fill_dir_t fuse_fill_dir, off_t offset,
struct fuse_file_info *fi)
struct fuse_file_info *f_info)
-> api_error override;
#endif
[[nodiscard]] auto release_impl(std::string api_path,
struct fuse_file_info *fi)
struct fuse_file_info *f_info)
-> api_error override;
[[nodiscard]] auto releasedir_impl(std::string api_path,
struct fuse_file_info *fi)
struct fuse_file_info *f_info)
-> api_error override;
#if FUSE_USE_VERSION >= 30
@ -210,7 +213,7 @@ protected:
#if FUSE_USE_VERSION >= 30
[[nodiscard]] auto truncate_impl(std::string api_path, off_t size,
struct fuse_file_info *fi)
struct fuse_file_info *f_info)
-> api_error override;
#else
[[nodiscard]] auto truncate_impl(std::string api_path, off_t size)
@ -222,7 +225,7 @@ protected:
#if FUSE_USE_VERSION >= 30
[[nodiscard]] auto utimens_impl(std::string api_path,
const struct timespec tv[2],
struct fuse_file_info *fi)
struct fuse_file_info *f_info)
-> api_error override;
#else
[[nodiscard]] auto utimens_impl(std::string api_path,
@ -232,7 +235,7 @@ protected:
[[nodiscard]] auto write_impl(std::string api_path, const char *buffer,
size_t write_size, off_t write_offset,
struct fuse_file_info *fi,
struct fuse_file_info *f_info,
std::size_t &bytes_written)
-> api_error override;
};

View File

@ -341,7 +341,7 @@ public:
ret = this->winfsp_read(file_desc, buffer.data(), offset, length,
&bytes_transferred);
if (ret == STATUS_SUCCESS) {
response.encode(static_cast<UINT32>(bytes_transferred));
response.encode(bytes_transferred);
if (bytes_transferred != 0U) {
response.encode(buffer.data(), bytes_transferred);
}
@ -1237,7 +1237,7 @@ public:
return -ERANGE;
}
data_buffer buffer(static_cast<std::size_t>(write_size));
data_buffer buffer(write_size);
if ((ret = request->decode(buffer.data(), buffer.size())) == 0) {
remote::file_offset write_offset{};
DECODE_OR_RETURN(request, write_offset);
@ -1267,7 +1267,7 @@ public:
return -ERANGE;
}
data_buffer buffer(static_cast<std::size_t>(write_size));
data_buffer buffer(write_size);
if ((ret = request->decode(buffer.data(), buffer.size())) == 0) {
buffer = macaron::Base64::Decode(
std::string(buffer.begin(), buffer.end()));

View File

@ -193,9 +193,9 @@ public:
void shutdown();
static void display_options(int argc, char *argv[]) {}
static void display_options(std::vector<const char *> args) {}
static void display_version_information(int argc, char *argv[]) {}
static void display_version_information(std::vector<const char *> args) {}
};
} // namespace repertory

View File

@ -60,6 +60,7 @@ using event_consumer = event_system::event_consumer;
return ss; \
})(d)
#define E_STRING(t) t
#define E_FROM_CURL_CODE(t) std::string(curl_easy_strerror(t))
#define E_FROM_UINT8(t) std::to_string(t)
#define E_FROM_UINT32(t) std::to_string(t)
#define E_FROM_UINT64(t) std::to_string(t)
@ -245,16 +246,17 @@ private: \
#define E_SUBSCRIBE(name, callback) \
event_consumers_.emplace_back(std::make_shared<repertory::event_consumer>( \
#name, [this](const event &e) { callback(e); }))
#name, [this](const event &evt) { callback(evt); }))
#define E_SUBSCRIBE_EXACT(name, callback) \
event_consumers_.emplace_back(std::make_shared<repertory::event_consumer>( \
#name, \
[this](const event &e) { callback(dynamic_cast<const name &>(e)); }))
#name, [this](const event &evt) { \
callback(dynamic_cast<const name &>(evt)); \
}))
#define E_SUBSCRIBE_ALL(callback) \
event_consumers_.emplace_back(std::make_shared<repertory::event_consumer>( \
[this](const event &e) { callback(e); }))
[this](const event &evt) { callback(evt); }))
} // namespace repertory
#endif // INCLUDE_EVENTS_EVENT_SYSTEM_HPP_

View File

@ -28,145 +28,9 @@
namespace repertory {
// clang-format off
E_SIMPLE3(cache_file_processed, normal, true,
std::string, api_path, ap, E_STRING,
std::string, source, src, E_STRING,
api_error, result, res, E_FROM_API_FILE_ERROR
);
E_SIMPLE2(comm_auth_begin, normal, true,
E_SIMPLE2(curl_error, normal, true,
std::string, url, url, E_STRING,
std::string, user, user, E_STRING
);
E_SIMPLE4(comm_auth_end, normal, true,
std::string, url, url, E_STRING,
std::string, user, user, E_STRING,
CURLcode, curl, curl, E_FROM_INT32,
int, http, http, E_FROM_INT32
);
E_SIMPLE2(comm_auth_logout_begin, normal, true,
std::string, url, url, E_STRING,
std::string, user, user, E_STRING
);
E_SIMPLE4(comm_auth_logout_end, normal, true,
std::string, url, url, E_STRING,
std::string, user, user, E_STRING,
CURLcode, curl, curl, E_FROM_INT32,
int, http, http, E_FROM_INT32
);
E_SIMPLE1(comm_del_begin, verbose, true,
std::string, url, url, E_STRING
);
E_SIMPLE4(comm_del_end, verbose, true,
std::string, url, url, E_STRING,
CURLcode, curl, curl, E_FROM_INT32,
int, http, http, E_FROM_INT32,
std::string, result, res, E_STRING
);
E_SIMPLE1(comm_get_begin, verbose, true,
std::string, url, url, E_STRING
);
E_SIMPLE4(comm_get_end, verbose, true,
std::string, url, url, E_STRING,
CURLcode, curl, curl, E_FROM_INT32,
int, http, http, E_FROM_INT32,
std::string, result, res, E_STRING
);
E_SIMPLE1(comm_get_range_begin, verbose, true,
std::string, url, url, E_STRING
);
E_SIMPLE4(comm_get_range_end, verbose, true,
std::string, url, url, E_STRING,
CURLcode, curl, curl, E_FROM_INT32,
int, http, http, E_FROM_INT32,
std::string, error, err, E_STRING
);
E_SIMPLE1(comm_get_raw_begin, verbose, true,
std::string, url, url, E_STRING
);
E_SIMPLE4(comm_get_raw_end, verbose, true,
std::string, url, url, E_STRING,
CURLcode, curl, curl, E_FROM_INT32,
int, http, http, E_FROM_INT32,
std::string, error, err, E_STRING
);
E_SIMPLE2(comm_post_begin, verbose, true,
std::string, url, url, E_STRING,
std::string, fields, fields, E_STRING
);
E_SIMPLE4(comm_post_end, verbose, true,
std::string, url, url, E_STRING,
CURLcode, curl, curl, E_FROM_INT32,
int, http, http, E_FROM_INT32,
std::string, result, res, E_STRING
);
E_SIMPLE2(comm_duration, normal, true,
std::string, url, url, E_STRING,
std::string, duration, duration, E_STRING
);
E_SIMPLE1(comm_post_file_begin, debug, true,
std::string, url, url, E_STRING
);
E_SIMPLE4(comm_post_file_end, debug, true,
std::string, url, url, E_STRING,
CURLcode, curl, curl, E_FROM_INT32,
int, http, http, E_FROM_INT32,
std::string, error, err, E_STRING
);
E_SIMPLE1(comm_post_multi_part_file_begin, debug, true,
std::string, url, url, E_STRING
);
E_SIMPLE4(comm_post_multi_part_file_end, debug, true,
std::string, url, url, E_STRING,
CURLcode, curl, curl, E_FROM_INT32,
int, http, http, E_FROM_INT32,
std::string, error, err, E_STRING
);
E_SIMPLE4(comm_tus_upload_begin, debug, true,
std::string, file_name, fn, E_STRING,
std::string, url, url, E_STRING,
std::uint64_t, remain, rem, E_FROM_UINT64,
std::uint64_t, offset, off, E_FROM_UINT64
);
E_SIMPLE6(comm_tus_upload_end, debug, true,
std::string, file_name, fn, E_STRING,
std::string, url, url, E_STRING,
std::uint64_t, remain, rem, E_FROM_UINT64,
std::uint64_t, offset, OFF, E_FROM_UINT64,
CURLcode, curl, curl, E_FROM_INT32,
int, http, http, E_FROM_INT32
);
E_SIMPLE2(comm_tus_upload_create_begin, debug, true,
std::string, file_name, fn, E_STRING,
std::string, url, url, E_STRING
);
E_SIMPLE4(comm_tus_upload_create_end, debug, true,
std::string, file_name, fn, E_STRING,
std::string, url, url, E_STRING,
CURLcode, curl, curl, E_FROM_INT32,
int, http, http, E_FROM_INT32
CURLcode, res, res, E_FROM_CURL_CODE
);
E_SIMPLE3(debug_log, debug, true,
@ -341,9 +205,8 @@ E_SIMPLE2(file_upload_queued, normal, true,
std::string, source, src, E_STRING
);
E_SIMPLE2(file_upload_removed, debug, true,
std::string, api_path, ap, E_STRING,
std::string, source, src, E_STRING
E_SIMPLE1(file_upload_removed, debug, true,
std::string, api_path, ap, E_STRING
);
E_SIMPLE3(file_upload_retry, normal, true,

View File

@ -93,7 +93,7 @@ E_SIMPLE3(download_stored_failed, error, true,
std::string, error, err, E_STRING
);
E_SIMPLE1(download_timeout, warn, true,
E_SIMPLE1(item_timeout, normal, true,
std::string, api_path, ap, E_STRING
);
// clang-format on

View File

@ -117,22 +117,23 @@ public:
i_provider &provider_;
private:
api_error error_ = api_error::success;
api_error error_{api_error::success};
mutable std::mutex error_mtx_;
stop_type io_stop_requested_ = false;
stop_type io_stop_requested_{false};
std::unique_ptr<std::thread> io_thread_;
protected:
std::unordered_map<std::size_t, std::shared_ptr<download>>
active_downloads_;
mutable std::recursive_mutex file_mtx_;
std::atomic<std::chrono::system_clock::time_point> last_access_ =
std::chrono::system_clock::now();
bool modified_ = false;
std::atomic<std::chrono::system_clock::time_point> last_access_{
std::chrono::system_clock::now()};
bool modified_{false};
native_file_ptr nf_;
mutable std::mutex io_thread_mtx_;
std::condition_variable io_thread_notify_;
std::deque<std::shared_ptr<io_item>> io_thread_queue_;
bool removed_{false};
private:
void file_io_thread();
@ -180,6 +181,10 @@ public:
return fsi_.source_path;
}
[[nodiscard]] auto has_handle(std::uint64_t handle) const -> bool override {
return open_data_.find(handle) != open_data_.end();
}
[[nodiscard]] auto is_directory() const -> bool override {
return fsi_.directory;
}
@ -242,7 +247,8 @@ public:
std::size_t end_chunk_index_inclusive,
bool should_reset);
private:
void set_modified();
void update_background_reader(std::size_t read_chunk);
protected:
@ -445,19 +451,14 @@ public:
private:
app_config &config_;
i_provider &provider_;
std::unique_ptr<rocksdb::DB> db_;
private:
rocksdb::ColumnFamilyHandle *default_family_{};
std::uint64_t next_handle_ = 0u;
db3_t db_{nullptr};
std::uint64_t next_handle_{0U};
mutable std::recursive_mutex open_file_mtx_;
std::unordered_map<std::string, std::shared_ptr<i_closeable_open_file>>
open_file_lookup_;
std::unordered_map<std::uint64_t, i_closeable_open_file *>
open_handle_lookup_;
stop_type stop_requested_ = false;
rocksdb::ColumnFamilyHandle *upload_family_{};
rocksdb::ColumnFamilyHandle *upload_active_family_{};
stop_type stop_requested_{false};
std::unordered_map<std::string, std::unique_ptr<upload>> upload_lookup_;
mutable std::mutex upload_mtx_;
std::condition_variable upload_notify_;
@ -466,12 +467,15 @@ private:
private:
void close_timed_out_files();
auto get_open_file_by_handle(std::uint64_t handle) const
-> std::shared_ptr<i_closeable_open_file>;
auto get_open_file_count(const std::string &api_path) const -> std::size_t;
auto open(const std::string &api_path, bool directory,
const open_file_data &ofd, std::uint64_t &handle,
std::shared_ptr<i_open_file> &f,
std::shared_ptr<i_closeable_open_file> of) -> api_error;
std::shared_ptr<i_open_file> &file,
std::shared_ptr<i_closeable_open_file> closeable_file) -> api_error;
void queue_upload(const std::string &api_path, const std::string &source_path,
bool no_lock);
@ -480,7 +484,7 @@ private:
void swap_renamed_items(std::string from_api_path, std::string to_api_path);
void upload_completed(const file_upload_completed &e);
void upload_completed(const file_upload_completed &evt);
void upload_handler();
@ -490,14 +494,14 @@ public:
auto handle_file_rename(const std::string &from_api_path,
const std::string &to_api_path) -> api_error;
void queue_upload(const i_open_file &o) override;
void queue_upload(const i_open_file &file) override;
void remove_resume(const std::string &api_path,
const std::string &source_path) override;
void remove_upload(const std::string &api_path) override;
void store_resume(const i_open_file &o) override;
void store_resume(const i_open_file &file) override;
public:
void close(std::uint64_t handle);
@ -506,7 +510,7 @@ public:
[[nodiscard]] auto create(const std::string &api_path, api_meta_map &meta,
open_file_data ofd, std::uint64_t &handle,
std::shared_ptr<i_open_file> &f) -> api_error;
std::shared_ptr<i_open_file> &file) -> api_error;
[[nodiscard]] auto evict_file(const std::string &api_path) -> bool override;
@ -514,7 +518,7 @@ public:
-> directory_item_list override;
[[nodiscard]] auto get_open_file(std::uint64_t handle, bool write_supported,
std::shared_ptr<i_open_file> &f) -> bool;
std::shared_ptr<i_open_file> &file) -> bool;
[[nodiscard]] auto get_open_file_count() const -> std::size_t;
@ -533,14 +537,11 @@ public:
#ifdef REPERTORY_TESTING
[[nodiscard]] auto open(std::shared_ptr<i_closeable_open_file> of,
const open_file_data &ofd, std::uint64_t &handle,
std::shared_ptr<i_open_file> &f) -> api_error;
std::shared_ptr<i_open_file> &file) -> api_error;
#endif
[[nodiscard]] auto open(const std::string &api_path, bool directory,
const open_file_data &ofd, std::uint64_t &handle,
std::shared_ptr<i_open_file> &f) -> api_error;
auto perform_locked_operation(locked_operation_callback locked_operation)
-> bool override;
std::shared_ptr<i_open_file> &file) -> api_error;
[[nodiscard]] auto remove_file(const std::string &api_path) -> api_error;

View File

@ -30,9 +30,6 @@ class i_provider;
class i_file_manager {
INTERFACE_SETUP(i_file_manager);
public:
using locked_operation_callback = std::function<bool(i_provider &)>;
public:
[[nodiscard]] virtual auto evict_file(const std::string &api_path)
-> bool = 0;
@ -49,10 +46,6 @@ public:
[[nodiscard]] virtual auto is_processing(const std::string &api_path) const
-> bool = 0;
virtual auto
perform_locked_operation(locked_operation_callback locked_operation)
-> bool = 0;
virtual void update_used_space(std::uint64_t &used_space) const = 0;
};
} // namespace repertory

View File

@ -40,6 +40,9 @@ public:
[[nodiscard]] virtual auto get_filesystem_item() const -> filesystem_item = 0;
[[nodiscard]] virtual auto get_open_data() const
-> std::map<std::uint64_t, open_file_data> = 0;
[[nodiscard]] virtual auto get_open_data(std::uint64_t handle) const
-> open_file_data = 0;
@ -55,6 +58,8 @@ public:
[[nodiscard]] virtual auto is_directory() const -> bool = 0;
[[nodiscard]] virtual auto has_handle(std::uint64_t handle) const -> bool = 0;
[[nodiscard]] virtual auto
native_operation(const native_operation_callback &callback) -> api_error = 0;
@ -89,9 +94,6 @@ public:
[[nodiscard]] virtual auto get_handles() const
-> std::vector<std::uint64_t> = 0;
[[nodiscard]] virtual auto get_open_data() const
-> std::map<std::uint64_t, open_file_data> = 0;
[[nodiscard]] virtual auto is_complete() const -> bool = 0;
[[nodiscard]] virtual auto is_modified() const -> bool = 0;

View File

@ -23,6 +23,7 @@
#define INCLUDE_PROVIDERS_BASE_PROVIDER_HPP_
#include "providers/i_provider.hpp"
#include "providers/meta_db.hpp"
#include "types/repertory.hpp"
namespace repertory {
@ -41,8 +42,7 @@ private:
private:
api_item_added_callback api_item_added_;
std::unique_ptr<rocksdb::DB> db_;
std::string DB_NAME = "meta_db";
std::unique_ptr<meta_db> db3_;
i_file_manager *fm_{};
private:
@ -56,6 +56,16 @@ protected:
std::uint64_t size,
api_meta_map &meta) -> api_file;
[[nodiscard]] virtual auto create_directory_impl(const std::string &api_path,
api_meta_map &meta)
-> api_error = 0;
[[nodiscard]] virtual auto
create_file_extra(const std::string & /* api_path */,
api_meta_map & /* meta */) -> api_error {
return api_error::success;
}
[[nodiscard]] auto get_api_item_added() -> api_item_added_callback & {
return api_item_added_;
}
@ -73,7 +83,11 @@ protected:
return config_;
}
[[nodiscard]] auto get_db() const -> rocksdb::DB * { return db_.get(); }
[[nodiscard]] auto get_db() -> meta_db & { return *db3_; }
[[nodiscard]] virtual auto
get_directory_items_impl(const std::string &api_path,
directory_item_list &list) const -> api_error = 0;
[[nodiscard]] auto get_file_mgr() -> i_file_manager * { return fm_; }
@ -81,16 +95,40 @@ protected:
return fm_;
}
[[nodiscard]] virtual auto get_used_drive_space_impl() const
-> std::uint64_t = 0;
[[nodiscard]] virtual auto remove_directory_impl(const std::string &api_path)
-> api_error = 0;
[[nodiscard]] virtual auto remove_file_impl(const std::string &api_path)
-> api_error = 0;
[[nodiscard]] virtual auto upload_file_impl(const std::string &api_path,
const std::string &source_path,
stop_type &stop_requested)
-> api_error = 0;
public:
[[nodiscard]] auto
create_directory_clone_source_meta(const std::string &source_api_path,
const std::string &api_path)
-> api_error override;
[[nodiscard]] auto create_directory(const std::string &api_path,
api_meta_map &meta) -> api_error override;
[[nodiscard]] auto create_file(const std::string &api_path,
api_meta_map &meta) -> api_error override;
[[nodiscard]] auto get_api_path_from_source(const std::string &source_path,
std::string &api_path) const
-> api_error override;
[[nodiscard]] auto get_directory_items(const std::string &api_path,
directory_item_list &list) const
-> api_error override;
[[nodiscard]] auto get_file_size(const std::string &api_path,
std::uint64_t &file_size) const
-> api_error override;
@ -124,9 +162,17 @@ public:
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t override;
[[nodiscard]] auto get_used_drive_space() const -> std::uint64_t override;
[[nodiscard]] auto is_file_writeable(const std::string &api_path) const
-> bool override;
[[nodiscard]] auto remove_directory(const std::string &api_path)
-> api_error override;
[[nodiscard]] auto remove_file(const std::string &api_path)
-> api_error override;
[[nodiscard]] auto remove_item_meta(const std::string &api_path,
const std::string &key)
-> api_error override;
@ -144,6 +190,11 @@ public:
i_file_manager *mgr) -> bool override;
void stop() override;
[[nodiscard]] auto upload_file(const std::string &api_path,
const std::string &source_path,
stop_type &stop_requested)
-> api_error override;
};
} // namespace repertory

View File

@ -49,11 +49,7 @@ private:
private:
app_config &config_;
std::unique_ptr<rocksdb::DB> db_;
rocksdb::ColumnFamilyHandle *dir_family_{};
rocksdb::ColumnFamilyHandle *file_family_{};
rocksdb::ColumnFamilyHandle *source_family_{};
std::string DB_NAME = "meta_db";
db3_t db_;
private:
i_file_manager *fm_ = nullptr;

View File

@ -0,0 +1,83 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef INCLUDE_PROVIDERS_META_DB_HPP_
#define INCLUDE_PROVIDERS_META_DB_HPP_
#include "types/repertory.hpp"
namespace repertory {
class app_config;
class meta_db final {
public:
meta_db(const app_config &cfg);
~meta_db();
meta_db(const meta_db &) = delete;
meta_db(meta_db &&) = delete;
auto operator=(const meta_db &) -> meta_db & = delete;
auto operator=(meta_db &&) -> meta_db & = delete;
private:
db3_t db_;
constexpr static const auto table_name = "meta";
private:
[[nodiscard]] auto update_item_meta(const std::string &api_path,
api_meta_map meta) -> api_error;
public:
[[nodiscard]] auto get_api_path(const std::string &source_path,
std::string &api_path) -> api_error;
[[nodiscard]] auto get_api_path_list() -> std::vector<std::string>;
[[nodiscard]] auto get_item_meta(const std::string &api_path,
api_meta_map &meta) -> api_error;
[[nodiscard]] auto get_item_meta(const std::string &api_path,
const std::string &key,
std::string &value) const -> api_error;
[[nodiscard]] auto get_pinned_files() const -> std::vector<std::string>;
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t;
void remove_api_path(const std::string &api_path);
[[nodiscard]] auto remove_item_meta(const std::string &api_path,
const std::string &key) -> api_error;
[[nodiscard]] auto rename_item_meta(const std::string &from_api_path,
const std::string &to_api_path)
-> api_error;
[[nodiscard]] auto set_item_meta(const std::string &api_path,
const std::string &key,
const std::string &value) -> api_error;
[[nodiscard]] auto set_item_meta(const std::string &api_path,
const api_meta_map &meta) -> api_error;
};
} // namespace repertory
#endif // INCLUDE_PROVIDERS_META_DB_HPP_

View File

@ -28,7 +28,8 @@ namespace repertory {
class app_config;
class i_provider;
[[nodiscard]] auto create_provider(const provider_type &pt, app_config &config)
[[nodiscard]] auto create_provider(const provider_type &prov,
app_config &config)
-> std::unique_ptr<i_provider>;
} // namespace repertory

View File

@ -49,6 +49,10 @@ private:
const std::string &object_name) const
-> api_error;
[[nodiscard]] auto create_file_extra(const std::string &api_path,
api_meta_map &meta)
-> api_error override;
[[nodiscard]] auto create_path_directories(const std::string &api_path,
const std::string &key) const
-> api_error;
@ -61,20 +65,39 @@ private:
bool &is_encrypted, std::string &object_name,
head_object_result &result) const -> api_error;
public:
[[nodiscard]] auto create_directory(const std::string &api_path,
api_meta_map &meta) -> api_error override;
[[nodiscard]] auto
get_object_list(std::string &response_data, long &response_code,
std::optional<std::string> delimiter = std::nullopt,
std::optional<std::string> prefix = std::nullopt) const
-> bool;
[[nodiscard]] auto create_file(const std::string &api_path,
api_meta_map &meta) -> api_error override;
protected:
[[nodiscard]] auto create_directory_impl(const std::string &api_path,
api_meta_map &meta)
-> api_error override;
[[nodiscard]] auto get_directory_item_count(const std::string &api_path) const
[[nodiscard]] auto get_directory_items_impl(const std::string &api_path,
directory_item_list &list) const
-> api_error override;
[[nodiscard]] auto get_used_drive_space_impl() const
-> std::uint64_t override;
[[nodiscard]] auto get_directory_items(const std::string &api_path,
directory_item_list &list) const
[[nodiscard]] auto remove_directory_impl(const std::string &api_path)
-> api_error override;
[[nodiscard]] auto remove_file_impl(const std::string &api_path)
-> api_error override;
[[nodiscard]] auto upload_file_impl(const std::string &api_path,
const std::string &source_path,
stop_type &stop_requested)
-> api_error override;
public:
[[nodiscard]] auto get_directory_item_count(const std::string &api_path) const
-> std::uint64_t override;
[[nodiscard]] auto get_file(const std::string &api_path, api_file &file) const
-> api_error override;
@ -87,8 +110,6 @@ public:
return provider_type::s3;
}
[[nodiscard]] auto get_used_drive_space() const -> std::uint64_t override;
[[nodiscard]] auto is_direct_only() const -> bool override { return false; }
[[nodiscard]] auto is_directory(const std::string &api_path,
@ -109,12 +130,6 @@ public:
stop_type &stop_requested)
-> api_error override;
[[nodiscard]] auto remove_directory(const std::string &api_path)
-> api_error override;
[[nodiscard]] auto remove_file(const std::string &api_path)
-> api_error override;
[[nodiscard]] auto rename_file(const std::string &from_api_path,
const std::string &to_api_path)
-> api_error override;
@ -123,11 +138,6 @@ public:
i_file_manager *mgr) -> bool override;
void stop() override;
[[nodiscard]] auto upload_file(const std::string &api_path,
const std::string &source_path,
stop_type &stop_requested)
-> api_error override;
};
} // namespace repertory

View File

@ -49,20 +49,33 @@ private:
[[nodiscard]] auto get_object_list(const std::string &api_path,
nlohmann::json &object_list) const -> bool;
public:
[[nodiscard]] auto create_directory(const std::string &api_path,
api_meta_map &meta) -> api_error override;
protected:
[[nodiscard]] auto create_directory_impl(const std::string &api_path,
api_meta_map &meta)
-> api_error override;
[[nodiscard]] auto get_directory_item_count(const std::string &api_path) const
[[nodiscard]] auto get_directory_items_impl(const std::string &api_path,
directory_item_list &list) const
-> api_error override;
[[nodiscard]] auto get_used_drive_space_impl() const
-> std::uint64_t override;
[[nodiscard]] auto create_file(const std::string &api_path,
api_meta_map &meta) -> api_error override;
[[nodiscard]] auto get_directory_items(const std::string &api_path,
directory_item_list &list) const
[[nodiscard]] auto remove_directory_impl(const std::string &api_path)
-> api_error override;
[[nodiscard]] auto remove_file_impl(const std::string &api_path)
-> api_error override;
[[nodiscard]] auto upload_file_impl(const std::string &api_path,
const std::string &source_path,
stop_type &stop_requested)
-> api_error override;
public:
[[nodiscard]] auto get_directory_item_count(const std::string &api_path) const
-> std::uint64_t override;
[[nodiscard]] auto get_file(const std::string &api_path, api_file &file) const
-> api_error override;
@ -75,8 +88,6 @@ public:
[[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override;
[[nodiscard]] auto get_used_drive_space() const -> std::uint64_t override;
[[nodiscard]] auto is_direct_only() const -> bool override { return false; }
[[nodiscard]] auto is_directory(const std::string &api_path,
@ -88,7 +99,7 @@ public:
[[nodiscard]] auto is_online() const -> bool override;
[[nodiscard]] auto is_rename_supported() const -> bool override {
return false;
return true;
}
[[nodiscard]] auto read_file_bytes(const std::string &api_path,
@ -97,12 +108,6 @@ public:
stop_type &stop_requested)
-> api_error override;
[[nodiscard]] auto remove_directory(const std::string &api_path)
-> api_error override;
[[nodiscard]] auto remove_file(const std::string &api_path)
-> api_error override;
[[nodiscard]] auto rename_file(const std::string &from_api_path,
const std::string &to_api_path)
-> api_error override;
@ -111,11 +116,6 @@ public:
i_file_manager *mgr) -> bool override;
void stop() override;
[[nodiscard]] auto upload_file(const std::string &api_path,
const std::string &source_path,
stop_type &stop_requested)
-> api_error override;
};
} // namespace repertory

View File

@ -30,7 +30,6 @@ const std::string META_CHANGED = "changed";
const std::string META_CREATION = "creation";
const std::string META_DIRECTORY = "directory";
const std::string META_GID = "gid";
const std::string META_ID = "id";
const std::string META_KEY = "key";
const std::string META_MODE = "mode";
const std::string META_MODIFIED = "modified";
@ -42,10 +41,10 @@ const std::string META_UID = "uid";
const std::string META_WRITTEN = "written";
const std::vector<std::string> META_USED_NAMES = {
META_ACCESSED, META_ATTRIBUTES, META_BACKUP, META_CHANGED, META_CREATION,
META_DIRECTORY, META_GID, META_ID, META_KEY, META_MODE,
META_MODIFIED, META_OSXFLAGS, META_PINNED, META_SIZE, META_SOURCE,
META_UID, META_WRITTEN,
META_ACCESSED, META_ATTRIBUTES, META_BACKUP, META_CHANGED,
META_CREATION, META_DIRECTORY, META_GID, META_KEY,
META_MODE, META_MODIFIED, META_OSXFLAGS, META_PINNED,
META_SIZE, META_SOURCE, META_UID, META_WRITTEN,
};
using api_meta_map = std::map<std::string, std::string>;

View File

@ -88,26 +88,28 @@ static const std::vector<option> option_list = {
// Prototypes
void get_api_authentication_data(std::string &user, std::string &password,
std::uint16_t &port, const provider_type &pt,
std::uint16_t &port, const provider_type &prov,
const std::string &data_directory);
[[nodiscard]] auto get_provider_type_from_args(int argc, char *argv[])
[[nodiscard]] auto get_provider_type_from_args(std::vector<const char *> args)
-> provider_type;
[[nodiscard]] auto has_option(int argc, char *argv[],
[[nodiscard]] auto has_option(std::vector<const char *> args,
const std::string &option_name) -> bool;
[[nodiscard]] auto has_option(int argc, char *argv[], const option &opt)
[[nodiscard]] auto has_option(std::vector<const char *> args, const option &opt)
-> bool;
[[nodiscard]] auto parse_option(int argc, char *argv[],
[[nodiscard]] auto parse_option(std::vector<const char *> args,
const std::string &option_name,
std::uint8_t count) -> std::vector<std::string>;
[[nodiscard]] auto parse_string_option(int argc, char **argv, const option &opt,
std::string &value) -> exit_code;
[[nodiscard]] auto parse_string_option(std::vector<const char *> args,
const option &opt, std::string &value)
-> exit_code;
[[nodiscard]] auto parse_drive_options(int argc, char **argv, provider_type &pt,
[[nodiscard]] auto parse_drive_options(std::vector<const char *> args,
provider_type &prov,
std::string &data_directory)
-> std::vector<std::string>;
} // namespace repertory::utils::cli

View File

@ -26,6 +26,9 @@
#include "utils/encrypting_reader.hpp"
namespace repertory::utils::encryption {
using reader_func = std::function<api_error(data_buffer &cypher_text,
std::uint64_t start_offset,
std::uint64_t end_offset)>;
// Prototypes
[[nodiscard]] auto decrypt_file_path(const std::string &encryption_token,
std::string &file_path) -> api_error;
@ -36,11 +39,10 @@ namespace repertory::utils::encryption {
[[nodiscard]] auto generate_key(const std::string &encryption_token)
-> key_type;
[[nodiscard]] auto read_encrypted_range(
const http_range &range, const key_type &key,
const std::function<api_error(data_buffer &ct, std::uint64_t start_offset,
std::uint64_t end_offset)> &reader,
std::uint64_t total_size, data_buffer &data) -> api_error;
[[nodiscard]] auto read_encrypted_range(const http_range &range,
const key_type &key, reader_func reader,
std::uint64_t total_size,
data_buffer &data) -> api_error;
// Implementations
template <typename result>

View File

@ -25,60 +25,60 @@
#include "types/repertory.hpp"
namespace repertory::utils::error {
void raise_error(std::string_view function, std::string_view msg);
void raise_error(std::string function, std::string_view msg);
void raise_error(std::string_view function, const api_error &e,
void raise_error(std::string function, const api_error &err,
std::string_view msg);
void raise_error(std::string_view function, const std::exception &e,
void raise_error(std::string function, const std::exception &exception,
std::string_view msg);
void raise_error(std::string_view function, std::int64_t e,
std::string_view msg);
void raise_error(std::string function, std::int64_t err, std::string_view msg);
void raise_error(std::string_view function, const json &e,
std::string_view msg);
void raise_error(std::string function, const json &err, std::string_view msg);
void raise_error(std::string_view function, const api_error &e,
void raise_error(std::string function, const api_error &err,
std::string_view file_path, std::string_view msg);
void raise_error(std::string_view function, std::int64_t e,
void raise_error(std::string function, std::int64_t err,
std::string_view file_path, std::string_view msg);
void raise_error(std::string_view function, const std::exception &e,
void raise_error(std::string function, const std::exception &exception,
std::string_view file_path, std::string_view msg);
void raise_api_path_error(std::string_view function, std::string_view api_path,
const api_error &e, std::string_view msg);
void raise_api_path_error(std::string function, std::string_view api_path,
const api_error &err, std::string_view msg);
void raise_api_path_error(std::string_view function, std::string_view api_path,
const std::exception &e, std::string_view msg);
void raise_api_path_error(std::string_view function, std::string_view api_path,
std::int64_t e, std::string_view msg);
void raise_api_path_error(std::string_view function, std::string_view api_path,
const json &e, std::string_view msg);
void raise_api_path_error(std::string_view function, std::string_view api_path,
std::string_view source_path, const api_error &e,
void raise_api_path_error(std::string function, std::string_view api_path,
const std::exception &exception,
std::string_view msg);
void raise_api_path_error(std::string_view function, std::string_view api_path,
std::string_view source_path, std::int64_t e,
void raise_api_path_error(std::string function, std::string_view api_path,
std::int64_t err, std::string_view msg);
void raise_api_path_error(std::string function, std::string_view api_path,
const json &err, std::string_view msg);
void raise_api_path_error(std::string function, std::string_view api_path,
std::string_view source_path, const api_error &err,
std::string_view msg);
void raise_api_path_error(std::string_view function, std::string_view api_path,
std::string_view source_path, const std::exception &e,
void raise_api_path_error(std::string function, std::string_view api_path,
std::string_view source_path, std::int64_t err,
std::string_view msg);
void raise_url_error(std::string_view function, std::string_view url,
CURLcode e, std::string_view msg);
void raise_api_path_error(std::string function, std::string_view api_path,
std::string_view source_path,
const std::exception &exception,
std::string_view msg);
void raise_url_error(std::string_view function, std::string_view url,
std::string_view source_path, const std::exception &e,
void raise_url_error(std::string function, std::string_view url, CURLcode err,
std::string_view msg);
void raise_url_error(std::string function, std::string_view url,
std::string_view source_path,
const std::exception &exception, std::string_view msg);
} // namespace repertory::utils::error
#endif // INCLUDE_UTILS_ERROR_UTILS_HPP_

View File

@ -28,7 +28,7 @@
namespace repertory::utils {
#if __linux__
inline const std::array<std::string, 4u> attribute_namespaces = {
inline const std::array<std::string, 4U> attribute_namespaces = {
"security",
"system",
"trusted",
@ -38,12 +38,12 @@ inline const std::array<std::string, 4u> attribute_namespaces = {
#if __APPLE__
template <typename t>
[[nodiscard]] auto convert_to_uint64(const t *v) -> std::uint64_t;
[[nodiscard]] auto convert_to_uint64(const t *ptr) -> std::uint64_t;
#else
[[nodiscard]] auto convert_to_uint64(const pthread_t &t) -> std::uint64_t;
[[nodiscard]] auto convert_to_uint64(const pthread_t &thread) -> std::uint64_t;
#endif
[[nodiscard]] auto from_api_error(const api_error &e) -> int;
[[nodiscard]] auto from_api_error(const api_error &err) -> int;
[[nodiscard]] auto get_last_error_code() -> int;
@ -54,20 +54,20 @@ template <typename t>
void set_last_error_code(int error_code);
[[nodiscard]] auto to_api_error(int e) -> api_error;
[[nodiscard]] auto to_api_error(int err) -> api_error;
[[nodiscard]] auto unix_error_to_windows(int e) -> std::int32_t;
[[nodiscard]] auto unix_error_to_windows(int err) -> std::int32_t;
[[nodiscard]] auto unix_time_to_windows_time(const remote::file_time &ts)
[[nodiscard]] auto unix_time_to_windows_time(const remote::file_time &file_time)
-> UINT64;
void use_getpwuid(uid_t uid, std::function<void(struct passwd *pw)> fn);
void use_getpwuid(uid_t uid, std::function<void(struct passwd *pass)> callback);
void windows_create_to_unix(const UINT32 &create_options,
const UINT32 &granted_access, std::uint32_t &flags,
remote::file_mode &mode);
[[nodiscard]] auto windows_time_to_unix_time(std::uint64_t t)
[[nodiscard]] auto windows_time_to_unix_time(std::uint64_t win_time)
-> remote::file_time;
// template implementations

View File

@ -151,7 +151,7 @@ template <typename t>
template <typename data_type>
[[nodiscard]] auto random_between(const data_type &begin, const data_type &end)
-> data_type {
return begin + repertory_rand<data_type>() % ((end + 1) - begin);
return begin + repertory_rand<data_type>() % ((end + data_type{1}) - begin);
}
template <typename collection_t>

View File

@ -50,7 +50,7 @@ namespace repertory::utils {
[[nodiscard]] auto is_process_elevated() -> bool;
[[nodiscard]] auto run_process_elevated(int argc, char *argv[]) -> int;
[[nodiscard]] auto run_process_elevated(std::vector<const char *> args) -> int;
void set_last_error_code(DWORD errorCode);

View File

@ -12,6 +12,8 @@ if [ -z "${BUILD_ARCH}" ]; then
BUILD_ARCH=64_bit
fi
ln -sf ${SOURCE_DIR}/build/compile_commands.json ${SOURCE_DIR}/compile_commands.json
docker stop repertory_${NAME}
docker rm repertory_${NAME}
docker build -t repertory:${NAME} - < ${SOURCE_DIR}/docker/${BUILD_ARCH}/${NAME} &&

View File

@ -41,6 +41,15 @@ cmake ../.. ${CMAKE_ADDITIONAL_OPTS} \
-DREPERTORY_ENABLE_S3=ON \
-DREPERTORY_ENABLE_S3_TESTING=ON || exit 1
pushd ..
ln -sf ${BUILD_FOLDER}/compile_commands.json .
ln -sf ${BUILD_FOLDER}/repertory${EXE_EXT} .
ln -sf ${BUILD_FOLDER}/unittests${EXE_EXT} .
if [ "${IS_MINGW}" == "1" ]; then
ln -sf ${BUILD_FOLDER}/winfsp-x64.dll .
fi
popd
if [ "${BUILD_CLEAN}" == "clean" ]; then
make clean
fi

View File

@ -28,55 +28,73 @@
#include "utils/unix/unix_utils.hpp"
#include "utils/utils.hpp"
namespace {
constexpr const auto default_api_auth_size = 48U;
constexpr const auto default_download_timeout_ces = 30U;
constexpr const auto default_eviction_delay_mins = 10U;
constexpr const auto default_high_freq_interval_secs = 30U;
constexpr const auto default_low_freq_interval_secs = 60U * 60U;
constexpr const auto default_max_cache_size_bytes =
20ULL * 1024ULL * 1024ULL * 1024ULL;
constexpr const auto default_max_upload_count = 5U;
constexpr const auto default_min_download_timeout_secs = 5U;
constexpr const auto default_online_check_retry_secs = 60U;
constexpr const auto default_orphaned_file_retention_days = 15U;
constexpr const auto default_read_ahead_count = 4U;
constexpr const auto default_remote_client_pool_size = 10U;
constexpr const auto default_remote_host_name_or_ip = "";
constexpr const auto default_remote_max_connections = 20U;
constexpr const auto default_remote_receive_timeout_secs = 120U;
constexpr const auto default_remote_send_timeout_secs = 30U;
constexpr const auto default_remote_token = "";
constexpr const auto default_retry_read_count = 6U;
constexpr const auto default_ring_buffer_file_size = 512U;
constexpr const auto retry_save_count = 5U;
} // namespace
namespace repertory {
app_config::app_config(const provider_type &prov,
const std::string &data_directory)
: prov_(prov),
api_auth_(utils::generate_random_string(48U)),
api_auth_(utils::generate_random_string(default_api_auth_size)),
api_port_(default_rpc_port(prov)),
api_user_("repertory"),
api_user_(REPERTORY),
config_changed_(false),
data_directory_(
data_directory.empty() ? default_data_directory(prov)
: ((prov == provider_type::remote) || (prov == provider_type::s3))
? utils::path::absolute(data_directory)
: utils::path::absolute(utils::path::combine(
data_directory, {get_provider_name(prov)}))),
download_timeout_secs_(30),
data_directory_(data_directory.empty()
? default_data_directory(prov)
: utils::path::absolute(data_directory)),
download_timeout_secs_(default_download_timeout_ces),
enable_chunk_downloader_timeout_(true),
enable_comm_duration_events_(false),
enable_drive_events_(false),
enable_max_cache_size_(true),
enable_max_cache_size_(false),
#ifdef _WIN32
enable_mount_manager_(false),
#endif
enable_remote_mount_(false),
event_level_(event_level::normal),
eviction_delay_mins_(30),
eviction_delay_mins_(default_eviction_delay_mins),
eviction_uses_accessed_time_(false),
high_freq_interval_secs_(30),
high_freq_interval_secs_(default_high_freq_interval_secs),
is_remote_mount_(false),
low_freq_interval_secs_(60 * 60),
max_cache_size_bytes_(20 * 1024 * 1024 * 1024ULL),
max_upload_count_(5U),
min_download_timeout_secs_(5),
online_check_retry_secs_(60),
orphaned_file_retention_days_(15),
low_freq_interval_secs_(default_low_freq_interval_secs),
max_cache_size_bytes_(default_max_cache_size_bytes),
max_upload_count_(default_max_upload_count),
min_download_timeout_secs_(default_min_download_timeout_secs),
online_check_retry_secs_(default_online_check_retry_secs),
orphaned_file_retention_days_(default_orphaned_file_retention_days),
preferred_download_type_(
utils::download_type_to_string(download_type::fallback)),
read_ahead_count_(4),
remote_client_pool_size_(10),
remote_host_name_or_ip_(""),
remote_max_connections_(20),
remote_port_((prov == provider_type::sia) ? 20000
: (prov == provider_type::s3) ? 20001
: (prov == provider_type::encrypt) ? 20002
: 20003),
remote_receive_timeout_secs_(120),
remote_send_timeout_secs_(30),
remote_token_(""),
retry_read_count_(6),
ring_buffer_file_size_(512) {
read_ahead_count_(default_read_ahead_count),
remote_client_pool_size_(default_remote_client_pool_size),
remote_host_name_or_ip_(default_remote_host_name_or_ip),
remote_max_connections_(default_remote_max_connections),
remote_port_(default_remote_port(prov)),
remote_receive_timeout_secs_(default_remote_receive_timeout_secs),
remote_send_timeout_secs_(default_remote_send_timeout_secs),
remote_token_(default_remote_token),
retry_read_count_(default_retry_read_count),
ring_buffer_file_size_(default_ring_buffer_file_size) {
cache_directory_ = utils::path::combine(data_directory_, {"cache"});
log_directory_ = utils::path::combine(data_directory_, {"logs"});
@ -108,16 +126,26 @@ auto app_config::get_config_file_path() const -> std::string {
auto app_config::default_agent_name(const provider_type &prov) -> std::string {
static const std::array<std::string,
static_cast<std::size_t>(provider_type::unknown)>
PROVIDER_AGENT_NAMES = {"Sia-Agent", "", "", ""};
PROVIDER_AGENT_NAMES = {
"Sia-Agent",
"",
"",
"",
};
return PROVIDER_AGENT_NAMES[static_cast<std::size_t>(prov)];
return PROVIDER_AGENT_NAMES.at(static_cast<std::size_t>(prov));
}
auto app_config::default_api_port(const provider_type &prov) -> std::uint16_t {
static const std::array<std::uint16_t,
static_cast<std::size_t>(provider_type::unknown)>
PROVIDER_API_PORTS = {9980U, 0U, 0U, 0U};
return PROVIDER_API_PORTS[static_cast<std::size_t>(prov)];
PROVIDER_API_PORTS = {
9980U,
0U,
0U,
0U,
};
return PROVIDER_API_PORTS.at(static_cast<std::size_t>(prov));
}
auto app_config::default_data_directory(const provider_type &prov)
@ -140,16 +168,28 @@ auto app_config::default_data_directory(const provider_type &prov)
return data_directory;
}
auto app_config::default_remote_port(const provider_type &prov)
-> std::uint16_t {
static const std::array<std::uint16_t,
static_cast<std::size_t>(provider_type::unknown)>
PROVIDER_REMOTE_PORTS = {
20000U,
20010U,
20100U,
20001U,
};
return PROVIDER_REMOTE_PORTS.at(static_cast<std::size_t>(prov));
}
auto app_config::default_rpc_port(const provider_type &prov) -> std::uint16_t {
static const std::array<std::uint16_t,
static_cast<std::size_t>(provider_type::unknown)>
PROVIDER_RPC_PORTS = {
11101U,
11102U,
11103U,
11104U,
10000U,
10010U,
10100U,
10002U,
};
return PROVIDER_RPC_PORTS[static_cast<std::size_t>(prov)];
return PROVIDER_RPC_PORTS.at(static_cast<std::size_t>(prov));
}
auto app_config::get_json() const -> json {
@ -292,7 +332,7 @@ auto app_config::get_provider_api_password(const provider_type &prov)
#endif
#endif
auto lines = utils::file::read_file_lines(api_file);
return lines.empty() ? "" : utils::string::trim(lines[0]);
return lines.empty() ? "" : utils::string::trim(lines[0U]);
}
auto app_config::get_provider_display_name(const provider_type &prov)
@ -305,7 +345,7 @@ auto app_config::get_provider_display_name(const provider_type &prov)
"S3",
"Encrypt",
};
return PROVIDER_DISPLAY_NAMES[static_cast<std::size_t>(prov)];
return PROVIDER_DISPLAY_NAMES.at(static_cast<std::size_t>(prov));
}
auto app_config::get_provider_name(const provider_type &prov) -> std::string {
@ -317,7 +357,7 @@ auto app_config::get_provider_name(const provider_type &prov) -> std::string {
"s3",
"encrypt",
};
return PROVIDER_NAMES[static_cast<std::size_t>(prov)];
return PROVIDER_NAMES.at(static_cast<std::size_t>(prov));
}
auto app_config::get_value_by_name(const std::string &name) -> std::string {
@ -335,16 +375,16 @@ auto app_config::get_value_by_name(const std::string &name) -> std::string {
return std::to_string(get_chunk_downloader_timeout_secs());
}
if (name == "EnableChunkDownloaderTimeout") {
return std::to_string(get_enable_chunk_download_timeout());
return utils::string::from_bool(get_enable_chunk_download_timeout());
}
if (name == "GetEnableCommDurationEvents") {
return std::to_string(get_enable_comm_duration_events());
return utils::string::from_bool(get_enable_comm_duration_events());
}
if (name == "EnableDriveEvents") {
return std::to_string(get_enable_drive_events());
return utils::string::from_bool(get_enable_drive_events());
}
if (name == "EnableMaxCacheSize") {
return std::to_string(get_enable_max_cache_size());
return utils::string::from_bool(get_enable_max_cache_size());
#ifdef _WIN32
}
if (name == "EnableMountManager") {
@ -364,7 +404,7 @@ auto app_config::get_value_by_name(const std::string &name) -> std::string {
return std::to_string(get_eviction_delay_mins());
}
if (name == "EvictionUsesAccessedTime") {
return std::to_string(get_eviction_uses_accessed_time());
return utils::string::from_bool(get_eviction_uses_accessed_time());
}
if (name == "HighFreqIntervalSeconds") {
return std::to_string(get_high_frequency_interval_secs());
@ -407,10 +447,10 @@ auto app_config::get_value_by_name(const std::string &name) -> std::string {
return std::to_string(get_read_ahead_count());
}
if (name == "RemoteMount.EnableRemoteMount") {
return std::to_string(get_enable_remote_mount());
return utils::string::from_bool(get_enable_remote_mount());
}
if (name == "RemoteMount.IsRemoteMount") {
return std::to_string(get_is_remote_mount());
return utils::string::from_bool(get_is_remote_mount());
}
if (name == "RemoteMount.RemoteClientPoolSize") {
return std::to_string(get_remote_client_pool_size());
@ -488,7 +528,8 @@ auto app_config::load() -> bool {
stream << config_file.rdbuf();
const auto json_text = stream.str();
config_file.close();
if ((ret = not json_text.empty())) {
ret = not json_text.empty();
if (ret) {
const auto json_document = json::parse(json_text);
get_value(json_document, "ApiAuth", api_auth_, ret);
@ -639,9 +680,9 @@ auto app_config::load() -> bool {
}
void app_config::save() {
const auto configFilePath = get_config_file_path();
const auto file_path = get_config_file_path();
recur_mutex_lock lock(read_write_mutex_);
if (config_changed_ || not utils::file::is_file(configFilePath)) {
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(
@ -653,8 +694,9 @@ void app_config::save() {
config_changed_ = false;
json data = get_json();
auto success = false;
for (auto i = 0; not success && (i < 5); i++) {
if (not(success = utils::file::write_json_file(configFilePath, data))) {
for (auto i = 0U; not success && (i < retry_save_count); i++) {
success = utils::file::write_json_file(file_path, data);
if (not success) {
std::this_thread::sleep_for(1s);
}
}

View File

@ -154,6 +154,16 @@ auto curl_comm::make_request(const curl::requests::http_head &head,
head, response_code, stop_requested);
}
auto curl_comm::make_request(const curl::requests::http_post &post,
long &response_code,
stop_type &stop_requested) const -> bool {
return make_request(
s3_config_.has_value()
? create_host_config(s3_config_.value(), use_s3_path_style_)
: host_config_.value_or(host_config{}),
post, response_code, stop_requested);
}
auto curl_comm::make_request(const curl::requests::http_put_file &put_file,
long &response_code,
stop_type &stop_requested) const -> bool {

View File

@ -19,22 +19,27 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef INCLUDE_UTILS_ROCKSDB_UTILS_HPP_
#define INCLUDE_UTILS_ROCKSDB_UTILS_HPP_
#include "comm/curl/requests/http_post.hpp"
namespace repertory {
class app_config;
namespace repertory::curl::requests {
http_post::~http_post() {
if (headers != nullptr) {
curl_slist_free_all(headers);
}
}
namespace utils::db {
void create_rocksdb(const app_config &config, const std::string &name,
std::unique_ptr<rocksdb::DB> &db);
auto http_post::set_method(CURL *curl, stop_type & /*stop_requested*/) const
-> bool {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
if (json.has_value()) {
headers = curl_slist_append(headers, "content-type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
void create_rocksdb(
const app_config &config, const std::string &name,
const std::vector<rocksdb::ColumnFamilyDescriptor> &families,
std::vector<rocksdb::ColumnFamilyHandle *> &handles,
std::unique_ptr<rocksdb::DB> &db);
} // namespace utils::db
} // namespace repertory
json_str = json->dump();
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_str->c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, -1L);
}
#endif // INCLUDE_UTILS_ROCKSDB_UTILS_HPP_
return true;
}
} // namespace repertory::curl::requests

View File

@ -1,399 +0,0 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#if defined(REPERTORY_ENABLE_S3)
#include "comm/s3/s3_requests.hpp"
#include "comm/curl/curl_comm.hpp"
#include "comm/curl/requests/http_get.hpp"
#include "utils/encryption.hpp"
#include "utils/error_utils.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
namespace {
[[nodiscard]] auto
get_object_list(i_http_comm &client, const s3_config &config,
std::string &response_data, long &response_code,
std::optional<std::string> delimiter = std::nullopt,
std::optional<std::string> prefix = std::nullopt) -> bool {
curl::requests::http_get get{};
get.allow_timeout = true;
get.aws_service = "aws:amz:" + config.region + ":s3";
get.path = '/';
get.query["list-type"] = "2";
if (delimiter.has_value() && not delimiter.value().empty()) {
get.query["delimiter"] = delimiter.value();
}
if (prefix.has_value() && not prefix.value().empty()) {
get.query["prefix"] = prefix.value();
}
get.response_handler = [&response_data](const data_buffer &data,
long /*response_code*/) {
response_data = std::string(data.begin(), data.end());
};
stop_type stop_requested{};
return client.make_request(get, response_code, stop_requested);
}
} // namespace
auto create_directory_object_request_impl(i_http_comm &client,
const s3_config &config,
const std::string &object_name,
long &response_code) -> bool {
try {
curl::requests::http_put_file put_file{};
put_file.allow_timeout = true;
put_file.aws_service = "aws:amz:" + config.region + ":s3";
put_file.path = '/' + object_name;
stop_type stop_requested{false};
return client.make_request(put_file, response_code, stop_requested);
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
}
return false;
}
auto delete_object_request_impl(i_http_comm &client, const s3_config &config,
const std::string &object_name,
long &response_code) -> bool {
try {
head_object_result result{};
if (not head_object_request_impl(client, config, object_name, result,
response_code)) {
return false;
}
if (response_code == http_error_codes::not_found) {
return true;
}
curl::requests::http_delete del{};
del.allow_timeout = true;
del.aws_service = "aws:amz:" + config.region + ":s3";
del.path = '/' + object_name;
stop_type stop_requested{false};
return client.make_request(del, response_code, stop_requested);
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
}
return false;
}
auto head_object_request_impl(i_http_comm &client, const s3_config &config,
const std::string &object_name,
head_object_result &result, long &response_code)
-> bool {
try {
curl::requests::http_head head{};
head.allow_timeout = true;
head.aws_service = "aws:amz:" + config.region + ":s3";
head.path = '/' + object_name;
head.response_headers = http_headers{};
stop_type stop_requested{false};
if (not client.make_request(head, response_code, stop_requested)) {
return false;
}
if (response_code == http_error_codes::ok) {
result.from_headers(head.response_headers.value());
}
return true;
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
}
return false;
}
auto list_directories_request_impl(i_http_comm &client, const s3_config &config,
list_directories_result &result,
long &response_code) -> bool {
try {
std::string response_data{};
if (not get_object_list(client, config, response_data, response_code)) {
return false;
}
if (response_code != http_error_codes::ok) {
return false;
}
pugi::xml_document doc;
auto res = doc.load_string(response_data.c_str());
if (res.status != pugi::xml_parse_status::status_ok) {
return false;
}
auto node_list = doc.select_nodes("/ListBucketResult/Contents");
for (const auto &node : node_list) {
const auto *object_name =
node.node().select_node("Key").node().text().as_string();
if (utils::string::ends_with(object_name, "/")) {
api_file directory{};
directory.api_path = utils::path::create_api_path(object_name);
directory.api_parent =
utils::path::get_parent_api_path(directory.api_path);
directory.accessed_date = utils::get_file_time_now();
directory.changed_date = utils::convert_api_date(
node.node().select_node("LastModified").node().text().as_string());
directory.creation_date = directory.changed_date;
directory.modified_date = directory.changed_date;
result.emplace_back(std::move(directory));
}
}
return true;
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
}
return false;
}
auto list_files_request_impl(
i_http_comm &client, const s3_config &config,
const get_api_file_token_callback &get_api_file_token,
const get_name_callback &get_name, list_files_result &result,
long &response_code) -> bool {
try {
std::string response_data{};
if (not get_object_list(client, config, response_data, response_code)) {
return false;
}
if (response_code != http_error_codes::ok) {
return false;
}
pugi::xml_document doc;
auto res = doc.load_string(response_data.c_str());
if (res.status != pugi::xml_parse_status::status_ok) {
return false;
}
auto node_list = doc.select_nodes("/ListBucketResult/Contents");
for (const auto &node : node_list) {
std::string object_name =
node.node().select_node("Key").node().text().as_string();
if (not utils::string::ends_with(object_name, "/")) {
api_file file{};
object_name = get_name(
*(utils::string::split(object_name, '/', false).end() - 1U),
object_name);
file.api_path = utils::path::create_api_path(object_name);
file.api_parent = utils::path::get_parent_api_path(file.api_path);
file.accessed_date = utils::get_file_time_now();
// file.encryption_token = get_api_file_token(file.api_path);
auto size = node.node().select_node("Size").node().text().as_ullong();
// file.file_size = file.encryption_token.empty()
// ? size
// : utils::encryption::encrypting_reader::
// calculate_decrypted_size(size);
file.changed_date = utils::convert_api_date(
node.node().select_node("LastModified").node().text().as_string());
file.creation_date = file.changed_date;
file.modified_date = file.changed_date;
result.emplace_back(std::move(file));
}
}
return true;
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
}
return false;
}
auto list_objects_in_directory_request_impl(
i_http_comm &client, const s3_config &config,
const std::string &object_name, meta_provider_callback meta_provider,
list_objects_result &result, long &response_code) -> bool {
try {
std::string response_data{};
auto prefix = object_name.empty() ? object_name : object_name + "/";
if (not get_object_list(client, config, response_data, response_code, "/",
prefix)) {
return false;
}
if (response_code != http_error_codes::ok) {
return false;
}
pugi::xml_document doc;
auto res = doc.load_string(response_data.c_str());
if (res.status != pugi::xml_parse_status::status_ok) {
return false;
}
const auto add_directory_item =
[&](bool directory, const std::string &name,
std::function<std::uint64_t(const directory_item &)> get_size) {
directory_item dir_item{};
dir_item.api_path =
utils::path::create_api_path(utils::path::combine("/", {name}));
dir_item.api_parent =
utils::path::get_parent_api_path(dir_item.api_path);
dir_item.directory = directory;
dir_item.size = get_size(dir_item);
meta_provider(dir_item);
result.emplace_back(std::move(dir_item));
};
auto node_list =
doc.select_nodes("/ListBucketResult/CommonPrefixes/Prefix");
for (const auto &node : node_list) {
add_directory_item(
true, node.node().text().as_string(),
[](const directory_item &) -> std::uint64_t { return 0U; });
}
node_list = doc.select_nodes("/ListBucketResult/Contents");
for (const auto &node : node_list) {
const auto *child_object_name =
node.node().select_node("Key").node().text().as_string();
if (child_object_name != prefix) {
auto size = node.node().select_node("Size").node().text().as_ullong();
add_directory_item(
false, child_object_name,
[&size](const directory_item &) -> std::uint64_t { return size; });
}
}
return true;
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
}
return false;
}
auto list_objects_request_impl(i_http_comm &client, const s3_config &config,
list_objects_result &result, long &response_code)
-> bool {
try {
std::string response_data{};
if (not get_object_list(client, config, response_data, response_code)) {
return false;
}
if (response_code != http_error_codes::ok) {
return false;
}
pugi::xml_document doc;
auto res = doc.load_string(response_data.c_str());
if (res.status != pugi::xml_parse_status::status_ok) {
return false;
}
auto node_list = doc.select_nodes("/ListBucketResult/Contents");
for (const auto &node : node_list) {
const auto *object_name =
node.node().select_node("Key").node().text().as_string();
auto size = node.node().select_node("Size").node().text().as_ullong();
directory_item dir_item{};
dir_item.api_path = utils::path::create_api_path(object_name);
dir_item.api_parent = utils::path::get_parent_api_path(dir_item.api_path);
dir_item.directory = utils::string::ends_with(object_name, "/");
dir_item.size = dir_item.directory ? 0U : size;
dir_item.resolved = false;
result.emplace_back(std::move(dir_item));
}
return true;
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
}
return false;
}
auto put_object_request_impl(i_http_comm &client, const s3_config &config,
std::string object_name,
const std::string &source_path,
const std::string &encryption_token,
get_key_callback get_key, set_key_callback set_key,
long &response_code, stop_type &stop_requested)
-> bool {
try {
curl::requests::http_put_file put_file{};
put_file.aws_service = "aws:amz:" + config.region + ":s3";
put_file.path = '/' + object_name;
put_file.source_path = source_path;
if (not encryption_token.empty()) {
static stop_type no_stop{false};
put_file.reader = std::make_shared<utils::encryption::encrypting_reader>(
*(utils::string::split(object_name, '/', false).end() - 1U),
source_path, no_stop, encryption_token, std::nullopt, -1);
auto key = get_key();
if (key.empty()) {
key = put_file.reader->get_encrypted_file_name();
set_key(key);
}
}
return client.make_request(put_file, response_code, stop_requested);
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
}
return false;
}
auto read_object_request_impl(i_http_comm &client, const s3_config &config,
const std::string &object_name, std::size_t size,
std::uint64_t offset, data_buffer &data,
long &response_code, stop_type &stop_requested)
-> bool {
try {
curl::requests::http_get get{};
get.aws_service = "aws:amz:" + config.region + ":s3";
get.headers["response-content-type"] = "binary/octet-stream";
get.path = '/' + object_name;
get.range = {{offset, offset + size - 1}};
get.response_handler = [&data](const data_buffer &response_data,
long /*response_code*/) {
data = response_data;
};
return client.make_request(get, response_code, stop_requested);
} catch (const std::exception &e) {
utils::error::raise_error(__FUNCTION__, e, "exception occurred");
}
return false;
}
} // namespace repertory
#endif

View File

@ -49,7 +49,11 @@ void repertory_init() {
}
curl_global_init(CURL_GLOBAL_DEFAULT);
sqlite3_initialize();
}
void repertory_shutdown() { curl_global_cleanup(); }
void repertory_shutdown() {
curl_global_cleanup();
sqlite3_shutdown();
}
} // namespace repertory

View File

@ -0,0 +1,96 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "database/db_insert.hpp"
namespace repertory::db {
auto db_insert::column_value(std::string column_name, db_types_t value)
-> db_insert & {
context_->values[column_name] = value;
return *this;
}
auto db_insert::dump() const -> std::string {
std::stringstream query;
query << "INSERT ";
if (context_->or_replace) {
query << "OR REPLACE ";
}
query << "INTO \"" << context_->table_name << "\" (";
for (std::int32_t idx = 0;
idx < static_cast<std::int32_t>(context_->values.size()); idx++) {
if (idx > 0) {
query << ", ";
}
query << '"' << std::next(context_->values.begin(), idx)->first << '"';
}
query << ") VALUES (";
for (std::int32_t idx = 0;
idx < static_cast<std::int32_t>(context_->values.size()); idx++) {
if (idx > 0) {
query << ", ";
}
query << "?" << (idx + 1);
}
query << ");";
return query.str();
}
auto db_insert::go() const -> db_result<context> {
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));
return {context_, res};
}
context_->stmt.reset(stmt_ptr);
for (std::int32_t idx = 0;
idx < static_cast<std::int32_t>(context_->values.size()); idx++) {
res = std::visit(
overloaded{
[this, &idx](std::int64_t data) -> std::int32_t {
return sqlite3_bind_int64(context_->stmt.get(), idx + 1, data);
},
[this, &idx](const std::string &data) -> std::int32_t {
return sqlite3_bind_text(context_->stmt.get(), idx + 1,
data.c_str(), -1, nullptr);
},
},
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));
return {context_, res};
}
}
return {context_, res};
}
} // namespace repertory::db

173
src/database/db_select.cpp Normal file
View File

@ -0,0 +1,173 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "database/db_select.hpp"
namespace repertory::db {
auto db_select::column(std::string column_name) -> db_select & {
if (context_->delete_query) {
throw std::runtime_error("columns may not be specified for delete");
}
context_->columns.push_back(column_name);
return *this;
}
auto db_select::count(std::string column_name, std::string as_column_name)
-> db_select & {
context_->count_columns[column_name] = as_column_name;
return *this;
}
auto db_select::delete_query() -> db_select & {
if (not context_->columns.empty()) {
throw std::runtime_error("columns must be empty for delete");
}
context_->delete_query = true;
return *this;
}
auto db_select::dump() const -> std::string {
std::stringstream query;
query << (context_->delete_query ? "DELETE " : "SELECT ");
if (not context_->delete_query) {
bool has_column{false};
if (context_->columns.empty()) {
if (context_->count_columns.empty()) {
query << "*";
has_column = true;
}
} else {
has_column = not context_->columns.empty();
for (std::size_t idx = 0U; idx < context_->columns.size(); idx++) {
if (idx > 0U) {
query << ", ";
}
query << context_->columns.at(idx);
}
}
for (std::int32_t idx = 0U;
idx < static_cast<std::int32_t>(context_->count_columns.size());
idx++) {
if (has_column || idx > 0) {
query << ", ";
}
query << "COUNT(\"";
auto &count_column = *std::next(context_->count_columns.begin(), idx);
query << count_column.first << "\") AS \"" << count_column.second << '"';
}
}
query << " FROM \"" << context_->table_name << "\"";
if (not context_->ands.empty()) {
query << " WHERE (";
for (std::int32_t idx = 0;
idx < static_cast<std::int32_t>(context_->ands.size()); idx++) {
if (idx > 0) {
query << " AND ";
}
auto &item = context_->ands.at(static_cast<std::size_t>(idx));
query << '"' << item.column_name << '"' << item.op_type << "?"
<< (idx + 1);
}
query << ")";
}
if (not context_->delete_query) {
if (context_->order_by.has_value()) {
query << " ORDER BY \"" << context_->order_by.value().first << "\" ";
query << (context_->order_by.value().second ? "ASC" : "DESC");
}
if (context_->limit.has_value()) {
query << " LIMIT " << context_->limit.value();
}
}
query << ';';
return query.str();
}
auto db_select::go() const -> db_result<context> {
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) + '|' + query_str);
return {context_, res};
}
context_->stmt.reset(stmt_ptr);
for (std::int32_t idx = 0;
idx < static_cast<std::int32_t>(context_->ands.size()); idx++) {
res = std::visit(
overloaded{
[this, &idx](std::int64_t data) -> std::int32_t {
return sqlite3_bind_int64(context_->stmt.get(), idx + 1, data);
},
[this, &idx](const std::string &data) -> std::int32_t {
return sqlite3_bind_text(context_->stmt.get(), idx + 1,
data.c_str(), -1, nullptr);
},
},
context_->ands.at(static_cast<std::size_t>(idx)).value);
if (res != SQLITE_OK) {
utils::error::raise_error(__FUNCTION__,
"failed to bind|" + std::to_string(res) + '|' +
sqlite3_errstr(res) + '|' + query_str);
return {context_, res};
}
}
return {context_, res};
}
auto db_select::limit(std::int32_t value) -> db_select & {
if (context_->delete_query) {
throw std::runtime_error("limit may not be specified for delete");
}
context_->limit = value;
return *this;
}
auto db_select::order_by(std::string column_name, bool ascending)
-> db_select & {
if (context_->delete_query) {
throw std::runtime_error("order_by may not be specified for delete");
}
context_->order_by = {column_name, ascending};
return *this;
}
auto db_select::where(std::string column_name) const -> db_where {
return db_where{context_, column_name};
}
} // namespace repertory::db

View File

@ -54,10 +54,12 @@ auto directory_iterator::fill_buffer(const remote::file_offset &offset,
}
#if FUSE_USE_VERSION >= 30
if (filler_function(buffer, &item_name[0], pst, offset + 1,
if (filler_function(buffer, item_name.data(), pst,
static_cast<off_t>(offset + 1),
FUSE_FILL_DIR_PLUS) != 0) {
#else
if (filler_function(buffer, &item_name[0], pst, offset + 1) != 0) {
if (filler_function(buffer, item_name.data(), pst,
static_cast<off_t>(offset + 1)) != 0) {
#endif
errno = ENOMEM;
return -1;
@ -121,13 +123,14 @@ auto directory_iterator::get_json(std::size_t offset, json &item) -> int {
auto directory_iterator::get_next_directory_offset(
const std::string &api_path) const -> std::size_t {
const auto it = std::find_if(
items_.begin(), items_.end(),
[&api_path](const auto &di) -> bool { return api_path == di.api_path; });
const auto iter = std::find_if(items_.begin(), items_.end(),
[&api_path](const auto &dir_item) -> bool {
return api_path == dir_item.api_path;
});
return (it == items_.end())
? 0
: std::distance(items_.begin(), it) + std::size_t(1u);
return (iter == items_.end()) ? 0U
: static_cast<std::size_t>(
std::distance(items_.begin(), iter) + 1);
}
auto directory_iterator::operator=(const directory_iterator &iterator) noexcept

View File

@ -41,12 +41,12 @@ auto eviction::check_minimum_requirements(const std::string &file_path)
}
auto ret = false;
if (file_size) {
if (file_size != 0U) {
std::uint64_t reference_time{};
if ((ret =
config_.get_eviction_uses_accessed_time()
? utils::file::get_accessed_time(file_path, reference_time)
: utils::file::get_modified_time(file_path, reference_time))) {
ret = config_.get_eviction_uses_accessed_time()
? utils::file::get_accessed_time(file_path, reference_time)
: utils::file::get_modified_time(file_path, reference_time);
if (ret) {
#ifdef _WIN32
const auto now = std::chrono::system_clock::now();
const auto delay =
@ -57,7 +57,7 @@ auto eviction::check_minimum_requirements(const std::string &file_path)
const auto now = utils::get_time_now();
const auto delay =
(config_.get_eviction_delay_mins() * 60L) * NANOS_PER_SECOND;
ret = ((reference_time + delay) <= now);
ret = ((reference_time + static_cast<std::uint64_t>(delay)) <= now);
#endif
}
}

View File

@ -19,6 +19,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "common.hpp"
#ifndef _WIN32
#include "drives/fuse/fuse_base.hpp"
@ -28,6 +29,7 @@
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "providers/i_provider.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/utils.hpp"
@ -160,21 +162,27 @@ void fuse_base::destroy_(void *ptr) {
execute_void_callback(__FUNCTION__, [&]() { instance().destroy_impl(ptr); });
}
void fuse_base::display_options([[maybe_unused]] int argc,
[[maybe_unused]] char *argv[]) {
void fuse_base::destroy_impl(void * /* ptr */) { repertory_shutdown(); }
void fuse_base::display_options(
[[maybe_unused]] std::vector<const char *> args) {
#if FUSE_USE_VERSION >= 30
fuse_cmdline_help();
#else
struct fuse_operations fuse_ops {};
fuse_main(argc, argv, &fuse_ops, nullptr);
fuse_main(args.size(),
reinterpret_cast<char **>(const_cast<char **>(args.data())),
&fuse_ops, nullptr);
#endif
std::cout << std::endl;
}
void fuse_base::display_version_information(int argc, char *argv[]) {
void fuse_base::display_version_information(std::vector<const char *> args) {
struct fuse_operations fuse_ops {};
fuse_main(argc, argv, &fuse_ops, nullptr);
fuse_main(static_cast<int>(args.size()),
reinterpret_cast<char **>(const_cast<char **>(args.data())),
&fuse_ops, nullptr);
}
auto fuse_base::execute_callback(
@ -308,6 +316,9 @@ auto fuse_base::init_(struct fuse_conn_info *conn) -> void * {
#if FUSE_USE_VERSION >= 30
auto fuse_base::init_impl([[maybe_unused]] struct fuse_conn_info *conn,
struct fuse_config *cfg) -> void * {
utils::file::change_to_process_directory();
repertory_init();
#ifdef __APPLE__
conn->want |= FUSE_CAP_VOL_RENAME;
conn->want |= FUSE_CAP_XTIMES;
@ -320,6 +331,9 @@ auto fuse_base::init_impl([[maybe_unused]] struct fuse_conn_info *conn,
}
#else
auto fuse_base::init_impl(struct fuse_conn_info *conn) -> void * {
utils::file::change_to_process_directory();
repertory_init();
#ifdef __APPLE__
conn->want |= FUSE_CAP_VOL_RENAME;
conn->want |= FUSE_CAP_XTIMES;
@ -347,10 +361,11 @@ auto fuse_base::mount(std::vector<std::string> args) -> int {
}
{
struct fuse_args fa = FUSE_ARGS_INIT(static_cast<int>(fuse_argv.size()),
(char **)&fuse_argv[0]);
struct fuse_args fa = FUSE_ARGS_INIT(
static_cast<int>(fuse_argv.size()),
reinterpret_cast<char **>(const_cast<char **>(fuse_argv.data())));
char *mount_location = nullptr;
char *mount_location{nullptr};
#if FUSE_USE_VERSION >= 30
struct fuse_cmdline_opts opts {};
fuse_parse_cmdline(&fa, &opts);
@ -370,8 +385,10 @@ auto fuse_base::mount(std::vector<std::string> args) -> int {
#if FUSE_USE_VERSION < 30
umask(0);
#endif
ret = fuse_main(static_cast<int>(fuse_argv.size()), (char **)&fuse_argv[0],
&fuse_ops_, this);
ret = fuse_main(
static_cast<int>(fuse_argv.size()),
reinterpret_cast<char **>(const_cast<char **>(fuse_argv.data())),
&fuse_ops_, this);
notify_fuse_main_exit(ret);
}

View File

@ -159,29 +159,32 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
}
std::uint64_t handle{};
std::shared_ptr<i_open_file> open_file;
if (is_create_op) {
const auto now = utils::get_file_time_now();
{
std::shared_ptr<i_open_file> open_file;
if (is_create_op) {
const auto now = utils::get_file_time_now();
#ifdef __APPLE__
const auto osx_flags = static_cast<std::uint32_t>(file_info->flags);
const auto osx_flags = static_cast<std::uint32_t>(file_info->flags);
#else
const auto osx_flags = 0U;
const auto osx_flags = 0U;
#endif
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now, now,
is_directory_op, get_effective_gid(), "", mode, now, 0U, osx_flags, 0U,
utils::path::combine(config_.get_cache_directory(),
{utils::create_uuid_string()}),
get_effective_uid(), now);
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now, now,
is_directory_op, get_effective_gid(), "", mode, now, 0U, osx_flags,
0U,
utils::path::combine(config_.get_cache_directory(),
{utils::create_uuid_string()}),
get_effective_uid(), now);
res = fm_->create(api_path, meta, file_info->flags, handle, open_file);
if ((res != api_error::item_exists) && (res != api_error::success)) {
res = fm_->create(api_path, meta, file_info->flags, handle, open_file);
if ((res != api_error::item_exists) && (res != api_error::success)) {
return res;
}
} else if (((res = fm_->open(api_path, is_directory_op, file_info->flags,
handle, open_file)) != api_error::success)) {
return res;
}
} else if (((res = fm_->open(api_path, is_directory_op, file_info->flags,
handle, open_file)) != api_error::success)) {
return res;
}
file_info->fh = handle;
@ -201,7 +204,7 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
return api_error::success;
}
void fuse_drive::destroy_impl(void * /* ptr */) {
void fuse_drive::destroy_impl(void *ptr) {
event_system::instance().raise<drive_unmount_pending>(get_mount_location());
remote_server_.reset();
@ -239,6 +242,8 @@ void 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");
}
fuse_base::destroy_impl(ptr);
}
auto fuse_drive::fallocate_impl(std::string /*api_path*/, int mode,
@ -348,9 +353,9 @@ auto fuse_drive::fsync_impl(std::string /*api_path*/, int datasync,
return open_file->native_operation([&datasync](int handle) -> api_error {
if (handle != REPERTORY_INVALID_HANDLE) {
#ifdef __APPLE__
if ((datasync ? fcntl(handle, F_FULLFSYNC) : fsync(handle)) == -1) {
if ((datasync == 0 ? fsync(handle) : fcntl(handle, F_FULLFSYNC)) == -1) {
#else // __APPLE__
if ((datasync ? fdatasync(handle) : fsync(handle)) == -1) {
if ((datasync == 0 ? fsync(handle) : fdatasync(handle)) == -1) {
#endif // __APPLE__
return api_error::os_error;
}
@ -516,7 +521,11 @@ 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
utils::file::change_to_process_directory();
#if FUSE_USE_VERSION >= 30
auto *ret = fuse_drive_base::init_impl(conn, cfg);
#else
auto *ret = fuse_drive_base::init_impl(conn);
#endif
if (console_enabled_) {
console_consumer_ = std::make_unique<console_consumer>();
@ -570,11 +579,7 @@ void *fuse_drive::init_impl(struct fuse_conn_info *conn) {
fuse_exit(fuse_get_context()->fuse);
}
#if FUSE_USE_VERSION >= 30
return fuse_drive_base::init_impl(conn, cfg);
#else
return fuse_drive_base::init_impl(conn);
#endif
return ret;
}
auto fuse_drive::is_processing(const std::string &api_path) const -> bool {
@ -658,13 +663,6 @@ auto fuse_drive::opendir_impl(std::string api_path,
return api_error::success;
}
void fuse_drive::populate_stat(const directory_item &dir_item,
struct stat &st) const {
fuse_drive_base::populate_stat(dir_item.api_path, dir_item.size,
dir_item.meta, dir_item.directory, provider_,
&st);
}
auto fuse_drive::read_impl(std::string api_path, char *buffer, size_t read_size,
off_t read_offset, struct fuse_file_info *file_info,
std::size_t &bytes_read) -> api_error {
@ -679,15 +677,9 @@ auto fuse_drive::read_impl(std::string api_path, char *buffer, size_t read_size,
return res;
}
// event_system::instance().raise<debug_log>(
// __FUNCTION__, api_path, std::to_string(read_size) + ':' +
// std::to_string(read_offset));
data_buffer data;
res =
open_file->read(read_size, static_cast<std::uint64_t>(read_offset), data);
// event_system::instance().raise<debug_log>(
// __FUNCTION__, api_path, std::to_string(bytes_read) + ':' +
// api_error_to_string(res));
if ((bytes_read = data.size()) != 0U) {
std::memcpy(buffer, data.data(), data.size());
data.clear();
@ -913,8 +905,8 @@ auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size,
#endif
const auto attribute_name_size = strlen(attribute_name.c_str()) + 1U;
if (size >= attribute_name_size) {
strncpy(&buffer[required_size], attribute_name.c_str(),
attribute_name_size);
std::memcpy(&buffer[required_size], attribute_name.data(),
attribute_name_size);
size -= attribute_name_size;
} else {
res = api_error::xattr_buffer_small;
@ -1206,11 +1198,10 @@ auto fuse_drive::statfs_impl(std::string /*api_path*/, struct statvfs *stbuf)
const auto total_bytes = provider_.get_total_drive_space();
const auto total_used = provider_.get_used_drive_space();
const auto used_blocks = utils::divide_with_ceiling(
total_used, static_cast<std::uint64_t>(stbuf->f_frsize));
const auto used_blocks =
utils::divide_with_ceiling(total_used, stbuf->f_frsize);
stbuf->f_files = 4294967295;
stbuf->f_blocks = utils::divide_with_ceiling(
total_bytes, static_cast<std::uint64_t>(stbuf->f_frsize));
stbuf->f_blocks = utils::divide_with_ceiling(total_bytes, stbuf->f_frsize);
stbuf->f_bavail = stbuf->f_bfree =
stbuf->f_blocks == 0U ? 0 : (stbuf->f_blocks - used_blocks);
stbuf->f_ffree = stbuf->f_favail =
@ -1242,20 +1233,20 @@ auto fuse_drive::truncate_impl(std::string api_path, off_t size) -> api_error {
return res;
}
open_file_data ofd = O_RDWR;
std::uint64_t handle{};
std::shared_ptr<i_open_file> open_file;
if ((res = fm_->open(api_path, false, ofd, handle, open_file)) !=
api_error::success) {
return res;
{
open_file_data ofd{O_RDWR};
std::shared_ptr<i_open_file> open_file;
if ((res = fm_->open(api_path, false, ofd, handle, open_file)) !=
api_error::success) {
return res;
}
res = open_file->resize(static_cast<std::uint64_t>(size));
}
const auto cleanup = [this, &handle](const api_error &err) -> api_error {
fm_->close(handle);
return err;
};
return cleanup(open_file->resize(static_cast<std::uint64_t>(size)));
fm_->close(handle);
return res;
}
auto fuse_drive::unlink_impl(std::string api_path) -> api_error {

View File

@ -232,9 +232,9 @@ auto fuse_drive_base::get_mode_from_meta(const api_meta_map &meta) -> mode_t {
void fuse_drive_base::get_timespec_from_meta(const api_meta_map &meta,
const std::string &name,
struct timespec &ts) {
const auto t = utils::string::to_uint64(meta.at(name));
ts.tv_nsec = t % NANOS_PER_SECOND;
ts.tv_sec = t / NANOS_PER_SECOND;
const auto meta_time = utils::string::to_int64(meta.at(name));
ts.tv_nsec = meta_time % NANOS_PER_SECOND;
ts.tv_sec = meta_time / NANOS_PER_SECOND;
}
auto fuse_drive_base::get_uid_from_meta(const api_meta_map &meta) -> uid_t {
@ -305,21 +305,22 @@ void fuse_drive_base::populate_stat(const std::string &api_path,
i_provider &provider, struct stat *st) {
memset(st, 0, sizeof(struct stat));
st->st_nlink =
(directory
? 2 + (size_or_count ? size_or_count
: provider.get_directory_item_count(api_path))
: 1);
(directory ? 2 + (size_or_count == 0U
? provider.get_directory_item_count(api_path)
: size_or_count)
: 1);
if (directory) {
st->st_blocks = 0;
} else {
st->st_size = size_or_count;
static const auto block_size_stat = static_cast<std::uint64_t>(512u);
static const auto block_size = static_cast<std::uint64_t>(4096u);
st->st_size = static_cast<off_t>(size_or_count);
static const auto block_size_stat = static_cast<std::uint64_t>(512U);
static const auto block_size = static_cast<std::uint64_t>(4096U);
const auto size = utils::divide_with_ceiling(
static_cast<std::uint64_t>(st->st_size), block_size) *
block_size;
st->st_blocks = std::max(block_size / block_size_stat,
utils::divide_with_ceiling(size, block_size_stat));
st->st_blocks = static_cast<blkcnt_t>(
std::max(block_size / block_size_stat,
utils::divide_with_ceiling(size, block_size_stat)));
}
st->st_gid = get_gid_from_meta(meta);
st->st_mode = (directory ? S_IFDIR : S_IFREG) | get_mode_from_meta(meta);
@ -344,9 +345,9 @@ void fuse_drive_base::populate_stat(const std::string &api_path,
void fuse_drive_base::set_timespec_from_meta(const api_meta_map &meta,
const std::string &name,
struct timespec &ts) {
const auto t = utils::string::to_uint64(meta.at(name));
ts.tv_nsec = t % NANOS_PER_SECOND;
ts.tv_sec = t / NANOS_PER_SECOND;
const auto meta_time = utils::string::to_int64(meta.at(name));
ts.tv_nsec = meta_time % NANOS_PER_SECOND;
ts.tv_sec = meta_time / NANOS_PER_SECOND;
}
} // namespace repertory

View File

@ -40,7 +40,7 @@ auto remote_client::fuse_access(const char *path, const std::int32_t &mask)
request.encode(path);
request.encode(mask);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -50,7 +50,7 @@ auto remote_client::fuse_chflags(const char *path, std::uint32_t flags)
request.encode(path);
request.encode(flags);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -60,7 +60,7 @@ auto remote_client::fuse_chmod(const char *path, const remote::file_mode &mode)
request.encode(path);
request.encode(mode);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -72,12 +72,12 @@ auto remote_client::fuse_chown(const char *path, const remote::user_id &uid,
request.encode(uid);
request.encode(gid);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
auto remote_client::fuse_destroy() -> packet::error_type {
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, service_flags);
}
@ -90,7 +90,7 @@ std::int32_t &mode, const remote::file_offset &offset, const remote::file_offset
request.encode(length);
request.encode(handle);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags {};
return packetClient_.send(__FUNCTION__, request, service_flags);
}*/
@ -105,12 +105,12 @@ auto remote_client::fuse_fgetattr(const char *path, remote::stat &st,
request.encode(gid_);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
if (ret == 0) {
if ((ret = response.decode(st)) == 0) {
std::uint8_t d = 0u;
std::uint8_t d{};
if ((ret = response.decode(d)) == 0) {
directory = static_cast<bool>(d);
}
@ -129,7 +129,7 @@ auto remote_client::fuse_fsetattr_x(const char *path,
request.encode(attr);
request.encode(handle);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -141,7 +141,7 @@ auto remote_client::fuse_fsync(const char *path, const std::int32_t &datasync,
request.encode(datasync);
request.encode(handle);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -154,7 +154,7 @@ auto remote_client::fuse_ftruncate(const char *path,
request.encode(size);
request.encode(handle);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -166,7 +166,7 @@ auto remote_client::fuse_getattr(const char *path, remote::stat &st,
request.encode(gid_);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
if (ret == 0) {
@ -188,7 +188,7 @@ packet request; request.encode(path); request.encode(name);
request.encode(size);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags {};
if ((ret = packetClient_.send(__FUNCTION__, request, response,
service_flags)) == 0) { remote::file_size size2; if ((ret =
response.decode(size2)) == 0) { if (size2 >
@ -211,7 +211,7 @@ packet::error_type ret = 0; if (size > std::numeric_limits<std::size_t>::max())
request.encode(position);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags {};
if ((ret = packetClient_.send(__FUNCTION__, request, response,
service_flags)) == 0) { remote::file_size size2; if ((ret =
response.decode(size2)) == 0) { if (size2 >
@ -233,7 +233,7 @@ auto remote_client::fuse_getxtimes(const char *path,
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);
if (ret == 0) {
@ -245,7 +245,7 @@ auto remote_client::fuse_getxtimes(const char *path,
}
auto remote_client::fuse_init() -> packet::error_type {
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, service_flags);
}
@ -255,7 +255,7 @@ std::numeric_limits<std::size_t>::max()) { ret = -ERANGE; } else { packet
request; request.encode(path); request.encode(size);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags {};
if ((ret = packetClient_.send(__FUNCTION__, request, response,
service_flags)) == 0) { remote::file_size size2; if ((ret =
response.decode(size2)) == 0) { if (size2 >
@ -276,7 +276,7 @@ auto remote_client::fuse_mkdir(const char *path, const remote::file_mode &mode)
request.encode(path);
request.encode(mode);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -286,7 +286,7 @@ auto remote_client::fuse_opendir(const char *path, remote::file_handle &handle)
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);
if (ret == 0) {
@ -306,7 +306,7 @@ auto remote_client::fuse_create(const char *path, const remote::file_mode &mode,
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);
if (ret == 0) {
@ -324,7 +324,7 @@ auto remote_client::fuse_open(const char *path, const remote::open_flags &flags,
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);
if (ret == 0) {
@ -346,11 +346,11 @@ auto remote_client::fuse_read(const char *path, char *buffer,
request.encode(handle);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
if (ret > 0) {
memcpy(buffer, response.current_pointer(), ret);
memcpy(buffer, response.current_pointer(), static_cast<std::size_t>(ret));
}
return ret;
@ -362,7 +362,7 @@ auto remote_client::fuse_rename(const char *from, const char *to)
request.encode(from);
request.encode(to);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -382,7 +382,7 @@ auto remote_client::fuse_write(const char *path, const char *buffer,
request.encode(write_offset);
request.encode(handle);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -402,7 +402,7 @@ auto remote_client::fuse_write_base64(const char *path, const char *buffer,
request.encode(write_offset);
request.encode(handle);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -416,7 +416,7 @@ auto remote_client::fuse_readdir(const char *path,
request.encode(handle);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
if (ret == 0) {
@ -433,7 +433,7 @@ auto remote_client::fuse_release(const char *path,
request.encode(path);
request.encode(handle);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -444,7 +444,7 @@ auto remote_client::fuse_releasedir(const char *path,
request.encode(path);
request.encode(handle);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -452,7 +452,7 @@ auto remote_client::fuse_releasedir(const char *path,
char *name) override { packet request; request.encode(path);
request.Encode(name);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags {};
return packetClient_.send(__FUNCTION__, request, service_flags);
}*/
@ -460,7 +460,7 @@ auto remote_client::fuse_rmdir(const char *path) -> packet::error_type {
packet request;
request.encode(path);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -470,7 +470,7 @@ auto remote_client::fuse_setattr_x(const char *path, remote::setattr_x &attr)
request.encode(path);
request.encode(attr);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -481,7 +481,7 @@ auto remote_client::fuse_setbkuptime(const char *path,
request.encode(path);
request.encode(bkuptime);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -492,7 +492,7 @@ auto remote_client::fuse_setchgtime(const char *path,
request.encode(path);
request.encode(chgtime);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -503,7 +503,7 @@ auto remote_client::fuse_setcrtime(const char *path,
request.encode(path);
request.encode(crtime);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -511,7 +511,7 @@ auto remote_client::fuse_setvolname(const char *volname) -> packet::error_type {
packet request;
request.encode(volname);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -523,7 +523,7 @@ request; request.encode(path); request.encode(name); request.encode(size);
request.encode(value, static_cast<std::size_t>(size));
request.encode(flags);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags {};
ret = packetClient_.send(__FUNCTION__, request, service_flags);
}
@ -538,7 +538,7 @@ packet request; request.encode(path); request.Encode(name);
request.Encode(size); request.encode(value, static_cast<std::size_t>(size));
request.encode(flags); request.encode(position);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags {};
ret = packetClient_.send(__FUNCTION__, request, service_flags);
}
@ -552,7 +552,7 @@ auto remote_client::fuse_statfs(const char *path, std::uint64_t frsize,
request.encode(frsize);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
if (ret == 0) {
@ -569,7 +569,7 @@ auto remote_client::fuse_statfs_x(const char *path, std::uint64_t bsize,
request.encode(bsize);
packet response;
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
auto ret =
packet_client_.send(__FUNCTION__, request, response, service_flags);
if (ret == 0) {
@ -586,7 +586,7 @@ auto remote_client::fuse_truncate(const char *path,
request.encode(path);
request.encode(size);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -594,7 +594,7 @@ auto remote_client::fuse_unlink(const char *path) -> packet::error_type {
packet request;
request.encode(path);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -607,7 +607,7 @@ auto remote_client::fuse_utimens(const char *path, const remote::file_time *tv,
request.encode(op0);
request.encode(op1);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}
@ -618,7 +618,7 @@ auto remote_client::json_create_directory_snapshot(const std::string &path,
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);
if (ret == 0) {
@ -637,7 +637,7 @@ auto remote_client::json_read_directory_snapshot(
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);
if (ret == 0) {
@ -654,7 +654,7 @@ auto remote_client::json_release_directory_snapshot(
request.encode(path);
request.encode(handle);
std::uint32_t service_flags = 0u;
std::uint32_t service_flags{};
return packet_client_.send(__FUNCTION__, request, service_flags);
}

View File

@ -54,7 +54,7 @@ api_error remote_fuse_drive::chflags_impl(std::string api_path,
#if FUSE_USE_VERSION >= 30
auto remote_fuse_drive::chmod_impl(std::string api_path, mode_t mode,
struct fuse_file_info * /*fi*/)
struct fuse_file_info * /*f_info*/)
-> api_error {
#else
auto remote_fuse_drive::chmod_impl(std::string api_path, mode_t mode)
@ -66,7 +66,7 @@ auto remote_fuse_drive::chmod_impl(std::string api_path, mode_t mode)
#if FUSE_USE_VERSION >= 30
auto remote_fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid,
struct fuse_file_info * /*fi*/)
struct fuse_file_info * /*f_info*/)
-> api_error {
#else
auto remote_fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid)
@ -77,14 +77,15 @@ auto remote_fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid)
}
auto remote_fuse_drive::create_impl(std::string api_path, mode_t mode,
struct fuse_file_info *fi) -> api_error {
struct fuse_file_info *f_info)
-> api_error {
return utils::to_api_error(remote_instance_->fuse_create(
api_path.c_str(), static_cast<remote::file_mode>(mode),
remote::create_open_flags(static_cast<std::uint32_t>(fi->flags)),
fi->fh));
remote::create_open_flags(static_cast<std::uint32_t>(f_info->flags)),
f_info->fh));
}
void remote_fuse_drive::destroy_impl(void * /*ptr*/) {
void remote_fuse_drive::destroy_impl(void *ptr) {
event_system::instance().raise<drive_unmount_pending>(get_mount_location());
if (server_) {
@ -107,17 +108,21 @@ void remote_fuse_drive::destroy_impl(void * /*ptr*/) {
}
event_system::instance().raise<drive_unmounted>(get_mount_location());
fuse_base::destroy_impl(ptr);
}
auto remote_fuse_drive::fgetattr_impl(std::string api_path, struct stat *st,
struct fuse_file_info *fi) -> api_error {
remote::stat r{};
auto remote_fuse_drive::fgetattr_impl(std::string api_path,
struct stat *unix_st,
struct fuse_file_info *f_info)
-> api_error {
remote::stat r_stat{};
auto directory = false;
const auto res =
remote_instance_->fuse_fgetattr(api_path.c_str(), r, directory, fi->fh);
const auto res = remote_instance_->fuse_fgetattr(api_path.c_str(), r_stat,
directory, f_info->fh);
if (res == 0) {
populate_stat(r, directory, *st);
populate_stat(r_stat, directory, *unix_st);
}
return utils::to_api_error(res);
@ -126,7 +131,7 @@ auto remote_fuse_drive::fgetattr_impl(std::string api_path, struct stat *st,
#ifdef __APPLE__
api_error remote_fuse_drive::fsetattr_x_impl(std::string api_path,
struct setattr_x *attr,
struct fuse_file_info *fi) {
struct fuse_file_info *f_info) {
remote::setattr_x attributes{};
attributes.valid = attr->valid;
attributes.mode = attr->mode;
@ -144,41 +149,42 @@ api_error remote_fuse_drive::fsetattr_x_impl(std::string api_path,
attributes.bkuptime =
((attr->bkuptime.tv_sec * NANOS_PER_SECOND) + attr->bkuptime.tv_nsec);
attributes.flags = attr->flags;
return utils::to_api_error(
remote_instance_->fuse_fsetattr_x(api_path.c_str(), attributes, fi->fh));
return utils::to_api_error(remote_instance_->fuse_fsetattr_x(
api_path.c_str(), attributes, f_info->fh));
}
#endif
auto remote_fuse_drive::fsync_impl(std::string api_path, int datasync,
struct fuse_file_info *fi) -> api_error {
struct fuse_file_info *f_info) -> api_error {
return utils::to_api_error(
remote_instance_->fuse_fsync(api_path.c_str(), datasync, fi->fh));
remote_instance_->fuse_fsync(api_path.c_str(), datasync, f_info->fh));
}
#if FUSE_USE_VERSION < 30
auto remote_fuse_drive::ftruncate_impl(std::string api_path, off_t size,
struct fuse_file_info *fi) -> api_error {
struct fuse_file_info *f_info)
-> api_error {
return utils::to_api_error(
remote_instance_->fuse_ftruncate(api_path.c_str(), size, fi->fh));
remote_instance_->fuse_ftruncate(api_path.c_str(), size, f_info->fh));
}
#endif
#if FUSE_USE_VERSION >= 30
auto remote_fuse_drive::getattr_impl(std::string api_path, struct stat *st,
struct fuse_file_info * /*fi*/)
auto remote_fuse_drive::getattr_impl(std::string api_path, struct stat *unix_st,
struct fuse_file_info * /*f_info*/)
-> api_error {
#else
auto remote_fuse_drive::getattr_impl(std::string api_path, struct stat *st)
auto remote_fuse_drive::getattr_impl(std::string api_path, struct stat *unix_st)
-> api_error {
#endif
bool directory = false;
remote::stat r{};
remote::stat r_stat{};
const auto res =
remote_instance_->fuse_getattr(api_path.c_str(), r, directory);
remote_instance_->fuse_getattr(api_path.c_str(), r_stat, directory);
if (res == 0) {
populate_stat(r, directory, *st);
populate_stat(r_stat, directory, *unix_st);
}
return utils::to_api_error(res);
@ -214,7 +220,12 @@ 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
utils::file::change_to_process_directory();
#if FUSE_USE_VERSION >= 30
auto *ret = fuse_base::init_impl(conn, cfg);
#else
auto *ret = fuse_base::init_impl(conn);
#endif
was_mounted_ = true;
if (console_enabled_) {
@ -241,11 +252,7 @@ auto remote_fuse_drive::init_impl(struct fuse_conn_info *conn) -> void * {
event_system::instance().raise<drive_mounted>(get_mount_location());
}
#if FUSE_USE_VERSION >= 30
return fuse_base::init_impl(conn, cfg);
#else
return fuse_base::init_impl(conn);
#endif
return ret;
}
auto remote_fuse_drive::mkdir_impl(std::string api_path, mode_t mode)
@ -264,76 +271,88 @@ void remote_fuse_drive::notify_fuse_main_exit(int &ret) {
}
auto remote_fuse_drive::open_impl(std::string api_path,
struct fuse_file_info *fi) -> api_error {
struct fuse_file_info *f_info) -> api_error {
return utils::to_api_error(remote_instance_->fuse_open(
api_path.c_str(), remote::create_open_flags(fi->flags), fi->fh));
api_path.c_str(),
remote::create_open_flags(static_cast<std::uint32_t>(f_info->flags)),
f_info->fh));
}
auto remote_fuse_drive::opendir_impl(std::string api_path,
struct fuse_file_info *fi) -> api_error {
struct fuse_file_info *f_info)
-> api_error {
return utils::to_api_error(
remote_instance_->fuse_opendir(api_path.c_str(), fi->fh));
remote_instance_->fuse_opendir(api_path.c_str(), f_info->fh));
}
void remote_fuse_drive::populate_stat(const remote::stat &r, bool directory,
struct stat &st) {
memset(&st, 0, sizeof(struct stat));
void remote_fuse_drive::populate_stat(const remote::stat &r_stat,
bool directory, struct stat &unix_st) {
memset(&unix_st, 0, sizeof(struct stat));
#ifdef __APPLE__
st.st_blksize = 0;
unix_st.st_blksize = 0;
st.st_atimespec.tv_nsec = r.st_atimespec % NANOS_PER_SECOND;
st.st_atimespec.tv_sec = r.st_atimespec / NANOS_PER_SECOND;
unix_st.st_atimespec.tv_nsec = r_stat.st_atimespec % NANOS_PER_SECOND;
unix_st.st_atimespec.tv_sec = r_stat.st_atimespec / NANOS_PER_SECOND;
st.st_birthtimespec.tv_nsec = r.st_birthtimespec % NANOS_PER_SECOND;
st.st_birthtimespec.tv_sec = r.st_birthtimespec / NANOS_PER_SECOND;
unix_st.st_birthtimespec.tv_nsec = r_stat.st_birthtimespec % NANOS_PER_SECOND;
unix_st.st_birthtimespec.tv_sec = r_stat.st_birthtimespec / NANOS_PER_SECOND;
st.st_ctimespec.tv_nsec = r.st_ctimespec % NANOS_PER_SECOND;
st.st_ctimespec.tv_sec = r.st_ctimespec / NANOS_PER_SECOND;
unix_st.st_ctimespec.tv_nsec = r_stat.st_ctimespec % NANOS_PER_SECOND;
unix_st.st_ctimespec.tv_sec = r_stat.st_ctimespec / NANOS_PER_SECOND;
st.st_mtimespec.tv_nsec = r.st_mtimespec % NANOS_PER_SECOND;
st.st_mtimespec.tv_sec = r.st_mtimespec / NANOS_PER_SECOND;
unix_st.st_mtimespec.tv_nsec = r_stat.st_mtimespec % NANOS_PER_SECOND;
unix_st.st_mtimespec.tv_sec = r_stat.st_mtimespec / NANOS_PER_SECOND;
st.st_flags = r.st_flags;
unix_st.st_flags = r_stat.st_flags;
#else
st.st_blksize = 4096;
unix_st.st_blksize = 4096;
st.st_atim.tv_nsec = r.st_atimespec % NANOS_PER_SECOND;
st.st_atim.tv_sec = r.st_atimespec / NANOS_PER_SECOND;
unix_st.st_atim.tv_nsec =
static_cast<suseconds_t>(r_stat.st_atimespec % NANOS_PER_SECOND);
unix_st.st_atim.tv_sec =
static_cast<suseconds_t>(r_stat.st_atimespec / NANOS_PER_SECOND);
st.st_ctim.tv_nsec = r.st_ctimespec % NANOS_PER_SECOND;
st.st_ctim.tv_sec = r.st_ctimespec / NANOS_PER_SECOND;
unix_st.st_ctim.tv_nsec =
static_cast<suseconds_t>(r_stat.st_ctimespec % NANOS_PER_SECOND);
unix_st.st_ctim.tv_sec =
static_cast<suseconds_t>(r_stat.st_ctimespec / NANOS_PER_SECOND);
st.st_mtim.tv_nsec = r.st_mtimespec % NANOS_PER_SECOND;
st.st_mtim.tv_sec = r.st_mtimespec / NANOS_PER_SECOND;
unix_st.st_mtim.tv_nsec =
static_cast<suseconds_t>(r_stat.st_mtimespec % NANOS_PER_SECOND);
unix_st.st_mtim.tv_sec =
static_cast<suseconds_t>(r_stat.st_mtimespec / NANOS_PER_SECOND);
#endif
if (not directory) {
const auto block_size_stat = static_cast<std::uint64_t>(512u);
const auto block_size = static_cast<std::uint64_t>(4096u);
const auto size = utils::divide_with_ceiling(
static_cast<std::uint64_t>(st.st_size), block_size) *
block_size;
st.st_blocks = std::max(block_size / block_size_stat,
utils::divide_with_ceiling(size, block_size_stat));
const auto block_size_stat = static_cast<std::uint64_t>(512U);
const auto block_size = static_cast<std::uint64_t>(4096U);
const auto size =
utils::divide_with_ceiling(static_cast<std::uint64_t>(unix_st.st_size),
block_size) *
block_size;
unix_st.st_blocks = static_cast<blkcnt_t>(
std::max(block_size / block_size_stat,
utils::divide_with_ceiling(size, block_size_stat)));
}
st.st_gid = r.st_gid;
st.st_mode = (directory ? S_IFDIR : S_IFREG) | r.st_mode;
unix_st.st_gid = r_stat.st_gid;
unix_st.st_mode = (directory ? S_IFDIR : S_IFREG) | r_stat.st_mode;
st.st_nlink = r.st_nlink;
st.st_size = r.st_size;
st.st_uid = r.st_uid;
unix_st.st_nlink = r_stat.st_nlink;
unix_st.st_size = static_cast<off_t>(r_stat.st_size);
unix_st.st_uid = r_stat.st_uid;
}
auto remote_fuse_drive::read_impl(std::string api_path, char *buffer,
size_t read_size, off_t read_offset,
struct fuse_file_info *fi,
struct fuse_file_info *f_info,
std::size_t &bytes_read) -> api_error {
auto res = remote_instance_->fuse_read(api_path.c_str(), buffer, read_size,
read_offset, fi->fh);
auto res = remote_instance_->fuse_read(
api_path.c_str(), buffer, read_size,
static_cast<remote::file_offset>(read_offset), f_info->fh);
if (res >= 0) {
bytes_read = res;
bytes_read = static_cast<size_t>(res);
return api_error::success;
}
@ -343,19 +362,22 @@ auto remote_fuse_drive::read_impl(std::string api_path, char *buffer,
#if FUSE_USE_VERSION >= 30
auto remote_fuse_drive::readdir_impl(std::string api_path, void *buf,
fuse_fill_dir_t fuse_fill_dir,
off_t offset, struct fuse_file_info *fi,
off_t offset,
struct fuse_file_info *f_info,
fuse_readdir_flags /*flags*/)
-> api_error {
#else
auto remote_fuse_drive::readdir_impl(std::string api_path, void *buf,
fuse_fill_dir_t fuse_fill_dir,
off_t offset, struct fuse_file_info *fi)
off_t offset,
struct fuse_file_info *f_info)
-> api_error {
#endif
std::string item_path;
int res = 0;
while ((res = remote_instance_->fuse_readdir(api_path.c_str(), offset, fi->fh,
item_path)) == 0) {
while ((res = remote_instance_->fuse_readdir(
api_path.c_str(), static_cast<remote::file_offset>(offset),
f_info->fh, item_path)) == 0) {
if ((item_path != ".") && (item_path != "..")) {
item_path = utils::path::strip_to_file_name(item_path);
}
@ -378,16 +400,17 @@ auto remote_fuse_drive::readdir_impl(std::string api_path, void *buf,
}
auto remote_fuse_drive::release_impl(std::string api_path,
struct fuse_file_info *fi) -> api_error {
struct fuse_file_info *f_info)
-> api_error {
return utils::to_api_error(
remote_instance_->fuse_release(api_path.c_str(), fi->fh));
remote_instance_->fuse_release(api_path.c_str(), f_info->fh));
}
auto remote_fuse_drive::releasedir_impl(std::string api_path,
struct fuse_file_info *fi)
struct fuse_file_info *f_info)
-> api_error {
return utils::to_api_error(
remote_instance_->fuse_releasedir(api_path.c_str(), fi->fh));
remote_instance_->fuse_releasedir(api_path.c_str(), f_info->fh));
}
#if FUSE_USE_VERSION >= 30
@ -471,8 +494,8 @@ api_error remote_fuse_drive::statfs_x_impl(std::string api_path,
stbuf->f_ffree = r.f_ffree;
stbuf->f_files = r.f_files;
stbuf->f_owner = getuid();
strncpy(&stbuf->f_mntonname[0u], get_mount_location().c_str(), MNAMELEN);
strncpy(&stbuf->f_mntfromname[0u], &r.f_mntfromname[0], MNAMELEN);
strncpy(&stbuf->f_mntonname[0U], get_mount_location().c_str(), MNAMELEN);
strncpy(&stbuf->f_mntfromname[0U], &r.f_mntfromname[0U], MNAMELEN);
}
} else {
res = -errno;
@ -485,15 +508,16 @@ auto remote_fuse_drive::statfs_impl(std::string api_path, struct statvfs *stbuf)
-> api_error {
auto res = statvfs(config_.get_data_directory().c_str(), stbuf);
if (res == 0) {
remote::statfs r{};
if ((res = remote_instance_->fuse_statfs(api_path.c_str(), stbuf->f_frsize,
r)) == 0) {
stbuf->f_blocks = r.f_blocks;
stbuf->f_bavail = r.f_bavail;
stbuf->f_bfree = r.f_bfree;
stbuf->f_ffree = r.f_ffree;
stbuf->f_favail = r.f_favail;
stbuf->f_files = r.f_files;
remote::statfs r_stat{};
res = remote_instance_->fuse_statfs(api_path.c_str(), stbuf->f_frsize,
r_stat);
if (res == 0) {
stbuf->f_blocks = r_stat.f_blocks;
stbuf->f_bavail = r_stat.f_bavail;
stbuf->f_bfree = r_stat.f_bfree;
stbuf->f_ffree = r_stat.f_ffree;
stbuf->f_favail = r_stat.f_favail;
stbuf->f_files = r_stat.f_files;
}
} else {
res = -errno;
@ -505,14 +529,14 @@ auto remote_fuse_drive::statfs_impl(std::string api_path, struct statvfs *stbuf)
#if FUSE_USE_VERSION >= 30
auto remote_fuse_drive::truncate_impl(std::string api_path, off_t size,
struct fuse_file_info * /*fi*/)
struct fuse_file_info * /*f_info*/)
-> api_error {
#else
auto remote_fuse_drive::truncate_impl(std::string api_path, off_t size)
-> api_error {
#endif
return utils::to_api_error(
remote_instance_->fuse_truncate(api_path.c_str(), size));
return utils::to_api_error(remote_instance_->fuse_truncate(
api_path.c_str(), static_cast<remote::file_offset>(size)));
}
auto remote_fuse_drive::unlink_impl(std::string api_path) -> api_error {
@ -522,31 +546,35 @@ auto remote_fuse_drive::unlink_impl(std::string api_path) -> api_error {
#if FUSE_USE_VERSION >= 30
auto remote_fuse_drive::utimens_impl(std::string api_path,
const struct timespec tv[2],
struct fuse_file_info * /*fi*/)
struct fuse_file_info * /*f_info*/)
-> api_error {
#else
auto remote_fuse_drive::utimens_impl(std::string api_path,
const struct timespec tv[2]) -> api_error {
#endif
remote::file_time rtv[2u] = {0};
if (tv) {
rtv[0u] = tv[0u].tv_nsec + (tv[0u].tv_sec * NANOS_PER_SECOND);
rtv[1u] = tv[1u].tv_nsec + (tv[1u].tv_sec * NANOS_PER_SECOND);
remote::file_time rtv[2U] = {0};
if (tv != nullptr) {
rtv[0U] = static_cast<remote::file_time>(
tv[0U].tv_nsec + (tv[0U].tv_sec * NANOS_PER_SECOND));
rtv[1U] = static_cast<remote::file_time>(
tv[1U].tv_nsec + (tv[1U].tv_sec * NANOS_PER_SECOND));
}
return utils::to_api_error(remote_instance_->fuse_utimens(
api_path.c_str(), rtv, tv ? tv[0u].tv_nsec : 0u,
tv ? tv[1u].tv_nsec : 0u));
api_path.c_str(), &rtv[0U],
static_cast<std::uint64_t>(tv == nullptr ? 0 : tv[0U].tv_nsec),
static_cast<std::uint64_t>(tv == nullptr ? 0 : tv[1U].tv_nsec)));
}
auto remote_fuse_drive::write_impl(std::string api_path, const char *buffer,
size_t write_size, off_t write_offset,
struct fuse_file_info *fi,
struct fuse_file_info *f_info,
std::size_t &bytes_written) -> api_error {
const auto res = remote_instance_->fuse_write(
api_path.c_str(), buffer, write_size, write_offset, fi->fh);
api_path.c_str(), buffer, write_size,
static_cast<remote::file_offset>(write_offset), f_info->fh);
if (res >= 0) {
bytes_written = res;
bytes_written = static_cast<std::size_t>(res);
return api_error::success;
}

View File

@ -157,14 +157,14 @@ void remote_server::populate_stat(const struct stat64 &st1, remote::stat &st) {
#else
st.st_flags = 0;
st.st_atimespec =
st1.st_atim.tv_nsec + (st1.st_atim.tv_sec * NANOS_PER_SECOND);
st.st_birthtimespec =
st1.st_ctim.tv_nsec + (st1.st_ctim.tv_sec * NANOS_PER_SECOND);
st.st_ctimespec =
st1.st_ctim.tv_nsec + (st1.st_ctim.tv_sec * NANOS_PER_SECOND);
st.st_mtimespec =
st1.st_mtim.tv_nsec + (st1.st_mtim.tv_sec * NANOS_PER_SECOND);
st.st_atimespec = static_cast<remote::file_time>(
st1.st_atim.tv_nsec + (st1.st_atim.tv_sec * NANOS_PER_SECOND));
st.st_birthtimespec = static_cast<remote::file_time>(
st1.st_ctim.tv_nsec + (st1.st_ctim.tv_sec * NANOS_PER_SECOND));
st.st_ctimespec = static_cast<remote::file_time>(
st1.st_ctim.tv_nsec + (st1.st_ctim.tv_sec * NANOS_PER_SECOND));
st.st_mtimespec = static_cast<remote::file_time>(
st1.st_mtim.tv_nsec + (st1.st_mtim.tv_sec * NANOS_PER_SECOND));
#endif
st.st_blksize = static_cast<remote::block_size>(st1.st_blksize);
st.st_blocks = static_cast<remote::block_count>(st1.st_blocks);
@ -337,8 +337,9 @@ auto remote_server::fuse_fsetattr_x(const char *path,
if (res >= 0) {
if (SETATTR_WANTS_SIZE(&attr)) {
res = (handle == static_cast<std::uint64_t>(REPERTORY_INVALID_HANDLE))
? truncate(file_path.c_str(), attr.size)
: ftruncate(static_cast<native_handle>(handle), attr.size);
? truncate(file_path.c_str(), static_cast<off_t>(attr.size))
: ftruncate(static_cast<native_handle>(handle),
static_cast<off_t>(attr.size));
}
}
@ -365,18 +366,20 @@ auto remote_server::fuse_fsetattr_x(const char *path,
if (res >= 0) {
if (SETATTR_WANTS_MODTIME(&attr)) {
struct timeval tv[2];
struct timeval val[2];
if (SETATTR_WANTS_ACCTIME(&attr)) {
tv[0].tv_sec = attr.acctime / NANOS_PER_SECOND;
tv[0].tv_usec = (attr.acctime % NANOS_PER_SECOND) / 1000;
val[0U].tv_sec = static_cast<time_t>(attr.acctime / NANOS_PER_SECOND);
val[0U].tv_usec =
static_cast<time_t>((attr.acctime % NANOS_PER_SECOND) / 1000);
} else {
gettimeofday(&tv[0], nullptr);
gettimeofday(&val[0U], nullptr);
}
tv[1].tv_sec = attr.modtime / NANOS_PER_SECOND;
tv[1].tv_usec = (attr.modtime % NANOS_PER_SECOND) / 1000;
val[1U].tv_sec = static_cast<time_t>(attr.modtime / NANOS_PER_SECOND);
val[1U].tv_usec =
static_cast<time_t>((attr.modtime % NANOS_PER_SECOND) / 1000);
res = utimes(file_path.c_str(), tv);
res = utimes(file_path.c_str(), &val[0U]);
}
}
@ -421,7 +424,8 @@ auto remote_server::fuse_ftruncate(const char *path,
auto res = has_open_info(static_cast<native_handle>(handle), EBADF);
if (res == 0) {
res = ftruncate(static_cast<native_handle>(handle), size);
res =
ftruncate(static_cast<native_handle>(handle), static_cast<off_t>(size));
}
auto ret = ((res < 0) ? -errno : 0);
@ -717,7 +721,8 @@ auto remote_server::fuse_rmdir(const char *path) -> packet::error_type {
auto remote_server::fuse_setattr_x(const char *path, remote::setattr_x &attr)
-> packet::error_type {
const auto file_path = construct_path(path);
auto ret = fuse_fsetattr_x(path, attr, REPERTORY_INVALID_HANDLE);
auto ret = fuse_fsetattr_x(
path, attr, static_cast<remote::file_handle>(REPERTORY_INVALID_HANDLE));
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, file_path, ret);
return ret;
}
@ -809,11 +814,9 @@ auto remote_server::fuse_statfs(const char *path, std::uint64_t frsize,
const auto total_bytes = drive_.get_total_drive_space();
const auto total_used = drive_.get_used_drive_space();
const auto used_blocks = utils::divide_with_ceiling(
total_used, static_cast<std::uint64_t>(frsize));
const auto used_blocks = utils::divide_with_ceiling(total_used, frsize);
st.f_files = 4294967295;
st.f_blocks = utils::divide_with_ceiling(total_bytes,
static_cast<std::uint64_t>(frsize));
st.f_blocks = utils::divide_with_ceiling(total_bytes, frsize);
st.f_bavail = st.f_bfree = st.f_blocks ? (st.f_blocks - used_blocks) : 0;
st.f_ffree = st.f_favail = st.f_files - drive_.get_total_item_count();
@ -827,16 +830,15 @@ auto remote_server::fuse_statfs_x(const char *path, std::uint64_t bsize,
const auto total_bytes = drive_.get_total_drive_space();
const auto total_used = drive_.get_used_drive_space();
const auto used_blocks =
utils::divide_with_ceiling(total_used, static_cast<std::uint64_t>(bsize));
const auto used_blocks = utils::divide_with_ceiling(total_used, bsize);
st.f_files = 4294967295;
st.f_blocks = utils::divide_with_ceiling(total_bytes,
static_cast<std::uint64_t>(bsize));
st.f_blocks = utils::divide_with_ceiling(total_bytes, bsize);
st.f_bavail = st.f_bfree = st.f_blocks ? (st.f_blocks - used_blocks) : 0;
st.f_ffree = st.f_favail = st.f_files - drive_.get_total_item_count();
strncpy(&st.f_mntfromname[0],
std::memset(&st.f_mntfromname[0U], 0, sizeof(st.f_mntfromname));
strncpy(&st.f_mntfromname[0U],
(utils::create_volume_label(config_.get_provider_type())).c_str(),
1024);
sizeof(st.f_mntfromname) - 1U);
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, file_path, 0);
return 0;
@ -846,7 +848,7 @@ auto remote_server::fuse_truncate(const char *path,
const remote::file_offset &size)
-> packet::error_type {
const auto file_path = construct_path(path);
const auto res = truncate(file_path.c_str(), size);
const auto res = truncate(file_path.c_str(), static_cast<off_t>(size));
auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, file_path, ret);
return ret;
@ -867,22 +869,23 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
struct timespec tv2[2] = {{0, 0}};
if ((op0 == UTIME_NOW) || (op0 == UTIME_OMIT)) {
tv2[0].tv_nsec = op0;
tv2[0].tv_sec = 0;
tv2[0U].tv_nsec = static_cast<time_t>(op0);
tv2[0U].tv_sec = 0;
} else {
tv2[0].tv_nsec = tv[0] % NANOS_PER_SECOND;
tv2[0].tv_sec = tv[0] / NANOS_PER_SECOND;
tv2[0U].tv_nsec = static_cast<time_t>(tv[0U] % NANOS_PER_SECOND);
tv2[0U].tv_sec = static_cast<time_t>(tv[0U] / NANOS_PER_SECOND);
}
if ((op1 == UTIME_NOW) || (op1 == UTIME_OMIT)) {
tv2[1].tv_nsec = op1;
tv2[1].tv_sec = 0;
tv2[1U].tv_nsec = static_cast<time_t>(op1);
tv2[1U].tv_sec = 0;
} else {
tv2[1].tv_nsec = tv[1] % NANOS_PER_SECOND;
tv2[1].tv_sec = tv[1] / NANOS_PER_SECOND;
tv2[1U].tv_nsec = static_cast<time_t>(tv[1U] % NANOS_PER_SECOND);
tv2[1U].tv_sec = static_cast<time_t>(tv[1U] / NANOS_PER_SECOND);
}
const auto res = utimensat(0, file_path.c_str(), tv2, AT_SYMLINK_NOFOLLOW);
const auto res =
utimensat(0, file_path.c_str(), &tv2[0U], AT_SYMLINK_NOFOLLOW);
auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_FUSE_SERVER_EVENT(__FUNCTION__, file_path, ret);
return ret;
@ -1025,10 +1028,10 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
const auto file_path = construct_path(relative_path);
exists = utils::file::is_file(file_path);
if (create_options & FILE_DIRECTORY_FILE) {
if ((create_options & FILE_DIRECTORY_FILE) != 0U) {
attributes |= FILE_ATTRIBUTE_DIRECTORY;
} else {
attributes &= ~FILE_ATTRIBUTE_DIRECTORY;
attributes &= static_cast<UINT32>(~FILE_ATTRIBUTE_DIRECTORY);
}
if (not attributes) {
@ -1040,12 +1043,13 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
utils::windows_create_to_unix(create_options, granted_access, flags, mode);
int res = 0;
if (create_options & FILE_DIRECTORY_FILE) {
if ((res = mkdir(file_path.c_str(), mode)) >= 0) {
res = open(file_path.c_str(), flags);
if ((create_options & FILE_DIRECTORY_FILE) != 0U) {
res = mkdir(file_path.c_str(), mode);
if (res >= 0) {
res = open(file_path.c_str(), static_cast<int>(flags));
}
} else {
res = open(file_path.c_str(), flags, mode);
res = open(file_path.c_str(), static_cast<int>(flags), mode);
}
if (res >= 0) {
@ -1155,9 +1159,9 @@ auto remote_server::winfsp_open(PWSTR file_name, UINT32 create_options,
remote::file_mode mode{};
std::uint32_t flags{};
utils::windows_create_to_unix(create_options, granted_access, flags, mode);
flags &= ~(O_CREAT);
flags &= static_cast<std::uint32_t>(~O_CREAT);
auto res = open(file_path.c_str(), flags);
auto res = open(file_path.c_str(), static_cast<int>(flags));
if (res >= 0) {
*file_desc = reinterpret_cast<PVOID>(res);
set_open_info(res, open_info{0, "", nullptr, file_path});
@ -1209,8 +1213,9 @@ auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
}
if (set_attributes) {
attributes &= ~(FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_NORMAL);
if (not attributes) {
attributes &= static_cast<UINT32>(
~(FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_NORMAL));
if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL;
}
drive_.set_item_meta(api_path, META_ATTRIBUTES,
@ -1335,34 +1340,34 @@ auto remote_server::winfsp_set_basic_info(
const auto api_path = construct_api_path(file_path);
api_meta_map meta;
if (attributes) {
if ((attributes & FILE_ATTRIBUTE_NORMAL) &&
if (attributes != 0U) {
if (((attributes & FILE_ATTRIBUTE_NORMAL) != 0U) &&
(attributes != FILE_ATTRIBUTE_NORMAL)) {
attributes &= ~(FILE_ATTRIBUTE_NORMAL);
attributes &= static_cast<UINT32>(~(FILE_ATTRIBUTE_NORMAL));
}
drive_.set_item_meta(api_path, META_ATTRIBUTES,
std::to_string(attributes));
}
if (creation_time && (creation_time != 0xFFFFFFFFFFFFFFFF)) {
if ((creation_time != 0U) && (creation_time != 0xFFFFFFFFFFFFFFFF)) {
drive_.set_item_meta(
api_path, META_CREATION,
std::to_string(utils::windows_time_to_unix_time(creation_time)));
}
if (last_access_time && (last_access_time != 0xFFFFFFFFFFFFFFFF)) {
if ((last_access_time != 0U) && (last_access_time != 0xFFFFFFFFFFFFFFFF)) {
drive_.set_item_meta(
api_path, META_ACCESSED,
std::to_string(utils::windows_time_to_unix_time(last_access_time)));
}
if (last_write_time && (last_write_time != 0xFFFFFFFFFFFFFFFF)) {
if ((last_write_time != 0U) && (last_write_time != 0xFFFFFFFFFFFFFFFF)) {
drive_.set_item_meta(
api_path, META_WRITTEN,
std::to_string(utils::windows_time_to_unix_time(last_write_time)));
}
if (change_time && (change_time != 0xFFFFFFFFFFFFFFFF)) {
if ((change_time != 0U) && (change_time != 0xFFFFFFFFFFFFFFFF)) {
drive_.set_item_meta(
api_path, META_MODIFIED,
std::to_string(utils::windows_time_to_unix_time(change_time)));
@ -1385,10 +1390,10 @@ auto remote_server::winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
auto ret =
has_open_info(static_cast<native_handle>(handle), STATUS_INVALID_HANDLE);
if (ret == STATUS_SUCCESS) {
const auto res =
set_allocation_size
? 0
: ftruncate(static_cast<native_handle>(handle), new_size);
const auto res = set_allocation_size == 0U
? ftruncate(static_cast<native_handle>(handle),
static_cast<off_t>(new_size))
: 0;
ret = ((res < 0) ? utils::unix_error_to_windows(errno) : 0);
if (ret == 0) {
ret = populate_file_info(construct_api_path(get_open_file_path(

View File

@ -98,10 +98,9 @@ remote_winfsp_drive::remote_winfsp_drive(app_config &config,
config_(config),
lock_(lock),
factory_(std::move(factory)) {
E_SUBSCRIBE_EXACT(unmount_requested,
[this](const unmount_requested & /* e */) {
std::thread([this]() { this->shutdown(); }).detach();
});
E_SUBSCRIBE_EXACT(unmount_requested, [this](const unmount_requested &) {
std::thread([this]() { this->shutdown(); }).detach();
});
}
auto remote_winfsp_drive::CanDelete(PVOID /*file_node*/, PVOID file_desc,

View File

@ -111,7 +111,7 @@ auto winfsp_drive::winfsp_service::OnStop() -> NTSTATUS {
winfsp_drive::winfsp_drive(app_config &config, lock_data &lock,
i_provider &provider)
: FileSystemBase(), provider_(provider), config_(config), lock_(lock) {
E_SUBSCRIBE_EXACT(unmount_requested, [this](const unmount_requested & /*e*/) {
E_SUBSCRIBE_EXACT(unmount_requested, [this](const unmount_requested &) {
std::thread([this]() { this->shutdown(); }).detach();
});
}

View File

@ -45,9 +45,9 @@ logging_consumer::logging_consumer(const std::string &log_directory,
reopen_log_file();
E_SUBSCRIBE_ALL(process_event);
E_SUBSCRIBE_EXACT(event_level_changed,
[this](const event_level_changed &evt) {
[this](const event_level_changed &changed) {
event_level_ = event_level_from_string(
evt.get_new_event_level().get<std::string>());
changed.get_new_event_level().get<std::string>());
});
logging_thread_ =
std::make_unique<std::thread>([this] { logging_thread(false); });

File diff suppressed because it is too large Load Diff

View File

@ -68,9 +68,8 @@ file_manager::open_file::open_file(
fsi.source_path, not provider_.is_direct_only(), nf_));
if (get_api_error() == api_error::success) {
if (read_state.has_value()) {
modified_ = true;
mgr_.store_resume(*this);
read_state_ = read_state.value();
set_modified();
} else if (fsi_.size > 0U) {
read_state_.resize(static_cast<std::size_t>(utils::divide_with_ceiling(
fsi_.size, chunk_size)),
@ -323,11 +322,7 @@ auto file_manager::open_file::native_operation(
}
if (original_file_size != new_file_size) {
if (not modified_) {
mgr_.store_resume(*this);
}
modified_ = true;
mgr_.remove_upload(get_api_path());
set_modified();
fsi_.size = new_file_size;
const auto now = std::to_string(utils::get_file_time_now());
@ -409,6 +404,10 @@ void file_manager::open_file::remove(std::uint64_t handle) {
mgr_.queue_upload(*this);
modified_ = false;
}
if (removed_ && (get_open_file_count() == 0U)) {
removed_ = false;
}
}
auto file_manager::open_file::resize(std::uint64_t new_file_size) -> api_error {
@ -486,6 +485,18 @@ auto file_manager::open_file::close() -> bool {
return false;
}
void file_manager::open_file::set_modified() {
if (not modified_) {
modified_ = true;
mgr_.store_resume(*this);
}
if (not removed_) {
removed_ = true;
mgr_.remove_upload(get_api_path());
}
}
void file_manager::open_file::update_background_reader(std::size_t read_chunk) {
recur_mutex_lock reader_lock(file_mtx_);
read_chunk_index_ = read_chunk;
@ -586,12 +597,7 @@ auto file_manager::open_file::write(std::uint64_t write_offset,
return set_api_error(res);
}
if (not modified_) {
mgr_.store_resume(*this);
}
modified_ = true;
mgr_.remove_upload(get_api_path());
set_modified();
return api_error::success;
}
} // namespace repertory

View File

@ -233,6 +233,8 @@ auto file_manager::open_file_base::close() -> bool {
io_thread_.reset();
return true;
}
return false;
}
io_thread_notify_.notify_all();

View File

@ -22,9 +22,9 @@
#include "file_manager/file_manager.hpp"
namespace repertory {
void file_manager::open_file_base::download::notify(const api_error &e) {
void file_manager::open_file_base::download::notify(const api_error &err) {
complete_ = true;
error_ = e;
error_ = err;
unique_mutex_lock lock(mtx_);
notify_.notify_all();
}

View File

@ -36,6 +36,6 @@ auto file_manager::open_file_base::io_item::get_result() -> api_error {
}
notify_.wait(lock);
return result_.value();
return result_.value_or(api_error::error);
}
} // namespace repertory

View File

@ -258,7 +258,8 @@ auto file_manager::ring_buffer_open_file::read(std::size_t read_size,
}
reset_timeout();
if ((res = download_chunk(chunk)) == api_error::success) {
res = download_chunk(chunk);
if (res == api_error::success) {
const auto to_read = std::min(
static_cast<std::size_t>(chunk_size_ - read_offset), read_size);
res = do_io([this, &buffer, &chunk, &data, read_offset,
@ -270,8 +271,10 @@ auto file_manager::ring_buffer_open_file::read(std::size_t read_size,
? api_error::success
: api_error::os_error;
if (ret == api_error::success) {
data.insert(data.end(), buffer.begin() + read_offset,
buffer.begin() + read_offset + to_read);
data.insert(data.end(),
buffer.begin() + static_cast<std::int64_t>(read_offset),
buffer.begin() +
static_cast<std::int64_t>(read_offset + to_read));
reset_timeout();
}

Some files were not shown because too many files have changed in this diff Show More