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
This commit is contained in:
Scott E. Graves 2023-12-10 18:11:20 +00:00
parent f43c41f88a
commit 1b8de3b097
404 changed files with 410072 additions and 146106 deletions

View File

@ -1,38 +1,8 @@
---
Checks: 'clang-*,misc-unused-*,llvm-header-guard,llvm-include-order,modernize-*'
Checks: '-*,clang-diagnostic-*,clang-analyzer-*,bugprone-*,concurrency-*,cppcoreguidelines-*,modernize-*,readability-*,-readability-redundant-access-specifiers,-readability-function-cognitive-complexity'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
User: sgraves
CheckOptions:
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: '0'
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: '1'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
...

View File

@ -70,6 +70,7 @@ duse_libidn2
dwith_gflags
dwith_liburing
dwith_tools
dxxh_no_inline_hints
dylib
endfunction
endmacro
@ -144,6 +145,7 @@ lptr
lpwstr
lzma
makefiles
markdownlint
mbig
mockwinfspdrive
mqtt
@ -157,6 +159,8 @@ nmake
noappledouble
nocache
nocloseprocess
nolintbegin
nolintend
nopath
npubbytes
ntfs
@ -209,6 +213,7 @@ smatch
sopen
stbuf
stdc
stduuid
stod
stoi
stoll
@ -224,6 +229,7 @@ szlib_libpath
target_precompile_headers
teventsystem
tolower
tomykaira
toolset
ttmath
ularge
@ -238,6 +244,7 @@ wcast
wconversion
wdouble
wduplicated
wfloat
wformat
windres
winfsp
@ -254,6 +261,7 @@ woverloaded
wpedantic
wshadow
wsign
wunknown
wunused
wuseless
xattr

1
.gitignore vendored
View File

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

View File

@ -6,7 +6,7 @@ pipeline {
environment {
BUILD_ARGS = '--build . -j 8'
CONFIGURE_ARGS = '../.. -DCMAKE_BUILD_TYPE=Release -DREPERTORY_ENABLE_S3=ON'
CONFIGURE_MINGW64_ARGS = '../.. -DCMAKE_BUILD_TYPE=Release -DREPERTORY_ENABLE_S3=ON -DCMAKE_TOOLCHAIN_FILE=../../cmake/mingw-w64-x86_64.cmake'
CONFIGURE_MINGW64_ARGS = '../.. -DCMAKE_BUILD_TYPE=Release -DREPERTORY_ENABLE_S3=ON -DCMAKE_TOOLCHAIN_FILE=${WORKSPACE}/cmake/mingw-w64-x86_64.cmake'
REPERTORY_TEST_DIR = "${HOME}/.ci/cfg"
}
@ -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

@ -36,7 +36,7 @@ pipeline {
steps {
retry(2) {
sleep time: 5, unit: 'SECONDS'
cmake arguments: '--build . -j 4', installation: 'InSearchPath', workingDir: 'build'
cmake arguments: '--build . -j 3', installation: 'InSearchPath', workingDir: 'build'
}
}
}
@ -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

@ -1,39 +0,0 @@
#!groovy
pipeline {
agent any
environment {
REPERTORY_TEST_DIR = "C:\\.ci\\cfg"
}
options {
disableConcurrentBuilds()
retry(2)
}
stages {
stage('clean') {
steps {
bat 'del /q build\\Release\\librepertory.lib || exit 0'
bat 'del /q build\\Release\\unittests.exe || exit 0'
bat 'del /q build\\Release\\repertory.exe || exit 0'
}
}
stage('configure') {
steps {
cmake arguments: '.. -DCMAKE_BUILD_TYPE=Release -DREPERTORY_ENABLE_S3=ON', installation: 'InSearchPath', workingDir: 'build'
}
}
stage('build') {
steps {
retry(2) {
sleep time: 5, unit: 'SECONDS'
cmake arguments: '--build . --target ALL_BUILD --config Release -j 4', installation: 'InSearchPath', workingDir: 'build'
}
}
}
}
}

File diff suppressed because it is too large Load Diff

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

876
3rd_party/stduuid/stduuid.h vendored Normal file
View File

@ -0,0 +1,876 @@
#ifndef STDUUID_H
#define STDUUID_H
#include <cstring>
#include <string>
#include <sstream>
#include <iomanip>
#include <array>
#include <string_view>
#include <iterator>
#include <random>
#include <memory>
#include <functional>
#include <type_traits>
#include <optional>
#include <chrono>
#include <numeric>
#include <atomic>
#ifdef __cplusplus
#if (__cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
#define LIBUUID_CPP20_OR_GREATER
#endif
#endif
#ifdef LIBUUID_CPP20_OR_GREATER
#include <span>
#else
#include <gsl/span>
#endif
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#ifdef UUID_SYSTEM_GENERATOR
#include <objbase.h>
#endif
#ifdef UUID_TIME_GENERATOR
#include <iphlpapi.h>
#pragma comment(lib, "IPHLPAPI.lib")
#endif
#elif defined(__linux__) || defined(__unix__)
#ifdef UUID_SYSTEM_GENERATOR
#include <uuid/uuid.h>
#endif
#elif defined(__APPLE__)
#ifdef UUID_SYSTEM_GENERATOR
#include <CoreFoundation/CFUUID.h>
#endif
#endif
namespace uuids {
#ifdef __cpp_lib_span
template <class ElementType, std::size_t Extent>
using span = std::span<ElementType, Extent>;
#else
template <class ElementType, std::ptrdiff_t Extent>
using span = gsl::span<ElementType, Extent>;
#endif
namespace detail {
template <typename TChar>
[[nodiscard]] constexpr inline unsigned char hex2char(TChar const ch) noexcept {
if (ch >= static_cast<TChar>('0') && ch <= static_cast<TChar>('9'))
return static_cast<unsigned char>(ch - static_cast<TChar>('0'));
if (ch >= static_cast<TChar>('a') && ch <= static_cast<TChar>('f'))
return static_cast<unsigned char>(10 + ch - static_cast<TChar>('a'));
if (ch >= static_cast<TChar>('A') && ch <= static_cast<TChar>('F'))
return static_cast<unsigned char>(10 + ch - static_cast<TChar>('A'));
return 0;
}
template <typename TChar>
[[nodiscard]] constexpr inline bool is_hex(TChar const ch) noexcept {
return (ch >= static_cast<TChar>('0') && ch <= static_cast<TChar>('9')) ||
(ch >= static_cast<TChar>('a') && ch <= static_cast<TChar>('f')) ||
(ch >= static_cast<TChar>('A') && ch <= static_cast<TChar>('F'));
}
template <typename TChar>
[[nodiscard]] constexpr std::basic_string_view<TChar>
to_string_view(TChar const *str) noexcept {
if (str)
return str;
return {};
}
template <typename StringType>
[[nodiscard]] constexpr std::basic_string_view<typename StringType::value_type,
typename StringType::traits_type>
to_string_view(StringType const &str) noexcept {
return str;
}
class sha1 {
public:
using digest32_t = uint32_t[5];
using digest8_t = uint8_t[20];
static constexpr unsigned int block_bytes = 64;
[[nodiscard]] inline static uint32_t
left_rotate(uint32_t value, size_t const count) noexcept {
return (value << count) ^ (value >> (32 - count));
}
sha1() { reset(); }
void reset() noexcept {
m_digest[0] = 0x67452301;
m_digest[1] = 0xEFCDAB89;
m_digest[2] = 0x98BADCFE;
m_digest[3] = 0x10325476;
m_digest[4] = 0xC3D2E1F0;
m_blockByteIndex = 0;
m_byteCount = 0;
}
void process_byte(uint8_t octet) {
this->m_block[this->m_blockByteIndex++] = octet;
++this->m_byteCount;
if (m_blockByteIndex == block_bytes) {
this->m_blockByteIndex = 0;
process_block();
}
}
void process_block(void const *const start, void const *const end) {
const uint8_t *begin = static_cast<const uint8_t *>(start);
const uint8_t *finish = static_cast<const uint8_t *>(end);
while (begin != finish) {
process_byte(*begin);
begin++;
}
}
void process_bytes(void const *const data, size_t const len) {
const uint8_t *block = static_cast<const uint8_t *>(data);
process_block(block, block + len);
}
uint32_t const *get_digest(digest32_t digest) {
size_t const bitCount = this->m_byteCount * 8;
process_byte(0x80);
if (this->m_blockByteIndex > 56) {
while (m_blockByteIndex != 0) {
process_byte(0);
}
while (m_blockByteIndex < 56) {
process_byte(0);
}
} else {
while (m_blockByteIndex < 56) {
process_byte(0);
}
}
process_byte(0);
process_byte(0);
process_byte(0);
process_byte(0);
process_byte(static_cast<unsigned char>((bitCount >> 24) & 0xFF));
process_byte(static_cast<unsigned char>((bitCount >> 16) & 0xFF));
process_byte(static_cast<unsigned char>((bitCount >> 8) & 0xFF));
process_byte(static_cast<unsigned char>((bitCount)&0xFF));
memcpy(digest, m_digest, 5 * sizeof(uint32_t));
return digest;
}
uint8_t const *get_digest_bytes(digest8_t digest) {
digest32_t d32;
get_digest(d32);
size_t di = 0;
digest[di++] = static_cast<uint8_t>(d32[0] >> 24);
digest[di++] = static_cast<uint8_t>(d32[0] >> 16);
digest[di++] = static_cast<uint8_t>(d32[0] >> 8);
digest[di++] = static_cast<uint8_t>(d32[0] >> 0);
digest[di++] = static_cast<uint8_t>(d32[1] >> 24);
digest[di++] = static_cast<uint8_t>(d32[1] >> 16);
digest[di++] = static_cast<uint8_t>(d32[1] >> 8);
digest[di++] = static_cast<uint8_t>(d32[1] >> 0);
digest[di++] = static_cast<uint8_t>(d32[2] >> 24);
digest[di++] = static_cast<uint8_t>(d32[2] >> 16);
digest[di++] = static_cast<uint8_t>(d32[2] >> 8);
digest[di++] = static_cast<uint8_t>(d32[2] >> 0);
digest[di++] = static_cast<uint8_t>(d32[3] >> 24);
digest[di++] = static_cast<uint8_t>(d32[3] >> 16);
digest[di++] = static_cast<uint8_t>(d32[3] >> 8);
digest[di++] = static_cast<uint8_t>(d32[3] >> 0);
digest[di++] = static_cast<uint8_t>(d32[4] >> 24);
digest[di++] = static_cast<uint8_t>(d32[4] >> 16);
digest[di++] = static_cast<uint8_t>(d32[4] >> 8);
digest[di++] = static_cast<uint8_t>(d32[4] >> 0);
return digest;
}
private:
void process_block() {
uint32_t w[80];
for (size_t i = 0; i < 16; i++) {
w[i] = static_cast<uint32_t>(m_block[i * 4 + 0] << 24);
w[i] |= static_cast<uint32_t>(m_block[i * 4 + 1] << 16);
w[i] |= static_cast<uint32_t>(m_block[i * 4 + 2] << 8);
w[i] |= static_cast<uint32_t>(m_block[i * 4 + 3]);
}
for (size_t i = 16; i < 80; i++) {
w[i] = left_rotate((w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16]), 1);
}
uint32_t a = m_digest[0];
uint32_t b = m_digest[1];
uint32_t c = m_digest[2];
uint32_t d = m_digest[3];
uint32_t e = m_digest[4];
for (std::size_t i = 0; i < 80; ++i) {
uint32_t f = 0;
uint32_t k = 0;
if (i < 20) {
f = (b & c) | (~b & d);
k = 0x5A827999;
} else if (i < 40) {
f = b ^ c ^ d;
k = 0x6ED9EBA1;
} else if (i < 60) {
f = (b & c) | (b & d) | (c & d);
k = 0x8F1BBCDC;
} else {
f = b ^ c ^ d;
k = 0xCA62C1D6;
}
uint32_t temp = left_rotate(a, 5) + f + e + k + w[i];
e = d;
d = c;
c = left_rotate(b, 30);
b = a;
a = temp;
}
m_digest[0] += a;
m_digest[1] += b;
m_digest[2] += c;
m_digest[3] += d;
m_digest[4] += e;
}
private:
digest32_t m_digest;
uint8_t m_block[64];
size_t m_blockByteIndex;
size_t m_byteCount;
};
template <typename CharT>
inline constexpr CharT empty_guid[37] = "00000000-0000-0000-0000-000000000000";
template <>
inline constexpr wchar_t empty_guid<wchar_t>[37] =
L"00000000-0000-0000-0000-000000000000";
template <typename CharT>
inline constexpr CharT guid_encoder[17] = "0123456789abcdef";
template <>
inline constexpr wchar_t guid_encoder<wchar_t>[17] = L"0123456789abcdef";
} // namespace detail
// --------------------------------------------------------------------------------------------------------------------------
// UUID format https://tools.ietf.org/html/rfc4122
// --------------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------------
// Field NDR Data Type Octet # Note
// --------------------------------------------------------------------------------------------------------------------------
// time_low unsigned long 0 - 3 The low field
// of the timestamp. time_mid unsigned short 4 - 5
// The middle field of the timestamp.
// time_hi_and_version unsigned short 6 - 7 The high
// field of the timestamp multiplexed with the version number.
// clock_seq_hi_and_reserved unsigned small 8 The high field of
// the clock sequence multiplexed with the variant. clock_seq_low
// unsigned small 9 The low field of the clock sequence. node
// character 10 - 15 The spatially unique node identifier.
// --------------------------------------------------------------------------------------------------------------------------
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | time_low |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | time_mid | time_hi_and_version |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |clk_seq_hi_res | clk_seq_low | node (0-1) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | node (2-5) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// --------------------------------------------------------------------------------------------------------------------------
// enumerations
// --------------------------------------------------------------------------------------------------------------------------
// indicated by a bit pattern in octet 8, marked with N in
// xxxxxxxx-xxxx-xxxx-Nxxx-xxxxxxxxxxxx
enum class uuid_variant {
// NCS backward compatibility (with the obsolete Apollo Network Computing
// System 1.5 UUID format) N bit pattern: 0xxx > the first 6 octets of the
// UUID are a 48-bit timestamp (the number of 4 microsecond units of time
// since 1 Jan 1980 UTC); > the next 2 octets are reserved; > the next octet
// is the "address family"; > the final 7 octets are a 56-bit host ID in the
// form specified by the address family
ncs,
// RFC 4122/DCE 1.1
// N bit pattern: 10xx
// > big-endian byte order
rfc,
// Microsoft Corporation backward compatibility
// N bit pattern: 110x
// > little endian byte order
// > formely used in the Component Object Model (COM) library
microsoft,
// reserved for possible future definition
// N bit pattern: 111x
reserved
};
// indicated by a bit pattern in octet 6, marked with M in
// xxxxxxxx-xxxx-Mxxx-xxxx-xxxxxxxxxxxx
enum class uuid_version {
none = 0, // only possible for nil or invalid uuids
time_based = 1, // The time-based version specified in RFC 4122
dce_security = 2, // DCE Security version, with embedded POSIX UIDs.
name_based_md5 =
3, // The name-based version specified in RFS 4122 with MD5 hashing
random_number_based = 4, // The randomly or pseudo-randomly generated version
// specified in RFS 4122
name_based_sha1 =
5 // The name-based version specified in RFS 4122 with SHA1 hashing
};
// Forward declare uuid & to_string so that we can declare to_string as a friend
// later.
class uuid;
template <class CharT = char, class Traits = std::char_traits<CharT>,
class Allocator = std::allocator<CharT>>
std::basic_string<CharT, Traits, Allocator> to_string(uuid const &id);
// --------------------------------------------------------------------------------------------------------------------------
// uuid class
// --------------------------------------------------------------------------------------------------------------------------
class uuid {
public:
using value_type = uint8_t;
constexpr uuid() noexcept = default;
uuid(value_type (&arr)[16]) noexcept {
std::copy(std::cbegin(arr), std::cend(arr), std::begin(data));
}
constexpr uuid(std::array<value_type, 16> const &arr) noexcept : data{arr} {}
explicit uuid(span<value_type, 16> bytes) {
std::copy(std::cbegin(bytes), std::cend(bytes), std::begin(data));
}
template <typename ForwardIterator>
explicit uuid(ForwardIterator first, ForwardIterator last) {
if (std::distance(first, last) == 16)
std::copy(first, last, std::begin(data));
}
[[nodiscard]] constexpr uuid_variant variant() const noexcept {
if ((data[8] & 0x80) == 0x00)
return uuid_variant::ncs;
else if ((data[8] & 0xC0) == 0x80)
return uuid_variant::rfc;
else if ((data[8] & 0xE0) == 0xC0)
return uuid_variant::microsoft;
else
return uuid_variant::reserved;
}
[[nodiscard]] constexpr uuid_version version() const noexcept {
if ((data[6] & 0xF0) == 0x10)
return uuid_version::time_based;
else if ((data[6] & 0xF0) == 0x20)
return uuid_version::dce_security;
else if ((data[6] & 0xF0) == 0x30)
return uuid_version::name_based_md5;
else if ((data[6] & 0xF0) == 0x40)
return uuid_version::random_number_based;
else if ((data[6] & 0xF0) == 0x50)
return uuid_version::name_based_sha1;
else
return uuid_version::none;
}
[[nodiscard]] constexpr bool is_nil() const noexcept {
for (size_t i = 0; i < data.size(); ++i)
if (data[i] != 0)
return false;
return true;
}
void swap(uuid &other) noexcept { data.swap(other.data); }
[[nodiscard]] inline span<std::byte const, 16> as_bytes() const {
return span<std::byte const, 16>(
reinterpret_cast<std::byte const *>(data.data()), 16);
}
template <typename StringType>
[[nodiscard]] constexpr static bool
is_valid_uuid(StringType const &in_str) noexcept {
auto str = detail::to_string_view(in_str);
bool firstDigit = true;
size_t hasBraces = 0;
size_t index = 0;
if (str.empty())
return false;
if (str.front() == '{')
hasBraces = 1;
if (hasBraces && str.back() != '}')
return false;
for (size_t i = hasBraces; i < str.size() - hasBraces; ++i) {
if (str[i] == '-')
continue;
if (index >= 16 || !detail::is_hex(str[i])) {
return false;
}
if (firstDigit) {
firstDigit = false;
} else {
index++;
firstDigit = true;
}
}
if (index < 16) {
return false;
}
return true;
}
template <typename StringType>
[[nodiscard]] constexpr static std::optional<uuid>
from_string(StringType const &in_str) noexcept {
auto str = detail::to_string_view(in_str);
bool firstDigit = true;
size_t hasBraces = 0;
size_t index = 0;
std::array<uint8_t, 16> data{{0}};
if (str.empty())
return {};
if (str.front() == '{')
hasBraces = 1;
if (hasBraces && str.back() != '}')
return {};
for (size_t i = hasBraces; i < str.size() - hasBraces; ++i) {
if (str[i] == '-')
continue;
if (index >= 16 || !detail::is_hex(str[i])) {
return {};
}
if (firstDigit) {
data[index] = static_cast<uint8_t>(detail::hex2char(str[i]) << 4);
firstDigit = false;
} else {
data[index] =
static_cast<uint8_t>(data[index] | detail::hex2char(str[i]));
index++;
firstDigit = true;
}
}
if (index < 16) {
return {};
}
return uuid{data};
}
private:
std::array<value_type, 16> data{{0}};
friend bool operator==(uuid const &lhs, uuid const &rhs) noexcept;
friend bool operator<(uuid const &lhs, uuid const &rhs) noexcept;
template <class Elem, class Traits>
friend std::basic_ostream<Elem, Traits> &
operator<<(std::basic_ostream<Elem, Traits> &s, uuid const &id);
template <class CharT, class Traits, class Allocator>
friend std::basic_string<CharT, Traits, Allocator> to_string(uuid const &id);
friend std::hash<uuid>;
};
// --------------------------------------------------------------------------------------------------------------------------
// operators and non-member functions
// --------------------------------------------------------------------------------------------------------------------------
[[nodiscard]] inline bool operator==(uuid const &lhs,
uuid const &rhs) noexcept {
return lhs.data == rhs.data;
}
[[nodiscard]] inline bool operator!=(uuid const &lhs,
uuid const &rhs) noexcept {
return !(lhs == rhs);
}
[[nodiscard]] inline bool operator<(uuid const &lhs, uuid const &rhs) noexcept {
return lhs.data < rhs.data;
}
template <class CharT, class Traits, class Allocator>
[[nodiscard]] inline std::basic_string<CharT, Traits, Allocator>
to_string(uuid const &id) {
std::basic_string<CharT, Traits, Allocator> uustr{detail::empty_guid<CharT>};
for (size_t i = 0, index = 0; i < 36; ++i) {
if (i == 8 || i == 13 || i == 18 || i == 23) {
continue;
}
uustr[i] = detail::guid_encoder<CharT>[id.data[index] >> 4 & 0x0f];
uustr[++i] = detail::guid_encoder<CharT>[id.data[index] & 0x0f];
index++;
}
return uustr;
}
template <class Elem, class Traits>
std::basic_ostream<Elem, Traits> &
operator<<(std::basic_ostream<Elem, Traits> &s, uuid const &id) {
s << to_string(id);
return s;
}
inline void swap(uuids::uuid &lhs, uuids::uuid &rhs) noexcept { lhs.swap(rhs); }
// --------------------------------------------------------------------------------------------------------------------------
// namespace IDs that could be used for generating name-based uuids
// --------------------------------------------------------------------------------------------------------------------------
// Name string is a fully-qualified domain name
static uuid uuid_namespace_dns{{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1,
0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30,
0xc8}};
// Name string is a URL
static uuid uuid_namespace_url{{0x6b, 0xa7, 0xb8, 0x11, 0x9d, 0xad, 0x11, 0xd1,
0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30,
0xc8}};
// Name string is an ISO OID (See https://oidref.com/,
// https://en.wikipedia.org/wiki/Object_identifier)
static uuid uuid_namespace_oid{{0x6b, 0xa7, 0xb8, 0x12, 0x9d, 0xad, 0x11, 0xd1,
0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30,
0xc8}};
// Name string is an X.500 DN, in DER or a text output format (See
// https://en.wikipedia.org/wiki/X.500,
// https://en.wikipedia.org/wiki/Abstract_Syntax_Notation_One)
static uuid uuid_namespace_x500{{0x6b, 0xa7, 0xb8, 0x14, 0x9d, 0xad, 0x11, 0xd1,
0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30,
0xc8}};
// --------------------------------------------------------------------------------------------------------------------------
// uuid generators
// --------------------------------------------------------------------------------------------------------------------------
#ifdef UUID_SYSTEM_GENERATOR
class uuid_system_generator {
public:
using result_type = uuid;
uuid operator()() {
#ifdef _WIN32
GUID newId;
HRESULT hr = ::CoCreateGuid(&newId);
if (FAILED(hr)) {
throw std::system_error(hr, std::system_category(),
"CoCreateGuid failed");
}
std::array<uint8_t, 16> bytes = {
{static_cast<unsigned char>((newId.Data1 >> 24) & 0xFF),
static_cast<unsigned char>((newId.Data1 >> 16) & 0xFF),
static_cast<unsigned char>((newId.Data1 >> 8) & 0xFF),
static_cast<unsigned char>((newId.Data1) & 0xFF),
(unsigned char)((newId.Data2 >> 8) & 0xFF),
(unsigned char)((newId.Data2) & 0xFF),
(unsigned char)((newId.Data3 >> 8) & 0xFF),
(unsigned char)((newId.Data3) & 0xFF),
newId.Data4[0], newId.Data4[1], newId.Data4[2], newId.Data4[3],
newId.Data4[4], newId.Data4[5], newId.Data4[6], newId.Data4[7]}};
return uuid{std::begin(bytes), std::end(bytes)};
#elif defined(__linux__) || defined(__unix__)
uuid_t id;
uuid_generate(id);
std::array<uint8_t, 16> bytes = {{id[0], id[1], id[2], id[3], id[4], id[5],
id[6], id[7], id[8], id[9], id[10],
id[11], id[12], id[13], id[14], id[15]}};
return uuid{std::begin(bytes), std::end(bytes)};
#elif defined(__APPLE__)
auto newId = CFUUIDCreate(NULL);
auto bytes = CFUUIDGetUUIDBytes(newId);
CFRelease(newId);
std::array<uint8_t, 16> arrbytes = {
{bytes.byte0, bytes.byte1, bytes.byte2, bytes.byte3, bytes.byte4,
bytes.byte5, bytes.byte6, bytes.byte7, bytes.byte8, bytes.byte9,
bytes.byte10, bytes.byte11, bytes.byte12, bytes.byte13, bytes.byte14,
bytes.byte15}};
return uuid{std::begin(arrbytes), std::end(arrbytes)};
#else
return uuid{};
#endif
}
};
#endif
template <typename UniformRandomNumberGenerator>
class basic_uuid_random_generator {
public:
using engine_type = UniformRandomNumberGenerator;
explicit basic_uuid_random_generator(engine_type &gen)
: generator(&gen, [](auto) {}) {}
explicit basic_uuid_random_generator(engine_type *gen)
: generator(gen, [](auto) {}) {}
[[nodiscard]] uuid operator()() {
alignas(uint32_t) uint8_t bytes[16];
for (int i = 0; i < 16; i += 4)
*reinterpret_cast<uint32_t *>(bytes + i) = distribution(*generator);
// variant must be 10xxxxxx
bytes[8] &= 0xBF;
bytes[8] |= 0x80;
// version must be 0100xxxx
bytes[6] &= 0x4F;
bytes[6] |= 0x40;
return uuid{std::begin(bytes), std::end(bytes)};
}
private:
std::uniform_int_distribution<uint32_t> distribution;
std::shared_ptr<UniformRandomNumberGenerator> generator;
};
using uuid_random_generator = basic_uuid_random_generator<std::mt19937>;
class uuid_name_generator {
public:
explicit uuid_name_generator(uuid const &namespace_uuid) noexcept
: nsuuid(namespace_uuid) {}
template <typename StringType>
[[nodiscard]] uuid operator()(StringType const &name) {
reset();
process_characters(detail::to_string_view(name));
return make_uuid();
}
private:
void reset() {
hasher.reset();
std::byte bytes[16];
auto nsbytes = nsuuid.as_bytes();
std::copy(std::cbegin(nsbytes), std::cend(nsbytes), bytes);
hasher.process_bytes(bytes, 16);
}
template <typename CharT, typename Traits>
void process_characters(std::basic_string_view<CharT, Traits> const str) {
for (uint32_t c : str) {
hasher.process_byte(static_cast<uint8_t>(c & 0xFF));
if constexpr (!std::is_same_v<CharT, char>) {
hasher.process_byte(static_cast<uint8_t>((c >> 8) & 0xFF));
hasher.process_byte(static_cast<uint8_t>((c >> 16) & 0xFF));
hasher.process_byte(static_cast<uint8_t>((c >> 24) & 0xFF));
}
}
}
[[nodiscard]] uuid make_uuid() {
detail::sha1::digest8_t digest;
hasher.get_digest_bytes(digest);
// variant must be 0b10xxxxxx
digest[8] &= 0xBF;
digest[8] |= 0x80;
// version must be 0b0101xxxx
digest[6] &= 0x5F;
digest[6] |= 0x50;
return uuid{digest, digest + 16};
}
private:
uuid nsuuid;
detail::sha1 hasher;
};
#ifdef UUID_TIME_GENERATOR
// !!! DO NOT USE THIS IN PRODUCTION
// this implementation is unreliable for good uuids
class uuid_time_generator {
using mac_address = std::array<unsigned char, 6>;
std::optional<mac_address> device_address;
[[nodiscard]] bool get_mac_address() {
if (device_address.has_value()) {
return true;
}
#ifdef _WIN32
DWORD len = 0;
auto ret = GetAdaptersInfo(nullptr, &len);
if (ret != ERROR_BUFFER_OVERFLOW)
return false;
std::vector<unsigned char> buf(len);
auto pips = reinterpret_cast<PIP_ADAPTER_INFO>(&buf.front());
ret = GetAdaptersInfo(pips, &len);
if (ret != ERROR_SUCCESS)
return false;
mac_address addr;
std::copy(pips->Address, pips->Address + 6, std::begin(addr));
device_address = addr;
#endif
return device_address.has_value();
}
[[nodiscard]] long long get_time_intervals() {
auto start = std::chrono::system_clock::from_time_t(time_t(-12219292800));
auto diff = std::chrono::system_clock::now() - start;
auto ns =
std::chrono::duration_cast<std::chrono::nanoseconds>(diff).count();
return ns / 100;
}
[[nodiscard]] static unsigned short get_clock_sequence() {
static std::mt19937 clock_gen(std::random_device{}());
static std::uniform_int_distribution<unsigned short> clock_dis;
static std::atomic_ushort clock_sequence = clock_dis(clock_gen);
return clock_sequence++;
}
public:
[[nodiscard]] uuid operator()() {
if (get_mac_address()) {
std::array<uuids::uuid::value_type, 16> data;
auto tm = get_time_intervals();
auto clock_seq = get_clock_sequence();
auto ptm = reinterpret_cast<uuids::uuid::value_type *>(&tm);
memcpy(&data[0], ptm + 4, 4);
memcpy(&data[4], ptm + 2, 2);
memcpy(&data[6], ptm, 2);
memcpy(&data[8], &clock_seq, 2);
// variant must be 0b10xxxxxx
data[8] &= 0xBF;
data[8] |= 0x80;
// version must be 0b0001xxxx
data[6] &= 0x1F;
data[6] |= 0x10;
memcpy(&data[10], &device_address.value()[0], 6);
return uuids::uuid{std::cbegin(data), std::cend(data)};
}
return {};
}
};
#endif
} // namespace uuids
namespace std {
template <> struct hash<uuids::uuid> {
using argument_type = uuids::uuid;
using result_type = std::size_t;
[[nodiscard]] result_type operator()(argument_type const &uuid) const {
#ifdef UUID_HASH_STRING_BASED
std::hash<std::string> hasher;
return static_cast<result_type>(hasher(uuids::to_string(uuid)));
#else
uint64_t l = static_cast<uint64_t>(uuid.data[0]) << 56 |
static_cast<uint64_t>(uuid.data[1]) << 48 |
static_cast<uint64_t>(uuid.data[2]) << 40 |
static_cast<uint64_t>(uuid.data[3]) << 32 |
static_cast<uint64_t>(uuid.data[4]) << 24 |
static_cast<uint64_t>(uuid.data[5]) << 16 |
static_cast<uint64_t>(uuid.data[6]) << 8 |
static_cast<uint64_t>(uuid.data[7]);
uint64_t h = static_cast<uint64_t>(uuid.data[8]) << 56 |
static_cast<uint64_t>(uuid.data[9]) << 48 |
static_cast<uint64_t>(uuid.data[10]) << 40 |
static_cast<uint64_t>(uuid.data[11]) << 32 |
static_cast<uint64_t>(uuid.data[12]) << 24 |
static_cast<uint64_t>(uuid.data[13]) << 16 |
static_cast<uint64_t>(uuid.data[14]) << 8 |
static_cast<uint64_t>(uuid.data[15]);
if constexpr (sizeof(result_type) > 4) {
return result_type(l ^ h);
} else {
uint64_t hash64 = l ^ h;
return result_type(uint32_t(hash64 >> 32) ^ uint32_t(hash64));
}
#endif
}
};
} // namespace std
#endif /* STDUUID_H */

View File

@ -1,7 +1,28 @@
# Changelog
## 2.0.1-rc
### Issues
* \#10 Address compiler warnings
* \#11 Switch to SQLite over RocksDB
### Changes from v2.0.0-rc
* Refactored Sia, S3 and base provider
* Fixed intermittent deadlock on file close
* Removed MSVC compilation support (MinGW-64 should be used)
* 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
<!-- markdownlint-disable-next-line -->
### Issues
* \#1 \[bug\] Unable to mount S3 due to 'item_not_found' exception

View File

@ -11,7 +11,7 @@ include(ExternalProject)
set(REPERTORY_MAJOR 2)
set(REPERTORY_MINOR 0)
set(REPERTORY_REV 0)
set(REPERTORY_REV 1)
set(REPERTORY_RELEASE_NUM 0)
set(REPERTORY_RELEASE_ITER rc)
set(REPERTORY_VERSION ${REPERTORY_MAJOR}.${REPERTORY_MINOR}.${REPERTORY_REV}-${REPERTORY_RELEASE_ITER})
@ -44,24 +44,13 @@ if (UNIX)
endif()
endif()
if (MSVC OR MINGW)
set(WINFSP_LIBRARY_BASENAME winfsp-x64)
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/3rd_party/winfsp-${WINFSP_VERSION}/inc)
link_directories(${CMAKE_SOURCE_DIR}/3rd_party/winfsp-${WINFSP_VERSION}/lib)
set(REPERTORY_LINK_LIBRARIES
${REPERTORY_LINK_LIBRARIES}
${WINFSP_LIBRARY_BASENAME}.lib
)
endif()
if (LINUX OR MINGW)
if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
message(FATAL_ERROR "Require at least gcc-8.0")
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)
@ -94,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)
@ -143,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)
@ -163,27 +151,20 @@ elseif (MACOS)
"-framework SystemConfiguration"
)
elseif (MSVC)
set(OPENSSL_USE_STATIC_LIBS TRUE)
if (NOT OPENSSL_ROOT_DIR)
set (OPENSSL_ROOT_DIR "$ENV{USERPROFILE}\\scoop\\apps\\openssl\\current")
endif()
find_package(OpenSSL 1.1.1 REQUIRED)
set(OPENSSL_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)
set(REPERTORY_DEFINITIONS ${REPERTORY_DEFINITIONS} -D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
if (NOT CMAKE_GENERATOR_LOWER STREQUAL "nmake makefiles")
set(REPERTORY_OUTPUT_DIR ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE})
endif()
message(FATAL_ERROR "MSVC is currently not supported [MinGW-64 should be used]")
endif()
if (MINGW)
set(WINFSP_LIBRARY_BASENAME winfsp-x64)
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/3rd_party/winfsp-${WINFSP_VERSION}/inc)
link_directories(${CMAKE_SOURCE_DIR}/3rd_party/winfsp-${WINFSP_VERSION}/lib)
set(REPERTORY_LINK_LIBRARIES
${REPERTORY_LINK_LIBRARIES}
${WINFSP_LIBRARY_BASENAME}.lib
mswsock
)
endif()
if (MSVC OR MINGW)
set(REPERTORY_VER_FILEVERSION ${REPERTORY_MAJOR},${REPERTORY_MINOR},${REPERTORY_REV},${REPERTORY_RELEASE_NUM})
set(REPERTORY_VER_FILEVERSION_STR ${REPERTORY_MAJOR}.${REPERTORY_MINOR}.${REPERTORY_REV}.${REPERTORY_RELEASE_NUM})
set(REPERTORY_VER_PRODUCTVERSION ${REPERTORY_MAJOR},${REPERTORY_MINOR},${REPERTORY_REV},${REPERTORY_RELEASE_NUM})
@ -195,10 +176,6 @@ if (MSVC OR MINGW)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in ${CMAKE_CURRENT_SOURCE_DIR}/src/version.rc @ONLY)
set(WINDOWS_VERSION_RC ${CMAKE_CURRENT_SOURCE_DIR}/src/version.rc)
if (MSVC)
set(LIB_EXT .lib)
endif()
set(REPERTORY_LINK_LIBRARIES
${REPERTORY_LINK_LIBRARIES}
advapi32${LIB_EXT}
@ -232,36 +209,33 @@ 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/libuuid.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)
include_directories(include)
include_directories(SYSTEM
${Boost_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/cpp-httplib
${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}
${LIBUUID_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
${ROCKSDB_INCLUDE_DIRS}
)
set(REPERTORY_LINK_LIBRARIES
${ROCKSDB_LIBRARIES}
${LIBFUSE2_LIBRARIES}
${LIBFUSE3_LIBRARIES}
${LIBUUID_LIBRARIES}
${Boost_LIBRARIES}
${CURL_LIBRARIES}
${OPENSSL_LIBRARIES}
@ -278,17 +252,17 @@ 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)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/common.cpp.in ${CMAKE_CURRENT_SOURCE_DIR}/src/common.cpp @ONLY)
include(cmake/helpers.cmake)
include(cmake/librepertory.cmake)
include(cmake/repertory.cmake)

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,17 +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/)
@ -79,4 +77,3 @@ mMH3segHBkRj0xJcfOxceRLj1a+ULIIR3xL/3f8s5Id25TDo/nqBoCvu5PeCpo6L
9wIDAQAB
-----END PUBLIC KEY-----
```

View File

@ -1,137 +1,97 @@
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_DLL_ARCH x64)
set(BOOST_DOWNLOAD_URL https://boostorg.jfrog.io/artifactory/main/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION_DL}.tar.gz)
if (UNIX OR MINGW)
if (IS_CLANG_COMPILER)
set(BOOST_TOOLSET --with-toolset=clang)
else ()
set(BOOST_OPENSSL_DIR "--openssldir=${EXTERNAL_BUILD_ROOT}")
endif()
set(BOOST_DOWNLOAD_URL https://boostorg.jfrog.io/artifactory/main/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION2}.tar.gz)
if (IS_ARM64)
set (BOOST_ARCH arm)
else()
set (BOOST_ARCH x86)
endif()
if (IS_CLANG_COMPILER)
set(BOOST_TOOLSET --with-toolset=clang)
else ()
set(BOOST_OPENSSL_DIR "--openssldir=${EXTERNAL_BUILD_ROOT}")
endif()
set (BOOST_COMMON_ARGS
${BOOST_OPENSSL_DIR}
--prefix=${EXTERNAL_BUILD_ROOT}
address-model=${BOOST_ADDRESS_MODEL}
architecture=${BOOST_ARCH}
cxxflags=-std=c++${CMAKE_CXX_STANDARD}
cxxstd=${CMAKE_CXX_STANDARD}
define=BOOST_ASIO_HAS_STD_STRING_VIEW
define=BOOST_SYSTEM_NO_DEPRECATED
link=static
linkflags=-std=c++${CMAKE_CXX_STANDARD}
threading=multi
variant=${CMAKE_BUILD_TYPE_LOWER}
)
if (IS_ARM64)
set (BOOST_ARCH arm)
else()
set (BOOST_ARCH x86)
endif()
if (MINGW)
set (BOOST_COMMON_ARGS
${BOOST_OPENSSL_DIR}
--prefix=${EXTERNAL_BUILD_ROOT}
address-model=${BOOST_ADDRESS_MODEL}
architecture=${BOOST_ARCH}
cxxflags=-std=c++${CMAKE_CXX_STANDARD}
cxxstd=${CMAKE_CXX_STANDARD}
define=BOOST_ASIO_HAS_STD_STRING_VIEW
define=BOOST_SYSTEM_NO_DEPRECATED
link=static
linkflags=-std=c++${CMAKE_CXX_STANDARD}
threading=multi
variant=${CMAKE_BUILD_TYPE_LOWER}
-sZLIB_BINARY=zlibstatic${DEBUG_EXTRA}
-sZLIB_LIBPATH="${EXTERNAL_BUILD_ROOT}/lib"
-sZLIB_INCLUDE="${EXTERNAL_BUILD_ROOT}/include"
)
if (MINGW)
if (NOT CMAKE_HOST_WIN32)
set(BOOST_COMMON_ARGS
${BOOST_COMMON_ARGS}
--user-config=./user-config.jam
)
set(BOOST_TARGET_OS target-os=windows)
endif()
ExternalProject_Add(boost_project
DOWNLOAD_NO_PROGRESS 1
URL ${BOOST_DOWNLOAD_URL}
PREFIX ${BOOST_BUILD_ROOT}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND
cp -f ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/user-config.jam . &&
./bootstrap.sh
${BOOST_TOOLSET}
${BOOST_TARGET_OS}
--with-libraries=atomic,chrono,date_time,filesystem,random,regex,serialization,system,thread
BUILD_COMMAND
./b2
${BOOST_COMMON_ARGS}
${BOOST_TARGET_OS}
INSTALL_COMMAND
./b2
${BOOST_COMMON_ARGS}
${BOOST_TARGET_OS}
install
)
add_dependencies(boost_project openssl_project)
set(BOOST_ROOT ${BOOST_BUILD_ROOT}/src/boost_project)
if (MINGW)
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}")
endif()
set(Boost_LIBRARIES
libboost_system${BOOST_LIB_EXTRA}.a
libboost_atomic${BOOST_LIB_EXTRA}.a
libboost_chrono${BOOST_LIB_EXTRA}.a
libboost_date_time${BOOST_LIB_EXTRA}.a
libboost_filesystem${BOOST_LIB_EXTRA}.a
libboost_random${BOOST_LIB_EXTRA}.a
libboost_regex${BOOST_LIB_EXTRA}.a
libboost_serialization${BOOST_LIB_EXTRA}.a
libboost_thread${BOOST_LIB_EXTRA}.a
)
elseif(MSVC)
set (BOOST_COMMON_ARGS
--with-date_time
--with-regex
--with-serialization
--with-system
--with-filesystem
--prefix=${EXTERNAL_BUILD_ROOT}
runtime-link=shared
threading=multi
address-model=${BOOST_ADDRESS_MODEL}
architecture=x86
toolset=${BOOST_MSVC_TOOLSET}
variant=${CMAKE_BUILD_TYPE_LOWER}
-sZLIB_BINARY=zlibstatic${DEBUG_EXTRA}
-sZLIB_LIBPATH="${EXTERNAL_BUILD_ROOT}/lib"
-sZLIB_INCLUDE="${EXTERNAL_BUILD_ROOT}/include"
)
ExternalProject_Add(boost_project
DOWNLOAD_NO_PROGRESS 1
URL ${BOOST_DOWNLOAD_URL}
PREFIX ${BOOST_BUILD_ROOT}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND
bootstrap.bat
--with-date_time
--with-regex
--with-system
--with-serialization
--with-filesystem
BUILD_COMMAND
b2.exe
${BOOST_COMMON_ARGS}
INSTALL_COMMAND
b2.exe
install
${BOOST_COMMON_ARGS}
)
add_dependencies(boost_project zlib_project)
set(BOOST_ROOT ${BOOST_BUILD_ROOT}/src/boost_project)
set(Boost_INCLUDE_DIR ${EXTERNAL_BUILD_ROOT}/include/boost-${BOOST_VERSION_DLL})
set(Boost_LIBRARIES
${EXTERNAL_BUILD_ROOT}/lib/libboost_date_time-vc${BOOST_MSVC_TOOLSET_DLL}-mt-${BOOST_DEBUG_EXTRA}${BOOST_DLL_ARCH}-${BOOST_VERSION_DLL}.lib
${EXTERNAL_BUILD_ROOT}/lib/libboost_filesystem-vc${BOOST_MSVC_TOOLSET_DLL}-mt-${BOOST_DEBUG_EXTRA}${BOOST_DLL_ARCH}-${BOOST_VERSION_DLL}.lib
${EXTERNAL_BUILD_ROOT}/lib/libboost_regex-vc${BOOST_MSVC_TOOLSET_DLL}-mt-${BOOST_DEBUG_EXTRA}${BOOST_DLL_ARCH}-${BOOST_VERSION_DLL}.lib
${EXTERNAL_BUILD_ROOT}/lib/libboost_serialization-vc${BOOST_MSVC_TOOLSET_DLL}-mt-${BOOST_DEBUG_EXTRA}${BOOST_DLL_ARCH}-${BOOST_VERSION_DLL}.lib
${EXTERNAL_BUILD_ROOT}/lib/libboost_system-vc${BOOST_MSVC_TOOLSET_DLL}-mt-${BOOST_DEBUG_EXTRA}${BOOST_DLL_ARCH}-${BOOST_VERSION_DLL}.lib
)
set(BOOST_TARGET_OS target-os=windows)
endif()
ExternalProject_Add(boost_project
DOWNLOAD_NO_PROGRESS 1
URL ${BOOST_DOWNLOAD_URL}
PREFIX ${BOOST_BUILD_ROOT}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND
cp -f ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/user-config.jam . &&
./bootstrap.sh
${BOOST_TOOLSET}
${BOOST_TARGET_OS}
--with-libraries=atomic,chrono,date_time,filesystem,random,regex,serialization,system,thread
BUILD_COMMAND
./b2
${BOOST_COMMON_ARGS}
${BOOST_TARGET_OS}
INSTALL_COMMAND
./b2
${BOOST_COMMON_ARGS}
${BOOST_TARGET_OS}
install
)
add_dependencies(boost_project openssl_project)
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${DEBUG_EXTRA2}-x64-${BOOST_MAJOR_VERSION}_${BOOST_MINOR_VERSION}")
endif()
set(Boost_LIBRARIES
libboost_system${BOOST_LIB_EXTRA}.a
libboost_atomic${BOOST_LIB_EXTRA}.a
libboost_chrono${BOOST_LIB_EXTRA}.a
libboost_date_time${BOOST_LIB_EXTRA}.a
libboost_filesystem${BOOST_LIB_EXTRA}.a
libboost_random${BOOST_LIB_EXTRA}.a
libboost_regex${BOOST_LIB_EXTRA}.a
libboost_serialization${BOOST_LIB_EXTRA}.a
libboost_thread${BOOST_LIB_EXTRA}.a
)
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

@ -31,14 +31,20 @@ set(CURL_CMAKE_ARGS
-DUSE_LIBIDN2=OFF
)
if (MINGW AND CMAKE_TOOLCHAIN_FILE)
if (CMAKE_TOOLCHAIN_FILE)
set(CURL_CMAKE_ARGS
${CURL_CMAKE_ARGS}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
)
endif()
if (MINGW)
set(CURL_CMAKE_ARGS
${CURL_CMAKE_ARGS}
-DCURL_USE_OPENSSL=OFF
-DUSE_WIN32_CRYPTO=ON
)
elseif(NOT MINGW)
else()
set(CURL_CMAKE_ARGS
${CURL_CMAKE_ARGS}
-DCURL_USE_OPENSSL=ON
@ -54,9 +60,8 @@ ExternalProject_Add(curl_project
set(REPERTORY_DEFINITIONS ${REPERTORY_DEFINITIONS} -DCURL_STATICLIB=ON -DCURL_DISABLE_LDAP=ON)
if (MSVC)
set(CURL_LIBRARIES ${EXTERNAL_BUILD_ROOT}/lib/libcurl${DEBUG_EXTRA2}${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
set(CURL_LIBRARIES libcurl${DEBUG_EXTRA2}${CMAKE_STATIC_LIBRARY_SUFFIX})
add_dependencies(curl_project openssl_project)
endif()
set(CURL_LIBRARIES libcurl${DEBUG_EXTRA2}${CMAKE_STATIC_LIBRARY_SUFFIX})
add_dependencies(curl_project
openssl_project
zlib_project
)

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()
@ -73,49 +71,32 @@ if (UNIX OR MINGW)
${REPERTORY_COMMON_FLAG_LIST}
-std=c++${CMAKE_CXX_STANDARD}
)
elseif (MSVC)
set(REPERTORY_C_FLAGS_LIST
${REPERTORY_C_FLAGS_LIST}
/D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
/DNOMINMAX
/bigobj
/Zi
)
set(REPERTORY_CXX_FLAGS_LIST
${REPERTORY_CXX_FLAGS_LIST}
/D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
/DNOMINMAX
/bigobj
/Zi
)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(REPERTORY_C_FLAGS_LIST
${REPERTORY_C_FLAGS_LIST}
/DEBUG
)
set(REPERTORY_CXX_FLAGS_LIST
${REPERTORY_CXX_FLAGS_LIST}
/DEBUG
)
set(REPERTORY_SHARED_LINKER_FLAGS_LIST
${REPERTORY_SHARED_LINKER_FLAGS_LIST}
/DEBUG
/OPT:REF
/OPT:ICF
)
endif()
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

@ -1,5 +1,5 @@
function(copy_support_files target)
if (MSVC OR MINGW)
if (MINGW)
add_custom_command(
TARGET ${target}
POST_BUILD

View File

@ -16,17 +16,6 @@ add_dependencies(librepertory
boost_project
curl_project
libsodium_project
rocksdb_project
openssl_project
zlib_project
)
if (LINUX)
add_dependencies(librepertory libuuid_project)
endif()
if (LINUX OR MINGW OR MACOS)
add_dependencies(librepertory openssl_project)
endif()
if (MSVC OR MINGW)
add_dependencies(librepertory zlib_project)
endif()

View File

@ -2,46 +2,26 @@ set(LIBSODIUM_PROJECT_NAME libsodium_${LIBSODIUM_VERSION})
set(LIBSODIUM_BUILD_ROOT ${EXTERNAL_BUILD_ROOT}/builds/${LIBSODIUM_PROJECT_NAME})
set(LIBSODIUM_BUILD_TYPE ${EXTERNAL_BUILD_TYPE})
if (MSVC)
ExternalProject_Add(libsodium_project
DOWNLOAD_NO_PROGRESS 1
PREFIX ${LIBSODIUM_BUILD_ROOT}
BUILD_IN_SOURCE 1
URL https://github.com/jedisct1/libsodium/releases/download/${LIBSODIUM_VERSION}-RELEASE/libsodium-${LIBSODIUM_VERSION}.tar.gz
CONFIGURE_COMMAND echo "Skipping Configure"
BUILD_COMMAND cd builds\\msvc\\vs2019 && msbuild
libsodium.sln
/p:Configuration=Static${LIBSODIUM_BUILD_TYPE}
/p:Platform=x64
/t:libsodium
INSTALL_COMMAND echo "Skipping Install"
)
link_directories(PRIVATE ${LIBSODIUM_BUILD_ROOT}/src/libsodium_project/bin/x64/${LIBSODIUM_BUILD_TYPE}/v142/static)
set(LIBSODIUM_LIBRARIES libsodium.lib)
add_definitions(-DSODIUM_STATIC)
include_directories(SYSTEM
${LIBSODIUM_BUILD_ROOT}/src/libsodium_project/src/libsodium/include
${LIBSODIUM_BUILD_ROOT}/src/libsodium_project/builds/msvc
)
else()
if (MINGW)
set(LIBSODIUM_HOST --host=x86_64-w64-mingw32)
endif()
ExternalProject_Add(libsodium_project
DOWNLOAD_NO_PROGRESS 1
PREFIX ${LIBSODIUM_BUILD_ROOT}
BUILD_IN_SOURCE 1
URL https://github.com/jedisct1/libsodium/releases/download/${LIBSODIUM_VERSION}-RELEASE/libsodium-${LIBSODIUM_VERSION}.tar.gz
CONFIGURE_COMMAND
./configure
${LIBSODIUM_HOST}
--prefix=${EXTERNAL_BUILD_ROOT}
--enable-shared=no
--enable-static=yes
--disable-asm
BUILD_COMMAND make
INSTALL_COMMAND make install
)
set(LIBSODIUM_LIBRARIES libsodium.a)
if (MINGW)
set(LIBSODIUM_HOST --host=x86_64-w64-mingw32)
endif()
ExternalProject_Add(libsodium_project
DOWNLOAD_NO_PROGRESS 1
PREFIX ${LIBSODIUM_BUILD_ROOT}
BUILD_IN_SOURCE 1
URL https://github.com/jedisct1/libsodium/releases/download/${LIBSODIUM_VERSION}-RELEASE/libsodium-${LIBSODIUM_VERSION}.tar.gz
CONFIGURE_COMMAND
./configure
${LIBSODIUM_HOST}
--prefix=${EXTERNAL_BUILD_ROOT}
--enable-shared=no
--enable-static=yes
--disable-asm
BUILD_COMMAND make
INSTALL_COMMAND make install
)
set(LIBSODIUM_LIBRARIES libsodium.a)
add_dependencies(libsodium_project zlib_project)

View File

@ -1,17 +0,0 @@
if (LINUX)
set(LIBUUID_PROJECT_NAME libuuid_${LIBUUID_VERSION})
set(LIBUUID_BUILD_ROOT ${EXTERNAL_BUILD_ROOT}/builds/${LIBUUID_PROJECT_NAME})
#URL "https://www.mirrorservice.org/sites/ftp.ossp.org/pkg/lib/uuid/uuid-${LIBUUID_VERSION}.tar.gz"
ExternalProject_Add(libuuid_project
DOWNLOAD_NO_PROGRESS 1
PREFIX ${LIBUUID_BUILD_ROOT}
URL https://src.fedoraproject.org/repo/pkgs/uuid/uuid-${LIBUUID_VERSION}.tar.gz/5db0d43a9022a6ebbbc25337ae28942f/uuid-${LIBUUID_VERSION}.tar.gz
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/config.guess ./config.guess &&
cp ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/config.sub ./config.sub &&
CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER};./configure --disable-shared --enable-static --prefix=${EXTERNAL_BUILD_ROOT}
BUILD_COMMAND CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER};make
INSTALL_COMMAND make install
)
set(LIBUUID_LIBRARIES libuuid.a)
endif()

View File

@ -1,43 +1,36 @@
if (MACOS OR LINUX OR MINGW)
if (IS_CLANG_COMPILER)
set(OPENSSL_COMPILE_TYPE_EXTRA -clang)
endif()
if (MACOS)
set(OPENSSL_COMPILE_TYPE darwin64-x86_64-cc)
elseif(IS_ARM64)
set(OPENSSL_COMPILE_TYPE linux-aarch64${OPENSSL_COMPILE_TYPE_EXTRA})
elseif(MINGW)
if (CMAKE_TOOLCHAIN_FILE)
set(OPENSSL_COMPILE_TYPE --cross-compile-prefix=x86_64-w64-mingw32- mingw64${OPENSSL_COMPILE_TYPE_EXTRA})
else()
set(OPENSSL_COMPILE_TYPE mingw64${OPENSSL_COMPILE_TYPE_EXTRA})
endif()
else()
set(OPENSSL_COMPILE_TYPE linux-x86_64${OPENSSL_COMPILE_TYPE_EXTRA})
endif()
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
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}
BUILD_COMMAND make -j1
INSTALL_COMMAND make install
)
if (MACOS)
set(OPENSSL_LIBRARIES
${EXTERNAL_BUILD_ROOT}/lib/libssl.a
${EXTERNAL_BUILD_ROOT}/lib/libcrypto.a
)
else()
set(OPENSSL_LIBRARIES
libssl.a
libcrypto.a
)
endif()
if (IS_CLANG_COMPILER)
set(OPENSSL_COMPILE_TYPE_EXTRA -clang)
endif()
if (MACOS)
set(OPENSSL_COMPILE_TYPE darwin64-x86_64-cc)
elseif(IS_ARM64)
set(OPENSSL_COMPILE_TYPE linux-aarch64${OPENSSL_COMPILE_TYPE_EXTRA})
elseif(MINGW)
if (CMAKE_TOOLCHAIN_FILE)
set(OPENSSL_COMPILE_TYPE --cross-compile-prefix=x86_64-w64-mingw32- mingw64${OPENSSL_COMPILE_TYPE_EXTRA})
else()
set(OPENSSL_COMPILE_TYPE mingw64${OPENSSL_COMPILE_TYPE_EXTRA})
endif()
else()
set(OPENSSL_COMPILE_TYPE linux-x86_64${OPENSSL_COMPILE_TYPE_EXTRA})
endif()
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/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}
BUILD_COMMAND make -j1
INSTALL_COMMAND make install
)
set(OPENSSL_LIBRARIES
${EXTERNAL_BUILD_ROOT}/lib/libssl.a
${EXTERNAL_BUILD_ROOT}/lib/libcrypto.a
)
add_dependencies(openssl_project zlib_project)

View File

@ -1,82 +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(MSVC)
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}
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping install step."
)
set(ROCKSDB_INCLUDE_DIRS ${ROCKSDB_BUILD_ROOT}/src/rocksdb_project/include)
if (CMAKE_GENERATOR_LOWER STREQUAL "nmake makefiles")
set(ROCKSDB_LIBRARIES ${ROCKSDB_BUILD_ROOT}/src/rocksdb_project-build/rocksdb.lib)
else ()
set(ROCKSDB_LIBRARIES ${ROCKSDB_BUILD_ROOT}/src/rocksdb_project-build/${CMAKE_BUILD_TYPE}/rocksdb.lib)
endif ()
else()
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()
endif()
if (MSVC OR LINUX OR MINGW)
add_dependencies(rocksdb_project curl_project)
endif()

View File

@ -8,7 +8,7 @@ else()
endif()
set(CMAKE_COLOR_MAKEFILE OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
@ -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

@ -4,58 +4,33 @@ if (REPERTORY_ENABLE_TESTING)
set(GTEST_PROJECT_NAME gtest_${GTEST_VERSION})
set(GTEST_BUILD_ROOT ${EXTERNAL_BUILD_ROOT}/builds/${GTEST_PROJECT_NAME})
if (MSVC)
ExternalProject_Add(gtest_project
DOWNLOAD_NO_PROGRESS 1
URL https://github.com/google/googletest/archive/refs/tags/${GTEST_VERSION}.tar.gz
PREFIX ${GTEST_BUILD_ROOT}
CMAKE_ARGS
-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}
-DCMAKE_BUILD_TYPE=${EXTERNAL_BUILD_TYPE}
-Dgtest_force_shared_crt=OFF
-DBUILD_SHARED_LIBS=ON
-DCMAKE_CXX_FLAGS=/D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping install step."
)
if (MACOS)
set(GTEST_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
set(GTEST_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
else()
if (MACOS)
set(GTEST_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
set(GTEST_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
else()
set(GTEST_C_FLAGS ${CMAKE_C_FLAGS})
set(GTEST_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()
ExternalProject_Add(gtest_project
DOWNLOAD_NO_PROGRESS 1
URL https://github.com/google/googletest/archive/refs/tags/${GTEST_VERSION}.tar.gz
PREFIX ${GTEST_BUILD_ROOT}
CMAKE_ARGS
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_C_FLAGS=${GTEST_C_FLAGS}
-DCMAKE_CXX_FLAGS=${GTEST_CXX_FLAGS}
-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}
-DCMAKE_BUILD_TYPE=${EXTERNAL_BUILD_TYPE}
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping install step."
)
set(GTEST_C_FLAGS ${CMAKE_C_FLAGS})
set(GTEST_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()
ExternalProject_Add(gtest_project
DOWNLOAD_NO_PROGRESS 1
URL https://github.com/google/googletest/archive/refs/tags/${GTEST_VERSION}.tar.gz
PREFIX ${GTEST_BUILD_ROOT}
CMAKE_ARGS
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_C_FLAGS=${GTEST_C_FLAGS}
-DCMAKE_CXX_FLAGS=${GTEST_CXX_FLAGS}
-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}
-DCMAKE_BUILD_TYPE=${EXTERNAL_BUILD_TYPE}
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping install step."
)
set(GTEST_INCLUDE_DIRS
${GTEST_BUILD_ROOT}/src/gtest_project/googletest/include
${GTEST_BUILD_ROOT}/src/gtest_project/googlemock/include
)
if (MSVC)
if (NOT CMAKE_GENERATOR_LOWER STREQUAL "nmake makefiles")
set (GTEST_PATH_EXTRA ${CMAKE_BUILD_TYPE}/)
endif()
set(GTEST_LIBRARIES
${GTEST_BUILD_ROOT}/src/gtest_project-build/lib/${GTEST_PATH_EXTRA}gmock${DEBUG_EXTRA}.lib
${GTEST_BUILD_ROOT}/src/gtest_project-build/lib/${GTEST_PATH_EXTRA}gmock_main${DEBUG_EXTRA}.lib
${GTEST_BUILD_ROOT}/src/gtest_project-build/lib/${GTEST_PATH_EXTRA}gtest${DEBUG_EXTRA}.lib
${GTEST_BUILD_ROOT}/src/gtest_project-build/lib/${GTEST_PATH_EXTRA}gtest_main${DEBUG_EXTRA}.lib
)
elseif (UNIX OR MINGW)
if(UNIX OR MINGW)
set(GTEST_LIBRARIES
${GTEST_BUILD_ROOT}/src/gtest_project-build/lib/libgmock.a
${GTEST_BUILD_ROOT}/src/gtest_project-build/lib/libgtest.a
@ -72,7 +47,11 @@ if (REPERTORY_ENABLE_TESTING)
)
add_project_executable(unittests "${UNITTEST_SOURCES}")
add_dependencies(unittests gtest_project)
add_dependencies(unittests
gtest_project
zlib_project
)
target_compile_definitions(unittests PUBLIC
GTEST_LINKED_AS_SHARED_LIBRARY=1
REPERTORY_TESTING
@ -83,28 +62,5 @@ if (REPERTORY_ENABLE_TESTING)
)
target_link_libraries(unittests PRIVATE ${GTEST_LIBRARIES})
if (MSVC)
add_custom_command(TARGET unittests
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${GTEST_BUILD_ROOT}/src/gtest_project-build/bin/${GTEST_PATH_EXTRA}gmock${DEBUG_EXTRA}.dll ${CMAKE_CURRENT_BINARY_DIR}/${GTEST_PATH_EXTRA}
)
add_custom_command(TARGET unittests
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${GTEST_BUILD_ROOT}/src/gtest_project-build/bin/${GTEST_PATH_EXTRA}gmock_main${DEBUG_EXTRA}.dll ${CMAKE_CURRENT_BINARY_DIR}/${GTEST_PATH_EXTRA}
)
add_custom_command(TARGET unittests
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${GTEST_BUILD_ROOT}/src/gtest_project-build/bin/${GTEST_PATH_EXTRA}gtest${DEBUG_EXTRA}.dll ${CMAKE_CURRENT_BINARY_DIR}/${GTEST_PATH_EXTRA}
)
add_custom_command(TARGET unittests
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${GTEST_BUILD_ROOT}/src/gtest_project-build/bin/${GTEST_PATH_EXTRA}gtest_main${DEBUG_EXTRA}.dll ${CMAKE_CURRENT_BINARY_DIR}/${GTEST_PATH_EXTRA}
)
endif()
if (CMAKE_GENERATOR_LOWER STREQUAL "nmake makefiles")
add_test(NAME AllTests COMMAND unittests WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
else()
add_test(NAME AllTests COMMAND unittests WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
endif()
add_test(NAME AllTests COMMAND unittests WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
endif()

View File

@ -1,16 +1,9 @@
set(BOOST_MAJOR_VERSION 1)
set(BOOST_MINOR_VERSION 78)
set(BOOST_MSVC_TOOLSET msvc-14.2)
set(BOOST_MSVC_TOOLSET_DLL 142)
set(BOOST_MINOR_VERSION 83)
set(BOOST_REVISION 0)
set(BOOST_VERSION ${BOOST_MAJOR_VERSION}.${BOOST_MINOR_VERSION}.${BOOST_REVISION})
set(BOOST_VERSION_DL ${BOOST_MAJOR_VERSION}_${BOOST_MINOR_VERSION}_${BOOST_REVISION})
set(BOOST_VERSION_DLL ${BOOST_MAJOR_VERSION}_${BOOST_MINOR_VERSION})
set(CURL_VERSION 8_3_0)
set(CURL_VERSION 8_5_0)
set(GTEST_VERSION v1.14.0)
set(LIBSODIUM_VERSION 1.0.18)
set(LIBUUID_VERSION 1.6.2)
set(OPENSSL_VERSION 1_1_1w)
set(ROCKSDB_VERSION 8.5.3)
set(LIBSODIUM_VERSION 1.0.19)
set(OPENSSL_VERSION 3.2.0)
set(WINFSP_VERSION 2.0)
set(ZLIB_VERSION v1.3)

View File

@ -1,42 +1,31 @@
if (MSVC OR MINGW)
set(ZLIB_PROJECT_NAME zlib_${ZLIB_VERSION})
set(ZLIB_BUILD_ROOT ${EXTERNAL_BUILD_ROOT}/builds/${ZLIB_PROJECT_NAME})
set(ZLIB_PROJECT_NAME zlib_${ZLIB_VERSION})
set(ZLIB_BUILD_ROOT ${EXTERNAL_BUILD_ROOT}/builds/${ZLIB_PROJECT_NAME})
set(ZLIB_CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${EXTERNAL_BUILD_TYPE}
-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}
)
if (CMAKE_TOOLCHAIN_FILE)
set(ZLIB_CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${EXTERNAL_BUILD_TYPE}
-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}
${ZLIB_CMAKE_ARGS}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
)
if (MINGW AND CMAKE_TOOLCHAIN_FILE)
set(ZLIB_CMAKE_ARGS
${ZLIB_CMAKE_ARGS}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
)
endif()
ExternalProject_Add(zlib_project
DOWNLOAD_NO_PROGRESS 1
URL https://github.com/madler/zlib/archive/${ZLIB_VERSION}.tar.gz
PREFIX ${ZLIB_BUILD_ROOT}
CMAKE_ARGS ${ZLIB_CMAKE_ARGS}
)
if (MINGW)
set(ZLIB_LIBRARIES ${EXTERNAL_BUILD_ROOT}/lib/libzlibstatic${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
set(ZLIB_LIBRARIES ${EXTERNAL_BUILD_ROOT}/lib/zlibstatic${DEBUG_EXTRA}${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
elseif(LINUX)
find_library(ZLIB_LIBRARIES NO_CACHE NAMES z)
if (NOT ZLIB_LIBRARIES)
message(FATAL_ERROR "'zlib' not found")
endif()
if (REPERTORY_MUSL)
set(ZLIB_LIBRARIES libz.a)
endif()
endif()
ExternalProject_Add(zlib_project
DOWNLOAD_NO_PROGRESS 1
URL https://github.com/madler/zlib/archive/${ZLIB_VERSION}.tar.gz
PREFIX ${ZLIB_BUILD_ROOT}
CMAKE_ARGS ${ZLIB_CMAKE_ARGS}
)
if(MINGW)
set(ZLIB_LIBRARIES ${EXTERNAL_BUILD_ROOT}/lib/libzlibstatic${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
set(ZLIB_LIBRARIES ${EXTERNAL_BUILD_ROOT}/lib/libz${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()

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

@ -30,39 +30,42 @@
namespace repertory {
class app_config final {
public:
[[nodiscard]] static auto default_agent_name(const provider_type &pt)
[[nodiscard]] static auto default_agent_name(const provider_type &prov)
-> std::string;
[[nodiscard]] static auto default_api_port(const provider_type &pt)
[[nodiscard]] static auto default_api_port(const provider_type &prov)
-> std::uint16_t;
[[nodiscard]] static auto default_data_directory(const provider_type &pt)
[[nodiscard]] static auto default_data_directory(const provider_type &prov)
-> std::string;
[[nodiscard]] static auto default_rpc_port(const provider_type &pt)
[[nodiscard]] static auto default_remote_port(const provider_type &prov)
-> std::uint16_t;
[[nodiscard]] static auto get_provider_api_password(const provider_type &pt)
[[nodiscard]] static auto default_rpc_port(const provider_type &prov)
-> std::uint16_t;
[[nodiscard]] static auto get_provider_api_password(const provider_type &prov)
-> std::string;
[[nodiscard]] static auto get_provider_display_name(const provider_type &pt)
[[nodiscard]] static auto get_provider_display_name(const provider_type &prov)
-> std::string;
[[nodiscard]] static auto get_provider_name(const provider_type &pt)
[[nodiscard]] static auto get_provider_name(const provider_type &prov)
-> std::string;
public:
app_config(const provider_type &pt, const std::string &data_directory = "");
app_config(const provider_type &prov, const std::string &data_directory = "");
~app_config() { save(); }
private:
const provider_type pt_;
provider_type prov_;
std::string api_auth_;
std::uint16_t api_port_;
std::string api_user_;
bool config_changed_;
const std::string data_directory_;
std::string data_directory_;
std::uint8_t download_timeout_secs_;
bool enable_chunk_downloader_timeout_;
bool enable_comm_duration_events_;
@ -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;
@ -129,7 +132,7 @@ private:
template <typename dest, typename source>
auto set_value(dest &dst, const source &src) -> bool {
auto ret = false;
recur_mutex_lock l(read_write_mutex_);
recur_mutex_lock lock(read_write_mutex_);
if (dst != src) {
dst = src;
config_changed_ = true;
@ -244,7 +247,9 @@ public:
download_type::fallback);
}
[[nodiscard]] auto get_provider_type() const -> provider_type { return pt_; }
[[nodiscard]] auto get_provider_type() const -> provider_type {
return prov_;
}
[[nodiscard]] auto get_read_ahead_count() const -> std::uint8_t {
return std::max(static_cast<std::uint8_t>(1U), read_ahead_count_);
@ -358,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

@ -23,14 +23,12 @@
#define INCLUDE_CLI_ACTIONS_HPP_
#include "cli/check_version.hpp"
#include "cli/create_directory.hpp"
#include "cli/display_config.hpp"
#include "cli/drive_information.hpp"
#include "cli/get.hpp"
#include "cli/get_directory_items.hpp"
#include "cli/get_pinned_files.hpp"
#include "cli/help.hpp"
#include "cli/list_objects.hpp"
#include "cli/mount.hpp"
#include "cli/open_files.hpp"
#include "cli/pin_file.hpp"
@ -44,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]);
}
};
@ -57,11 +55,6 @@ static const std::unordered_map<utils::cli::option, action, option_hasher>
option_actions = {
{utils::cli::options::check_version_option,
cli::actions::check_version},
#if defined(REPERTORY_ENABLE_S3)
{utils::cli::options::create_directory_option,
cli::actions::create_directory},
{utils::cli::options::list_objects_option, cli::actions::list_objects},
#endif
{utils::cli::options::display_config_option,
cli::actions::display_config},
{utils::cli::options::drive_information_option,
@ -82,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

@ -1,80 +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_CLI_CREATE_DIRECTORY_HPP_
#define INCLUDE_CLI_CREATE_DIRECTORY_HPP_
#if defined(REPERTORY_ENABLE_S3)
#include "app_config.hpp"
#include "comm/s3/s3_comm.hpp"
#include "platform/platform.hpp"
#include "providers/i_provider.hpp"
#include "providers/provider.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
[[nodiscard]] inline auto
create_directory(int argc, char *argv[], 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::invalid_provider_type;
if (pt == provider_type::s3) {
std::string api_path;
if ((ret = utils::cli::parse_string_option(
argc, argv, utils::cli::options::create_directory_option,
api_path)) == exit_code::success) {
lock_data lock(pt, 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,
* data_directory); */
/* const auto response = */
/* client({"localhost", password, port,
* user}).create_directory(api_path); */
/* std::cout << static_cast<int>(response.response_type) << std::endl; */
/* std::cout << response.data.dump(2) << std::endl; */
/* } else */
if (res == lock_result::success) {
std::cout << "creating directory: '" << api_path << "'" << std::endl;
app_config config(pt, data_directory);
s3_comm comm(config);
const auto res = comm.create_directory(api_path);
std::cout << api_error_to_string(res) << std::endl;
ret = exit_code::success;
} else {
std::cout << "failed to grab lock: '" << static_cast<int>(res) << "'"
<< std::endl;
ret = exit_code::lock_failed;
}
}
}
return ret;
}
} // namespace repertory::cli::actions
#endif // REPERTORY_ENABLE_S3
#endif // INCLUDE_CLI_CREATE_DIRECTORY_HPP_

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"
@ -42,11 +42,6 @@ template <typename drive> inline void help(int argc, char *argv[]) {
std::cout << " -na,--name Unique name for S3 "
"instance [Required]"
<< std::endl;
std::cout
<< " -cd,--create_directory [API path] Create directory object in S3"
<< std::endl;
std::cout << " -lo,--list_objects List all S3 objects"
<< std::endl;
#endif // defined(REPERTORY_ENABLE_S3)
std::cout
<< " -gc,--generate_config Generate initial configuration"

View File

@ -1,81 +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_CLI_LIST_OBJECTS_HPP_
#define INCLUDE_CLI_LIST_OBJECTS_HPP_
#if defined(REPERTORY_ENABLE_S3)
#include "app_config.hpp"
#include "comm/s3/s3_comm.hpp"
#include "platform/platform.hpp"
#include "providers/i_provider.hpp"
#include "providers/provider.hpp"
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "utils/cli_utils.hpp"
namespace repertory::cli::actions {
[[nodiscard]] inline auto
list_objects(int /* argc */, char * /* argv */[],
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::invalid_provider_type;
if (pt == provider_type::s3) {
lock_data lock(pt, 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,
* data_directory); */
/* const auto response = */
/* client({"localhost", password, port,
* user}).create_directory(api_path); */
/* std::cout << static_cast<int>(response.response_type) << std::endl; */
/* std::cout << response.data.dump(2) << std::endl; */
/* } else */
if (res == lock_result::success) {
app_config config(pt, data_directory);
s3_comm comm(config);
std::vector<directory_item> list{};
const auto res = comm.get_object_list(list);
if (res == api_error::success) {
for (const auto &di : list) {
std::cout << di.to_json().dump(2) << std::endl;
}
ret = exit_code::success;
} else {
std::cout << api_error_to_string(res) << std::endl;
}
} else {
std::cout << "failed to grab lock: '" << static_cast<int>(res) << "'"
<< std::endl;
ret = exit_code::lock_failed;
}
}
return ret;
}
} // namespace repertory::cli::actions
#endif // REPERTORY_ENABLE_S3
#endif // INCLUDE_CLI_LIST_OBJECTS_HPP_

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"
@ -32,9 +34,9 @@ class curl_comm final : public i_http_comm {
public:
curl_comm() = delete;
explicit curl_comm(host_config hc);
explicit curl_comm(host_config cfg);
explicit curl_comm(s3_config s3);
explicit curl_comm(s3_config cfg);
private:
using write_callback = size_t (*)(char *, size_t, size_t, void *);
@ -57,9 +59,10 @@ private:
public:
[[nodiscard]] static auto construct_url(CURL *curl,
const std::string &relative_path,
const host_config &hc) -> std::string;
const host_config &cfg)
-> std::string;
[[nodiscard]] static auto create_host_config(const s3_config &config,
[[nodiscard]] static auto create_host_config(const s3_config &cfg,
bool use_s3_path_style)
-> host_config;
@ -68,7 +71,7 @@ public:
template <typename request_type>
[[nodiscard]] static auto
make_encrypted_request(const host_config &hc, const request_type &request,
make_encrypted_request(const host_config &cfg, const request_type &request,
long &response_code, stop_type &stop_requested)
-> bool {
response_code = 0;
@ -102,7 +105,7 @@ public:
};
encrypted_request.total_size = std::nullopt;
if (not make_request(hc, encrypted_request, response_code,
if (not make_request(cfg, encrypted_request, response_code,
stop_requested)) {
return api_error::comm_error;
}
@ -127,11 +130,12 @@ public:
template <typename request_type>
[[nodiscard]] static auto
make_request(const host_config &hc, const request_type &request,
make_request(const host_config &cfg, const request_type &request,
long &response_code, stop_type &stop_requested) -> bool {
if (request.decryption_token.has_value() &&
not request.decryption_token.value().empty()) {
return make_encrypted_request(hc, request, response_code, stop_requested);
return make_encrypted_request(cfg, request, response_code,
stop_requested);
}
response_code = 0;
@ -141,12 +145,12 @@ public:
return false;
}
if (not hc.agent_string.empty()) {
curl_easy_setopt(curl, CURLOPT_USERAGENT, hc.agent_string.c_str());
if (not cfg.agent_string.empty()) {
curl_easy_setopt(curl, CURLOPT_USERAGENT, cfg.agent_string.c_str());
}
if (request.allow_timeout && hc.timeout_ms) {
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, hc.timeout_ms);
if (request.allow_timeout && cfg.timeout_ms) {
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, cfg.timeout_ms);
}
std::string range_list{};
@ -169,16 +173,16 @@ public:
}
std::string parameters{};
for (const auto &kv : request.query) {
parameters += (parameters.empty() ? '?' : '&') + kv.first + '=' +
url_encode(curl, kv.second, false);
for (const auto &param : request.query) {
parameters += (parameters.empty() ? '?' : '&') + param.first + '=' +
url_encode(curl, param.second, false);
}
if (not hc.api_password.empty()) {
curl_easy_setopt(curl, CURLOPT_USERNAME, hc.api_user.c_str());
curl_easy_setopt(curl, CURLOPT_PASSWORD, hc.api_password.c_str());
} else if (not hc.api_user.empty()) {
curl_easy_setopt(curl, CURLOPT_USERNAME, hc.api_user.c_str());
if (not cfg.api_password.empty()) {
curl_easy_setopt(curl, CURLOPT_USERNAME, cfg.api_user.c_str());
curl_easy_setopt(curl, CURLOPT_PASSWORD, cfg.api_password.c_str());
} else if (not cfg.api_user.empty()) {
curl_easy_setopt(curl, CURLOPT_USERNAME, cfg.api_user.c_str());
}
if (request.aws_service.has_value()) {
@ -186,7 +190,7 @@ public:
request.aws_service.value().c_str());
}
auto url = construct_url(curl, request.get_path(), hc) + parameters;
auto url = construct_url(curl, request.get_path(), cfg) + parameters;
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
multi_request curl_request(curl, stop_requested);
@ -194,6 +198,7 @@ public:
CURLcode curl_code{};
curl_request.get_result(curl_code, response_code);
if (curl_code != CURLE_OK) {
event_system::instance().raise<curl_error>(url, curl_code);
return false;
}
@ -222,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

@ -26,6 +26,11 @@
namespace repertory::curl::requests {
struct http_get final : http_request_base {
http_get() = default;
http_get(const http_get &) = default;
http_get(http_get &&) = default;
auto operator=(const http_get &) -> http_get & = default;
auto operator=(http_get &&) -> http_get & = default;
~http_get() override = default;
[[nodiscard]] auto set_method(CURL *curl,

View File

@ -19,39 +19,31 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef REPERTORY_META_DB_FIXTURE_H
#define REPERTORY_META_DB_FIXTURE_H
#ifndef INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_POST_HPP_
#define INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_POST_HPP_
#include "test_common.hpp"
#include "comm/curl/requests/http_request_base.hpp"
#include "app_config.hpp"
#include "db/meta_db.hpp"
#include "utils/path_utils.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;
namespace repertory {
class meta_db_test : public ::testing::Test {
private:
const std::string config_location_ = utils::path::absolute("./metadb");
protected:
std::unique_ptr<app_config> config_;
std::unique_ptr<meta_db> db_;
public:
void SetUp() override {
ASSERT_TRUE(utils::file::delete_directory_recursively(config_location_));
config_ =
std::make_unique<app_config>(provider_type::sia, config_location_);
db_ = std::make_unique<meta_db>(*config_.get());
}
void TearDown() override {
db_.reset();
config_.reset();
EXPECT_TRUE(utils::file::delete_directory_recursively(config_location_));
}
mutable curl_slist *headers{nullptr};
mutable std::optional<std::string> json_str;
};
} // namespace repertory
} // namespace repertory::curl::requests
#endif // REPERTORY_META_DB_FIXTURE_H
#endif // INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_POST_HPP_

View File

@ -27,14 +27,17 @@
namespace repertory::curl::requests {
struct http_put_file final : http_request_base {
http_put_file() = default;
http_put_file(const http_put_file &) = default;
http_put_file(http_put_file &&) = default;
auto operator=(const http_put_file &) -> http_put_file & = default;
auto operator=(http_put_file &&) -> http_put_file & = default;
~http_put_file() override = default;
std::optional<std::string> encryption_token{};
std::string file_name{};
mutable std::shared_ptr<utils::encryption::encrypting_reader> reader{};
std::string source_path{};
[[nodiscard]] auto get_path() const -> std::string override;
std::shared_ptr<utils::encryption::encrypting_reader> reader;
std::string source_path;
[[nodiscard]] auto set_method(CURL *curl, stop_type &stop_requested) const
-> bool override;

View File

@ -39,17 +39,25 @@ struct read_file_info final {
inline const auto read_file_data = static_cast<read_callback>(
[](char *buffer, size_t size, size_t nitems, void *instream) -> size_t {
auto *rd = reinterpret_cast<read_file_info *>(instream);
auto *read_info = reinterpret_cast<read_file_info *>(instream);
std::size_t bytes_read{};
auto ret =
rd->nf->read_bytes(buffer, size * nitems, rd->offset, bytes_read);
auto ret = read_info->nf->read_bytes(buffer, size * nitems,
read_info->offset, bytes_read);
if (ret) {
rd->offset += bytes_read;
read_info->offset += bytes_read;
}
return ret && not rd->stop_requested ? bytes_read : CURL_READFUNC_ABORT;
return ret && not read_info->stop_requested ? bytes_read
: CURL_READFUNC_ABORT;
});
struct http_request_base {
http_request_base() = default;
http_request_base(const http_request_base &) = default;
http_request_base(http_request_base &&) = default;
auto operator=(const http_request_base &) -> http_request_base & = default;
auto operator=(http_request_base &&) -> http_request_base & = default;
virtual ~http_request_base() = default;
bool allow_timeout{};

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,109 +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_I_S3_COMM_HPP_
#define INCLUDE_COMM_I_S3_COMM_HPP_
#if defined(REPERTORY_ENABLE_S3)
#include "types/repertory.hpp"
#include "types/s3.hpp"
namespace repertory {
class i_provider;
class i_s3_comm {
INTERFACE_SETUP(i_s3_comm);
public:
[[nodiscard]] virtual auto create_directory(const std::string &api_path)
-> api_error = 0;
[[nodiscard]] virtual auto directory_exists(const std::string &api_path) const
-> api_error = 0;
[[nodiscard]] virtual auto file_exists(const std::string &api_path,
const get_key_callback &get_key) const
-> api_error = 0;
[[nodiscard]] virtual auto
get_directory_item_count(const std::string &api_path,
meta_provider_callback meta_provider) const
-> std::size_t = 0;
[[nodiscard]] virtual auto
get_directory_items(const std::string &api_path,
meta_provider_callback meta_provider,
directory_item_list &list) const -> api_error = 0;
[[nodiscard]] virtual auto get_directory_list(api_file_list &list) const
-> api_error = 0;
[[nodiscard]] virtual auto get_file(const std::string &api_path,
const get_key_callback &get_key,
const get_name_callback &get_name,
const get_token_callback &get_token,
api_file &file) const -> api_error = 0;
[[nodiscard]] virtual auto
get_file_list(const get_api_file_token_callback &get_api_file_token,
const get_name_callback &get_name, api_file_list &list) const
-> api_error = 0;
[[nodiscard]] virtual auto
get_object_list(std::vector<directory_item> &list) const -> api_error = 0;
[[nodiscard]] virtual auto
get_object_name(const std::string &api_path,
const get_key_callback &get_key) const -> std::string = 0;
[[nodiscard]] virtual auto get_s3_config() -> s3_config = 0;
[[nodiscard]] virtual auto get_s3_config() const -> s3_config = 0;
[[nodiscard]] virtual auto is_online() const -> bool = 0;
[[nodiscard]] virtual auto read_file_bytes(
const std::string &api_path, std::size_t size, std::uint64_t offset,
data_buffer &data, const get_key_callback &get_key,
const get_size_callback &get_size, const get_token_callback &get_token,
stop_type &stop_requested) const -> api_error = 0;
[[nodiscard]] virtual auto remove_directory(const std::string &api_path)
-> api_error = 0;
[[nodiscard]] virtual auto remove_file(const std::string &api_path,
const get_key_callback &get_key)
-> api_error = 0;
[[nodiscard]] virtual auto rename_file(const std::string &api_path,
const std::string &new_api_path)
-> api_error = 0;
[[nodiscard]] virtual auto
upload_file(const std::string &api_path, const std::string &source_path,
const std::string &encryption_token,
const get_key_callback &get_key, const set_key_callback &set_key,
stop_type &stop_requested) -> api_error = 0;
};
} // namespace repertory
#endif // REPERTORY_ENABLE_S3
#endif // INCLUDE_COMM_I_S3_COMM_HPP_

View File

@ -56,11 +56,17 @@ private:
~pool() { shutdown(); }
public:
pool(const pool &) = delete;
pool(pool &&) = delete;
auto operator=(const pool &) -> pool & = delete;
auto operator=(pool &&) -> pool & = delete;
private:
std::vector<std::unique_ptr<work_queue>> pool_queues_;
std::vector<std::thread> pool_threads_;
bool shutdown_ = false;
std::atomic<std::uint8_t> thread_index_;
bool shutdown_{false};
std::atomic<std::uint8_t> thread_index_{};
public:
void execute(std::uint64_t thread_id, const worker_callback &worker,
@ -70,17 +76,26 @@ private:
};
public:
explicit client_pool(std::uint8_t pool_size = 10u)
: pool_size_(pool_size ? pool_size : 10u) {}
explicit client_pool(std::uint8_t pool_size = min_pool_size)
: pool_size_(pool_size == 0U ? min_pool_size : pool_size) {}
~client_pool() { shutdown(); }
public:
client_pool(const client_pool &) = delete;
client_pool(client_pool &&) = delete;
auto operator=(const client_pool &) -> client_pool & = delete;
auto operator=(client_pool &&) -> client_pool & = delete;
private:
const std::uint8_t pool_size_;
std::uint8_t pool_size_;
std::unordered_map<std::string, std::shared_ptr<pool>> pool_lookup_;
std::mutex pool_mutex_;
bool shutdown_ = false;
private:
static constexpr const auto min_pool_size = 10U;
public:
void execute(const std::string &client_id, std::uint64_t thread_id,
const worker_callback &worker,

View File

@ -44,14 +44,16 @@ public:
explicit packet(data_buffer &&buffer) : buffer_(std::move(buffer)) {}
packet(const packet &p) noexcept = default;
packet(const packet &pkt) noexcept = default;
packet(packet &&p) noexcept
: buffer_(std::move(p.buffer_)), decode_offset_(p.decode_offset_) {}
packet(packet &&pkt) noexcept
: buffer_(std::move(pkt.buffer_)), decode_offset_(pkt.decode_offset_) {}
~packet() = default;
private:
data_buffer buffer_;
std::size_t decode_offset_ = 0u;
std::size_t decode_offset_ = 0U;
public:
[[nodiscard]] static auto decode_json(packet &response, json &json_data)
@ -78,48 +80,46 @@ public:
[[nodiscard]] auto decode(void *&ptr) -> error_type;
[[nodiscard]] auto decode(std::int8_t &i) -> error_type;
[[nodiscard]] auto decode(std::int8_t &val) -> error_type;
[[nodiscard]] auto decode(std::uint8_t &i) -> error_type;
[[nodiscard]] auto decode(std::uint8_t &val) -> error_type;
[[nodiscard]] auto decode(std::int16_t &i) -> error_type;
[[nodiscard]] auto decode(std::int16_t &val) -> error_type;
[[nodiscard]] auto decode(std::uint16_t &i) -> error_type;
[[nodiscard]] auto decode(std::uint16_t &val) -> error_type;
[[nodiscard]] auto decode(std::int32_t &i) -> error_type;
[[nodiscard]] auto decode(std::int32_t &val) -> error_type;
[[nodiscard]] auto decode(std::uint32_t &i) -> error_type;
[[nodiscard]] auto decode(std::uint32_t &val) -> error_type;
[[nodiscard]] auto decode(std::int64_t &i) -> error_type;
[[nodiscard]] auto decode(std::int64_t &val) -> error_type;
[[nodiscard]] auto decode(std::uint64_t &i) -> error_type;
[[nodiscard]] auto decode(std::uint64_t &val) -> error_type;
[[nodiscard]] auto decode(remote::open_flags &i) -> error_type {
return decode(reinterpret_cast<std::uint32_t &>(i));
[[nodiscard]] auto decode(remote::open_flags &val) -> error_type {
return decode(reinterpret_cast<std::uint32_t &>(val));
}
[[nodiscard]] auto decode(remote::setattr_x &i) -> error_type;
[[nodiscard]] auto decode(remote::setattr_x &val) -> error_type;
[[nodiscard]] auto decode(remote::stat &i) -> error_type;
[[nodiscard]] auto decode(remote::stat &val) -> error_type;
[[nodiscard]] auto decode(remote::statfs &i) -> error_type;
[[nodiscard]] auto decode(remote::statfs &val) -> error_type;
[[nodiscard]] auto decode(remote::statfs_x &i) -> error_type;
[[nodiscard]] auto decode(remote::statfs_x &val) -> error_type;
[[nodiscard]] auto decode(remote::file_info &i) -> error_type;
[[nodiscard]] auto decode(remote::file_info &val) -> error_type;
[[nodiscard]] auto decrypt(const std::string &token) -> error_type;
void encode(const void *buffer, std::size_t size, bool should_reserve = true);
void encode(char *str) { encode(std::string(str ? str : "")); }
void encode(const char *str) { encode(std::string(str ? str : "")); }
void encode(const char *str) {
encode(std::string(str == nullptr ? "" : str));
}
void encode(const std::string &str);
void encode(wchar_t *str);
void encode(const wchar_t *str);
void encode(const std::wstring &str);
@ -128,33 +128,35 @@ public:
encode(static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(ptr)));
}
void encode(std::int8_t i);
void encode(std::int8_t val);
void encode(std::uint8_t i);
void encode(std::uint8_t val);
void encode(std::int16_t i);
void encode(std::int16_t val);
void encode(std::uint16_t i);
void encode(std::uint16_t val);
void encode(std::int32_t i);
void encode(std::int32_t val);
void encode(std::uint32_t i);
void encode(std::uint32_t val);
void encode(std::int64_t i);
void encode(std::int64_t val);
void encode(std::uint64_t i);
void encode(std::uint64_t val);
void encode(remote::open_flags i) { encode(static_cast<std::uint32_t>(i)); }
void encode(remote::open_flags val) {
encode(static_cast<std::uint32_t>(val));
}
void encode(remote::setattr_x i);
void encode(remote::setattr_x val);
void encode(remote::stat i);
void encode(remote::stat val);
void encode(remote::statfs i, bool should_reserve = true);
void encode(remote::statfs val, bool should_reserve = true);
void encode(remote::statfs_x i);
void encode(remote::statfs_x val);
void encode(remote::file_info i);
void encode(remote::file_info val);
void encode_top(const void *buffer, std::size_t size,
bool should_reserve = true);
@ -168,35 +170,35 @@ public:
static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(ptr)));
}
void encode_top(std::int8_t i);
void encode_top(std::int8_t val);
void encode_top(std::uint8_t i);
void encode_top(std::uint8_t val);
void encode_top(std::int16_t i);
void encode_top(std::int16_t val);
void encode_top(std::uint16_t i);
void encode_top(std::uint16_t val);
void encode_top(std::int32_t i);
void encode_top(std::int32_t val);
void encode_top(std::uint32_t i);
void encode_top(std::uint32_t val);
void encode_top(std::int64_t i);
void encode_top(std::int64_t val);
void encode_top(std::uint64_t i);
void encode_top(std::uint64_t val);
void encode_top(remote::open_flags i) {
encode_top(static_cast<std::uint32_t>(i));
void encode_top(remote::open_flags val) {
encode_top(static_cast<std::uint32_t>(val));
}
void encode_top(remote::setattr_x i);
void encode_top(remote::setattr_x val);
void encode_top(remote::stat i);
void encode_top(remote::stat val);
void encode_top(remote::statfs i, bool should_reserve = true);
void encode_top(remote::statfs val, bool should_reserve = true);
void encode_top(remote::statfs_x i);
void encode_top(remote::statfs_x val);
void encode_top(remote::file_info i);
void encode_top(remote::file_info val);
void encrypt(const std::string &token);
@ -211,9 +213,9 @@ public:
auto operator=(data_buffer &&buffer) noexcept -> packet &;
auto operator=(const packet &p) noexcept -> packet &;
auto operator=(const packet &pkt) noexcept -> packet &;
auto operator=(packet &&p) noexcept -> packet &;
auto operator=(packet &&pkt) noexcept -> packet &;
[[nodiscard]] auto operator[](std::size_t index) -> char & {
return buffer_[index];

View File

@ -1,177 +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_COMM_HPP_
#define INCLUDE_COMM_S3_S3_COMM_HPP_
#if defined(REPERTORY_ENABLE_S3)
#include "comm/i_http_comm.hpp"
#include "comm/i_s3_comm.hpp"
#include "types/repertory.hpp"
namespace repertory {
class app_config;
class s3_comm final : public i_s3_comm {
public:
explicit s3_comm(const app_config &config);
s3_comm(s3_comm &&comm);
~s3_comm() override;
private:
struct cache_entry final {
std::chrono::system_clock::time_point expiration;
directory_item_list items;
void reset_timeout(std::chrono::seconds timeout) {
timeout = std::max(std::chrono::seconds(5u), timeout);
expiration = std::chrono::system_clock::now() + timeout;
}
};
private:
const app_config &config_;
s3_config s3_config_;
std::unique_ptr<i_http_comm> s3_client_;
private:
mutable std::recursive_mutex cached_directories_mutex_;
mutable std::unordered_map<std::string, cache_entry> cached_directories_;
protected:
bool active_ = true;
private:
void clear_expired_directories();
[[nodiscard]] auto
get_cached_directory_item_count(const std::string &api_path,
std::size_t &count) const -> bool;
[[nodiscard]] auto
get_cached_directory_items(const std::string &api_path,
meta_provider_callback meta_provider,
directory_item_list &list) const -> bool;
[[nodiscard]] auto get_cached_file_exists(const std::string &api_path) const
-> bool;
[[nodiscard]] auto grab_directory_items(const std::string &api_path,
meta_provider_callback meta_provider,
directory_item_list &list) const
-> api_error;
void raise_begin(const std::string &function_name,
const std::string &api_path) const;
[[nodiscard]] auto raise_end(const std::string &function_name,
const std::string &api_path,
const api_error &error, long code) const
-> api_error;
void remove_cached_directory(const std::string &api_path);
void set_cached_directory_items(const std::string &api_path,
directory_item_list list) const;
public:
[[nodiscard]] auto create_directory(const std::string &api_path)
-> api_error override;
[[nodiscard]] auto directory_exists(const std::string &api_path) const
-> api_error override;
[[nodiscard]] auto file_exists(const std::string &api_path,
const get_key_callback &get_key) const
-> api_error override;
[[nodiscard]] auto
get_directory_item_count(const std::string &api_path,
meta_provider_callback meta_provider) const
-> std::size_t override;
[[nodiscard]] auto get_directory_items(const std::string &api_path,
meta_provider_callback meta_provider,
directory_item_list &list) const
-> api_error override;
[[nodiscard]] auto get_directory_list(api_file_list &list) const
-> api_error override;
[[nodiscard]] auto get_file(const std::string &api_path,
const get_key_callback &get_key,
const get_name_callback &get_name,
const get_token_callback &get_token,
api_file &file) const -> api_error override;
[[nodiscard]] auto
get_file_list(const get_api_file_token_callback &get_api_file_token,
const get_name_callback &get_name, api_file_list &list) const
-> api_error override;
[[nodiscard]] auto get_object_list(std::vector<directory_item> &list) const
-> api_error override;
[[nodiscard]] auto get_object_name(const std::string &api_path,
const get_key_callback &getKey) const
-> std::string override;
[[nodiscard]] auto get_s3_config() -> s3_config override {
return s3_config_;
}
[[nodiscard]] auto get_s3_config() const -> s3_config override {
return s3_config_;
}
[[nodiscard]] auto is_online() const -> bool override {
// TODO implement this
return true;
}
[[nodiscard]] auto read_file_bytes(
const std::string &api_path, std::size_t size, std::uint64_t offset,
data_buffer &data, const get_key_callback &get_key,
const get_size_callback &get_size, const get_token_callback &get_token,
stop_type &stop_requested) const -> api_error override;
[[nodiscard]] auto remove_directory(const std::string &api_path)
-> api_error override;
[[nodiscard]] auto remove_file(const std::string &api_path,
const get_key_callback &get_key)
-> api_error override;
[[nodiscard]] auto rename_file(const std::string &api_path,
const std::string &new_api_path)
-> api_error override;
[[nodiscard]] auto
upload_file(const std::string &api_path, const std::string &source_path,
const std::string &encryption_token,
const get_key_callback &get_key, const set_key_callback &set_key,
stop_type &stop_requested) -> api_error override;
};
} // namespace repertory
#endif // REPERTORY_ENABLE_S3
#endif // INCLUDE_COMM_S3_S3_COMM_HPP_

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>
@ -59,11 +85,6 @@
#include <sys/mount.h>
#include <sys/statvfs.h>
#endif
#if __linux__
#include <utils/uuid++.hh>
#else
#include <uuid/uuid.h>
#endif
#endif
#include <algorithm>
@ -82,7 +103,6 @@
#include <optional>
#include <random>
#include <sstream>
#include <sstream>
#include <string>
#include <string_view>
#include <thread>
@ -90,6 +110,14 @@
#include <unordered_map>
#include <vector>
#include <sodium.h>
template <typename data_type>
[[nodiscard]] inline auto repertory_rand() -> data_type {
data_type ret{};
randombytes_buf(&ret, sizeof(ret));
return ret;
}
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/asio.hpp>
@ -101,7 +129,8 @@
#include <curl/curl.h>
#include <curl/multi.h>
#include <json.hpp>
#include <rocksdb/db.h>
#include <sqlite3.h>
#include <stduuid.h>
#ifdef _WIN32
#include <sddl.h>
@ -116,12 +145,33 @@
#endif
#include <pugixml.hpp>
#include <sodium.h>
#define CPPHTTPLIB_TCP_NODELAY true
#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;
@ -136,12 +186,12 @@ using json = nlohmann::json;
#define REPERTORY_API_INVALID_HANDLE static_cast<std::uint64_t>(-1)
using native_handle = HANDLE;
#else
#define REPERTORY_INVALID_HANDLE -1
#define REPERTORY_INVALID_HANDLE (-1)
#define REPERTORY_API_INVALID_HANDLE REPERTORY_INVALID_HANDLE
using native_handle = int;
#endif
#define NANOS_PER_SECOND 1000000000L
constexpr const auto NANOS_PER_SECOND = 1000000000L;
#ifdef _WIN32
#ifdef CreateDirectory
@ -339,6 +389,7 @@ using WCHAR = wchar_t;
#define STATUS_OBJECT_NAME_NOT_FOUND std::int32_t(0xC0000034L)
#define STATUS_OBJECT_PATH_INVALID std::int32_t(0xC0000039L)
#define STATUS_UNEXPECTED_IO_ERROR std::int32_t(0xC00000E9L)
#define CONVERT_STATUS_NOT_IMPLEMENTED(e) \
((std::int32_t(e) == STATUS_NOT_IMPLEMENTED) ? -ENOTSUP : e)
@ -353,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;
@ -379,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; \
@ -392,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

@ -19,39 +19,51 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef REPERTORY_DIRECTORY_DB_FIXTURE_H
#define REPERTORY_DIRECTORY_DB_FIXTURE_H
#ifndef INCLUDE_DATABASE_DB_INSERT_HPP_
#define INCLUDE_DATABASE_DB_INSERT_HPP_
#include "test_common.hpp"
#include "database/db_common.hpp"
#include "utils/error_utils.hpp"
#include "app_config.hpp"
#include "db/directory_db.hpp"
#include "utils/path_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_)) {}
namespace repertory {
class directory_db_test : public ::testing::Test {
private:
const std::string config_location_ = utils::path::absolute("./directorydb");
sqlite3 &db3;
std::string table_name;
protected:
std::unique_ptr<app_config> config_;
std::unique_ptr<directory_db> db_;
bool or_replace{false};
std::map<std::string, db_types_t> values{};
db3_stmt_t stmt{nullptr};
};
using row = db_row<context>;
public:
void SetUp() override {
ASSERT_TRUE(utils::file::delete_directory_recursively(config_location_));
config_ =
std::make_unique<app_config>(provider_type::encrypt, config_location_);
db_ = std::make_unique<directory_db>(*config_.get());
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;
}
void TearDown() override {
db_.reset();
config_.reset();
[[nodiscard]] auto column_value(std::string column_name, db_types_t value)
-> db_insert &;
EXPECT_TRUE(utils::file::delete_directory_recursively(config_location_));
}
[[nodiscard]] auto dump() const -> std::string;
[[nodiscard]] auto go() const -> db_result<context>;
};
} // namespace repertory
} // namespace repertory::db
#endif // REPERTORY_DIRECTORY_DB_FIXTURE_H
#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

@ -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_DB_DIRECTORY_DB_HPP_
#define INCLUDE_DB_DIRECTORY_DB_HPP_
#include "app_config.hpp"
#include "types/repertory.hpp"
#include "utils/rocksdb_utils.hpp"
namespace repertory {
class directory_db final {
private:
class directory_tree final {
private:
std::unordered_map<std::string, std::vector<std::string>>
sub_directory_lookup_;
public:
void add_path(const std::string &api_path,
const std::vector<std::string> &files, rocksdb::DB &db);
[[nodiscard]] auto get_count(const std::string &api_path) const
-> std::size_t;
[[nodiscard]] auto get_directories() const -> std::vector<std::string>;
[[nodiscard]] auto get_sub_directories(const std::string &api_path) const
-> std::vector<std::string>;
[[nodiscard]] auto is_directory(const std::string &api_path) const -> bool;
void remove_directory(const std::string &api_path, rocksdb::DB &db,
bool allow_remove_root = false);
};
public:
explicit directory_db(const app_config &config);
public:
~directory_db();
private:
mutable std::recursive_mutex directory_mutex_;
std::unique_ptr<rocksdb::DB> db_;
directory_tree tree_;
const std::string DIRDB_NAME = "directory_db";
private:
[[nodiscard]] auto get_directory_data(const std::string &api_path) const
-> json;
public:
[[nodiscard]] auto create_directory(const std::string &api_path,
bool create_always = false) -> api_error;
[[nodiscard]] auto create_file(const std::string &api_path) -> api_error;
[[nodiscard]] auto get_directory_item_count(const std::string &api_path) const
-> std::uint64_t;
[[nodiscard]] auto
get_file(const std::string &api_path, api_file &file,
api_file_provider_callback api_file_provider) const -> api_error;
[[nodiscard]] auto
get_file_list(api_file_list &list,
api_file_provider_callback api_file_provider) const
-> api_error;
[[nodiscard]] auto get_sub_directory_count(const std::string &api_path) const
-> std::size_t;
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t;
[[nodiscard]] auto is_directory(const std::string &api_path) const -> bool;
[[nodiscard]] auto is_file(const std::string &api_path) const -> bool;
void populate_directory_files(const std::string &api_path,
meta_provider_callback meta_provider,
directory_item_list &list) const;
void populate_sub_directories(const std::string &api_path,
meta_provider_callback meta_provider,
directory_item_list &list) const;
[[nodiscard]] auto remove_directory(const std::string &api_path,
bool allow_remove_root = false)
-> api_error;
[[nodiscard]] auto remove_file(const std::string &api_path) -> bool;
[[nodiscard]] auto rename_file(const std::string &from_api_path,
const std::string &to_api_path) -> api_error;
};
} // namespace repertory
#endif // INCLUDE_DB_DIRECTORY_DB_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

@ -27,12 +27,12 @@
#include "file_manager/file_manager.hpp"
namespace repertory {
class i_provider;
class app_config;
class console_consumer;
class directory_cache;
class eviction;
class full_server;
class i_provider;
class lock_data;
class logging_consumer;
namespace remote_fuse {
@ -45,6 +45,13 @@ public:
~fuse_drive() override = default;
public:
fuse_drive(const fuse_drive &) = delete;
fuse_drive(fuse_drive &&) = delete;
auto operator=(const fuse_drive &) -> fuse_drive & = delete;
auto operator=(fuse_drive &&) -> fuse_drive & = delete;
private:
lock_data &lock_data_;
i_provider &provider_;
@ -69,7 +76,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 *file_info)
-> api_error override;
#else
[[nodiscard]] auto chmod_impl(std::string api_path, mode_t mode)
@ -78,7 +85,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 *file_info)
-> api_error override;
#else
[[nodiscard]] auto chown_impl(std::string api_path, uid_t uid, gid_t gid)
@ -86,40 +93,40 @@ protected:
#endif
[[nodiscard]] auto create_impl(std::string api_path, mode_t mode,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
void destroy_impl(void *ptr) override;
[[nodiscard]] auto fallocate_impl(std::string api_path, int mode,
off_t offset, off_t length,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
[[nodiscard]] auto fgetattr_impl(std::string api_path, struct stat *st,
struct fuse_file_info *fi)
struct fuse_file_info *file_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 *file_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 *file_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 *file_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)
struct fuse_file_info *file_info)
-> api_error override;
#else
[[nodiscard]] auto getattr_impl(std::string api_path, struct stat *st)
@ -145,37 +152,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 *file_info)
-> api_error override;
[[nodiscard]] auto opendir_impl(std::string api_path,
struct fuse_file_info *fi)
struct fuse_file_info *file_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 *file_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 *file_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 *file_info)
-> api_error override;
#endif
[[nodiscard]] auto release_impl(std::string api_path,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
[[nodiscard]] auto releasedir_impl(std::string api_path,
struct fuse_file_info *fi)
struct fuse_file_info *file_info)
-> api_error override;
#if FUSE_USE_VERSION >= 30
@ -197,8 +205,7 @@ protected:
#ifdef __APPLE__
[[nodiscard]] auto getxattr_impl(std::string api_path, const char *name,
char *value, size_t size,
[[nodiscard]] uint32_t position,
char *value, size_t size, uint32_t position,
int &attribute_size) -> api_error override;
#else // __APPLE__
[[nodiscard]] auto getxattr_impl(std::string api_path, const char *name,
@ -252,7 +259,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 *file_info)
-> api_error override;
#else
[[nodiscard]] auto truncate_impl(std::string api_path, off_t size)
@ -264,7 +271,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 *file_info)
-> api_error override;
#else
[[nodiscard]] auto utimens_impl(std::string api_path,
@ -274,7 +281,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 *file_info,
std::size_t &bytes_written)
-> api_error override;
@ -309,8 +316,6 @@ public:
[[nodiscard]] auto is_processing(const std::string &api_path) const
-> bool override;
void populate_stat(const directory_item &di, 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 &di,
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

@ -237,12 +237,12 @@ public:
}
[[nodiscard]] auto json_create_directory_snapshot(const std::string &path,
json &jsonData)
json &json_data)
-> packet::error_type override;
[[nodiscard]] auto json_read_directory_snapshot(
const std::string &path, const remote::file_handle &handle,
std::uint32_t page, json &jsonData) -> packet::error_type override;
std::uint32_t page, json &json_data) -> packet::error_type override;
[[nodiscard]] auto
json_release_directory_snapshot(const std::string &path,
@ -254,7 +254,7 @@ public:
-> packet::error_type override;
[[nodiscard]] auto winfsp_cleanup(PVOID file_desc, PWSTR file_name,
UINT32 flags, BOOLEAN &wasClosed)
UINT32 flags, BOOLEAN &was_closed)
-> packet::error_type override;
[[nodiscard]] auto winfsp_close(PVOID file_desc)
@ -275,8 +275,8 @@ public:
[[nodiscard]] auto
winfsp_get_security_by_name(PWSTR file_name, PUINT32 attributes,
std::uint64_t * /*securityDescriptorSize*/,
std::wstring & /*strDescriptor*/)
std::uint64_t * /*security_descriptor_size*/,
std::wstring & /*str_descriptor*/)
-> packet::error_type override;
[[nodiscard]] auto winfsp_get_volume_info(UINT64 &total_size,
@ -317,7 +317,7 @@ public:
UINT64 last_access_time, UINT64 last_write_time, UINT64 change_time,
remote::file_info *file_info) -> packet::error_type override;
[[nodiscard]] auto winfsp_set_file_size(PVOID file_desc, UINT64 newSize,
[[nodiscard]] auto winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
BOOLEAN set_allocation_size,
remote::file_info *file_info)
-> packet::error_type override;

View File

@ -44,9 +44,15 @@ class remote_server_base : public remote_open_file_table,
public virtual remote_winfsp::i_remote_instance,
public virtual remote_fuse::i_remote_instance {
public:
remote_server_base(app_config &config, drive &d, std::string mount_location)
remote_server_base(const remote_server_base &) = delete;
remote_server_base(remote_server_base &&) = delete;
auto operator=(const remote_server_base &) -> remote_server_base & = delete;
auto operator=(remote_server_base &&) -> remote_server_base & = delete;
public:
remote_server_base(app_config &config, drive &drv, std::string mount_location)
: config_(config),
drive_(d),
drive_(drv),
mount_location_(std::move(mount_location)),
client_pool_(config.get_remote_client_pool_size()) {
event_system::instance().raise<service_started>("remote_server_base");
@ -57,14 +63,13 @@ public:
packet &) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
std::wstring file_name;
DECODE_OR_RETURN(request, file_name);
ret = this->winfsp_can_delete(file_desc, &file_name[0]);
return ret;
return this->winfsp_can_delete(file_desc, file_name.data());
}});
handler_lookup_.insert(
{"::winfsp_cleanup",
@ -73,17 +78,17 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
std::wstring file_name;
DECODE_OR_RETURN(request, file_name);
UINT32 flags;
UINT32 flags{};
DECODE_OR_RETURN(request, flags);
BOOLEAN was_closed;
ret = this->winfsp_cleanup(file_desc, &file_name[0], flags,
BOOLEAN was_closed{};
ret = this->winfsp_cleanup(file_desc, file_name.data(), flags,
was_closed);
response.encode(was_closed);
@ -96,11 +101,10 @@ public:
packet &) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
ret = this->winfsp_close(file_desc);
return ret;
return this->winfsp_close(file_desc);
}});
handler_lookup_.insert(
{"::winfsp_create",
@ -112,23 +116,23 @@ public:
std::wstring file_name;
DECODE_OR_RETURN(request, file_name);
UINT32 create_options;
UINT32 create_options{};
DECODE_OR_RETURN(request, create_options);
UINT32 granted_access;
UINT32 granted_access{};
DECODE_OR_RETURN(request, granted_access);
UINT32 attributes;
UINT32 attributes{};
DECODE_OR_RETURN(request, attributes);
UINT64 allocation_size;
UINT64 allocation_size{};
DECODE_OR_RETURN(request, allocation_size);
BOOLEAN exists = 0;
BOOLEAN exists{0};
remote::file_info file_info{};
std::string normalized_name;
PVOID file_desc;
ret = this->winfsp_create(&file_name[0], create_options,
PVOID file_desc{};
ret = this->winfsp_create(file_name.data(), create_options,
granted_access, attributes,
allocation_size, &file_desc, &file_info,
normalized_name, exists);
@ -136,8 +140,10 @@ public:
#ifdef _WIN32
this->set_client_id(file_desc, client_id);
#else
this->set_client_id(reinterpret_cast<std::uintptr_t>(file_desc),
client_id);
this->set_client_id(
static_cast<native_handle>(
reinterpret_cast<std::uintptr_t>(file_desc)),
client_id);
#endif
response.encode(file_desc);
response.encode(file_info);
@ -154,7 +160,7 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
remote::file_info file_info{};
@ -172,7 +178,7 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
remote::file_info file_info{};
@ -192,21 +198,22 @@ public:
std::wstring file_name;
DECODE_OR_RETURN(request, file_name);
std::uint64_t descriptor_size;
std::uint64_t descriptor_size{};
DECODE_OR_RETURN(request, descriptor_size);
std::uint8_t get_attributes;
std::uint8_t get_attributes{};
DECODE_OR_RETURN(request, get_attributes);
UINT32 attributes;
auto *attrPtr = get_attributes ? &attributes : nullptr;
UINT32 attributes{};
auto *attr_ptr = get_attributes == 0U ? nullptr : &attributes;
std::wstring string_descriptor;
ret = this->winfsp_get_security_by_name(
&file_name[0], attrPtr,
descriptor_size ? &descriptor_size : nullptr, string_descriptor);
file_name.data(), attr_ptr,
descriptor_size == 0U ? nullptr : &descriptor_size,
string_descriptor);
if (ret == STATUS_SUCCESS) {
response.encode(string_descriptor);
if (get_attributes) {
if (get_attributes != 0U) {
response.encode(attributes);
}
}
@ -219,8 +226,8 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
UINT64 total_size = 0u;
UINT64 free_size = 0u;
UINT64 total_size{};
UINT64 free_size{};
std::string volume_label;
if ((ret = this->winfsp_get_volume_info(
total_size, free_size, volume_label)) ==
@ -257,24 +264,26 @@ public:
std::wstring file_name;
DECODE_OR_RETURN(request, file_name);
UINT32 create_options;
UINT32 create_options{};
DECODE_OR_RETURN(request, create_options);
UINT32 granted_access;
UINT32 granted_access{};
DECODE_OR_RETURN(request, granted_access);
remote::file_info file_info{};
std::string normalized_name;
PVOID file_desc;
ret =
this->winfsp_open(&file_name[0], create_options, granted_access,
&file_desc, &file_info, normalized_name);
PVOID file_desc{};
ret = this->winfsp_open(file_name.data(), create_options,
granted_access, &file_desc, &file_info,
normalized_name);
if (ret == STATUS_SUCCESS) {
#ifdef _WIN32
this->set_client_id(file_desc, client_id);
#else
this->set_client_id(reinterpret_cast<std::uintptr_t>(file_desc),
client_id);
this->set_client_id(
static_cast<native_handle>(
reinterpret_cast<std::uintptr_t>(file_desc)),
client_id);
#endif
response.encode(file_desc);
response.encode(file_info);
@ -290,16 +299,16 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
UINT32 attributes;
UINT32 attributes{};
DECODE_OR_RETURN(request, attributes);
BOOLEAN replace_attributes;
BOOLEAN replace_attributes{};
DECODE_OR_RETURN(request, replace_attributes);
UINT64 allocation_size;
UINT64 allocation_size{};
DECODE_OR_RETURN(request, allocation_size);
remote::file_info file_info{};
@ -318,23 +327,23 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
UINT64 offset;
UINT64 offset{};
DECODE_OR_RETURN(request, offset);
UINT32 length;
UINT32 length{};
DECODE_OR_RETURN(request, length);
data_buffer buffer(length);
UINT32 bytes_transferred = 0;
ret = this->winfsp_read(file_desc, &buffer[0], offset, length,
ret = this->winfsp_read(file_desc, buffer.data(), offset, length,
&bytes_transferred);
if (ret == STATUS_SUCCESS) {
response.encode(static_cast<UINT32>(bytes_transferred));
if (bytes_transferred) {
response.encode(&buffer[0], bytes_transferred);
response.encode(bytes_transferred);
if (bytes_transferred != 0U) {
response.encode(buffer.data(), bytes_transferred);
}
}
return ret;
@ -346,7 +355,7 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
std::wstring pattern;
@ -355,13 +364,14 @@ public:
std::wstring marker;
DECODE_OR_IGNORE(request, marker);
json itemList;
json item_list;
ret = this->winfsp_read_directory(
file_desc, &pattern[0],
wcsnlen(&marker[0], marker.size()) ? &marker[0] : nullptr,
itemList);
file_desc, pattern.data(),
wcsnlen(marker.data(), marker.size()) == 0U ? nullptr
: marker.data(),
item_list);
if (ret == STATUS_SUCCESS) {
response.encode(itemList.dump(0));
response.encode(item_list.dump(0));
}
return ret;
}});
@ -372,7 +382,7 @@ public:
packet &) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
std::wstring file_name;
@ -381,11 +391,11 @@ public:
std::wstring new_file_name;
DECODE_OR_RETURN(request, new_file_name);
BOOLEAN replace_if_exists;
BOOLEAN replace_if_exists{};
DECODE_OR_RETURN(request, replace_if_exists);
ret = this->winfsp_rename(file_desc, &file_name[0],
&new_file_name[0], replace_if_exists);
ret = this->winfsp_rename(file_desc, file_name.data(),
new_file_name.data(), replace_if_exists);
return ret;
}});
handler_lookup_.insert(
@ -395,22 +405,22 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
UINT32 attributes;
UINT32 attributes{};
DECODE_OR_RETURN(request, attributes);
UINT64 creation_time;
UINT64 creation_time{};
DECODE_OR_RETURN(request, creation_time);
UINT64 last_access_time;
UINT64 last_access_time{};
DECODE_OR_RETURN(request, last_access_time);
UINT64 last_write_time;
UINT64 last_write_time{};
DECODE_OR_RETURN(request, last_write_time);
UINT64 change_time;
UINT64 change_time{};
DECODE_OR_RETURN(request, change_time);
remote::file_info file_info{};
@ -429,13 +439,13 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
UINT64 new_size;
UINT64 new_size{};
DECODE_OR_RETURN(request, new_size);
BOOLEAN set_allocation_size;
BOOLEAN set_allocation_size{};
DECODE_OR_RETURN(request, set_allocation_size);
remote::file_info file_info{};
@ -456,8 +466,7 @@ public:
std::wstring location;
DECODE_OR_RETURN(request, location);
ret = this->winfsp_unmounted(location);
return ret;
return this->winfsp_unmounted(location);
}});
handler_lookup_.insert(
{"::winfsp_write",
@ -466,19 +475,19 @@ public:
packet &response) -> packet::error_type {
auto ret = STATUS_SUCCESS;
HANDLE file_desc;
HANDLE file_desc{};
DECODE_OR_RETURN(request, file_desc);
UINT32 length;
UINT32 length{};
DECODE_OR_RETURN(request, length);
UINT64 offset;
UINT64 offset{};
DECODE_OR_RETURN(request, offset);
BOOLEAN write_to_end;
BOOLEAN write_to_end{};
DECODE_OR_RETURN(request, write_to_end);
BOOLEAN constrained_io;
BOOLEAN constrained_io{};
DECODE_OR_RETURN(request, constrained_io);
auto *buffer = request->current_pointer();
@ -504,10 +513,10 @@ public:
std::string path;
DECODE_OR_RETURN(request, path);
std::int32_t mask;
std::int32_t mask{};
DECODE_OR_RETURN(request, mask);
return this->fuse_access(&path[0], mask);
return this->fuse_access(path.data(), mask);
}});
handler_lookup_.insert(
{"::fuse_chflags",
@ -519,10 +528,10 @@ public:
std::string path;
DECODE_OR_RETURN(request, path);
std::uint32_t flags;
std::uint32_t flags{};
DECODE_OR_RETURN(request, flags);
return this->fuse_chflags(&path[0], flags);
return this->fuse_chflags(path.data(), flags);
}});
handler_lookup_.insert(
{"::fuse_chmod",
@ -549,10 +558,10 @@ public:
std::string path;
DECODE_OR_RETURN(request, path);
remote::user_id uid;
remote::user_id uid{};
DECODE_OR_RETURN(request, uid);
remote::group_id gid;
remote::group_id gid{};
DECODE_OR_RETURN(request, gid);
return this->fuse_chown(&path[0], uid, gid);
@ -567,18 +576,19 @@ public:
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_mode mode;
remote::file_mode mode{};
DECODE_OR_RETURN(request, mode);
remote::open_flags flags;
remote::open_flags flags{};
DECODE_OR_RETURN(request, flags);
remote::file_handle handle;
if ((ret = this->fuse_create(&path[0], mode, flags, handle)) >= 0) {
remote::file_handle handle{};
if ((ret = this->fuse_create(path.data(), mode, flags, handle)) >=
0) {
#ifdef _WIN32
this->set_compat_client_id(handle, client_id);
#else
this->set_client_id(handle, client_id);
this->set_client_id(static_cast<native_handle>(handle), client_id);
#endif
response.encode(handle);
}
@ -623,18 +633,18 @@ public:
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_handle handle;
remote::file_handle handle{};
DECODE_OR_RETURN(request, handle);
remote::user_id uid;
remote::user_id uid{};
DECODE_OR_RETURN(request, uid);
remote::group_id gid;
remote::group_id gid{};
DECODE_OR_RETURN(request, gid);
remote::stat st{};
bool directory = false;
ret = this->fuse_fgetattr(&path[0], st, directory, handle);
ret = this->fuse_fgetattr(path.data(), st, directory, handle);
if (ret == 0) {
st.st_uid = uid;
st.st_gid = gid;
@ -657,10 +667,10 @@ public:
remote::setattr_x attr{};
DECODE_OR_RETURN(request, attr);
remote::file_handle handle;
remote::file_handle handle{};
DECODE_OR_RETURN(request, handle);
return this->fuse_fsetattr_x(&path[0], attr, handle);
return this->fuse_fsetattr_x(path.data(), attr, handle);
}});
handler_lookup_.insert(
{"::fuse_fsync",
@ -833,7 +843,7 @@ public:
#ifdef _WIN32
this->set_compat_client_id(handle, client_id);
#else
this->set_client_id(handle, client_id);
this->set_client_id(static_cast<native_handle>(handle), client_id);
#endif
response.encode(handle);
}
@ -965,7 +975,7 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{0};
std::string from;
DECODE_OR_RETURN(request, from);
@ -973,26 +983,26 @@ public:
std::string to;
DECODE_OR_RETURN(request, to);
return this->fuse_rename(&from[0], &to[0]);
return this->fuse_rename(from.data(), to.data());
}});
handler_lookup_.insert(
{"::fuse_rmdir",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{0};
std::string path;
DECODE_OR_RETURN(request, path);
return this->fuse_rmdir(&path[0]);
return this->fuse_rmdir(path.data());
}});
handler_lookup_.insert(
{"::fuse_setattr_x",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{0};
std::string path;
DECODE_OR_RETURN(request, path);
@ -1000,64 +1010,64 @@ public:
remote::setattr_x attr{};
DECODE_OR_RETURN(request, attr);
return this->fuse_setattr_x(&path[0], attr);
return this->fuse_setattr_x(path.data(), attr);
}});
handler_lookup_.insert(
{"::fuse_setbkuptime",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{0};
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_time bkuptime;
remote::file_time bkuptime{};
DECODE_OR_RETURN(request, bkuptime);
return this->fuse_setbkuptime(&path[0], bkuptime);
return this->fuse_setbkuptime(path.data(), bkuptime);
}});
handler_lookup_.insert(
{"::fuse_setchgtime",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{0};
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_time chgtime;
remote::file_time chgtime{};
DECODE_OR_RETURN(request, chgtime);
return this->fuse_setchgtime(&path[0], chgtime);
return this->fuse_setchgtime(path.data(), chgtime);
}});
handler_lookup_.insert(
{"::fuse_setcrtime",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{0};
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_time crtime;
remote::file_time crtime{};
DECODE_OR_RETURN(request, crtime);
return this->fuse_setcrtime(&path[0], crtime);
return this->fuse_setcrtime(path.data(), crtime);
}});
handler_lookup_.insert(
{"::fuse_setvolname",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{0};
std::string name;
DECODE_OR_RETURN(request, name);
return this->fuse_setvolname(&name[0]);
return this->fuse_setvolname(name.data());
}});
/*handlerLookup_.insert({"::fuse_setxattr",
[this](std::uint32_t serviceFlags, const std::string
@ -1125,16 +1135,16 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &response) -> packet::error_type {
auto ret = -1;
std::int32_t ret{-1};
std::string path;
DECODE_OR_RETURN(request, path);
std::uint64_t frsize;
std::uint64_t frsize{};
DECODE_OR_RETURN(request, frsize);
remote::statfs st{};
ret = this->fuse_statfs(&path[0], frsize, st);
ret = this->fuse_statfs(path.data(), frsize, st);
if (ret == 0) {
response.encode(st);
}
@ -1145,16 +1155,16 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &response) -> packet::error_type {
auto ret = -1;
std::int32_t ret{-1};
std::string path;
DECODE_OR_RETURN(request, path);
std::uint64_t bsize;
std::uint64_t bsize{};
DECODE_OR_RETURN(request, bsize);
remote::statfs_x st{};
ret = this->fuse_statfs_x(&path[0], bsize, st);
ret = this->fuse_statfs_x(path.data(), bsize, st);
if (ret == 0) {
response.encode(st);
}
@ -1165,34 +1175,34 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{};
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_offset size;
remote::file_offset size{};
DECODE_OR_IGNORE(request, size);
return this->fuse_truncate(&path[0], size);
return this->fuse_truncate(path.data(), size);
}});
handler_lookup_.insert(
{"::fuse_unlink",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{};
std::string path;
DECODE_OR_RETURN(request, path);
return this->fuse_unlink(&path[0]);
return this->fuse_unlink(path.data());
}});
handler_lookup_.insert(
{"::fuse_utimens",
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
auto ret = 0;
std::int32_t ret{};
std::string path;
DECODE_OR_RETURN(request, path);
@ -1200,13 +1210,13 @@ public:
remote::file_time tv[2] = {0};
if ((ret = request->decode(&tv[0], sizeof(remote::file_time) * 2)) ==
0) {
std::uint64_t op0;
std::uint64_t op0{};
DECODE_OR_RETURN(request, op0);
std::uint64_t op1;
std::uint64_t op1{};
DECODE_OR_RETURN(request, op1);
ret = this->fuse_utimens(&path[0], tv, op0, op1);
ret = this->fuse_utimens(path.data(), tv, op0, op1);
}
return ret;
}});
@ -1215,27 +1225,27 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
std::int32_t ret = 0;
std::int32_t ret{};
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_size writeSize;
DECODE_OR_RETURN(request, writeSize);
remote::file_size write_size{};
DECODE_OR_RETURN(request, write_size);
if (writeSize > std::numeric_limits<std::size_t>::max()) {
if (write_size > std::numeric_limits<std::size_t>::max()) {
return -ERANGE;
}
data_buffer buffer(static_cast<std::size_t>(writeSize));
if ((ret = request->decode(&buffer[0], buffer.size())) == 0) {
remote::file_offset write_offset;
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);
remote::file_handle handle;
remote::file_handle handle{};
DECODE_OR_RETURN(request, handle);
ret = this->fuse_write(&path[0], &buffer[0], writeSize,
ret = this->fuse_write(path.data(), buffer.data(), write_size,
write_offset, handle);
}
return ret;
@ -1245,31 +1255,31 @@ public:
[this](std::uint32_t, const std::string &, std::uint64_t,
const std::string &, packet *request,
packet &) -> packet::error_type {
std::int32_t ret = 0;
std::int32_t ret{};
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_size write_size;
remote::file_size write_size{};
DECODE_OR_RETURN(request, write_size);
if (write_size > std::numeric_limits<std::size_t>::max()) {
return -ERANGE;
}
data_buffer buffer(static_cast<std::size_t>(write_size));
if ((ret = request->decode(&buffer[0], buffer.size())) == 0) {
data_buffer buffer(write_size);
if ((ret = request->decode(buffer.data(), buffer.size())) == 0) {
buffer = macaron::Base64::Decode(
std::string(buffer.begin(), buffer.end()));
write_size = buffer.size();
remote::file_offset write_offset;
remote::file_offset write_offset{};
DECODE_OR_RETURN(request, write_offset);
remote::file_handle handle;
remote::file_handle handle{};
DECODE_OR_RETURN(request, handle);
ret = this->fuse_write(&path[0], &buffer[0], write_size,
ret = this->fuse_write(path.data(), buffer.data(), write_size,
write_offset, handle);
}
return ret;
@ -1279,7 +1289,7 @@ public:
[this](std::uint32_t, const std::string &client_id, std::uint64_t,
const std::string &, packet *request,
packet &response) -> packet::error_type {
std::int32_t ret = 0;
std::int32_t ret{};
std::string path;
DECODE_OR_RETURN(request, path);
@ -1288,7 +1298,7 @@ public:
json_data["handle"] = -1;
json_data["page_count"] = 0;
json_data["path"] = path;
if ((ret = this->json_create_directory_snapshot(&path[0],
if ((ret = this->json_create_directory_snapshot(path.data(),
json_data)) == 0) {
this->add_directory(client_id,
reinterpret_cast<void *>(
@ -1307,10 +1317,10 @@ public:
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_handle handle;
remote::file_handle handle{};
DECODE_OR_RETURN(request, handle);
std::uint32_t page;
std::uint32_t page{};
DECODE_OR_RETURN(request, page);
ret = -EBADF;
@ -1338,10 +1348,10 @@ public:
std::string path;
DECODE_OR_RETURN(request, path);
remote::file_handle handle;
remote::file_handle handle{};
DECODE_OR_RETURN(request, handle);
ret = this->json_release_directory_snapshot(&path[0], handle);
ret = this->json_release_directory_snapshot(path.data(), handle);
if (this->remove_directory(client_id,
reinterpret_cast<void *>(handle))) {
return ret;
@ -1380,7 +1390,7 @@ public:
protected:
app_config &config_;
drive &drive_;
const std::string mount_location_;
std::string mount_location_;
private:
client_pool client_pool_;
@ -1422,7 +1432,7 @@ protected:
}
void delete_open_directory(void *dir) override {
if (dir) {
if (dir != nullptr) {
delete reinterpret_cast<directory_iterator *>(dir);
}
}

View File

@ -29,84 +29,84 @@ class i_remote_instance : public virtual i_remote_json {
INTERFACE_SETUP(i_remote_instance);
public:
virtual auto winfsp_can_delete(PVOID fileDesc, PWSTR fileName)
virtual auto winfsp_can_delete(PVOID file_desc, PWSTR file_name)
-> packet::error_type = 0;
virtual auto winfsp_cleanup(PVOID fileDesc, PWSTR fileName, UINT32 flags,
BOOLEAN &wasClosed) -> packet::error_type = 0;
virtual auto winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags,
BOOLEAN &was_closed) -> packet::error_type = 0;
virtual auto winfsp_close(PVOID fileDesc) -> packet::error_type = 0;
virtual auto winfsp_close(PVOID file_desc) -> packet::error_type = 0;
virtual auto winfsp_create(PWSTR fileName, UINT32 createOptions,
UINT32 grantedAccess, UINT32 fileAttributes,
UINT64 allocationSize, PVOID *fileDesc,
remote::file_info *fileInfo,
std::string &normalizedName, BOOLEAN &exists)
virtual auto winfsp_create(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, UINT32 file_attributes,
UINT64 allocation_size, PVOID *file_desc,
remote::file_info *file_info,
std::string &normalized_name, BOOLEAN &exists)
-> packet::error_type = 0;
virtual auto winfsp_flush(PVOID fileDesc, remote::file_info *fileInfo)
virtual auto winfsp_flush(PVOID file_desc, remote::file_info *file_info)
-> packet::error_type = 0;
virtual auto winfsp_get_dir_buffer(PVOID fileDesc, PVOID *&ptr)
virtual auto winfsp_get_dir_buffer(PVOID file_desc, PVOID *&ptr)
-> packet::error_type = 0;
virtual auto winfsp_get_file_info(PVOID fileDesc, remote::file_info *fileInfo)
virtual auto winfsp_get_file_info(PVOID file_desc, remote::file_info *file_info)
-> packet::error_type = 0;
virtual auto
winfsp_get_security_by_name(PWSTR fileName, PUINT32 fileAttributes,
std::uint64_t *securityDescriptorSize,
std::wstring &strDescriptor)
winfsp_get_security_by_name(PWSTR file_name, PUINT32 file_attributes,
std::uint64_t *security_descriptor_size,
std::wstring &str_descriptor)
-> packet::error_type = 0;
virtual auto winfsp_get_volume_info(UINT64 &totalSize, UINT64 &freeSize,
std::string &volumeLabel)
virtual auto winfsp_get_volume_info(UINT64 &total_size, UINT64 &free_size,
std::string &volume_label)
-> packet::error_type = 0;
virtual auto winfsp_mounted(const std::wstring &location)
-> packet::error_type = 0;
virtual auto winfsp_open(PWSTR fileName, UINT32 createOptions,
UINT32 grantedAccess, PVOID *fileDesc,
remote::file_info *fileInfo,
std::string &normalizedName)
virtual auto winfsp_open(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, PVOID *file_desc,
remote::file_info *file_info,
std::string &normalized_name)
-> packet::error_type = 0;
virtual auto winfsp_overwrite(PVOID fileDesc, UINT32 fileAttributes,
BOOLEAN replaceFileAttributes,
UINT64 allocationSize,
remote::file_info *fileInfo)
virtual auto winfsp_overwrite(PVOID file_desc, UINT32 file_attributes,
BOOLEAN replace_file_attributes,
UINT64 allocation_size,
remote::file_info *file_info)
-> packet::error_type = 0;
virtual auto winfsp_read(PVOID fileDesc, PVOID buffer, UINT64 offset,
UINT32 length, PUINT32 bytesTransferred)
virtual auto winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
UINT32 length, PUINT32 bytes_transferred)
-> packet::error_type = 0;
virtual auto winfsp_read_directory(PVOID fileDesc, PWSTR pattern,
virtual auto winfsp_read_directory(PVOID file_desc, PWSTR pattern,
PWSTR marker, json &itemList)
-> packet::error_type = 0;
virtual auto winfsp_rename(PVOID fileDesc, PWSTR fileName, PWSTR newFileName,
BOOLEAN replaceIfExists) -> packet::error_type = 0;
virtual auto winfsp_rename(PVOID file_desc, PWSTR file_name, PWSTR new_file_name,
BOOLEAN replace_if_exists) -> packet::error_type = 0;
virtual auto winfsp_set_basic_info(PVOID fileDesc, UINT32 fileAttributes,
UINT64 creationTime, UINT64 lastAccessTime,
UINT64 lastWriteTime, UINT64 changeTime,
remote::file_info *fileInfo)
virtual auto winfsp_set_basic_info(PVOID file_desc, UINT32 file_attributes,
UINT64 creation_time, UINT64 last_access_time,
UINT64 last_write_time, UINT64 change_time,
remote::file_info *file_info)
-> packet::error_type = 0;
virtual auto winfsp_set_file_size(PVOID fileDesc, UINT64 newSize,
BOOLEAN setAllocationSize,
remote::file_info *fileInfo)
virtual auto winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
BOOLEAN set_allocation_size,
remote::file_info *file_info)
-> packet::error_type = 0;
virtual auto winfsp_unmounted(const std::wstring &location)
-> packet::error_type = 0;
virtual auto winfsp_write(PVOID fileDesc, PVOID buffer, UINT64 offset,
UINT32 length, BOOLEAN writeToEndOfFile,
BOOLEAN constrainedIo, PUINT32 bytesTransferred,
remote::file_info *fileInfo)
virtual auto winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
UINT32 length, BOOLEAN write_to_end,
BOOLEAN constrained_io, PUINT32 bytes_transferred,
remote::file_info *file_info)
-> packet::error_type = 0;
};

View File

@ -266,7 +266,7 @@ public:
remote::file_info *file_info)
-> packet::error_type override;
auto winfsp_set_file_size(PVOID file_desc, UINT64 newSize,
auto winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
BOOLEAN set_allocation_size,
remote::file_info *file_info)
-> packet::error_type override;

View File

@ -172,7 +172,7 @@ public:
PULONG bytes_transferred) -> NTSTATUS override;
auto Rename(PVOID file_node, PVOID file_desc, PWSTR file_name,
PWSTR newFileName, BOOLEAN replace_if_exists)
PWSTR new_file_name, BOOLEAN replace_if_exists)
-> NTSTATUS override;
auto SetBasicInfo(PVOID file_node, PVOID file_desc, UINT32 attributes,
@ -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

@ -23,7 +23,13 @@
#define INCLUDE_EVENTS_EVENT_HPP_
namespace repertory {
enum class event_level { error, warn, normal, debug, verbose };
enum class event_level {
error,
warn,
normal,
debug,
verbose,
};
auto event_level_from_string(std::string level) -> event_level;
@ -37,10 +43,14 @@ protected:
: allow_async_(allow_async), ss_(ss.str()), j_(std::move(j)) {}
public:
event(const event &) = delete;
event(event &&) = delete;
auto operator=(const event &) -> event & = delete;
auto operator=(event &&) -> event & = delete;
virtual ~event() = default;
private:
const bool allow_async_;
bool allow_async_;
protected:
std::stringstream ss_;

View File

@ -32,12 +32,12 @@ using event_consumer = event_system::event_consumer;
#define E_CAST(t) ((std::string)t)
#define E_DOUBLE(d) std::to_string(d)
#define E_DOUBLE_PRECISE(d) \
#define E_DOUBLE_PRECISE(dbl_val) \
([](const double &d) -> std::string { \
std::stringstream ss; \
ss << std::fixed << std::setprecision(2) << d; \
return ss.str(); \
})(d)
})(dbl_val)
#define E_FROM_BOOL(t) std::to_string(t)
#define E_FROM_EXCEPTION(e) std::string(e.what() ? e.what() : "")
#define E_FROM_INT32(t) std::to_string(t)
@ -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)
@ -69,8 +70,9 @@ using event_consumer = event_system::event_consumer;
#define E_PROP(type, name, short_name, ts) \
private: \
void init_##short_name(const type &val) { \
ss_ << "|" << #short_name << "|" << ts(val); \
j_[#name] = ts(val); \
auto ts_val = ts(val); \
ss_ << "|" << #short_name << "|" << ts_val; \
j_[#name] = ts_val; \
} \
\
public: \
@ -244,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

@ -54,6 +54,12 @@ public:
~event_consumer() { t_event_system::instance().release(this); }
public:
event_consumer(const event_consumer &) = delete;
event_consumer(event_consumer &&) = delete;
auto operator=(const event_consumer &) -> event_consumer & = delete;
auto operator=(event_consumer &&) -> event_consumer & = delete;
private:
std::function<void(const event &)> callback_;
@ -82,9 +88,9 @@ private:
void process_events() {
std::vector<std::shared_ptr<event_type>> events;
{
unique_mutex_lock l(event_mutex_);
unique_mutex_lock lock(event_mutex_);
if (not stop_requested_ && event_list_.empty()) {
event_notify_.wait_for(l, 1s);
event_notify_.wait_for(lock, 1s);
}
if (not event_list_.empty()) {
@ -96,15 +102,16 @@ private:
const auto notify_events = [this](const std::string &name,
const event_type &event) {
std::deque<std::future<void>> futures;
recur_mutex_lock l(consumer_mutex_);
recur_mutex_lock lock(consumer_mutex_);
if (event_consumers_.find(name) != event_consumers_.end()) {
for (auto *ec : event_consumers_[name]) {
for (auto *consumer : event_consumers_[name]) {
if (event.get_allow_async()) {
futures.emplace_back(std::async(std::launch::async, [ec, &event]() {
ec->notify_event(event);
}));
futures.emplace_back(
std::async(std::launch::async, [consumer, &event]() {
consumer->notify_event(event);
}));
} else {
ec->notify_event(event);
consumer->notify_event(event);
}
}
}
@ -115,48 +122,48 @@ private:
}
};
for (const auto &e : events) {
notify_events("", *e.get());
notify_events(e->get_name(), *e.get());
for (const auto &evt : events) {
notify_events("", *evt.get());
notify_events(evt->get_name(), *evt.get());
}
}
void queue_event(event_type *e) {
mutex_lock l(event_mutex_);
event_list_.emplace_back(std::shared_ptr<event_type>(e));
void queue_event(std::shared_ptr<event_type> evt) {
mutex_lock lock(event_mutex_);
event_list_.push_back(std::move(evt));
event_notify_.notify_all();
}
public:
void attach(event_consumer *ec) {
recur_mutex_lock l(consumer_mutex_);
event_consumers_[""].push_back(ec);
void attach(event_consumer *consumer) {
recur_mutex_lock lock(consumer_mutex_);
event_consumers_[""].push_back(consumer);
}
void attach(const std::string &event_name, event_consumer *ec) {
recur_mutex_lock l(consumer_mutex_);
event_consumers_[event_name].push_back(ec);
void attach(const std::string &event_name, event_consumer *consumer) {
recur_mutex_lock lock(consumer_mutex_);
event_consumers_[event_name].push_back(consumer);
}
template <typename t, typename... args> void raise(args &&...a) {
queue_event(new t(std::forward<args>(a)...));
template <typename event_t, typename... arg_t> void raise(arg_t &&...args) {
queue_event(std::make_shared<event_t>(std::forward<arg_t>(args)...));
}
void release(event_consumer *ec) {
recur_mutex_lock l(consumer_mutex_);
auto it = std::find_if(event_consumers_.begin(), event_consumers_.end(),
[&](const auto &kv) -> bool {
return utils::collection_includes(kv.second, ec);
});
void release(event_consumer *consumer) {
recur_mutex_lock lock(consumer_mutex_);
auto iter =
std::find_if(event_consumers_.begin(), event_consumers_.end(),
[&](const auto &item) -> bool {
return utils::collection_includes(item.second, consumer);
});
if (it != event_consumers_.end()) {
auto &q = (*it).second;
utils::remove_element_from(q, ec);
if (iter != event_consumers_.end()) {
utils::remove_element_from((*iter).second, consumer);
}
}
void start() {
mutex_lock l(run_mutex_);
mutex_lock lock(run_mutex_);
if (not event_thread_) {
stop_requested_ = false;
event_thread_ = std::make_unique<std::thread>([this]() {
@ -168,7 +175,7 @@ public:
}
void stop() {
mutex_lock l(run_mutex_);
mutex_lock lock(run_mutex_);
if (event_thread_) {
stop_requested_ = true;
event_notify_.notify_all();

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

@ -72,13 +72,13 @@ public:
auto operator=(const download &) noexcept -> download & = delete;
private:
bool complete_ = false;
api_error error_ = api_error::success;
bool complete_{false};
api_error error_{api_error::success};
std::mutex mtx_;
std::condition_variable notify_;
public:
void notify(const api_error &e);
void notify(const api_error &err);
auto wait() -> api_error;
};
@ -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;
}
@ -194,17 +199,17 @@ public:
class open_file final : public open_file_base {
public:
open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
filesystem_item fsi, i_provider &provider, i_upload_manager &um);
filesystem_item fsi, i_provider &provider, i_upload_manager &mgr);
open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
filesystem_item fsi,
std::map<std::uint64_t, open_file_data> open_data,
i_provider &provider, i_upload_manager &um);
i_provider &provider, i_upload_manager &mgr);
open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
filesystem_item fsi, i_provider &provider,
std::optional<boost::dynamic_bitset<>> read_state,
i_upload_manager &um);
i_upload_manager &mgr);
private:
open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
@ -212,7 +217,7 @@ public:
std::map<std::uint64_t, open_file_data> open_data,
i_provider &provider,
std::optional<boost::dynamic_bitset<>> read_state,
i_upload_manager &um);
i_upload_manager &mgr);
public:
open_file() = delete;
@ -225,11 +230,11 @@ public:
~open_file() override;
private:
i_upload_manager &um_;
i_upload_manager &mgr_;
private:
bool notified_ = false;
std::size_t read_chunk_index_ = 0u;
std::size_t read_chunk_index_{};
boost::dynamic_bitset<> read_state_;
std::unique_ptr<std::thread> reader_thread_;
std::unique_ptr<std::thread> download_thread_;
@ -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:
@ -262,11 +268,13 @@ public:
auto is_write_supported() const -> bool override { return true; }
[[nodiscard]] auto native_operation(const native_operation_callback &cb)
[[nodiscard]] auto
native_operation(const native_operation_callback &callback)
-> api_error override;
[[nodiscard]] auto native_operation(std::uint64_t new_file_size,
const native_operation_callback &cb)
[[nodiscard]] auto
native_operation(std::uint64_t new_file_size,
const native_operation_callback &callback)
-> api_error override;
void remove(std::uint64_t handle) override;
@ -313,8 +321,8 @@ public:
std::unique_ptr<std::thread> chunk_reverse_thread_;
std::condition_variable chunk_notify_;
mutable std::mutex chunk_mtx_;
std::size_t current_chunk_ = 0u;
std::size_t first_chunk_ = 0u;
std::size_t current_chunk_{};
std::size_t first_chunk_{};
std::size_t last_chunk_;
private:
@ -355,7 +363,8 @@ public:
auto is_write_supported() const -> bool override { return false; }
[[nodiscard]] auto native_operation(const native_operation_callback &cb)
[[nodiscard]] auto
native_operation(const native_operation_callback &callback)
-> api_error override;
[[nodiscard]] auto native_operation(std::uint64_t,
@ -442,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_;
@ -463,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);
@ -477,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();
@ -487,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);
@ -503,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;
@ -511,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;
@ -530,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,12 +58,14 @@ 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 &cb) -> api_error = 0;
native_operation(const native_operation_callback &callback) -> api_error = 0;
[[nodiscard]] virtual auto
native_operation(std::uint64_t new_file_size,
const native_operation_callback &cb) -> api_error = 0;
const native_operation_callback &callback) -> api_error = 0;
[[nodiscard]] virtual auto read(std::size_t read_size,
std::uint64_t read_offset, data_buffer &data)
@ -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

@ -68,11 +68,10 @@ public:
[[nodiscard]] auto create_meta_attributes(
std::uint64_t accessed_date, std::uint32_t attributes,
std::uint64_t changed_date, std::uint64_t creation_date, bool directory,
const std::string &encryption_token, std::uint32_t gid,
const std::string &key, std::uint32_t mode, std::uint64_t modified_date,
std::uint32_t osx_backup, std::uint32_t osx_flags, std::uint64_t size,
const std::string &source_path, std::uint32_t uid,
std::uint64_t written_date) -> api_meta_map;
std::uint32_t gid, const std::string &key, std::uint32_t mode,
std::uint64_t modified_date, std::uint32_t osx_backup,
std::uint32_t osx_flags, std::uint64_t size, const std::string &source_path,
std::uint32_t uid, std::uint64_t written_date) -> api_meta_map;
[[nodiscard]] auto provider_meta_handler(i_provider &provider, bool directory,
const api_file &file) -> api_error;

View File

@ -73,11 +73,10 @@ public:
[[nodiscard]] auto create_meta_attributes(
std::uint64_t accessed_date, std::uint32_t attributes,
std::uint64_t changed_date, std::uint64_t creation_date, bool directory,
const std::string &encryption_token, std::uint32_t gid,
const std::string &key, std::uint32_t mode, std::uint64_t modified_date,
std::uint32_t osx_backup, std::uint32_t osx_flags, std::uint64_t size,
const std::string &source_path, std::uint32_t uid,
std::uint64_t written_date) -> api_meta_map;
std::uint32_t gid, const std::string &key, std::uint32_t mode,
std::uint64_t modified_date, std::uint32_t osx_backup,
std::uint32_t osx_flags, std::uint64_t size, const std::string &source_path,
std::uint32_t uid, std::uint64_t written_date) -> api_meta_map;
[[nodiscard]] auto provider_meta_handler(i_provider &provider, bool directory,
const api_file &file) -> api_error;

View File

@ -22,95 +22,92 @@
#ifndef INCLUDE_PROVIDERS_BASE_PROVIDER_HPP_
#define INCLUDE_PROVIDERS_BASE_PROVIDER_HPP_
#include "db/meta_db.hpp"
#include "providers/i_provider.hpp"
#include "providers/meta_db.hpp"
#include "types/repertory.hpp"
namespace repertory {
class app_config;
class i_file_manager;
class i_http_comm;
class base_provider : public i_provider {
public:
explicit base_provider(app_config &config);
~base_provider() override = default;
base_provider(app_config &config, i_http_comm &comm)
: config_(config), comm_(comm) {}
private:
app_config &config_;
std::atomic<std::uint64_t> used_space_{0U};
i_http_comm &comm_;
protected:
private:
api_item_added_callback api_item_added_;
std::unique_ptr<meta_db> meta_db_;
mutable std::recursive_mutex notify_added_mutex_;
i_file_manager *fm_ = nullptr;
stop_type stop_requested_ = false;
std::unique_ptr<meta_db> db3_;
i_file_manager *fm_{};
private:
void remove_deleted_files();
protected:
void calculate_used_drive_space(bool add_missing);
[[nodiscard]] static auto create_api_file(std::string path, std::string key,
std::uint64_t size) -> api_file;
[[nodiscard]] static auto create_api_file(std::string path,
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
check_file_exists(const std::string &api_path) const -> api_error = 0;
create_file_extra(const std::string & /* api_path */,
api_meta_map & /* meta */) -> api_error {
return api_error::success;
}
void cleanup();
[[nodiscard]] auto get_api_item_added() -> api_item_added_callback & {
return api_item_added_;
}
[[nodiscard]] auto get_api_item_added() const
-> const api_item_added_callback & {
return api_item_added_;
}
[[nodiscard]] auto get_comm() const -> i_http_comm & { return comm_; }
[[nodiscard]] auto get_config() -> app_config & { return config_; }
[[nodiscard]] auto get_config() const -> app_config & { return config_; }
[[nodiscard]] virtual auto
handle_rename_file(const std::string &from_api_path,
const std::string &to_api_path,
const std::string &source_path) -> api_error = 0;
[[nodiscard]] auto notify_directory_added(const std::string &api_path,
const std::string &api_parent) const
-> api_error {
return const_cast<base_provider *>(this)->notify_directory_added(
api_path, api_parent);
[[nodiscard]] auto get_config() const -> const app_config & {
return config_;
}
[[nodiscard]] virtual auto
notify_directory_added(const std::string &api_path,
const std::string &api_parent) -> api_error;
[[nodiscard]] auto notify_file_added(const std::string &api_path,
const std::string &api_parent,
std::uint64_t size) const -> api_error {
return const_cast<base_provider *>(this)->notify_file_added(
api_path, api_parent, size);
}
[[nodiscard]] virtual auto notify_file_added(const std::string &api_path,
const std::string &api_parent,
std::uint64_t size)
-> api_error = 0;
[[nodiscard]] auto get_db() -> meta_db & { return *db3_; }
[[nodiscard]] virtual auto
populate_directory_items(const std::string &api_path,
get_directory_items_impl(const std::string &api_path,
directory_item_list &list) const -> api_error = 0;
[[nodiscard]] virtual auto populate_file(const std::string &api_path,
api_file &file) const
-> api_error = 0;
[[nodiscard]] auto get_file_mgr() -> i_file_manager * { return fm_; }
auto processed_orphaned_file(const std::string &source_path,
const std::string &api_path = "") const -> bool;
void remove_deleted_files();
void remove_expired_orphaned_files();
void remove_unknown_source_files();
[[nodiscard]] auto remove_item_meta(const std::string &api_path)
-> api_error {
return meta_db_->remove_item_meta(api_path);
[[nodiscard]] auto get_file_mgr() const -> const i_file_manager * {
return fm_;
}
void update_filesystem_item(bool directory, const api_error &error,
const std::string &api_path,
filesystem_item &fsi) const;
[[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
@ -118,6 +115,9 @@ public:
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;
@ -129,9 +129,6 @@ public:
directory_item_list &list) const
-> api_error override;
[[nodiscard]] auto get_file(const std::string &api_path, api_file &file) const
-> api_error override;
[[nodiscard]] auto get_file_size(const std::string &api_path,
std::uint64_t &file_size) const
-> api_error override;
@ -142,7 +139,7 @@ public:
-> api_error override;
[[nodiscard]] auto get_filesystem_item_and_file(const std::string &api_path,
api_file &file,
api_file &f,
filesystem_item &fsi) const
-> api_error override;
@ -161,44 +158,43 @@ public:
-> api_error override;
[[nodiscard]] auto get_pinned_files() const
-> std::vector<std::string> override {
return meta_db_->get_pinned_files();
}
-> std::vector<std::string> override;
[[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 &) const
-> bool override {
return true;
}
[[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 {
return meta_db_->remove_item_meta(api_path, key);
}
[[nodiscard]] auto rename_file(const std::string &from_api_path,
const std::string &to_api_path)
-> api_error override;
[[nodiscard]] auto set_item_meta(const std::string &api_path,
const std::string &key,
const std::string &value)
-> api_error override {
return meta_db_->set_item_meta(api_path, key, value);
}
-> api_error override;
[[nodiscard]] auto set_item_meta(const std::string &api_path,
const api_meta_map &meta)
-> api_error override {
return meta_db_->set_item_meta(api_path, meta);
}
-> api_error override;
[[nodiscard]] auto start(api_item_added_callback api_item_added,
i_file_manager *fm) -> bool override;
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

@ -33,6 +33,12 @@ public:
~encrypt_provider() override = default;
public:
encrypt_provider(const encrypt_provider &) = delete;
encrypt_provider(encrypt_provider &&) = delete;
auto operator=(const encrypt_provider &) -> encrypt_provider & = delete;
auto operator=(encrypt_provider &&) -> encrypt_provider & = delete;
private:
struct reader_info final {
std::chrono::system_clock::time_point last_access_time =
@ -43,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_{};
const std::string DB_NAME = "meta_db";
db3_t db_;
private:
i_file_manager *fm_ = nullptr;
@ -56,7 +58,7 @@ private:
std::recursive_mutex reader_lookup_mtx_{};
private:
static auto create_api_file(const std::string api_path, bool directory,
static auto create_api_file(const std::string &api_path, bool directory,
const std::string &source_path) -> api_file;
static void create_item_meta(api_meta_map &meta, bool directory,
@ -201,13 +203,12 @@ public:
}
[[nodiscard]] auto start(api_item_added_callback api_item_added,
i_file_manager *fm) -> bool override;
i_file_manager *mgr) -> bool override;
void stop() override;
[[nodiscard]] auto upload_file(const std::string & /*api_path*/,
const std::string & /*source_path*/,
const std::string & /*encryption_token*/,
stop_type & /*stop_requested*/)
-> api_error override {
return api_error::not_implemented;

View File

@ -143,13 +143,13 @@ public:
-> api_error = 0;
[[nodiscard]] virtual auto start(api_item_added_callback api_item_added,
i_file_manager *fm) -> bool = 0;
i_file_manager *mgr) -> bool = 0;
virtual void stop() = 0;
[[nodiscard]] virtual auto
upload_file(const std::string &api_path, const std::string &source_path,
const std::string &encryption_token, stop_type &stop_requested)
[[nodiscard]] virtual auto upload_file(const std::string &api_path,
const std::string &source_path,
stop_type &stop_requested)
-> api_error = 0;
};
} // namespace repertory

View File

@ -19,77 +19,55 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef INCLUDE_DB_META_DB_HPP_
#define INCLUDE_DB_META_DB_HPP_
#ifndef INCLUDE_PROVIDERS_META_DB_HPP_
#define INCLUDE_PROVIDERS_META_DB_HPP_
#include "app_config.hpp"
#include "types/repertory.hpp"
#include "utils/rocksdb_utils.hpp"
namespace repertory {
class app_config;
class meta_db final {
public:
explicit meta_db(const app_config &config);
public:
meta_db(const app_config &cfg);
~meta_db();
private:
std::unique_ptr<rocksdb::DB> db_;
rocksdb::ColumnFamilyHandle *default_family_{};
rocksdb::ColumnFamilyHandle *source_family_{};
rocksdb::ColumnFamilyHandle *keys_family_{};
const std::string METADB_NAME = "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:
[[nodiscard]] auto
perform_action(const std::string &function_name,
const std::function<rocksdb::Status()> &action) const
-> api_error;
db3_t db_;
constexpr static const auto table_name = "meta";
[[nodiscard]] auto get_item_meta_json(const std::string &api_path,
json &json_data) const -> api_error;
[[nodiscard]] auto store_item_meta(const std::string &api_path,
const std::string &key,
const std::string &value) -> api_error;
private:
[[nodiscard]] auto update_item_meta(const std::string &api_path,
api_meta_map meta) -> api_error;
public:
[[nodiscard]] auto create_iterator(bool source_family) const
-> std::shared_ptr<rocksdb::Iterator>;
[[nodiscard]] auto get_api_path(const std::string &source_path,
std::string &api_path) -> api_error;
[[nodiscard]] auto get_api_path_from_key(const std::string &key,
std::string &api_path) const
-> api_error;
[[nodiscard]] auto get_api_path_from_source(const std::string &source_path,
std::string &api_path) const
-> 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) const -> api_error;
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_item_meta_exists(const std::string &api_path) const
-> bool;
[[nodiscard]] auto get_pinned_files() const -> std::vector<std::string>;
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t;
[[nodiscard]] auto get_pinned_files() const -> std::vector<std::string>;
[[nodiscard]] auto
get_source_path_exists(const std::string &source_path) const -> bool;
[[nodiscard]] auto remove_item_meta(const std::string &api_path) -> api_error;
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 &source_path,
const std::string &from_api_path,
[[nodiscard]] auto rename_item_meta(const std::string &from_api_path,
const std::string &to_api_path)
-> api_error;
@ -99,11 +77,7 @@ public:
[[nodiscard]] auto set_item_meta(const std::string &api_path,
const api_meta_map &meta) -> api_error;
[[nodiscard]] auto set_source_path(const std::string &api_path,
const std::string &source_path)
-> api_error;
};
} // namespace repertory
#endif // INCLUDE_DB_META_DB_HPP_
#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

@ -23,87 +23,93 @@
#define INCLUDE_PROVIDERS_S3_S3_PROVIDER_HPP_
#if defined(REPERTORY_ENABLE_S3)
#include "db/directory_db.hpp"
#include "providers/base_provider.hpp"
#include "types/repertory.hpp"
namespace repertory {
class app_config;
class i_file_manager;
class i_s3_comm;
class i_http_comm;
struct head_object_result;
class s3_provider final : public base_provider {
public:
s3_provider(app_config &config, i_s3_comm &s3_comm);
s3_provider(app_config &config, i_http_comm &comm);
~s3_provider() override = default;
private:
i_s3_comm &s3_comm_;
public:
s3_provider(const s3_provider &) = delete;
s3_provider(s3_provider &&) = delete;
auto operator=(const s3_provider &) -> s3_provider & = delete;
auto operator=(s3_provider &&) -> s3_provider & = delete;
private:
std::unique_ptr<directory_db> directory_db_;
std::unique_ptr<std::thread> background_thread_;
[[nodiscard]] auto add_if_not_found(api_file &file,
const std::string &object_name) const
-> api_error;
private:
void create_directories();
[[nodiscard]] auto create_file_extra(const std::string &api_path,
api_meta_map &meta)
-> api_error override;
void create_parent_directories(const api_file &file, bool directory);
[[nodiscard]] auto create_path_directories(const std::string &api_path,
const std::string &key) const
-> api_error;
void update_item_meta(directory_item &di) const;
[[nodiscard]] auto decrypt_object_name(std::string &object_name) const
-> api_error;
[[nodiscard]] auto
get_object_info(bool directory, const std::string &api_path,
bool &is_encrypted, std::string &object_name,
head_object_result &result) const -> api_error;
[[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;
protected:
[[nodiscard]] auto check_file_exists(const std::string &api_path) const
[[nodiscard]] auto create_directory_impl(const std::string &api_path,
api_meta_map &meta)
-> api_error override;
[[nodiscard]] auto handle_rename_file(const std::string &from_api_path,
const std::string &to_api_path,
const std::string &source_path)
-> api_error override;
[[nodiscard]] auto notify_directory_added(const std::string &api_path,
const std::string &api_parent)
-> api_error override;
[[nodiscard]] auto notify_file_added(const std::string &api_path,
const std::string &api_parent,
std::uint64_t size)
-> api_error override;
[[nodiscard]] auto populate_directory_items(const std::string &api_path,
[[nodiscard]] auto get_directory_items_impl(const std::string &api_path,
directory_item_list &list) const
-> api_error override;
[[nodiscard]] auto populate_file(const std::string &api_path,
api_file &file) const -> api_error override;
[[nodiscard]] auto get_used_drive_space_impl() const
-> std::uint64_t override;
[[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:
#ifdef REPERTORY_TESTING
void set_callback(api_item_added_callback cb) { api_item_added_ = cb; }
#endif // REPERTORY_TESTING
[[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_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;
[[nodiscard]] auto get_file_list(api_file_list &list) const
-> api_error override;
[[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override;
[[nodiscard]] auto get_provider_type() const -> provider_type override {
return provider_type::s3;
}
[[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override {
return std::numeric_limits<std::int64_t>::max() / std::int64_t(2);
}
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t override;
[[nodiscard]] auto is_direct_only() const -> bool override { return false; }
[[nodiscard]] auto is_directory(const std::string &api_path,
@ -116,7 +122,7 @@ public:
[[nodiscard]] auto is_rename_supported() const -> bool override {
return false;
}
};
[[nodiscard]] auto read_file_bytes(const std::string &api_path,
std::size_t size, std::uint64_t offset,
@ -124,21 +130,14 @@ 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)
[[nodiscard]] auto rename_file(const std::string &from_api_path,
const std::string &to_api_path)
-> api_error override;
[[nodiscard]] auto start(api_item_added_callback api_item_added,
i_file_manager *fm) -> bool override;
i_file_manager *mgr) -> bool override;
void stop() override;
[[nodiscard]] auto
upload_file(const std::string &api_path, const std::string &source_path,
const std::string &encryption_token, stop_type &stop_requested)
-> api_error override;
};
} // namespace repertory

View File

@ -22,7 +22,7 @@
#ifndef INCLUDE_PROVIDERS_SIA_SIA_PROVIDER_HPP_
#define INCLUDE_PROVIDERS_SIA_SIA_PROVIDER_HPP_
#include "providers/i_provider.hpp"
#include "providers/base_provider.hpp"
#include "types/repertory.hpp"
namespace repertory {
@ -30,108 +30,64 @@ class app_config;
class i_file_manager;
class i_http_comm;
class sia_provider : public i_provider {
class sia_provider : public base_provider {
public:
sia_provider(app_config &config, i_http_comm &comm);
~sia_provider() override = default;
private:
app_config &config_;
i_http_comm &comm_;
public:
sia_provider(const sia_provider &) = delete;
sia_provider(sia_provider &&) = delete;
auto operator=(const sia_provider &) -> sia_provider & = delete;
auto operator=(sia_provider &&) -> sia_provider & = delete;
private:
const std::string DB_NAME = "meta_db";
api_item_added_callback api_item_added_;
std::unique_ptr<rocksdb::DB> db_;
i_file_manager *fm_ = nullptr;
private:
[[nodiscard]] static auto create_api_file(std::string path,
std::uint64_t size) -> api_file;
[[nodiscard]] static auto create_api_file(std::string path,
std::uint64_t size,
api_meta_map &meta) -> api_file;
[[nodiscard]] auto get_object_info(const std::string &api_path,
json &object_info) const -> api_error;
[[nodiscard]] auto get_object_list(const std::string api_path,
[[nodiscard]] auto get_object_list(const std::string &api_path,
nlohmann::json &object_list) const -> bool;
void remove_deleted_files();
public:
[[nodiscard]] auto create_directory(const std::string &api_path,
api_meta_map &meta) -> api_error override;
[[nodiscard]] auto
create_directory_clone_source_meta(const std::string &source_api_path,
const std::string &api_path)
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_api_path_from_source(const std::string &source_path,
std::string &api_path) const
[[nodiscard]] auto remove_directory_impl(const std::string &api_path)
-> api_error override;
[[nodiscard]] auto get_directory_items(const std::string &api_path,
directory_item_list &list) const
[[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;
[[nodiscard]] auto get_file_list(api_file_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;
[[nodiscard]] auto get_filesystem_item(const std::string &api_path,
bool directory,
filesystem_item &fsi) const
-> api_error override;
[[nodiscard]] auto get_filesystem_item_and_file(const std::string &api_path,
api_file &f,
filesystem_item &fsi) const
-> api_error override;
[[nodiscard]] auto
get_filesystem_item_from_source_path(const std::string &source_path,
filesystem_item &fsi) const
-> api_error override;
[[nodiscard]] auto get_item_meta(const std::string &api_path,
api_meta_map &meta) const
-> api_error override;
[[nodiscard]] auto get_item_meta(const std::string &api_path,
const std::string &key,
std::string &value) const
-> api_error override;
[[nodiscard]] auto get_pinned_files() const
-> std::vector<std::string> override;
[[nodiscard]] auto get_provider_type() const -> provider_type override {
return provider_type::sia;
}
[[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override;
[[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_direct_only() const -> bool override { return false; }
[[nodiscard]] auto is_directory(const std::string &api_path,
@ -140,13 +96,10 @@ public:
[[nodiscard]] auto is_file(const std::string &api_path, bool &exists) const
-> api_error override;
[[nodiscard]] auto is_file_writeable(const std::string &api_path) const
-> bool override;
[[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,
@ -155,39 +108,14 @@ 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 remove_item_meta(const std::string &api_path,
const std::string &key)
-> api_error override;
[[nodiscard]] auto rename_file(const std::string &from_api_path,
const std::string &to_api_path)
-> api_error override;
[[nodiscard]] auto set_item_meta(const std::string &api_path,
const std::string &key,
const std::string &value)
-> api_error override;
[[nodiscard]] auto set_item_meta(const std::string &api_path,
const api_meta_map &meta)
-> api_error override;
[[nodiscard]] auto start(api_item_added_callback api_item_added,
i_file_manager *fm) -> bool override;
i_file_manager *mgr) -> bool override;
void stop() override;
[[nodiscard]] auto upload_file(const std::string &api_path,
const std::string &source_path,
const std::string & /* encryption_token */,
stop_type &stop_requested)
-> api_error override;
};
} // namespace repertory

View File

@ -22,8 +22,8 @@
#ifndef INCLUDE_TYPES_REMOTE_HPP_
#define INCLUDE_TYPES_REMOTE_HPP_
#define PACKET_SERVICE_FUSE std::uint32_t(1)
#define PACKET_SERVICE_WINFSP std::uint32_t(2)
#define PACKET_SERVICE_FUSE 1U
#define PACKET_SERVICE_WINFSP 2U
#ifdef _WIN32
#define PACKET_SERVICE_FLAGS PACKET_SERVICE_WINFSP
@ -44,48 +44,51 @@ using group_id = std::uint32_t;
using user_id = std::uint32_t;
enum class open_flags : std::uint32_t {
read_only = 0u,
write_only = 1u,
read_write = 2u,
create = 4u,
excl = 8u,
no_ctty = 16u,
truncate = 32u,
append = 64u,
non_blocking = 128u,
sync = 256u,
async = 512u,
directory = 1024u,
no_follow = 2048u,
clo_exec = 4096u,
direct = 8192u,
no_atime = 16384u,
path = 32768u,
temp_file = 65536u,
dsync = 131072u,
read_only = 0U,
write_only = 1U,
read_write = 2U,
create = 4U,
excl = 8U,
no_ctty = 16U,
truncate = 32U,
append = 64U,
non_blocking = 128U,
sync = 256U,
async = 512U,
directory = 1024U,
no_follow = 2048U,
clo_exec = 4096U,
direct = 8192U,
no_atime = 16384U,
path = 32768U,
temp_file = 65536U,
dsync = 131072U,
};
inline auto operator|(const open_flags &a, const open_flags &b) -> open_flags {
inline auto operator|(const open_flags &flag_1, const open_flags &flag_2)
-> open_flags {
using t = std::underlying_type_t<open_flags>;
return static_cast<open_flags>(static_cast<t>(a) | static_cast<t>(b));
return static_cast<open_flags>(static_cast<t>(flag_1) |
static_cast<t>(flag_2));
}
#ifdef __GNUG__
__attribute__((unused))
#endif
inline auto
operator|=(open_flags &a, const open_flags &b) -> open_flags & {
a = a | b;
return a;
operator|=(open_flags &flag_1, const open_flags &flag_2) -> open_flags & {
flag_1 = flag_1 | flag_2;
return flag_1;
}
#ifdef __GNUG__
__attribute__((unused))
#endif
inline auto
operator&(const open_flags &a, const open_flags &b) -> open_flags {
operator&(const open_flags &flag_1, const open_flags &flag_2) -> open_flags {
using t = std::underlying_type_t<open_flags>;
return static_cast<open_flags>(static_cast<t>(a) & static_cast<t>(b));
return static_cast<open_flags>(static_cast<t>(flag_1) &
static_cast<t>(flag_2));
}
#pragma pack(1)

View File

@ -29,9 +29,7 @@ const std::string META_BACKUP = "backup";
const std::string META_CHANGED = "changed";
const std::string META_CREATION = "creation";
const std::string META_DIRECTORY = "directory";
const std::string META_ENCRYPTION_TOKEN = "token";
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";
@ -43,24 +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_ENCRYPTION_TOKEN,
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>;
@ -139,6 +123,12 @@ enum class exit_code : std::int32_t {
init_failed = -18,
};
enum http_error_codes : std::int32_t {
ok = 200,
multiple_choices = 300,
not_found = 404,
};
enum class lock_result {
success,
locked,
@ -149,39 +139,37 @@ enum class provider_type : std::size_t {
sia,
remote,
s3,
passthrough,
encrypt,
unknown,
};
#ifdef _WIN32
struct open_file_data {
void *directory_buffer = nullptr;
void *directory_buffer{};
};
#else
using open_file_data = int;
#endif
struct api_file {
std::string api_path{};
std::string api_parent{};
std::uint64_t accessed_date = 0u;
std::uint64_t changed_date = 0u;
std::uint64_t creation_date = 0u;
std::string encryption_token{};
std::uint64_t file_size = 0u;
std::string key{};
std::uint64_t modified_date = 0u;
std::string source_path{};
std::string api_path;
std::string api_parent;
std::uint64_t accessed_date{};
std::uint64_t changed_date{};
std::uint64_t creation_date{};
std::uint64_t file_size{};
std::string key;
std::uint64_t modified_date{};
std::string source_path;
};
struct directory_item {
std::string api_path{};
std::string api_parent{};
bool directory = false;
std::uint64_t size = 0u;
std::string api_path;
std::string api_parent;
bool directory{false};
std::uint64_t size{};
api_meta_map meta{};
bool resolved = false;
bool resolved{false};
[[nodiscard]] static auto from_json(const json &item) -> directory_item {
directory_item ret{};
@ -203,27 +191,22 @@ struct directory_item {
};
struct filesystem_item {
std::string api_path{};
std::string api_parent{};
bool directory = false;
std::string encryption_token{};
std::uint64_t size = 0u;
std::string source_path{};
[[nodiscard]] auto is_encrypted() const -> bool {
return not encryption_token.empty();
}
std::string api_path;
std::string api_parent;
bool directory{false};
std::uint64_t size{};
std::string source_path;
};
struct host_config {
std::string agent_string{};
std::string api_password{};
std::string api_user{};
std::uint16_t api_port = 0u;
std::string host_name_or_ip = "localhost";
std::string agent_string;
std::string api_password;
std::string api_user;
std::uint16_t api_port{};
std::string host_name_or_ip{"localhost"};
std::string path{};
std::string protocol = "http";
std::uint32_t timeout_ms = 60000u;
std::string protocol{"http"};
std::uint32_t timeout_ms{60000U};
auto operator==(const host_config &hc) const noexcept -> bool {
if (&hc != this) {
@ -275,29 +258,25 @@ from_json(const json &j, host_config &hc) {
}
struct http_range {
std::uint64_t begin = 0u;
std::uint64_t end = 0u;
};
struct passthrough_config {
std::string location{};
std::string name{};
std::uint64_t begin;
std::uint64_t end;
};
struct encrypt_config {
std::string encryption_token{};
std::string path{};
std::string encryption_token;
std::string path;
};
struct s3_config {
std::string access_key{};
std::string bucket{};
std::uint16_t cache_timeout_secs = 60u;
std::string encryption_token{};
std::string access_key;
std::string bucket;
std::uint16_t cache_timeout_secs{60U};
std::string encryption_token;
std::string region = "any";
std::string secret_key{};
std::uint32_t timeout_ms = 60000u;
std::string secret_key;
std::uint32_t timeout_ms{60000U};
std::string url;
bool use_path_style{false};
bool use_region_in_url{false};
};

View File

@ -1,3 +1,4 @@
// NOLINTBEGIN
#ifndef _MACARON_BASE64_H_
#define _MACARON_BASE64_H_
@ -25,11 +26,22 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wold-style-cast"
#pragma GCC diagnostic ignored "-Wuseless-cast"
#endif
#include <string>
#include <vector>
namespace macaron {
namespace Base64 {
namespace macaron::Base64 {
static std::string Encode(const char *data, const size_t &len) {
static constexpr char sEncodingTable[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
@ -135,7 +147,16 @@ static std::string Encode(const char *data, const size_t &len) {
return out;
}
} // namespace Base64
} // namespace macaron
} // namespace macaron::Base64
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif /* _MACARON_BASE64_H_ */
// NOLINTEND

View File

@ -34,8 +34,6 @@ static const option data_directory_option = {"-dd", "--data_directory"};
static const option encrypt_option = {"-en", "--encrypt"};
static const option drive_information_option = {"-di", "--drive_information"};
#if defined(REPERTORY_ENABLE_S3)
static const option create_directory_option = {"-cd", "--create_directory"};
static const option list_objects_option = {"-lo", "--list_objects"};
static const option name_option = {"-na", "--name"};
static const option s3_option = {"-s3", "--s3"};
#endif // defined(REPERTORY_ENABLE_S3)
@ -67,8 +65,6 @@ static const std::vector<option> option_list = {
#if defined(REPERTORY_ENABLE_S3)
s3_option,
name_option,
create_directory_option,
list_objects_option,
#endif // defined(REPERTORY_ENABLE_S3)
generate_config_option,
get_option,
@ -92,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

@ -30,11 +30,15 @@ using key_type = std::array<unsigned char, 32U>;
class encrypting_reader final {
public:
encrypting_reader(
const std::string &file_name, const std::string &source_path,
stop_type &stop_requested, const std::string &token,
std::optional<std::string> relative_parent_path = std::nullopt,
const size_t error_return = 0);
encrypting_reader(const std::string &file_name,
const std::string &source_path, stop_type &stop_requested,
const std::string &token,
std::optional<std::string> relative_parent_path,
std::size_t error_return = 0U);
encrypting_reader(const std::string &encrypted_file_path,
const std::string &source_path, stop_type &stop_requested,
const std::string &token, std::size_t error_return = 0U);
encrypting_reader(
const std::string &encrypted_file_path, const std::string &source_path,
@ -42,9 +46,13 @@ public:
std::vector<std::array<unsigned char,
crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>>
iv_list,
const size_t error_return = 0);
std::size_t error_return = 0U);
encrypting_reader(const encrypting_reader &r);
encrypting_reader(const encrypting_reader &reader);
encrypting_reader(encrypting_reader &&) = delete;
auto operator=(const encrypting_reader &) -> encrypting_reader & = delete;
auto operator=(encrypting_reader &&) -> encrypting_reader & = delete;
~encrypting_reader();
@ -62,11 +70,11 @@ private:
std::vector<
std::array<unsigned char, crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>>
iv_list_;
std::size_t last_data_chunk_ = 0u;
std::size_t last_data_chunk_size_ = 0u;
std::uint64_t read_offset_ = 0u;
std::size_t last_data_chunk_{};
std::size_t last_data_chunk_size_{};
std::uint64_t read_offset_{};
native_file_ptr source_file_;
std::uint64_t total_size_ = 0u;
std::uint64_t total_size_{};
private:
static const std::size_t header_size_;

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>

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