14 Commits

Author SHA1 Message Date
cf9e0a356c updated build system
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
2024-08-02 11:25:14 -05:00
e66b783df8 updated build system 2024-08-02 11:24:30 -05:00
b695200123 updated build system 2024-08-02 11:14:44 -05:00
a383fb405e updated build system 2024-08-02 11:14:28 -05:00
1cebaf83e1 updated build system 2024-08-02 10:57:34 -05:00
4976825bd6 updated build system 2024-08-02 10:56:40 -05:00
098d172f40 updated build system 2024-08-02 10:53:11 -05:00
f4a3c52428 refactor 2024-08-02 10:29:31 -05:00
2d60b637ec refactor 2024-08-02 10:00:14 -05:00
79b16d9a34 refactor 2024-08-02 09:58:16 -05:00
d69f2fd321 refactor 2024-08-02 09:52:12 -05:00
4015c1bb6e refactor 2024-08-02 09:50:53 -05:00
9f76f20ea8 refactor 2024-08-02 09:32:26 -05:00
b399ff3291 refactor 2024-08-02 09:30:41 -05:00
125 changed files with 4258 additions and 2090 deletions

View File

@ -99,7 +99,7 @@ PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false

View File

@ -18,6 +18,7 @@ cppflags
cpphttplib
cpptrace
cppvsdbg
crypto_aead_xchacha20poly1305_ietf_npubbytes
cstdint
cxxflags
cxxstd
@ -136,6 +137,7 @@ project_enable_gtkmm
propgrid
pugi
pugixml_project
remote_winfsp
richtext
rocksdb_library
rpcrt4

View File

@ -13,6 +13,16 @@ include(CheckIncludeFileCXX)
include(CheckIncludeFiles)
include(ExternalProject)
check_include_files(sys/xattr.h HAS_SETXATTR)
if(HAS_SETXATTR)
add_definitions(-DHAS_SETXATTR)
endif()
check_include_files("wordexp.h" HAS_WORDEXP_H)
if(HAS_WORDEXP_H)
add_definitions(-DHAS_WORDEXP_H)
endif()
include(cmake/versions.cmake)
include(cmake/arch.cmake)
include(cmake/os.cmake)

View File

@ -1,4 +1,7 @@
list(APPEND PROJECT_COMMON_FLAG_LIST
-D_GNU_SOURCE
-D_LARGEFILE_SOURCE
-D_LARGEFILE64_SOURCE
-D_FILE_OFFSET_BITS=64
-D_TIME_BITS=64
-march=${PROJECT_MARCH}

View File

@ -26,21 +26,7 @@ function(set_common_target_options name)
endif()
endfunction(set_common_target_options)
function(add_project_executable name dependencies libraries)
file(GLOB_RECURSE headers
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/include/*.h
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/include/*.hh
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/include/*.hxx
)
file(GLOB_RECURSE sources
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/src/*.c
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/src/*.cc
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/src/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/src/*.cxx
)
function(add_project_executable2 name dependencies libraries headers sources)
if (PROJECT_WINDOWS_VERSION_RC)
list(APPEND sources ${PROJECT_WINDOWS_VERSION_RC})
endif()
@ -62,6 +48,28 @@ function(add_project_executable name dependencies libraries)
endif()
target_link_libraries(${name} PRIVATE ${libraries})
if(PROJECT_ENABLE_SDL AND PROJECT_IS_MINGW)
target_link_libraries(${name} PRIVATE SDL2::SDL2main)
endif ()
endfunction(add_project_executable2)
function(add_project_executable name dependencies libraries)
file(GLOB_RECURSE headers
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/include/*.h
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/include/*.hh
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/include/*.hxx
)
file(GLOB_RECURSE sources
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/src/*.c
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/src/*.cc
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/src/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/src/*.cxx
)
add_project_executable2(${name} "${dependencies}" "${libraries}" "${headers}" "${sources}")
endfunction(add_project_executable)
function(add_project_library name dependencies libraries additional_sources)
@ -96,7 +104,24 @@ function(add_project_test_executable name dependencies libraries)
find_package(GTest ${GTEST_VERSION} REQUIRED)
enable_testing()
add_project_executable(${name} "${dependencies}" "${libraries}")
file(GLOB_RECURSE headers
${PROJECT_3RD_PARTY_DIR}/test/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/include/*.h
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/include/*.hh
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/include/${name}/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/include/${name}/include/${name}/include/*.hxx
)
file(GLOB_RECURSE sources
${PROJECT_3RD_PARTY_DIR}/test/src/*.cpp
${additional_sources}
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/src/*.c
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/src/*.cc
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/src/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${name}/src/*.cxx
)
add_project_executable2(${name} "${dependencies}" "${libraries}" "${headers}" "${sources}")
target_compile_definitions(${name} PRIVATE -DPROJECT_TESTING)
@ -104,6 +129,10 @@ function(add_project_test_executable name dependencies libraries)
${GTEST_INCLUDE_DIRS}
)
target_include_directories(${name} AFTER PRIVATE
${PROJECT_3RD_PARTY_DIR}/test/include
)
target_link_libraries(${name} PRIVATE
GTest::gtest
GTest::gmock

View File

@ -1,8 +1,8 @@
if(PROJECT_ENABLE_BACKWARD_CPP AND PROJECT_BUILD)
add_definitions(-DPROJECT_ENABLE_BACKWARD_CPP)
if(PROJECT_IS_MINGW)
link_libraries(msvcr90)
add_definitions(-DPROJECT_ENABLE_BACKWARD_CPP)
else()
link_libraries(bfd)
add_definitions(-DBACKWARD_HAS_BFD)

View File

@ -1,8 +1,6 @@
set(Boost_USE_STATIC_LIBS ${PROJECT_STATIC_LINK})
if(PROJECT_ENABLE_BOOST)
add_definitions(-DPROJECT_ENABLE_BOOST)
if(PROJECT_ENABLE_LIBBITCOIN_SYSTEM)
set(BOOST_MAJOR_VERSION ${BOOST2_MAJOR_VERSION})
set(BOOST_MINOR_VERSION ${BOOST2_MINOR_VERSION})
@ -40,6 +38,8 @@ if(PROJECT_ENABLE_BOOST)
wserialization
)
add_definitions(-DPROJECT_ENABLE_BOOST)
include_directories(BEFORE SYSTEM
${Boost_INCLUDE_DIRS}
)
@ -107,5 +107,7 @@ if(PROJECT_ENABLE_BOOST)
)
list(APPEND PROJECT_DEPENDENCIES boost_project)
add_dependencies(boost_project openssl_project)
endif()
endif()

View File

@ -1,15 +1,10 @@
if(PROJECT_ENABLE_CPP_HTTPLIB)
if(PROJECT_BUILD)
if(PROJECT_ENABLE_OPENSSL)
add_definitions(
-DCPPHTTPLIB_OPENSSL_SUPPORT
)
endif()
add_definitions(
-DPROJECT_ENABLE_CPP_HTTPLIB
-DCPPHTTPLIB_OPENSSL_SUPPORT
-DCPPHTTPLIB_TCP_NODELAY=true
-DCPPHTTPLIB_ZLIB_SUPPORT
-DPROJECT_ENABLE_CPP_HTTPLIB
)
elseif(NOT PROJECT_IS_MINGW OR CMAKE_HOST_WIN32)
ExternalProject_Add(cpphttplib_project
@ -29,10 +24,9 @@ if(PROJECT_ENABLE_CPP_HTTPLIB)
list(APPEND PROJECT_DEPENDENCIES cpphttplib_project)
add_dependencies(cpphttplib_project curl_project)
if(PROJECT_ENABLE_OPENSSL)
add_dependencies(cpphttplib_project openssl_project)
endif()
add_dependencies(cpphttplib_project
curl_project
openssl_project
)
endif()
endif()

View File

@ -48,8 +48,6 @@ if(PROJECT_ENABLE_CURL)
list(APPEND PROJECT_DEPENDENCIES curl_project)
if(PROJECT_ENABLE_OPENSSL)
add_dependencies(curl_project openssl_project)
endif()
add_dependencies(curl_project openssl_project)
endif()
endif()

View File

@ -1,6 +1,7 @@
if(PROJECT_ENABLE_FUSE AND NOT PROJECT_IS_MINGW)
if(PROJECT_BUILD)
add_definitions(-DPROJECT_ENABLE_FUSE)
include_directories(BEFORE SYSTEM ${PROJECT_FUSE_INCLUDE_DIRS})
if(PROJECT_FUSE STREQUAL "fuse3")
@ -18,11 +19,6 @@ if(PROJECT_ENABLE_FUSE AND NOT PROJECT_IS_MINGW)
link_libraries(fuse)
endif()
endif()
check_include_files(sys/xattr.h HAS_SETXATTR)
if(HAS_SETXATTR)
add_definitions(-DHAS_SETXATTR)
endif()
else()
pkg_check_modules(LIBFUSE3 fuse3>=3.0.0)
if(LIBFUSE3_FOUND)

View File

@ -246,8 +246,8 @@ public:
}
[[nodiscard]] auto get_preferred_download_type() const -> download_type {
return utils::download_type_from_string(preferred_download_type_,
download_type::fallback);
return download_type_from_string(preferred_download_type_,
download_type::fallback);
}
[[nodiscard]] auto get_provider_type() const -> provider_type {
@ -404,7 +404,7 @@ public:
}
void set_preferred_download_type(const download_type &dt) {
set_value(preferred_download_type_, utils::download_type_to_string(dt));
set_value(preferred_download_type_, download_type_to_string(dt));
}
void set_read_ahead_count(std::uint8_t read_ahead_count) {

View File

@ -26,7 +26,7 @@
#include "comm/i_http_comm.hpp"
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "utils/encryption.hpp"
#include "utils/encrypt.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -57,14 +57,13 @@ private:
bool use_s3_path_style_{false};
public:
[[nodiscard]] static auto construct_url(CURL *curl,
const std::string &relative_path,
const host_config &cfg)
-> std::string;
[[nodiscard]] static auto
construct_url(CURL *curl, const std::string &relative_path,
const host_config &cfg) -> std::string;
[[nodiscard]] static auto create_host_config(const s3_config &cfg,
bool use_s3_path_style)
-> host_config;
[[nodiscard]] static auto
create_host_config(const s3_config &cfg,
bool use_s3_path_style) -> host_config;
[[nodiscard]] static auto url_encode(CURL *curl, const std::string &data,
bool allow_slash) -> std::string;
@ -72,8 +71,8 @@ public:
template <typename request_type>
[[nodiscard]] static auto
make_encrypted_request(const host_config &cfg, const request_type &request,
long &response_code, stop_type &stop_requested)
-> bool {
long &response_code,
stop_type &stop_requested) -> bool {
response_code = 0;
if (not request.decryption_token.has_value() ||
@ -94,7 +93,7 @@ public:
utils::encryption::generate_key(request.decryption_token.value());
const auto result = utils::encryption::read_encrypted_range(
request.range.value(), key,
[&](std::vector<char> &ct, std::uint64_t start_offset,
[&](data_buffer &ct, std::uint64_t start_offset,
std::uint64_t end_offset) -> api_error {
auto encrypted_request = request;
encrypted_request.decryption_token = std::nullopt;
@ -212,30 +211,26 @@ public:
public:
void enable_s3_path_style(bool enable) override;
[[nodiscard]] auto make_request(const curl::requests::http_delete &del,
long &response_code,
stop_type &stop_requested) const
-> bool override;
[[nodiscard]] auto
make_request(const curl::requests::http_delete &del, long &response_code,
stop_type &stop_requested) const -> bool override;
[[nodiscard]] auto make_request(const curl::requests::http_get &get,
long &response_code,
stop_type &stop_requested) const
-> bool override;
[[nodiscard]] auto
make_request(const curl::requests::http_get &get, long &response_code,
stop_type &stop_requested) const -> bool override;
[[nodiscard]] auto make_request(const curl::requests::http_head &head,
long &response_code,
stop_type &stop_requested) const
-> bool override;
[[nodiscard]] auto
make_request(const curl::requests::http_head &head, long &response_code,
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_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
-> bool override;
[[nodiscard]] auto
make_request(const curl::requests::http_put_file &put_file,
long &response_code,
stop_type &stop_requested) const -> bool override;
};
} // namespace repertory

View File

@ -41,8 +41,9 @@ inline const auto read_file_data = static_cast<read_callback>(
[](char *buffer, size_t size, size_t nitems, void *instream) -> size_t {
auto *read_info = reinterpret_cast<read_file_info *>(instream);
std::size_t bytes_read{};
auto ret = read_info->nf->read_bytes(buffer, size * nitems,
read_info->offset, bytes_read);
auto ret = read_info->nf->read_bytes(
reinterpret_cast<unsigned char *>(buffer), size * nitems,
read_info->offset, bytes_read);
if (ret) {
read_info->offset += bytes_read;
}
@ -73,9 +74,8 @@ struct http_request_base {
[[nodiscard]] virtual auto get_path() const -> std::string { return path; }
[[nodiscard]] virtual auto set_method(CURL *curl,
stop_type &stop_requested) const
-> bool = 0;
[[nodiscard]] virtual auto
set_method(CURL *curl, stop_type &stop_requested) const -> bool = 0;
};
} // namespace repertory::curl::requests

View File

@ -56,18 +56,18 @@ private:
std::size_t decode_offset_ = 0U;
public:
[[nodiscard]] static auto decode_json(packet &response, json &json_data)
-> int;
[[nodiscard]] static auto decode_json(packet &response,
json &json_data) -> int;
public:
void clear();
[[nodiscard]] auto current_pointer() -> char * {
[[nodiscard]] auto current_pointer() -> unsigned char * {
return (decode_offset_ < buffer_.size()) ? &buffer_[decode_offset_]
: nullptr;
}
[[nodiscard]] auto current_pointer() const -> const char * {
[[nodiscard]] auto current_pointer() const -> const unsigned char * {
return (decode_offset_ < buffer_.size()) ? &buffer_[decode_offset_]
: nullptr;
}
@ -110,19 +110,19 @@ public:
[[nodiscard]] auto decode(remote::file_info &val) -> error_type;
[[nodiscard]] auto decrypt(const std::string &token) -> error_type;
[[nodiscard]] auto decrypt(std::string_view token) -> error_type;
void encode(const void *buffer, std::size_t size, bool should_reserve = true);
void encode(const char *str) {
encode(std::string(str == nullptr ? "" : str));
encode(std::string{str == nullptr ? "" : str});
}
void encode(const std::string &str);
void encode(std::string_view str);
void encode(const wchar_t *str);
void encode(const std::wstring &str);
void encode(std::wstring_view str);
void encode(void *ptr) {
encode(static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(ptr)));
@ -161,9 +161,9 @@ public:
void encode_top(const void *buffer, std::size_t size,
bool should_reserve = true);
void encode_top(const std::string &str);
void encode_top(std::string_view str);
void encode_top(const std::wstring &str);
void encode_top(std::wstring_view str);
void encode_top(void *ptr) {
encode_top(
@ -200,7 +200,7 @@ public:
void encode_top(remote::file_info val);
void encrypt(const std::string &token);
void encrypt(std::string_view token);
[[nodiscard]] auto get_size() const -> std::uint32_t {
return static_cast<std::uint32_t>(buffer_.size());
@ -217,11 +217,12 @@ public:
auto operator=(packet &&pkt) noexcept -> packet &;
[[nodiscard]] auto operator[](std::size_t index) -> char & {
[[nodiscard]] auto operator[](std::size_t index) -> unsigned char & {
return buffer_[index];
}
[[nodiscard]] auto operator[](std::size_t index) const -> const char & {
[[nodiscard]] auto operator[](std::size_t index) const -> const
unsigned char & {
return buffer_.at(index);
}
};

View File

@ -48,113 +48,7 @@
#if defined(__cplusplus)
REPERTORY_IGNORE_WARNINGS_ENABLE()
#if defined(_WIN32)
#define WINVER 0x0602
#define _WIN32_WINNT WINVER
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#include <shellapi.h>
#include <shlwapi.h>
#include <shlobj.h>
#include <ciso646>
#include <direct.h>
#include <fcntl.h>
#include <io.h>
#include <time.h>
#else
#include <climits>
#include <dirent.h>
#include <fcntl.h>
#include <grp.h>
#include <libgen.h>
#include <pwd.h>
#include <sys/file.h>
#include <sys/stat.h>
#if defined(__linux__)
#include <sys/statfs.h>
#endif
#include <unistd.h>
#if defined(HAS_SETXATTR)
#include <sys/types.h>
#include <sys/xattr.h>
#endif
#if defined(__APPLE__)
#include <libproc.h>
#include <sys/attr.h>
#include <sys/vnode.h>
#endif
#if defined(__APPLE__)
#include <sys/mount.h>
#include <sys/statvfs.h>
#endif
#endif
#include <algorithm>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <deque>
#include <filesystem>
#include <fstream>
#include <future>
#include <iomanip>
#include <iostream>
#include <limits>
#include <mutex>
#include <optional>
#include <random>
#include <sstream>
#include <string>
#include <string_view>
#include <thread>
#include <type_traits>
#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"
#include "boost/asio/io_context.hpp"
#include "boost/bind/bind.hpp"
#include "boost/dynamic_bitset.hpp"
#include "boost/dynamic_bitset/serialization.hpp"
#include "boost/endian/conversion.hpp"
#include "boost/serialization/vector.hpp"
#include "curl/curl.h"
#include "curl/multi.h"
#include "json.hpp"
#include "sqlite3.h"
#include "uuid.h"
#if defined(_WIN32)
#include <sddl.h>
#include "winfsp/winfsp.hpp"
#else
#if FUSE_USE_VERSION >= 30
#include <fuse.h>
#include <fuse_lowlevel.h>
#else
#include <fuse/fuse.h>
#endif
#endif
#include "pugixml.hpp"
#include "httplib.h"
#include "utils/config.hpp"
REPERTORY_IGNORE_WARNINGS_DISABLE()
using namespace std::chrono_literals;
@ -279,26 +173,6 @@ inline constexpr const auto NANOS_PER_SECOND = 1000000000L;
#endif
#endif
#ifndef fstat64
#define fstat64 fstat
#endif
#ifndef pread64
#define pread64 pread
#endif
#ifndef pwrite64
#define pwrite64 pwrite
#endif
#ifndef stat64
#define stat64 stat
#endif
#ifndef statfs64
#define statfs64 statfs
#endif
#define WINFSP_ALLOCATION_UNIT UINT64(4096U)
#if defined(_WIN32)
@ -409,13 +283,6 @@ using FileInfo = FSP_FSCTL_FILE_INFO;
using namespace Fsp;
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; \

View File

@ -24,7 +24,7 @@
#if !defined(_WIN32)
#include "events/event_system.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
namespace repertory {
class app_config;

View File

@ -31,8 +31,8 @@
#include "drives/winfsp/remotewinfsp/i_remote_instance.hpp"
#include "types/remote.hpp"
#include "types/repertory.hpp"
#include "utils/Base64.hpp"
#include "utils/path_utils.hpp"
#include "utils/base64.hpp"
#include "utils/path.hpp"
#define REPERTORY_DIRECTORY_PAGE_SIZE std::size_t(100U)
@ -1243,8 +1243,9 @@ public:
remote::file_handle handle{};
DECODE_OR_RETURN(request, handle);
ret = this->fuse_write(path.data(), buffer.data(), write_size,
write_offset, handle);
ret = this->fuse_write(
path.data(), reinterpret_cast<const char *>(buffer.data()),
write_size, write_offset, handle);
}
return ret;
}});
@ -1268,7 +1269,7 @@ public:
data_buffer buffer(write_size);
if ((ret = request->decode(buffer.data(), buffer.size())) == 0) {
buffer = macaron::Base64::Decode(
std::string(buffer.begin(), buffer.end()));
std::string{buffer.begin(), buffer.end()});
write_size = buffer.size();
remote::file_offset write_offset{};
@ -1277,8 +1278,9 @@ public:
remote::file_handle handle{};
DECODE_OR_RETURN(request, handle);
ret = this->fuse_write(path.data(), buffer.data(), write_size,
write_offset, handle);
ret = this->fuse_write(path.data(),
reinterpret_cast<char *>(buffer.data()),
write_size, write_offset, handle);
}
return ret;
}});

View File

@ -24,7 +24,7 @@
#include "events/event.hpp"
#include "events/t_event_system.hpp"
#include "utils/string_utils.hpp"
#include "utils/string.hpp"
namespace repertory {
using event_system = t_event_system<event>;

View File

@ -23,6 +23,7 @@
#define INCLUDE_EVENTS_T_EVENT_SYSTEM_HPP_
#include "events/event.hpp"
#include "utils/collection.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -151,14 +152,14 @@ public:
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);
});
auto iter = std::find_if(event_consumers_.begin(), event_consumers_.end(),
[&](const auto &item) -> bool {
return utils::collection::includes(item.second,
consumer);
});
if (iter != event_consumers_.end()) {
utils::remove_element_from((*iter).second, consumer);
utils::collection::remove_element((*iter).second, consumer);
}
}

View File

@ -102,6 +102,12 @@ enum class api_error {
api_error_to_string(const api_error &error) -> const std::string &;
enum class download_type { direct, fallback, ring_buffer };
[[nodiscard]] auto
download_type_from_string(std::string type,
const download_type &default_type) -> download_type;
[[nodiscard]] auto
download_type_to_string(const download_type &type) -> std::string;
enum class exit_code : std::int32_t {
success,
@ -274,7 +280,7 @@ struct s3_config {
std::string bucket;
std::uint16_t cache_timeout_secs{60U};
std::string encryption_token;
std::string region = "any";
std::string region{"any"};
std::string secret_key;
std::uint32_t timeout_ms{60000U};
std::string url;
@ -282,7 +288,12 @@ struct s3_config {
bool use_region_in_url{false};
};
using data_buffer = std::vector<char>;
using data_buffer = std::vector<unsigned char>;
using key_type = std::array<unsigned char, 32U>;
using mutex_lock = std::lock_guard<std::mutex>;
using recur_mutex_lock = std::lock_guard<std::recursive_mutex>;
using unique_mutex_lock = std::unique_lock<std::mutex>;
using unique_recur_mutex_lock = std::unique_lock<std::recursive_mutex>;
using api_file_list = std::vector<api_file>;
using api_file_provider_callback = std::function<void(api_file &)>;
@ -292,11 +303,7 @@ using http_headers = std::unordered_map<std::string, std::string>;
using http_parameters = std::unordered_map<std::string, std::string>;
using http_ranges = std::vector<http_range>;
using meta_provider_callback = std::function<void(directory_item &)>;
using mutex_lock = std::lock_guard<std::mutex>;
using query_parameters = std::map<std::string, std::string>;
using recur_mutex_lock = std::lock_guard<std::recursive_mutex>;
using unique_mutex_lock = std::unique_lock<std::mutex>;
using unique_recur_mutex_lock = std::unique_lock<std::recursive_mutex>;
} // namespace repertory
#endif // INCLUDE_TYPES_REPERTORY_HPP_

View File

@ -23,7 +23,7 @@
#define INCLUDE_TYPES_S3_HPP_
#include "types/repertory.hpp"
#include "utils/string_utils.hpp"
#include "utils/string.hpp"
#include "utils/utils.hpp"
namespace repertory {

View File

@ -0,0 +1,46 @@
/*
Copyright <2018-2024> <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_UTILS_ENCRYPT_HPP_
#define INCLUDE_UTILS_ENCRYPT_HPP_
#include "types/repertory.hpp"
#include "utils/encryption.hpp"
#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(std::string_view encryption_token,
std::string &file_path) -> api_error;
[[nodiscard]] auto decrypt_file_name(std::string_view encryption_token,
std::string &file_name) -> 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;
} // namespace repertory::utils::encryption
#endif // INCLUDE_UTILS_ENCRYPT_HPP_

View File

@ -26,23 +26,20 @@
#include "utils/file_utils.hpp"
namespace repertory::utils::encryption {
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,
encrypting_reader(std::string_view file_name, std::string_view source_path,
stop_type &stop_requested, std::string_view token,
std::optional<std::string_view> 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(std::string_view encrypted_file_path,
std::string_view source_path, stop_type &stop_requested,
std::string_view token, 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::string_view encrypted_file_path, std::string_view source_path,
stop_type &stop_requested, std::string_view token,
std::vector<std::array<unsigned char,
crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>>
iv_list,
@ -61,9 +58,9 @@ public:
using streambuf = std::basic_streambuf<char, std::char_traits<char>>;
private:
const key_type key_;
key_type key_;
stop_type &stop_requested_;
const size_t error_return_;
size_t error_return_;
std::unordered_map<std::size_t, data_buffer> chunk_buffers_;
std::string encrypted_file_name_;
std::string encrypted_file_path_;
@ -85,16 +82,16 @@ private:
auto reader_function(char *buffer, size_t size, size_t nitems) -> size_t;
public:
[[nodiscard]] static auto calculate_decrypted_size(std::uint64_t total_size)
-> std::uint64_t;
[[nodiscard]] static auto
calculate_decrypted_size(std::uint64_t total_size) -> std::uint64_t;
[[nodiscard]] static auto
calculate_encrypted_size(const std::string &source_path) -> std::uint64_t;
calculate_encrypted_size(std::string_view source_path) -> std::uint64_t;
[[nodiscard]] auto create_iostream() const -> std::shared_ptr<iostream>;
[[nodiscard]] static constexpr auto get_encrypted_chunk_size()
-> std::size_t {
[[nodiscard]] static constexpr auto
get_encrypted_chunk_size() -> std::size_t {
return encrypted_chunk_size_;
}
@ -118,8 +115,9 @@ public:
return header_size_;
}
[[nodiscard]] auto get_iv_list() -> std::vector<
std::array<unsigned char, crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>> {
[[nodiscard]] auto get_iv_list()
-> std::vector<std::array<unsigned char,
crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>> {
return iv_list_;
}
@ -132,8 +130,8 @@ public:
}
[[nodiscard]] static auto reader_function(char *buffer, size_t size,
size_t nitems, void *instream)
-> size_t {
size_t nitems,
void *instream) -> size_t {
return reinterpret_cast<encrypting_reader *>(instream)->reader_function(
buffer, size, nitems);
}

View File

@ -1,160 +0,0 @@
/*
Copyright <2018-2024> <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_UTILS_ENCRYPTION_HPP_
#define INCLUDE_UTILS_ENCRYPTION_HPP_
#include "types/repertory.hpp"
#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;
[[nodiscard]] auto decrypt_file_name(const std::string &encryption_token,
std::string &file_name) -> api_error;
[[nodiscard]] auto generate_key(const std::string &encryption_token)
-> key_type;
[[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>
[[nodiscard]] inline auto decrypt_data(const key_type &key, const char *buffer,
std::size_t buffer_size, result &res)
-> bool {
const auto header_size =
static_cast<std::uint32_t>(encrypting_reader::get_header_size());
if (buffer_size > header_size) {
const std::uint32_t size =
boost::endian::native_to_big(static_cast<std::uint32_t>(buffer_size));
res.resize(buffer_size - header_size);
return crypto_aead_xchacha20poly1305_ietf_decrypt_detached(
reinterpret_cast<unsigned char *>(&res[0u]), nullptr,
reinterpret_cast<const unsigned char *>(&buffer[header_size]),
res.size(),
reinterpret_cast<const unsigned char *>(
&buffer[crypto_aead_xchacha20poly1305_IETF_NPUBBYTES]),
reinterpret_cast<const unsigned char *>(&size), sizeof(size),
reinterpret_cast<const unsigned char *>(buffer),
key.data()) == 0;
}
return false;
}
template <typename buffer, typename result>
[[nodiscard]] inline auto decrypt_data(const key_type &key, const buffer &buf,
result &res) -> bool {
return decrypt_data<result>(key, &buf[0u], buf.size(), res);
}
template <typename buffer, typename result>
[[nodiscard]] inline auto decrypt_data(const std::string &encryption_token,
const buffer &buf, result &res) -> bool {
return decrypt_data<buffer, result>(generate_key(encryption_token), buf, res);
}
template <typename result>
[[nodiscard]] inline auto decrypt_data(const std::string &encryption_token,
const char *buffer,
std::size_t buffer_size, result &res)
-> bool {
return decrypt_data<result>(generate_key(encryption_token), buffer,
buffer_size, res);
}
template <typename result>
inline void
encrypt_data(const std::array<unsigned char,
crypto_aead_xchacha20poly1305_IETF_NPUBBYTES> &iv,
const key_type &key, const char *buffer, std::size_t buffer_size,
result &res) {
std::array<unsigned char, crypto_aead_xchacha20poly1305_IETF_ABYTES> mac{};
const auto header_size =
static_cast<std::uint32_t>(encrypting_reader::get_header_size());
const std::uint32_t size = boost::endian::native_to_big(
static_cast<std::uint32_t>(buffer_size + header_size));
res.resize(buffer_size + header_size);
unsigned long long mac_length{};
if (crypto_aead_xchacha20poly1305_ietf_encrypt_detached(
reinterpret_cast<unsigned char *>(&res[header_size]), mac.data(),
&mac_length, reinterpret_cast<const unsigned char *>(buffer),
buffer_size, reinterpret_cast<const unsigned char *>(&size),
sizeof(size), nullptr, iv.data(), key.data()) != 0) {
throw std::runtime_error("encryption failed");
}
std::memcpy(&res[0u], &iv[0u], iv.size());
std::memcpy(&res[iv.size()], &mac[0u], mac.size());
}
template <typename result>
inline void encrypt_data(const key_type &key, const char *buffer,
std::size_t buffer_size, result &res) {
std::array<unsigned char, crypto_aead_xchacha20poly1305_IETF_NPUBBYTES> iv{};
randombytes_buf(iv.data(), iv.size());
encrypt_data<result>(iv, key, buffer, buffer_size, res);
}
template <typename result>
inline void encrypt_data(const std::string &encryption_token,
const char *buffer, std::size_t buffer_size,
result &res) {
encrypt_data<result>(generate_key(encryption_token), buffer, buffer_size,
res);
}
template <typename buffer, typename result>
inline void encrypt_data(const std::string &encryption_token, const buffer &buf,
result &res) {
encrypt_data<result>(generate_key(encryption_token), &buf[0u], buf.size(),
res);
}
template <typename buffer, typename result>
inline void encrypt_data(const key_type &key, const buffer &buf, result &res) {
encrypt_data<result>(key, &buf[0u], buf.size(), res);
}
template <typename buffer, typename result>
inline void
encrypt_data(const std::array<unsigned char,
crypto_aead_xchacha20poly1305_IETF_NPUBBYTES> &iv,
const key_type &key, const buffer &buf, result &res) {
encrypt_data<result>(iv, key, &buf[0u], buf.size(), res);
}
} // namespace repertory::utils::encryption
#endif // INCLUDE_UTILS_ENCRYPTION_HPP_

View File

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

View File

@ -23,25 +23,26 @@
#define INCLUDE_UTILS_FILE_UTILS_HPP_
#include "types/repertory.hpp"
#include "utils/file.hpp"
#include "utils/native_file.hpp"
namespace repertory::utils::file {
// Prototypes
[[nodiscard]] auto calculate_used_space(std::string path, bool recursive)
-> std::uint64_t;
[[nodiscard]] auto calculate_used_space(std::string path,
bool recursive) -> std::uint64_t;
void change_to_process_directory();
[[nodiscard]] auto copy_directory_recursively(std::string from_path,
std::string to_path) -> bool;
[[nodiscard]] auto copy_file(std::string from_path, std::string to_path)
-> bool;
[[nodiscard]] auto copy_file(std::string from_path,
std::string to_path) -> bool;
[[nodiscard]] auto create_full_directory_path(std::string path) -> bool;
[[nodiscard]] auto delete_directory(std::string path, bool recursive = false)
-> bool;
[[nodiscard]] auto delete_directory(std::string path,
bool recursive = false) -> bool;
[[nodiscard]] auto delete_directory_recursively(std::string path) -> bool;
@ -52,45 +53,33 @@ void change_to_process_directory();
[[nodiscard]] auto get_accessed_time(const std::string &path,
std::uint64_t &accessed) -> bool;
[[nodiscard]] auto get_directory_files(std::string path, bool oldest_first,
bool recursive = false)
-> std::deque<std::string>;
[[nodiscard]] auto
get_directory_files(std::string path, bool oldest_first,
bool recursive = false) -> std::deque<std::string>;
[[nodiscard]] auto get_free_drive_space(const std::string &path)
-> std::uint64_t;
[[nodiscard]] auto
get_free_drive_space(const std::string &path) -> std::uint64_t;
[[nodiscard]] auto get_total_drive_space(const std::string &path)
-> std::uint64_t;
[[nodiscard]] auto get_file_size(std::string path, std::uint64_t &file_size)
-> bool;
[[nodiscard]] auto
get_total_drive_space(const std::string &path) -> std::uint64_t;
[[nodiscard]] auto get_modified_time(const std::string &path,
std::uint64_t &modified) -> bool;
[[nodiscard]] auto is_directory(const std::string &path) -> bool;
[[nodiscard]] auto is_file(const std::string &path) -> bool;
[[nodiscard]] auto is_modified_date_older_than(const std::string &path,
const std::chrono::hours &hours)
-> bool;
[[nodiscard]] auto
is_modified_date_older_than(const std::string &path,
const std::chrono::hours &hours) -> bool;
[[nodiscard]] auto move_file(std::string from, std::string to) -> bool;
[[nodiscard]] auto read_file_lines(const std::string &path)
-> std::vector<std::string>;
[[nodiscard]] auto read_json_file(const std::string &path, json &data) -> bool;
[[nodiscard]] auto
read_file_lines(const std::string &path) -> std::vector<std::string>;
[[nodiscard]] auto reset_modified_time(const std::string &path) -> bool;
[[nodiscard]] auto retry_delete_directory(const std::string &dir) -> bool;
[[nodiscard]] auto retry_delete_file(const std::string &file) -> bool;
[[nodiscard]] auto write_json_file(const std::string &path, const json &j)
-> bool;
} // namespace repertory::utils::file
#endif // INCLUDE_UTILS_FILE_UTILS_HPP_

View File

@ -42,17 +42,17 @@ public:
[[nodiscard]] static auto
clone(const native_file_ptr &ptr) -> native_file_ptr;
[[nodiscard]] static auto create_or_open(const std::string &source_path,
[[nodiscard]] static auto create_or_open(std::string_view source_path,
bool read_only,
native_file_ptr &ptr) -> api_error;
[[nodiscard]] static auto create_or_open(const std::string &source_path,
[[nodiscard]] static auto create_or_open(std::string_view source_path,
native_file_ptr &ptr) -> api_error;
[[nodiscard]] static auto open(const std::string &source_path,
[[nodiscard]] static auto open(std::string_view source_path,
native_file_ptr &ptr) -> api_error;
[[nodiscard]] static auto open(const std::string &source_path, bool read_only,
[[nodiscard]] static auto open(std::string_view source_path, bool read_only,
native_file_ptr &ptr) -> api_error;
private:
@ -86,11 +86,11 @@ public:
[[nodiscard]] auto get_handle() -> native_handle;
#if defined(_WIN32)
[[nodiscard]] auto read_bytes(char *buffer, std::size_t read_size,
[[nodiscard]] auto read_bytes(unsigned char *buffer, std::size_t read_size,
std::uint64_t read_offset,
std::size_t &bytes_read) -> bool;
#else
[[nodiscard]] auto read_bytes(char *buffer, std::size_t read_size,
[[nodiscard]] auto read_bytes(unsigned char *buffer, std::size_t read_size,
std::uint64_t read_offset,
std::size_t &bytes_read) -> bool;
#endif
@ -99,11 +99,13 @@ public:
[[nodiscard]] auto truncate(std::uint64_t file_size) -> bool;
#if defined(_WIN32)
[[nodiscard]] auto write_bytes(const char *buffer, std::size_t write_size,
[[nodiscard]] auto write_bytes(const unsigned char *buffer,
std::size_t write_size,
std::uint64_t write_offset,
std::size_t &bytes_written) -> bool;
#else
[[nodiscard]] auto write_bytes(const char *buffer, std::size_t write_size,
[[nodiscard]] auto write_bytes(const unsigned char *buffer,
std::size_t write_size,
std::uint64_t write_offset,
std::size_t &bytes_written) -> bool;
#endif

View File

@ -1,66 +0,0 @@
/*
Copyright <2018-2024> <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_UTILS_PATH_UTILS_HPP_
#define INCLUDE_UTILS_PATH_UTILS_HPP_
namespace repertory::utils::path {
#if defined(_WIN32)
static const std::string directory_seperator = "\\";
static const std::string not_directory_seperator = "/";
#else
static const std::string directory_seperator = "/";
static const std::string not_directory_seperator = "\\";
#endif
// Prototypes
[[nodiscard]] auto absolute(std::string path) -> std::string;
[[nodiscard]] auto
combine(std::string path, const std::vector<std::string> &paths) -> std::string;
[[nodiscard]] auto create_api_path(std::string path) -> std::string;
[[nodiscard]] auto finalize(std::string path) -> std::string;
auto format_path(std::string &path, const std::string &sep,
const std::string &not_sep) -> std::string &;
[[nodiscard]] auto get_parent_api_path(const std::string &path) -> std::string;
#if !defined(_WIN32)
[[nodiscard]] auto get_parent_directory(std::string path) -> std::string;
#endif
[[nodiscard]] auto is_ads_file_path(const std::string &path) -> bool;
[[nodiscard]] auto is_trash_directory(std::string path) -> bool;
[[nodiscard]] auto remove_file_name(std::string path) -> std::string;
#if !defined(_WIN32)
[[nodiscard]] auto resolve(std::string path) -> std::string;
#endif
[[nodiscard]] auto strip_to_file_name(std::string path) -> std::string;
} // namespace repertory::utils::path
#endif // INCLUDE_UTILS_PATH_UTILS_HPP_

View File

@ -1,115 +0,0 @@
/*
Copyright <2018-2024> <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_UTILS_STRING_UTILS_HPP_
#define INCLUDE_UTILS_STRING_UTILS_HPP_
namespace repertory::utils::string {
// Prototypes
constexpr auto begins_with(std::string_view str, std::string_view val) -> bool {
return (str.find(val) == 0U);
}
constexpr auto contains(std::string_view str, std::string_view search) -> bool {
return (str.find(search) != std::string_view::npos);
}
[[nodiscard]] /* constexpr c++20 */ auto ends_with(std::string_view str,
std::string_view val)
-> bool;
[[nodiscard]] auto from_bool(bool val) -> std::string;
[[nodiscard]] auto from_dynamic_bitset(const boost::dynamic_bitset<> &bitset)
-> std::string;
[[nodiscard]] auto from_utf8(const std::string &str) -> std::wstring;
[[nodiscard]] /* constexpr c++20 */ auto is_numeric(std::string_view str)
-> bool;
[[nodiscard]] auto join(const std::vector<std::string> &arr, const char &delim)
-> std::string;
auto left_trim(std::string &str) -> std::string &;
auto left_trim(std::string &str, const char &trim_ch) -> std::string &;
auto replace(std::string &src, const char &character, const char &with)
-> std::string &;
auto replace(std::string &src, const std::string &find, const std::string &with,
size_t start_pos = 0) -> std::string &;
[[nodiscard]] auto replace_copy(std::string src, const char &character,
const char &with) -> std::string;
[[nodiscard]] auto replace_copy(std::string src, const std::string &find,
const std::string &with, size_t start_pos = 0)
-> std::string;
auto right_trim(std::string &str) -> std::string &;
auto right_trim(std::string &str, const char &trim_ch) -> std::string &;
[[nodiscard]] auto split(const std::string &str, const char &delim,
bool should_trim = true) -> std::vector<std::string>;
[[nodiscard]] auto to_bool(std::string val) -> bool;
[[nodiscard]] auto to_double(const std::string &str) -> double;
[[nodiscard]] auto to_dynamic_bitset(const std::string &val)
-> boost::dynamic_bitset<>;
[[nodiscard]] auto to_lower(std::string str) -> std::string;
[[nodiscard]] auto to_int32(const std::string &val) -> std::int32_t;
[[nodiscard]] auto to_int64(const std::string &val) -> std::int64_t;
[[nodiscard]] auto to_size_t(const std::string &val) -> std::size_t;
[[nodiscard]] auto to_uint8(const std::string &val) -> std::uint8_t;
[[nodiscard]] auto to_uint16(const std::string &val) -> std::uint16_t;
[[nodiscard]] auto to_uint32(const std::string &val) -> std::uint32_t;
[[nodiscard]] auto to_uint64(const std::string &val) -> std::uint64_t;
[[nodiscard]] auto to_upper(std::string str) -> std::string;
[[nodiscard]] auto to_utf8(std::string str) -> std::string;
[[nodiscard]] auto to_utf8(const std::wstring &str) -> std::string;
auto trim(std::string &str) -> std::string &;
auto trim(std::string &str, const char &trim_ch) -> std::string &;
[[nodiscard]] auto trim_copy(std::string str) -> std::string;
[[nodiscard]] auto trim_copy(std::string str, const char &trim_ch)
-> std::string;
} // namespace repertory::utils::string
#endif // INCLUDE_UTILS_STRING_UTILS_HPP_

View File

@ -25,6 +25,7 @@
#include "types/remote.hpp"
#include "types/repertory.hpp"
#include "utils/unix.hpp"
namespace repertory::utils {
#if defined(__linux__)
@ -35,25 +36,8 @@ inline const std::array<std::string, 4U> attribute_namespaces = {
"user",
};
#endif
#if defined(__APPLE__)
template <typename t>
[[nodiscard]] auto convert_to_uint64(const t *ptr) -> std::uint64_t;
#else
[[nodiscard]] auto convert_to_uint64(const pthread_t &thread) -> std::uint64_t;
#endif
[[nodiscard]] auto from_api_error(const api_error &err) -> int;
[[nodiscard]] auto get_last_error_code() -> int;
[[nodiscard]] auto get_thread_id() -> std::uint64_t;
[[nodiscard]] auto is_uid_member_of_group(const uid_t &uid,
const gid_t &gid) -> bool;
void set_last_error_code(int error_code);
[[nodiscard]] auto to_api_error(int err) -> api_error;
[[nodiscard]] auto unix_error_to_windows(int err) -> std::int32_t;
@ -61,22 +45,12 @@ void set_last_error_code(int error_code);
[[nodiscard]] auto
unix_time_to_windows_time(const remote::file_time &file_time) -> UINT64;
void use_getpwuid(uid_t uid, std::function<void(struct passwd *pass)> callback);
void windows_create_to_unix(const UINT32 &create_options,
const UINT32 &granted_access, std::uint32_t &flags,
remote::file_mode &mode);
[[nodiscard]] auto
windows_time_to_unix_time(std::uint64_t win_time) -> remote::file_time;
// template implementations
#if defined(__APPLE__)
template <typename t>
[[nodiscard]] auto convert_to_uint64(const t *v) -> std::uint64_t {
return static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(v));
}
#endif
} // namespace repertory::utils
#endif // !_WIN32

View File

@ -32,73 +32,19 @@ void calculate_allocation_size(bool directory, std::uint64_t file_size,
UINT64 allocation_size,
std::string &allocation_meta_size);
[[nodiscard]] auto calculate_read_size(const uint64_t &total_size,
std::size_t read_size,
const uint64_t &offset) -> std::size_t;
template <typename t>
[[nodiscard]] auto collection_excludes(t collection,
const typename t::value_type &val)
-> bool;
template <typename t>
[[nodiscard]] auto collection_includes(t collection,
const typename t::value_type &val)
-> bool;
[[nodiscard]] auto compare_version_strings(std::string version1,
std::string version2) -> int;
[[nodiscard]] auto convert_api_date(const std::string &date) -> std::uint64_t;
[[nodiscard]] auto create_curl() -> CURL *;
[[nodiscard]] auto create_uuid_string() -> std::string;
[[nodiscard]] auto create_volume_label(const provider_type &prov)
-> std::string;
template <typename t>
[[nodiscard]] auto divide_with_ceiling(const t &n, const t &d) -> t;
[[nodiscard]] auto download_type_from_string(std::string type,
const download_type &default_type)
-> download_type;
[[nodiscard]] auto download_type_to_string(const download_type &type)
-> std::string;
template <typename t>
[[nodiscard]] auto from_hex_string(const std::string &str, t &val) -> bool;
[[nodiscard]] auto generate_random_string(std::uint16_t length) -> std::string;
[[nodiscard]] auto
create_volume_label(const provider_type &prov) -> std::string;
[[nodiscard]] auto get_attributes_from_meta(const api_meta_map &meta) -> DWORD;
[[nodiscard]] auto get_environment_variable(const std::string &variable)
-> std::string;
[[nodiscard]] auto get_file_time_now() -> std::uint64_t;
void get_local_time_now(struct tm &local_time);
[[nodiscard]] auto get_next_available_port(std::uint16_t first_port,
std::uint16_t &available_port)
-> bool;
[[nodiscard]] auto get_time_now() -> std::uint64_t;
template <typename data_type>
[[nodiscard]] auto random_between(const data_type &begin, const data_type &end)
-> data_type;
template <typename t>
void remove_element_from(t &collection, const typename t::value_type &val);
[[nodiscard]] auto reset_curl(CURL *curl_handle) -> CURL *;
[[nodiscard]] auto retryable_action(const std::function<bool()> &action)
-> bool;
[[nodiscard]] auto
retryable_action(const std::function<bool()> &action) -> bool;
void spin_wait_for_mutex(std::function<bool()> complete,
std::condition_variable &cond, std::mutex &mtx,
@ -107,75 +53,6 @@ void spin_wait_for_mutex(std::function<bool()> complete,
void spin_wait_for_mutex(bool &complete, std::condition_variable &cond,
std::mutex &mtx, const std::string &text = "");
template <typename collection_t>
[[nodiscard]] auto to_hex_string(const collection_t &collection) -> std::string;
// template implementations
template <typename t>
[[nodiscard]] auto collection_excludes(t collection,
const typename t::value_type &val)
-> bool {
return std::find(collection.begin(), collection.end(), val) ==
collection.end();
}
template <typename t>
[[nodiscard]] auto collection_includes(t collection,
const typename t::value_type &val)
-> bool {
return std::find(collection.begin(), collection.end(), val) !=
collection.end();
}
template <typename t>
[[nodiscard]] auto divide_with_ceiling(const t &n, const t &d) -> t {
return n ? (n / d) + (n % d != 0) : 0;
}
template <typename t>
[[nodiscard]] auto from_hex_string(const std::string &str, t &val) -> bool {
static constexpr const auto base16 = 16;
val.clear();
if (not(str.length() % 2U)) {
for (std::size_t i = 0U; i < str.length(); i += 2U) {
val.emplace_back(static_cast<typename t::value_type>(
strtol(str.substr(i, 2U).c_str(), nullptr, base16)));
}
return true;
}
return false;
}
template <typename data_type>
[[nodiscard]] auto random_between(const data_type &begin, const data_type &end)
-> data_type {
return begin + repertory_rand<data_type>() % ((end + data_type{1}) - begin);
}
template <typename collection_t>
void remove_element_from(collection_t &collection,
const typename collection_t::value_type &value) {
collection.erase(std::remove(collection.begin(), collection.end(), value),
collection.end());
}
template <typename collection_t>
[[nodiscard]] auto to_hex_string(const collection_t &collection)
-> std::string {
static_assert(sizeof(typename collection_t::value_type) == 1U,
"value_type must be 1 byte in size");
static constexpr const auto mask = 0xFF;
std::stringstream stream;
for (const auto &val : collection) {
stream << std::setfill('0') << std::setw(2) << std::hex
<< (static_cast<std::uint32_t>(val) & mask);
}
return stream.str();
}
} // namespace repertory::utils
#endif // INCLUDE_UTILS_UTILS_HPP_

View File

@ -25,15 +25,9 @@
#include "types/remote.hpp"
#include "types/repertory.hpp"
#include "utils/windows.hpp"
namespace repertory::utils {
[[nodiscard]] auto
filetime_to_unix_time(const FILETIME &ft) -> remote::file_time;
[[nodiscard]] auto get_last_error_code() -> DWORD;
[[nodiscard]] auto get_local_app_data_directory() -> const std::string &;
[[nodiscard]] auto
get_accessed_time_from_meta(const api_meta_map &meta) -> std::uint64_t;
@ -46,29 +40,14 @@ get_creation_time_from_meta(const api_meta_map &meta) -> std::uint64_t;
[[nodiscard]] auto
get_written_time_from_meta(const api_meta_map &meta) -> std::uint64_t;
[[nodiscard]] auto get_thread_id() -> std::uint64_t;
[[nodiscard]] auto is_process_elevated() -> bool;
[[nodiscard]] auto run_process_elevated(std::vector<const char *> args) -> int;
void set_last_error_code(DWORD errorCode);
[[nodiscard]] auto from_api_error(const api_error &e) -> NTSTATUS;
auto strptime(const char *s, const char *f, struct tm *tm) -> const char *;
[[nodiscard]] auto unix_access_mask_to_windows(std::int32_t mask) -> int;
[[nodiscard]] auto
unix_open_flags_to_flags_and_perms(const remote::file_mode &mode,
const remote::open_flags &flags,
std::int32_t &perms) -> int;
void unix_time_to_filetime(const remote::file_time &ts, FILETIME &ft);
[[nodiscard]] auto
time64_to_unix_time(const __time64_t &t) -> remote::file_time;
} // namespace repertory::utils
#endif // _WIN32

View File

@ -24,7 +24,7 @@
#include "types/startup_exception.hpp"
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/unix/unix_utils.hpp"
#include "utils/utils.hpp"
@ -84,7 +84,7 @@ app_config::app_config(const provider_type &prov,
online_check_retry_secs_(default_online_check_retry_secs),
orphaned_file_retention_days_(default_orphaned_file_retention_days),
preferred_download_type_(
utils::download_type_to_string(download_type::fallback)),
download_type_to_string(download_type::fallback)),
read_ahead_count_(default_read_ahead_count),
remote_client_pool_size_(default_remote_client_pool_size),
remote_host_name_or_ip_(default_remote_host_name_or_ip),
@ -443,7 +443,7 @@ auto app_config::get_value_by_name(const std::string &name) -> std::string {
return std::to_string(get_orphaned_file_retention_days());
}
if (name == "PreferredDownloadType") {
return utils::download_type_to_string(utils::download_type_from_string(
return download_type_to_string(download_type_from_string(
preferred_download_type_, download_type::fallback));
}
if (name == "ReadAheadCount") {
@ -839,8 +839,8 @@ auto app_config::set_value_by_name(const std::string &name,
}
if (name == "PreferredDownloadType") {
set_preferred_download_type(
utils::download_type_from_string(value, download_type::fallback));
return utils::download_type_to_string(get_preferred_download_type());
download_type_from_string(value, download_type::fallback));
return download_type_to_string(get_preferred_download_type());
}
if (name == "ReadAheadCount") {
set_read_ahead_count(utils::string::to_uint8(value));

View File

@ -22,8 +22,8 @@
#include "comm/curl/curl_comm.hpp"
#include "types/repertory.hpp"
#include "utils/path_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp"
namespace repertory {
const curl_comm::write_callback curl_comm::write_data =
@ -42,7 +42,7 @@ const curl_comm::write_callback curl_comm::write_headers =
void *outstream) -> size_t {
auto &headers = *reinterpret_cast<http_headers *>(outstream);
const auto header = std::string(buffer, size * nitems);
const auto parts = utils::string::split(header, ':');
const auto parts = utils::string::split(header, ':', false);
if (parts.size() > 1U) {
auto data = header.substr(parts[0U].size() + 1U);
utils::string::left_trim(data);
@ -92,8 +92,8 @@ auto curl_comm::construct_url(CURL *curl, const std::string &relative_path,
relative_path, url);
}
auto curl_comm::create_host_config(const s3_config &cfg, bool use_s3_path_style)
-> host_config {
auto curl_comm::create_host_config(const s3_config &cfg,
bool use_s3_path_style) -> host_config {
host_config host_cfg{};
host_cfg.api_password = cfg.secret_key;
host_cfg.api_user = cfg.access_key;
@ -101,7 +101,7 @@ auto curl_comm::create_host_config(const s3_config &cfg, bool use_s3_path_style)
auto pos = cfg.url.find(':');
host_cfg.host_name_or_ip = cfg.url.substr(pos + 3U);
if (cfg.use_region_in_url && not cfg.region.empty()) {
auto parts = utils::string::split(host_cfg.host_name_or_ip, '.', false);
auto parts = utils::string::split(host_cfg.host_name_or_ip, '.', true);
if (parts.size() > 1U) {
parts.insert(parts.begin() + 1U, cfg.region);
host_cfg.host_name_or_ip = utils::string::join(parts, '.');

View File

@ -21,7 +21,7 @@
*/
#include "comm/curl/requests/http_put_file.hpp"
#include "utils/string_utils.hpp"
#include "utils/string.hpp"
namespace repertory::curl::requests {
auto http_put_file::set_method(CURL *curl, stop_type &stop_requested) const

View File

@ -25,7 +25,7 @@
#include "events/events.hpp"
#include "types/remote.hpp"
#include "types/repertory.hpp"
#include "utils/encryption.hpp"
#include "utils/encrypt.hpp"
#include "utils/error_utils.hpp"
#include "utils/utils.hpp"
@ -36,9 +36,9 @@ void packet::clear() {
}
auto packet::decode(std::string &data) -> packet::error_type {
const auto *str = &buffer_[decode_offset_];
const auto *str = reinterpret_cast<const char *>(&buffer_[decode_offset_]);
const auto length = strnlen(str, buffer_.size() - decode_offset_);
data = std::string(str, length);
data = std::string{str, length};
decode_offset_ += (length + 1);
return utils::from_api_error(api_error::success);
@ -236,7 +236,7 @@ auto packet::decode_json(packet &response, json &json_data) -> int {
return ret;
}
auto packet::decrypt(const std::string &token) -> packet::error_type {
auto packet::decrypt(std::string_view token) -> packet::error_type {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto ret = utils::from_api_error(api_error::success);
@ -267,10 +267,10 @@ void packet::encode(const void *buffer, std::size_t size, bool should_reserve) {
}
}
void packet::encode(const std::string &str) {
const auto len = strnlen(str.c_str(), str.size());
void packet::encode(std::string_view str) {
const auto len = str.size();
buffer_.reserve(len + 1 + buffer_.size());
encode(str.c_str(), len, false);
encode(str.data(), len, false);
buffer_.emplace_back(0);
}
@ -278,7 +278,7 @@ void packet::encode(const wchar_t *str) {
encode(utils::string::to_utf8(str == nullptr ? L"" : str));
}
void packet::encode(const std::wstring &str) {
void packet::encode(std::wstring_view str) {
encode(utils::string::to_utf8(str));
}
@ -400,14 +400,14 @@ void packet::encode_top(const void *buffer, std::size_t size,
}
}
void packet::encode_top(const std::string &str) {
const auto len = strnlen(str.c_str(), str.size());
void packet::encode_top(std::string_view str) {
const auto len = str.size();
buffer_.reserve(len + 1U + buffer_.size());
encode_top(str.c_str(), len, false);
encode_top(str.data(), len, false);
buffer_.insert(buffer_.begin() + static_cast<std::int32_t>(len), 0);
}
void packet::encode_top(const std::wstring &str) {
void packet::encode_top(std::wstring_view str) {
encode_top(utils::string::to_utf8(str));
}
@ -518,7 +518,7 @@ void packet::encode_top(remote::file_info val) {
encode_top(&val, sizeof(val), true);
}
void packet::encrypt(const std::string &token) {
void packet::encrypt(std::string_view token) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
try {

View File

@ -23,6 +23,7 @@
#include "events/events.hpp"
#include "types/repertory.hpp"
#include "utils/collection.hpp"
#include "utils/error_utils.hpp"
#include "utils/timeout.hpp"
#include "version.hpp"
@ -102,7 +103,7 @@ auto packet_client::get_client() -> std::shared_ptr<packet_client::client> {
connect(*ret);
} else {
ret = clients_[0U];
utils::remove_element_from(clients_, ret);
utils::collection::remove_element(clients_, ret);
clients_lock.unlock();
}
}

View File

@ -26,7 +26,7 @@
#include "events/events.hpp"
#include "types/repertory.hpp"
#include "utils/error_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/string.hpp"
#include "utils/utils.hpp"
namespace repertory {

View File

@ -23,6 +23,7 @@
#include "drives/directory_iterator.hpp"
#include "types/repertory.hpp"
#include "utils/collection.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -72,7 +73,7 @@ void directory_cache::remove_directory(std::uint64_t handle) {
handle) != kv.second.handles.end();
});
if (it != directory_lookup_.end()) {
utils::remove_element_from(it->second.handles, handle);
utils::collection::remove_element(it->second.handles, handle);
if (it->second.handles.empty()) {
directory_lookup_.erase(it);
}

View File

@ -22,7 +22,7 @@
#include "drives/directory_iterator.hpp"
#include "utils/error_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
namespace repertory {
#if !defined(_WIN32)

View File

@ -27,6 +27,7 @@
#include "types/repertory.hpp"
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/time.hpp"
#include "utils/unix/unix_utils.hpp"
#include "utils/utils.hpp"
@ -57,7 +58,7 @@ auto eviction::check_minimum_requirements(const std::string &file_path)
static_cast<time_t>(reference_time)) +
delay) <= now);
#else
const auto now = utils::get_time_now();
const auto now = utils::time::get_time_now();
const auto delay =
(config_.get_eviction_delay_mins() * 60L) * NANOS_PER_SECOND;
ret = ((reference_time + static_cast<std::uint64_t>(delay)) <= now);

View File

@ -29,9 +29,10 @@
#include "events/events.hpp"
#include "initialize.hpp"
#include "providers/i_provider.hpp"
#include "utils/collection.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -615,7 +616,7 @@ auto fuse_base::parse_args(std::vector<std::string> &args) -> int {
force_no_console = true;
}
}
utils::remove_element_from(args, "-nc");
utils::collection::remove_element(args, "-nc");
for (std::size_t i = 1u; i < args.size(); i++) {
if (args[i] == "-f") {
@ -630,10 +631,10 @@ auto fuse_base::parse_args(std::vector<std::string> &args) -> int {
options = args[i].substr(2);
}
const auto option_parts = utils::string::split(options, ',');
const auto option_parts = utils::string::split(options, ',', true);
for (const auto &option : option_parts) {
if (option.find("gid") == 0) {
const auto parts = utils::string::split(option, '=');
const auto parts = utils::string::split(option, '=', true);
if (parts.size() == 2u) {
auto gid = getgrnam(parts[1].c_str());
if (not gid) {
@ -649,7 +650,7 @@ auto fuse_base::parse_args(std::vector<std::string> &args) -> int {
} else if (option.find("noatime") == 0) {
atime_enabled_ = false;
} else if (option.find("uid") == 0) {
const auto parts = utils::string::split(option, '=');
const auto parts = utils::string::split(option, '=', true);
if (parts.size() == 2u) {
auto *uid = getpwnam(parts[1u].c_str());
if (not uid) {
@ -663,7 +664,7 @@ auto fuse_base::parse_args(std::vector<std::string> &args) -> int {
}
}
} else if (option.find("umask") == 0) {
const auto parts = utils::string::split(option, '=');
const auto parts = utils::string::split(option, '=', true);
if (parts.size() == 2u) {
static const auto match_number_regex = std::regex("[0-9]+");
try {

View File

@ -38,10 +38,12 @@
#include "rpc/server/full_server.hpp"
#include "types/repertory.hpp"
#include "types/startup_exception.hpp"
#include "utils/Base64.hpp"
#include "utils/base64.hpp"
#include "utils/collection.hpp"
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/polling.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -162,7 +164,7 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
{
std::shared_ptr<i_open_file> open_file;
if (is_create_op) {
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
#if defined(__APPLE__)
const auto osx_flags = static_cast<std::uint32_t>(file_info->flags);
#else
@ -603,7 +605,7 @@ auto fuse_drive::mkdir_impl(std::string api_path, mode_t mode) -> api_error {
return res;
}
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_DIRECTORY, now, now,
true, get_effective_gid(), "", mode, now,
0U, 0U, 0U, "", get_effective_uid(), now);
@ -905,7 +907,7 @@ auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size,
api_meta_map meta;
if ((res = provider_.get_item_meta(api_path, meta)) == api_error::success) {
for (const auto &meta_item : meta) {
if (utils::collection_excludes(META_USED_NAMES, meta_item.first)) {
if (utils::collection::excludes(META_USED_NAMES, meta_item.first)) {
auto attribute_name = meta_item.first;
#if defined(__APPLE__)
if (attribute_name != G_KAUTH_FILESEC_XATTR) {
@ -948,7 +950,7 @@ auto fuse_drive::removexattr_impl(std::string api_path,
return check_and_perform(
api_path, X_OK, [&](api_meta_map &meta) -> api_error {
if ((meta.find(name) != meta.end()) &&
(utils::collection_excludes(META_USED_NAMES, name))) {
(utils::collection::excludes(META_USED_NAMES, name))) {
return provider_.remove_item_meta(api_path, attribute_name);
}
@ -988,8 +990,8 @@ auto fuse_drive::setxattr_impl(std::string api_path, const char *name,
if (utils::string::contains(attribute_name, " .") ||
utils::string::contains(attribute_name, ". ")
#if !defined(__APPLE__)
|| utils::collection_excludes(utils::attribute_namespaces,
attribute_namespace)
|| utils::collection::excludes(utils::attribute_namespaces,
attribute_namespace)
#endif
) {
return api_error::not_supported;
@ -1018,8 +1020,10 @@ auto fuse_drive::setxattr_impl(std::string api_path, const char *name,
}
}
return provider_.set_item_meta(api_path, attribute_name,
macaron::Base64::Encode(value, size));
return provider_.set_item_meta(
api_path, attribute_name,
macaron::Base64::Encode(reinterpret_cast<const unsigned char *>(value),
size));
}
#endif // HAS_SETXATTR
@ -1296,14 +1300,14 @@ auto fuse_drive::utimens_impl(std::string api_path,
meta.clear();
if ((tv == nullptr) || (tv[0U].tv_nsec == UTIME_NOW)) {
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
meta[META_ACCESSED] = std::to_string(utils::time::get_file_time_now());
} else if (tv[0U].tv_nsec != UTIME_OMIT) {
const auto val = tv[0U].tv_nsec + (tv[0U].tv_sec * NANOS_PER_SECOND);
meta[META_ACCESSED] = std::to_string(val);
}
if ((tv == nullptr) || (tv[1U].tv_nsec == UTIME_NOW)) {
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
meta[META_MODIFIED] = std::to_string(utils::time::get_file_time_now());
} else if (tv[1U].tv_nsec != UTIME_OMIT) {
const auto val = tv[1U].tv_nsec + (tv[1U].tv_sec * NANOS_PER_SECOND);
meta[META_MODIFIED] = std::to_string(val);
@ -1352,7 +1356,8 @@ void fuse_drive::update_accessed_time(const std::string &api_path) {
if (atime_enabled_) {
auto res = provider_.set_item_meta(
api_path, META_ACCESSED, std::to_string(utils::get_file_time_now()));
api_path, META_ACCESSED,
std::to_string(utils::time::get_file_time_now()));
if (res != api_error::success) {
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to set accessed time");

View File

@ -23,7 +23,7 @@
#include "app_config.hpp"
#include "comm/packet/packet.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
namespace repertory::remote_fuse {
remote_client::remote_client(const app_config &config)

View File

@ -34,7 +34,7 @@
#include "types/remote.hpp"
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/utils.hpp"
namespace repertory::remote_fuse {

View File

@ -35,10 +35,11 @@
#include "events/events.hpp"
#include "types/remote.hpp"
#include "types/repertory.hpp"
#include "utils/Base64.hpp"
#include "utils/base64.hpp"
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/time.hpp"
namespace repertory::remote_fuse {
#define RAISE_REMOTE_FUSE_SERVER_EVENT(func, file, ret) \
@ -1045,7 +1046,7 @@ auto remote_server::winfsp_cleanup(PVOID /*file_desc*/, PWSTR file_name,
if (flags & (FileSystemBase::FspCleanupSetLastAccessTime |
FileSystemBase::FspCleanupSetLastWriteTime |
FileSystemBase::FspCleanupSetChangeTime)) {
const auto file_time_now = utils::get_time_now();
const auto file_time_now = utils::time::get_time_now();
if (flags & FileSystemBase::FspCleanupSetLastAccessTime) {
drive_.set_item_meta(api_path, META_ACCESSED,
std::to_string(file_time_now));

View File

@ -23,6 +23,7 @@
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "utils/collection.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -30,7 +31,7 @@ void remote_open_file_table::add_directory(const std::string &client_id,
std::uint64_t handle) {
recur_mutex_lock directory_lock(directory_mutex_);
auto &list = directory_lookup_[client_id];
if (utils::collection_excludes(list, handle)) {
if (utils::collection::excludes(list, handle)) {
directory_lookup_[client_id].emplace_back(handle);
}
}
@ -144,7 +145,7 @@ auto remote_open_file_table::has_open_directory(const std::string &client_id,
std::uint64_t handle) -> bool {
recur_mutex_lock directory_lock(directory_mutex_);
auto &list = directory_lookup_[client_id];
return (utils::collection_includes(list, handle));
return (utils::collection::includes(list, handle));
}
auto remote_open_file_table::has_compat_open_info(
@ -207,8 +208,8 @@ auto remote_open_file_table::remove_directory(const std::string &client_id,
std::uint64_t handle) -> bool {
recur_mutex_lock directory_lock(directory_mutex_);
auto &list = directory_lookup_[client_id];
if (utils::collection_includes(list, handle)) {
utils::remove_element_from(list, handle);
if (utils::collection::includes(list, handle)) {
utils::collection::remove_element(list, handle);
if (directory_lookup_[client_id].empty()) {
directory_lookup_.erase(client_id);
}

View File

@ -26,7 +26,7 @@
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "types/repertory.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "version.hpp"
namespace repertory::remote_winfsp {

View File

@ -37,7 +37,7 @@
#include "types/remote.hpp"
#include "types/repertory.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#if !defined(_SH_DENYNO)
#define _SH_DENYRW 0x10 // deny read/write mode
@ -782,7 +782,7 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
FILETIME *write_time_ptr = nullptr;
if ((tv[0U] == 0U) || (op0 == UTIME_NOW)) {
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
access_time.dwHighDateTime =
static_cast<DWORD>((now >> 32U) & 0xFFFFFFFF);
access_time.dwLowDateTime = now & 0xFFFFFFFF;
@ -793,7 +793,7 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
}
if ((tv[1U] == 0U) || (op1 == UTIME_NOW)) {
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
write_time.dwHighDateTime = static_cast<DWORD>((now >> 32U) & 0xFFFFFFFF);
write_time.dwLowDateTime = now & 0xFFFFFFFF;
write_time_ptr = &write_time;

View File

@ -29,9 +29,11 @@
#include "events/events.hpp"
#include "platform/platform.hpp"
#include "rpc/server/server.hpp"
#include "utils/collection.hpp"
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory::remote_winfsp {
@ -223,7 +225,7 @@ auto remote_winfsp_drive::Init(PVOID host) -> NTSTATUS {
file_system_host->SetPersistentAcls(FALSE);
file_system_host->SetPostCleanupWhenModifiedOnly(TRUE);
file_system_host->SetPassQueryDirectoryPattern(FALSE);
file_system_host->SetVolumeCreationTime(utils::get_file_time_now());
file_system_host->SetVolumeCreationTime(utils::time::get_file_time_now());
file_system_host->SetVolumeSerialNumber(0);
return STATUS_SUCCESS;
}
@ -232,7 +234,7 @@ auto remote_winfsp_drive::mount(const std::vector<std::string> &drive_args)
-> int {
std::vector<std::string> parsed_drive_args;
const auto force_no_console = utils::collection_includes(drive_args, "-nc");
const auto force_no_console = utils::collection::includes(drive_args, "-nc");
auto enable_console = false;
for (const auto &arg : drive_args) {

View File

@ -32,10 +32,12 @@
#include "providers/i_provider.hpp"
#include "types/repertory.hpp"
#include "types/startup_exception.hpp"
#include "utils/collection.hpp"
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/polling.hpp"
#include "utils/string_utils.hpp"
#include "utils/string.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -204,7 +206,7 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
if ((flags & (FspCleanupSetLastAccessTime | FspCleanupSetLastWriteTime |
FspCleanupSetChangeTime)) != 0U) {
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
if ((flags & FspCleanupSetLastAccessTime) != 0U) {
auto res = provider_.set_item_meta(api_path, META_ACCESSED,
std::to_string(now));
@ -295,7 +297,7 @@ auto winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
attributes = FILE_ATTRIBUTE_NORMAL;
}
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
auto meta = create_meta_attributes(
now, attributes, now, now, (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0U,
0U, "", 0U, now, 0U, 0U, 0U,
@ -552,7 +554,7 @@ auto winfsp_drive::Init(PVOID host) -> NTSTATUS {
file_system_host->SetPersistentAcls(FALSE);
file_system_host->SetPostCleanupWhenModifiedOnly(TRUE);
file_system_host->SetPassQueryDirectoryPattern(FALSE);
file_system_host->SetVolumeCreationTime(utils::get_file_time_now());
file_system_host->SetVolumeCreationTime(utils::time::get_file_time_now());
file_system_host->SetVolumeSerialNumber(0);
return STATUS_SUCCESS;
}
@ -560,7 +562,7 @@ auto winfsp_drive::Init(PVOID host) -> NTSTATUS {
auto winfsp_drive::mount(const std::vector<std::string> &drive_args) -> int {
std::vector<std::string> parsed_drive_args;
const auto force_no_console = utils::collection_includes(drive_args, "-nc");
const auto force_no_console = utils::collection::includes(drive_args, "-nc");
auto enable_console = false;
for (const auto &arg : drive_args) {
@ -833,7 +835,7 @@ auto winfsp_drive::Read(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
data.clear();
auto res = provider_.set_item_meta(
api_path, META_ACCESSED,
std::to_string(utils::get_file_time_now()));
std::to_string(utils::time::get_file_time_now()));
if (res != api_error::success) {
utils::error::raise_api_path_error(
function_name, api_path, res,

View File

@ -25,7 +25,7 @@
#include "spdlog/async.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/spdlog.h"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
namespace repertory {
logging_consumer::logging_consumer(event_level level,

View File

@ -21,7 +21,7 @@
*/
#include "events/event.hpp"
#include "utils/string_utils.hpp"
#include "utils/string.hpp"
namespace repertory {
auto event_level_from_string(std::string level) -> event_level {

View File

@ -32,13 +32,14 @@
#include "utils/encrypting_reader.hpp"
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/polling.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
namespace {
[[nodiscard]] auto create_resume_entry(const repertory::i_open_file &file)
-> json {
[[nodiscard]] auto
create_resume_entry(const repertory::i_open_file &file) -> json {
return {
{"chunk_size", file.get_chunk_size()},
{"path", file.get_api_path()},
@ -439,11 +440,10 @@ auto file_manager::open(const std::string &api_path, bool directory,
return open(api_path, directory, ofd, handle, file, nullptr);
}
auto file_manager::open(const std::string &api_path, bool directory,
const open_file_data &ofd, std::uint64_t &handle,
std::shared_ptr<i_open_file> &file,
std::shared_ptr<i_closeable_open_file> closeable_file)
-> api_error {
auto file_manager::open(
const std::string &api_path, bool directory, const open_file_data &ofd,
std::uint64_t &handle, std::shared_ptr<i_open_file> &file,
std::shared_ptr<i_closeable_open_file> closeable_file) -> api_error {
const auto create_and_add_handle =
[&](std::shared_ptr<i_closeable_open_file> cur_file) {
handle = get_next_handle();
@ -506,8 +506,8 @@ void file_manager::queue_upload(const std::string &api_path,
db::db_insert{*db_.get(), upload_table}
.or_replace()
.column_value("api_path", api_path)
.column_value("date_time",
static_cast<std::int64_t>(utils::get_file_time_now()))
.column_value("date_time", static_cast<std::int64_t>(
utils::time::get_file_time_now()))
.column_value("source_path", source_path)
.go();
if (result.ok()) {
@ -696,8 +696,8 @@ auto file_manager::rename_directory(const std::string &from_api_path,
}
auto file_manager::rename_file(const std::string &from_api_path,
const std::string &to_api_path, bool overwrite)
-> api_error {
const std::string &to_api_path,
bool overwrite) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (not provider_.is_rename_supported()) {

View File

@ -27,7 +27,8 @@
#include "types/startup_exception.hpp"
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/time.hpp"
#include "utils/unix/unix_utils.hpp"
#include "utils/utils.hpp"
@ -327,7 +328,7 @@ auto file_manager::open_file::native_operation(
set_modified();
fsi_.size = new_file_size;
const auto now = std::to_string(utils::get_file_time_now());
const auto now = std::to_string(utils::time::get_file_time_now());
res = provider_.set_item_meta(
fsi_.api_path, {
{META_CHANGED, now},
@ -346,8 +347,8 @@ auto file_manager::open_file::native_operation(
}
auto file_manager::open_file::read(std::size_t read_size,
std::uint64_t read_offset, data_buffer &data)
-> api_error {
std::uint64_t read_offset,
data_buffer &data) -> api_error {
if (fsi_.directory) {
return api_error::invalid_operation;
}
@ -591,7 +592,7 @@ auto file_manager::open_file::write(std::uint64_t write_offset,
return set_api_error(res);
}
const auto now = std::to_string(utils::get_file_time_now());
const auto now = std::to_string(utils::time::get_file_time_now());
res = provider_.set_item_meta(fsi_.api_path, {
{META_CHANGED, now},
{META_MODIFIED, now},

View File

@ -21,7 +21,7 @@
*/
#include "file_manager/file_manager.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
namespace repertory {
file_manager::open_file_base::open_file_base(std::uint64_t chunk_size,

View File

@ -27,7 +27,7 @@
#include "types/repertory.hpp"
#include "utils/encrypting_reader.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/unix/unix_utils.hpp"
#include "utils/utils.hpp"

View File

@ -28,7 +28,7 @@
#include "types/startup_exception.hpp"
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/unix/unix_utils.hpp"
namespace repertory {

View File

@ -29,8 +29,9 @@
#include "events/events.hpp"
#include "file_manager/i_file_manager.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/polling.hpp"
#include "utils/time.hpp"
namespace repertory {
auto base_provider::create_api_file(std::string path, std::string key,
@ -38,10 +39,10 @@ auto base_provider::create_api_file(std::string path, std::string key,
api_file file{};
file.api_path = utils::path::create_api_path(path);
file.api_parent = utils::path::get_parent_api_path(file.api_path);
file.accessed_date = utils::get_file_time_now();
file.changed_date = utils::get_file_time_now();
file.creation_date = utils::get_file_time_now();
file.modified_date = utils::get_file_time_now();
file.accessed_date = utils::time::get_file_time_now();
file.changed_date = utils::time::get_file_time_now();
file.creation_date = utils::time::get_file_time_now();
file.modified_date = utils::time::get_file_time_now();
file.key = key;
file.file_size = size;
return file;
@ -66,8 +67,8 @@ auto base_provider::create_api_file(std::string path, std::uint64_t size,
}
auto base_provider::create_directory_clone_source_meta(
const std::string &source_api_path, const std::string &api_path)
-> api_error {
const std::string &source_api_path,
const std::string &api_path) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
bool exists{};
@ -164,8 +165,8 @@ auto base_provider::create_directory(const std::string &api_path,
return set_item_meta(api_path, meta);
}
auto base_provider::create_file(const std::string &api_path, api_meta_map &meta)
-> api_error {
auto base_provider::create_file(const std::string &api_path,
api_meta_map &meta) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
bool exists{};
@ -222,9 +223,8 @@ auto base_provider::create_file(const std::string &api_path, api_meta_map &meta)
return api_error::error;
}
auto base_provider::get_api_path_from_source(const std::string &source_path,
std::string &api_path) const
-> api_error {
auto base_provider::get_api_path_from_source(
const std::string &source_path, std::string &api_path) const -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (source_path.empty()) {
@ -237,9 +237,8 @@ auto base_provider::get_api_path_from_source(const std::string &source_path,
return db3_->get_api_path(source_path, api_path);
}
auto base_provider::get_directory_items(const std::string &api_path,
directory_item_list &list) const
-> api_error {
auto base_provider::get_directory_items(
const std::string &api_path, directory_item_list &list) const -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
bool exists{};
@ -303,10 +302,9 @@ auto base_provider::get_file_size(const std::string &api_path,
return api_error::success;
}
auto base_provider::get_filesystem_item(const std::string &api_path,
bool directory,
filesystem_item &fsi) const
-> api_error {
auto base_provider::get_filesystem_item(
const std::string &api_path, bool directory,
filesystem_item &fsi) const -> api_error {
bool exists{};
auto res = is_directory(api_path, exists);
if (res != api_error::success) {
@ -339,10 +337,9 @@ auto base_provider::get_filesystem_item(const std::string &api_path,
return api_error::success;
}
auto base_provider::get_filesystem_item_and_file(const std::string &api_path,
api_file &file,
filesystem_item &fsi) const
-> api_error {
auto base_provider::get_filesystem_item_and_file(
const std::string &api_path, api_file &file,
filesystem_item &fsi) const -> api_error {
auto res = get_file(api_path, file);
if (res != api_error::success) {
return res;

View File

@ -27,9 +27,10 @@
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "types/repertory.hpp"
#include "utils/collection.hpp"
#include "utils/encrypt.hpp"
#include "utils/encrypting_reader.hpp"
#include "utils/encryption.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/polling.hpp"
namespace {
@ -186,8 +187,8 @@ auto encrypt_provider::do_fs_operation(
source_path = utils::path::combine(cfg.path, {source_path});
if (source_path != cfg.path &&
not source_path.starts_with(cfg.path +
utils::path::directory_seperator)) {
not source_path.starts_with(
cfg.path + std::string{utils::path::directory_seperator})) {
return directory ? api_error::directory_not_found
: api_error::item_not_found;
}
@ -691,11 +692,14 @@ auto encrypt_provider::process_directory_entry(
part_idx++) {
data_buffer encrypted_data;
utils::encryption::encrypt_data(
cfg.encryption_token, encrypted_parts.at(part_idx).c_str(),
cfg.encryption_token,
reinterpret_cast<const unsigned char *>(
encrypted_parts.at(part_idx).c_str()),
strnlen(encrypted_parts.at(part_idx).c_str(),
encrypted_parts.at(part_idx).size()),
encrypted_data);
encrypted_parts[part_idx] = utils::to_hex_string(encrypted_data);
encrypted_parts[part_idx] =
utils::collection::to_hex_string(encrypted_data);
}
std::size_t current_idx{1U};
@ -917,8 +921,9 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
info->reader->set_read_position(offset);
data.resize(size);
const auto res = info->reader->reader_function(data.data(), 1U, data.size(),
info->reader.get());
const auto res =
info->reader->reader_function(reinterpret_cast<char *>(data.data()), 1U,
data.size(), info->reader.get());
if (res == 0) {
return api_error::os_error;
}

View File

@ -26,8 +26,8 @@
#include "database/db_insert.hpp"
#include "database/db_select.hpp"
#include "utils/error_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp"
namespace repertory {
meta_db::meta_db(const app_config &cfg) {
@ -101,8 +101,8 @@ auto meta_db::get_api_path_list() -> std::vector<std::string> {
return ret;
}
auto meta_db::get_item_meta(const std::string &api_path, api_meta_map &meta)
-> api_error {
auto meta_db::get_item_meta(const std::string &api_path,
api_meta_map &meta) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto result = db::db_select{*db_, table_name}
@ -283,8 +283,8 @@ auto meta_db::set_item_meta(const std::string &api_path,
return update_item_meta(api_path, existing_meta);
}
auto meta_db::update_item_meta(const std::string &api_path, api_meta_map meta)
-> api_error {
auto meta_db::update_item_meta(const std::string &api_path,
api_meta_map meta) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
auto directory = utils::string::to_bool(meta[META_DIRECTORY]);

View File

@ -28,13 +28,15 @@
#include "types/repertory.hpp"
#include "types/s3.hpp"
#include "types/startup_exception.hpp"
#include "utils/encryption.hpp"
#include "utils/collection.hpp"
#include "utils/encrypt.hpp"
#include "utils/encrypting_reader.hpp"
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/polling.hpp"
#include "utils/string_utils.hpp"
#include "utils/string.hpp"
#include "utils/time.hpp"
namespace repertory {
s3_provider::s3_provider(app_config &config, i_http_comm &comm)
@ -83,7 +85,7 @@ auto s3_provider::create_directory_impl(const std::string &api_path,
meta[META_KEY] = utils::path::create_api_path(
utils::path::combine(utils::path::create_api_path(encrypted_file_path),
{utils::to_hex_string(result)}));
{utils::collection::to_hex_string(result)}));
}
const auto object_name =
@ -132,7 +134,7 @@ auto s3_provider::create_file_extra(const std::string &api_path,
meta[META_KEY] = utils::path::create_api_path(
utils::path::combine(utils::path::create_api_path(encrypted_file_path),
{utils::to_hex_string(result)}));
{utils::collection::to_hex_string(result)}));
}
return api_error::success;
@ -384,7 +386,7 @@ auto s3_provider::get_file(const std::string &api_path,
return res;
}
file.accessed_date = utils::get_file_time_now();
file.accessed_date = utils::time::get_file_time_now();
file.api_path = api_path;
file.api_parent = utils::path::get_parent_api_path(file.api_path);
file.changed_date = utils::aws::format_time(result.last_modified);
@ -439,7 +441,7 @@ auto s3_provider::get_file_list(api_file_list &list) const -> api_error {
api_file file{};
file.api_path = utils::path::create_api_path(api_path);
file.api_parent = utils::path::get_parent_api_path(file.api_path);
file.accessed_date = utils::get_file_time_now();
file.accessed_date = utils::time::get_file_time_now();
file.changed_date = utils::convert_api_date(
node.node().select_node("LastModified").node().text().as_string());
file.creation_date = file.changed_date;

View File

@ -29,9 +29,9 @@
#include "types/repertory.hpp"
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/polling.hpp"
#include "utils/string_utils.hpp"
#include "utils/string.hpp"
#include "utils/utils.hpp"
namespace repertory {

View File

@ -22,7 +22,7 @@
#include "rpc/client/client.hpp"
#include "types/repertory.hpp"
#include "utils/Base64.hpp"
#include "utils/base64.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -195,9 +195,8 @@ auto client::pinned_status(const std::string &api_path) -> rpc_response {
return rpc_response{rpc_response_type::success, json::parse(resp->body)};
}
auto client::set_config_value_by_name(const std::string &name,
const std::string &value)
-> rpc_response {
auto client::set_config_value_by_name(
const std::string &name, const std::string &value) -> rpc_response {
const auto base_url =
"http://" + host_info_.host + ":" + std::to_string(host_info_.port);

View File

@ -28,7 +28,7 @@
#include "types/repertory.hpp"
#include "types/rpc.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
namespace repertory {
full_server::full_server(app_config &config, i_provider &provider,

View File

@ -22,7 +22,7 @@
#include "rpc/server/server.hpp"
#include "app_config.hpp"
#include "utils/Base64.hpp"
#include "utils/base64.hpp"
#include "utils/error_utils.hpp"
namespace repertory {
@ -42,7 +42,7 @@ auto server::check_authorization(const httplib::Request &req) -> bool {
return false;
}
const auto auth_parts = utils::string::split(authorization, ' ');
const auto auth_parts = utils::string::split(authorization, ' ', true);
if (auth_parts.empty()) {
return false;
}
@ -54,7 +54,7 @@ auto server::check_authorization(const httplib::Request &req) -> bool {
const auto data = macaron::Base64::Decode(authorization.substr(6U));
const auto auth =
utils::string::split(std::string(data.begin(), data.end()), ':');
utils::string::split(std::string(data.begin(), data.end()), ':', true);
if (auth.size() != 2U) {
return false;
}

View File

@ -22,8 +22,40 @@
#include "types/repertory.hpp"
#include "types/startup_exception.hpp"
#include "utils/string.hpp"
namespace repertory {
auto download_type_from_string(
std::string type, const download_type &default_type) -> download_type {
type = utils::string::to_lower(utils::string::trim(type));
if (type == "direct") {
return download_type::direct;
}
if (type == "fallback") {
return download_type::fallback;
}
if (type == "ring_buffer") {
return download_type::ring_buffer;
}
return default_type;
}
auto download_type_to_string(const download_type &type) -> std::string {
switch (type) {
case download_type::direct:
return "direct";
case download_type::fallback:
return "fallback";
case download_type::ring_buffer:
return "ring_buffer";
default:
return "fallback";
}
}
static const std::unordered_map<api_error, std::string> LOOKUP = {
{api_error::success, "success"},
{api_error::access_denied, "access_denied"},

View File

@ -22,9 +22,10 @@
#include "utils/cli_utils.hpp"
#include "app_config.hpp"
#include "utils/collection.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp"
#include "utils/utils.hpp"
namespace repertory::utils::cli {
@ -157,7 +158,7 @@ auto parse_drive_options(
options = drive_args.at(i).substr(2);
}
const auto fuse_option_list = utils::string::split(options, ',');
const auto fuse_option_list = utils::string::split(options, ',', true);
for (const auto &fuse_option : fuse_option_list) {
if (fuse_option.find("s3") == 0) {
prov = provider_type::s3;
@ -165,7 +166,7 @@ auto parse_drive_options(
}
if ((fuse_option.find("dd") == 0) ||
(fuse_option.find("data_directory") == 0)) {
const auto data = utils::string::split(fuse_option, '=');
const auto data = utils::string::split(fuse_option, '=', true);
if (data.size() == 2U) {
data_directory = data.at(1U);
} else {
@ -187,14 +188,16 @@ auto parse_drive_options(
if (new_drive_args[i].find("-o") == 0) {
if (new_drive_args[i].size() == 2) {
if ((i + 1) < drive_args.size()) {
utils::remove_element_from(new_drive_args, new_drive_args[i]);
utils::remove_element_from(new_drive_args, new_drive_args[i]);
utils::collection::remove_element(new_drive_args,
new_drive_args[i]);
utils::collection::remove_element(new_drive_args,
new_drive_args[i]);
i--;
}
continue;
}
utils::remove_element_from(new_drive_args, new_drive_args[i]);
utils::collection::remove_element(new_drive_args, new_drive_args[i]);
i--;
continue;
}

View File

@ -19,16 +19,17 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "utils/encryption.hpp"
#include "utils/encrypt.hpp"
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "types/repertory.hpp"
#include "utils/collection.hpp"
#include "utils/encrypting_reader.hpp"
#include "utils/utils.hpp"
namespace repertory::utils::encryption {
auto decrypt_file_path(const std::string &encryption_token,
auto decrypt_file_path(std::string_view encryption_token,
std::string &file_path) -> api_error {
std::string decrypted_file_path{};
for (const auto &part : std::filesystem::path(file_path)) {
@ -49,10 +50,10 @@ auto decrypt_file_path(const std::string &encryption_token,
return api_error::success;
}
auto decrypt_file_name(const std::string &encryption_token,
auto decrypt_file_name(std::string_view encryption_token,
std::string &file_name) -> api_error {
data_buffer buffer;
if (not utils::from_hex_string(file_name, buffer)) {
if (not utils::collection::from_hex_string(file_name, buffer)) {
return api_error::error;
}
@ -65,30 +66,6 @@ auto decrypt_file_name(const std::string &encryption_token,
return api_error::success;
}
auto generate_key(const std::string &encryption_token) -> key_type {
crypto_hash_sha256_state state{};
auto res = crypto_hash_sha256_init(&state);
if (res != 0) {
throw std::runtime_error("failed to initialize sha256|" +
std::to_string(res));
}
res = crypto_hash_sha256_update(
&state, reinterpret_cast<const unsigned char *>(encryption_token.c_str()),
strnlen(encryption_token.c_str(), encryption_token.size()));
if (res != 0) {
throw std::runtime_error("failed to update sha256|" + std::to_string(res));
}
key_type ret{};
res = crypto_hash_sha256_final(&state, ret.data());
if (res != 0) {
throw std::runtime_error("failed to finalize sha256|" +
std::to_string(res));
}
return ret;
}
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 {

View File

@ -24,7 +24,8 @@
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "types/repertory.hpp"
#include "utils/encryption.hpp"
#include "utils/collection.hpp"
#include "utils/encrypt.hpp"
#include "utils/error_utils.hpp"
#include "utils/utils.hpp"
@ -33,8 +34,8 @@ class encrypting_streambuf final : public encrypting_reader::streambuf {
public:
encrypting_streambuf(const encrypting_streambuf &) = default;
encrypting_streambuf(encrypting_streambuf &&) = delete;
auto operator=(const encrypting_streambuf &)
-> encrypting_streambuf & = delete;
auto
operator=(const encrypting_streambuf &) -> encrypting_streambuf & = delete;
auto operator=(encrypting_streambuf &&) -> encrypting_streambuf & = delete;
explicit encrypting_streambuf(const encrypting_reader &reader)
@ -81,10 +82,9 @@ protected:
return encrypting_reader::streambuf::seekoff(off, dir, which);
}
auto seekpos(pos_type pos,
std::ios_base::openmode which = std::ios_base::out |
std::ios_base::in)
-> pos_type override {
auto seekpos(pos_type pos, std::ios_base::openmode which =
std::ios_base::out |
std::ios_base::in) -> pos_type override {
return seekoff(pos, std::ios_base::beg, which);
}
@ -164,38 +164,40 @@ const std::size_t encrypting_reader::encrypted_chunk_size_ =
data_chunk_size_ + header_size_;
encrypting_reader::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)
std::string_view file_name, std::string_view source_path,
stop_type &stop_requested, std::string_view token,
std::optional<std::string_view> relative_parent_path,
std::size_t error_return)
: key_(utils::encryption::generate_key(token)),
stop_requested_(stop_requested),
error_return_(error_return) {
const auto res = native_file::create_or_open(source_path, true, source_file_);
if (res != api_error::success) {
throw std::runtime_error("file open failed|src|" + source_path + '|' +
throw std::runtime_error("file open failed|src|" +
std::string{source_path} + '|' +
api_error_to_string(res));
}
data_buffer result;
utils::encryption::encrypt_data(key_, file_name.c_str(),
strnlen(file_name.c_str(), file_name.size()),
result);
encrypted_file_name_ = utils::to_hex_string(result);
utils::encryption::encrypt_data(
key_, reinterpret_cast<const unsigned char *>(file_name.data()),
file_name.size(), result);
encrypted_file_name_ = utils::collection::to_hex_string(result);
if (relative_parent_path.has_value()) {
for (const auto &part :
std::filesystem::path(relative_parent_path.value())) {
for (auto &&part : std::filesystem::path(relative_parent_path.value())) {
utils::encryption::encrypt_data(
key_, part.string().c_str(),
key_, reinterpret_cast<const unsigned char *>(part.string().c_str()),
strnlen(part.string().c_str(), part.string().size()), result);
encrypted_file_path_ += '/' + utils::to_hex_string(result);
encrypted_file_path_ += '/' + utils::collection::to_hex_string(result);
}
encrypted_file_path_ += '/' + encrypted_file_name_;
}
std::uint64_t file_size{};
if (not utils::file::get_file_size(source_path, file_size)) {
throw std::runtime_error("get file size failed|src|" + source_path + '|' +
throw std::runtime_error("get file size failed|src|" +
std::string{source_path} + '|' +
std::to_string(utils::get_last_error_code()));
}
@ -214,17 +216,18 @@ encrypting_reader::encrypting_reader(
}
}
encrypting_reader::encrypting_reader(const std::string &encrypted_file_path,
const std::string &source_path,
encrypting_reader::encrypting_reader(std::string_view encrypted_file_path,
std::string_view source_path,
stop_type &stop_requested,
const std::string &token,
std::string_view token,
std::size_t error_return)
: key_(utils::encryption::generate_key(token)),
stop_requested_(stop_requested),
error_return_(error_return) {
const auto res = native_file::create_or_open(source_path, true, source_file_);
if (res != api_error::success) {
throw std::runtime_error("file open failed|src|" + source_path + '|' +
throw std::runtime_error("file open failed|src|" +
std::string{source_path} + '|' +
api_error_to_string(res));
}
@ -234,7 +237,8 @@ encrypting_reader::encrypting_reader(const std::string &encrypted_file_path,
std::uint64_t file_size{};
if (not utils::file::get_file_size(source_path, file_size)) {
throw std::runtime_error("get file size failed|src|" + source_path + '|' +
throw std::runtime_error("get file size failed|src|" +
std::string{source_path} + '|' +
std::to_string(utils::get_last_error_code()));
}
@ -254,8 +258,8 @@ encrypting_reader::encrypting_reader(const std::string &encrypted_file_path,
}
encrypting_reader::encrypting_reader(
const std::string &encrypted_file_path, const std::string &source_path,
stop_type &stop_requested, const std::string &token,
std::string_view encrypted_file_path, std::string_view source_path,
stop_type &stop_requested, std::string_view token,
std::vector<
std::array<unsigned char, crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>>
iv_list,
@ -265,7 +269,8 @@ encrypting_reader::encrypting_reader(
error_return_(error_return) {
const auto res = native_file::create_or_open(source_path, true, source_file_);
if (res != api_error::success) {
throw std::runtime_error("file open failed|src|" + source_path + '|' +
throw std::runtime_error("file open failed|src|" +
std::string{source_path} + '|' +
api_error_to_string(res));
}
@ -275,7 +280,8 @@ encrypting_reader::encrypting_reader(
std::uint64_t file_size{};
if (not utils::file::get_file_size(source_path, file_size)) {
throw std::runtime_error("get file size failed|src|" + source_path + '|' +
throw std::runtime_error("get file size failed|src|" +
std::string{source_path} + '|' +
std::to_string(utils::get_last_error_code()));
}
@ -319,11 +325,12 @@ auto encrypting_reader::calculate_decrypted_size(std::uint64_t total_size)
get_header_size());
}
auto encrypting_reader::calculate_encrypted_size(const std::string &source_path)
auto encrypting_reader::calculate_encrypted_size(std::string_view source_path)
-> std::uint64_t {
std::uint64_t file_size{};
if (not utils::file::get_file_size(source_path, file_size)) {
throw std::runtime_error("get file size failed|src|" + source_path + '|' +
throw std::runtime_error("get file size failed|src|" +
std::string{source_path} + '|' +
std::to_string(utils::get_last_error_code()));
}

View File

@ -25,20 +25,41 @@
#include "events/events.hpp"
#include "types/repertory.hpp"
namespace {
struct repertory_exception_handler final
: repertory::utils::error::i_exception_handler {
void handle_exception(std::string_view function_name) const override {
repertory::utils::error::raise_error(function_name, "|exception|unknown");
}
void handle_exception(std::string_view function_name,
const std::exception &ex) const override {
repertory::utils::error::raise_error(function_name, ex);
}
};
} // namespace
namespace repertory::utils::error {
void raise_error(std::string function, std::string_view msg) {
void raise_error(std::string_view function, std::string_view msg) {
event_system::instance().raise<repertory_exception>(
function, static_cast<std::string>(msg));
}
void raise_error(std::string function, const api_error &err,
void raise_error(std::string_view function, const api_error &err,
std::string_view msg) {
event_system::instance().raise<repertory_exception>(
function,
static_cast<std::string>(msg) + "|err|" + api_error_to_string(err));
}
void raise_error(std::string function, const std::exception &exception,
void raise_error(std::string_view function, const std::exception &exception) {
event_system::instance().raise<repertory_exception>(
function,
"err|" + std::string(exception.what() == nullptr ? "unknown error"
: exception.what()));
}
void raise_error(std::string_view function, const std::exception &exception,
std::string_view msg) {
event_system::instance().raise<repertory_exception>(
function,
@ -46,17 +67,19 @@ void raise_error(std::string function, const std::exception &exception,
(exception.what() == nullptr ? "unknown error" : exception.what()));
}
void raise_error(std::string function, const json &err, std::string_view msg) {
void raise_error(std::string_view function, const json &err,
std::string_view msg) {
event_system::instance().raise<repertory_exception>(
function, static_cast<std::string>(msg) + "|err|" + err.dump(2));
}
void raise_error(std::string function, std::int64_t err, std::string_view msg) {
void raise_error(std::string_view function, std::int64_t err,
std::string_view msg) {
event_system::instance().raise<repertory_exception>(
function, static_cast<std::string>(msg) + "|err|" + std::to_string(err));
}
void raise_error(std::string function, const api_error &err,
void raise_error(std::string_view function, const api_error &err,
std::string_view file_path, std::string_view msg) {
event_system::instance().raise<repertory_exception>(
function, static_cast<std::string>(msg) + "|sp|" +
@ -64,7 +87,7 @@ void raise_error(std::string function, const api_error &err,
api_error_to_string(err));
}
void raise_error(std::string function, std::int64_t err,
void raise_error(std::string_view function, std::int64_t err,
std::string_view file_path, std::string_view msg) {
event_system::instance().raise<repertory_exception>(
function, static_cast<std::string>(msg) + "|sp|" +
@ -72,7 +95,7 @@ void raise_error(std::string function, std::int64_t err,
std::to_string(err));
}
void raise_error(std::string function, const std::exception &exception,
void raise_error(std::string_view function, const std::exception &exception,
std::string_view file_path, std::string_view msg) {
event_system::instance().raise<repertory_exception>(
function,
@ -81,7 +104,7 @@ void raise_error(std::string function, const std::exception &exception,
(exception.what() == nullptr ? "unknown error" : exception.what()));
}
void raise_api_path_error(std::string function, std::string_view api_path,
void raise_api_path_error(std::string_view function, std::string_view api_path,
const api_error &err, std::string_view msg) {
event_system::instance().raise<repertory_exception>(
function, static_cast<std::string>(msg) + "|ap|" +
@ -89,7 +112,7 @@ void raise_api_path_error(std::string function, std::string_view api_path,
api_error_to_string(err));
}
void raise_api_path_error(std::string function, std::string_view api_path,
void raise_api_path_error(std::string_view function, std::string_view api_path,
std::int64_t err, std::string_view msg) {
event_system::instance().raise<repertory_exception>(
function, static_cast<std::string>(msg) + "|ap|" +
@ -97,7 +120,15 @@ void raise_api_path_error(std::string function, std::string_view api_path,
std::to_string(err));
}
void raise_api_path_error(std::string function, std::string_view api_path,
void raise_api_path_error(std::string_view function, std::string_view api_path,
const std::exception &exception) {
event_system::instance().raise<repertory_exception>(
function,
"ap|" + static_cast<std::string>(api_path) + "|err|" +
(exception.what() == nullptr ? "unknown error" : exception.what()));
}
void raise_api_path_error(std::string_view function, std::string_view api_path,
const std::exception &exception,
std::string_view msg) {
event_system::instance().raise<repertory_exception>(
@ -107,7 +138,7 @@ void raise_api_path_error(std::string function, std::string_view api_path,
(exception.what() == nullptr ? "unknown error" : exception.what()));
}
void raise_api_path_error(std::string function, std::string_view api_path,
void raise_api_path_error(std::string_view function, std::string_view api_path,
std::string_view source_path, const api_error &err,
std::string_view msg) {
event_system::instance().raise<repertory_exception>(
@ -117,7 +148,7 @@ void raise_api_path_error(std::string function, std::string_view api_path,
api_error_to_string(err));
}
void raise_api_path_error(std::string function, std::string_view api_path,
void raise_api_path_error(std::string_view function, std::string_view api_path,
std::string_view source_path, std::int64_t err,
std::string_view msg) {
event_system::instance().raise<repertory_exception>(
@ -127,14 +158,14 @@ void raise_api_path_error(std::string function, std::string_view api_path,
std::to_string(err));
}
void raise_api_path_error(std::string function, std::string_view api_path,
void raise_api_path_error(std::string_view function, std::string_view api_path,
const json &err, std::string_view msg) {
event_system::instance().raise<repertory_exception>(
function, static_cast<std::string>(msg) + "|ap|" +
static_cast<std::string>(api_path) + "|err|" + err.dump(2));
}
void raise_api_path_error(std::string function, std::string_view api_path,
void raise_api_path_error(std::string_view function, std::string_view api_path,
std::string_view source_path,
const std::exception &exception,
std::string_view msg) {
@ -146,15 +177,25 @@ void raise_api_path_error(std::string function, std::string_view api_path,
(exception.what() == nullptr ? "unknown error" : exception.what()));
}
void raise_url_error(std::string function, std::string_view url, CURLcode err,
std::string_view msg) {
void raise_url_error(std::string_view function, std::string_view url,
CURLcode err, std::string_view msg) {
event_system::instance().raise<repertory_exception>(
function, static_cast<std::string>(msg) + "|url|" +
static_cast<std::string>(url) + "|err|" +
curl_easy_strerror(err));
}
void raise_url_error(std::string function, std::string_view url,
void raise_url_error(std::string_view function, std::string_view url,
std::string_view source_path,
const std::exception &exception) {
event_system::instance().raise<repertory_exception>(
function,
"url|" + static_cast<std::string>(url) + "|sp|" +
static_cast<std::string>(source_path) + "|err|" +
(exception.what() == nullptr ? "unknown error" : exception.what()));
}
void raise_url_error(std::string_view function, std::string_view url,
std::string_view source_path,
const std::exception &exception, std::string_view msg) {
event_system::instance().raise<repertory_exception>(

View File

@ -22,9 +22,11 @@
#include "utils/file_utils.hpp"
#include "types/repertory.hpp"
#include "utils/collection.hpp"
#include "utils/error_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory::utils::file {
@ -82,19 +84,19 @@ void change_to_process_directory() {
#if defined(_WIN32)
std::string file_name;
file_name.resize(MAX_PATH);
::GetModuleFileNameA(nullptr, &file_name[0u],
::GetModuleFileNameA(nullptr, &file_name[0U],
static_cast<DWORD>(file_name.size()));
std::string path = file_name.c_str();
::PathRemoveFileSpecA(&path[0u]);
::SetCurrentDirectoryA(&path[0u]);
::PathRemoveFileSpecA(&path[0U]);
::SetCurrentDirectoryA(&path[0U]);
#else
std::string path;
path.resize(PATH_MAX + 1);
#if defined(__APPLE__)
proc_pidpath(getpid(), &path[0u], path.size());
proc_pidpath(getpid(), &path[0U], path.size());
#else
readlink("/proc/self/exe", &path[0u], path.size());
readlink("/proc/self/exe", &path[0U], path.size());
#endif
path = utils::path::get_parent_directory(path);
chdir(path.c_str());
@ -173,10 +175,10 @@ auto create_full_directory_path(std::string path) -> bool {
(::SHCreateDirectory(nullptr, unicode_path.c_str()) == ERROR_SUCCESS);
#else
auto ret = true;
const auto paths = utils::string::split(utils::path::absolute(path),
utils::path::directory_seperator[0u]);
const auto paths = utils::string::split(
utils::path::absolute(path), utils::path::directory_seperator[0U], false);
std::string current_path;
for (std::size_t i = 0u; ret && (i < paths.size()); i++) {
for (std::size_t i = 0U; ret && (i < paths.size()); i++) {
if (paths[i].empty()) { // Skip root
current_path = utils::path::directory_seperator;
} else {
@ -282,8 +284,8 @@ auto generate_sha256(const std::string &file_path) -> std::string {
{
data_buffer buffer(1048576u);
std::uint64_t read_offset = 0u;
std::size_t bytes_read = 0u;
std::uint64_t read_offset = 0U;
std::size_t bytes_read = 0U;
while (
nf->read_bytes(buffer.data(), buffer.size(), read_offset, bytes_read)) {
if (not bytes_read) {
@ -310,7 +312,7 @@ auto generate_sha256(const std::string &file_path) -> std::string {
std::to_string(res));
}
return utils::to_hex_string(out);
return utils::collection::to_hex_string(out);
}
auto get_free_drive_space(const std::string &path) -> std::uint64_t {
@ -461,7 +463,7 @@ auto get_accessed_time(const std::string &path,
auto get_modified_time(const std::string &path,
std::uint64_t &modified) -> bool {
auto ret = false;
modified = 0u;
modified = 0U;
#if defined(_WIN32)
struct _stat64 st {};
if (_stat64(path.c_str(), &st) != -1) {
@ -483,51 +485,6 @@ auto get_modified_time(const std::string &path,
return ret;
}
auto get_file_size(std::string path, std::uint64_t &file_size) -> bool {
file_size = 0u;
path = utils::path::absolute(path);
#if defined(_WIN32)
struct _stat64 st {};
if (_stat64(path.c_str(), &st) != 0) {
#else
#if defined(__APPLE__)
struct stat st {};
if (stat(path.c_str(), &st) != 0) {
#else
struct stat64 st {};
if (stat64(path.c_str(), &st) != 0) {
#endif
#endif
return false;
}
if (st.st_size >= 0) {
file_size = static_cast<std::uint64_t>(st.st_size);
}
return (st.st_size >= 0);
}
auto is_directory(const std::string &path) -> bool {
#if defined(_WIN32)
return ::PathIsDirectory(path.c_str()) != 0;
#else
struct stat st {};
return (not stat(path.c_str(), &st) && S_ISDIR(st.st_mode));
#endif
}
auto is_file(const std::string &path) -> bool {
#if defined(_WIN32)
return (::PathFileExists(path.c_str()) &&
not ::PathIsDirectory(path.c_str()));
#else
struct stat st {};
return (not stat(path.c_str(), &st) && not S_ISDIR(st.st_mode));
#endif
}
auto is_modified_date_older_than(const std::string &path,
const std::chrono::hours &hours) -> bool {
auto ret = false;
@ -542,7 +499,7 @@ auto is_modified_date_older_than(const std::string &path,
#else
return (modified +
static_cast<std::uint64_t>(seconds.count() * NANOS_PER_SECOND)) <
utils::get_time_now();
utils::time::get_time_now();
#endif
}
return ret;
@ -580,40 +537,6 @@ auto read_file_lines(const std::string &path) -> std::vector<std::string> {
return ret;
}
auto read_json_file(const std::string &path, json &data) -> bool {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (not utils::file::is_file(path)) {
return true;
}
try {
std::ifstream file_stream(path.c_str());
if (file_stream.is_open()) {
try {
std::stringstream ss;
ss << file_stream.rdbuf();
std::string json_text = ss.str();
if (not json_text.empty()) {
data = json::parse(json_text.c_str());
}
file_stream.close();
return true;
} catch (const std::exception &e) {
file_stream.close();
throw e;
}
}
} catch (const std::exception &e) {
utils::error::raise_error(function_name, e, path,
"failed to read json file");
}
return false;
}
auto reset_modified_time(const std::string &path) -> bool {
auto ret = false;
#if defined(_WIN32)
@ -643,7 +566,7 @@ auto reset_modified_time(const std::string &path) -> bool {
auto retry_delete_directory(const std::string &dir) -> bool {
auto deleted = false;
for (std::uint8_t i = 0u; not(deleted = delete_directory(dir)) && (i < 200u);
for (std::uint8_t i = 0U; not(deleted = delete_directory(dir)) && (i < 200U);
i++) {
std::this_thread::sleep_for(10ms);
}
@ -653,30 +576,11 @@ auto retry_delete_directory(const std::string &dir) -> bool {
auto retry_delete_file(const std::string &file) -> bool {
auto deleted = false;
for (std::uint8_t i = 0u; not(deleted = delete_file(file)) && (i < 200u);
for (std::uint8_t i = 0U; not(deleted = delete_file(file)) && (i < 200U);
i++) {
std::this_thread::sleep_for(10ms);
}
return deleted;
}
auto write_json_file(const std::string &path, const json &j) -> bool {
std::string data;
{
std::stringstream ss;
ss << std::setw(2) << j;
data = ss.str();
}
native_file_ptr nf;
auto ret = (native_file::create_or_open(path, nf) == api_error::success);
if (ret) {
std::size_t bytes_written = 0u;
ret = nf->truncate(0) &&
nf->write_bytes(&data[0u], data.size(), 0u, bytes_written);
nf->close();
}
return ret;
}
} // namespace repertory::utils::file

View File

@ -22,7 +22,7 @@
#include "utils/native_file.hpp"
#include "types/repertory.hpp"
#include "utils/string_utils.hpp"
#include "utils/string.hpp"
#include "utils/unix/unix_utils.hpp"
#include "utils/utils.hpp"
@ -64,24 +64,24 @@ auto native_file::clone(const native_file_ptr &ptr) -> native_file_ptr {
return clone;
}
auto native_file::create_or_open(const std::string &source_path, bool read_only,
auto native_file::create_or_open(std::string_view source_path, bool read_only,
native_file_ptr &ptr) -> api_error {
#if defined(_WIN32)
auto handle =
read_only
? ::CreateFileA(source_path.c_str(), GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
OPEN_ALWAYS, FILE_FLAG_RANDOM_ACCESS, nullptr)
: ::CreateFileA(source_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
OPEN_ALWAYS, FILE_FLAG_RANDOM_ACCESS, nullptr);
read_only ? ::CreateFileA(std::string{source_path}.c_str(), GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
OPEN_ALWAYS, FILE_FLAG_RANDOM_ACCESS, nullptr)
: ::CreateFileA(std::string{source_path}.c_str(),
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
OPEN_ALWAYS, FILE_FLAG_RANDOM_ACCESS, nullptr);
#else
auto handle =
read_only
? ::open(source_path.c_str(), O_CREAT | O_RDONLY | O_CLOEXEC, 0600U)
: ::open(source_path.c_str(), O_CREAT | O_RDWR | O_CLOEXEC, 0600U);
auto handle = read_only ? ::open(std::string{source_path}.c_str(),
O_CREAT | O_RDONLY | O_CLOEXEC, 0600U)
: ::open(std::string{source_path}.c_str(),
O_CREAT | O_RDWR | O_CLOEXEC, 0600U);
if (not read_only) {
chmod(source_path.c_str(), 0600U);
chmod(std::string{source_path}.c_str(), 0600U);
}
#endif
ptr = native_file::attach(handle);
@ -89,32 +89,34 @@ auto native_file::create_or_open(const std::string &source_path, bool read_only,
: api_error::success);
}
auto native_file::create_or_open(const std::string &source_path,
auto native_file::create_or_open(std::string_view source_path,
native_file_ptr &ptr) -> api_error {
return create_or_open(source_path, false, ptr);
}
auto native_file::open(const std::string &source_path,
auto native_file::open(std::string_view source_path,
native_file_ptr &ptr) -> api_error {
return open(source_path, false, ptr);
}
auto native_file::open(const std::string &source_path, bool read_only,
auto native_file::open(std::string_view source_path, bool read_only,
native_file_ptr &ptr) -> api_error {
#if defined(_WIN32)
auto handle =
read_only
? ::CreateFileA(source_path.c_str(), GENERIC_READ,
? ::CreateFileA(std::string{source_path}.c_str(), GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, nullptr)
: ::CreateFileA(source_path.c_str(), GENERIC_READ | GENERIC_WRITE,
: ::CreateFileA(std::string{source_path}.c_str(),
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, nullptr);
#else
auto handle = read_only ? ::open(source_path.c_str(), O_RDONLY | O_CLOEXEC)
: ::open(source_path.c_str(), O_RDWR | O_CLOEXEC);
auto handle =
read_only ? ::open(std::string{source_path}.c_str(), O_RDONLY | O_CLOEXEC)
: ::open(std::string{source_path}.c_str(), O_RDWR | O_CLOEXEC);
if (not read_only) {
chmod(source_path.c_str(), 0600U);
chmod(std::string{source_path}.c_str(), 0600U);
}
#endif
ptr = native_file::attach(handle);
@ -216,7 +218,7 @@ auto native_file::get_file_size(std::uint64_t &file_size) -> bool {
}
#if defined(_WIN32)
auto native_file::read_bytes(char *buffer, std::size_t read_size,
auto native_file::read_bytes(unsigned char *buffer, std::size_t read_size,
std::uint64_t read_offset,
std::size_t &bytes_read) -> bool {
recur_mutex_lock l(read_write_mutex_);
@ -243,7 +245,7 @@ auto native_file::read_bytes(char *buffer, std::size_t read_size,
return ret;
}
#else
auto native_file::read_bytes(char *buffer, std::size_t read_size,
auto native_file::read_bytes(unsigned char *buffer, std::size_t read_size,
std::uint64_t read_offset,
std::size_t &bytes_read) -> bool {
bytes_read = 0U;
@ -272,7 +274,8 @@ auto native_file::truncate(std::uint64_t file_size) -> bool {
}
#if defined(_WIN32)
auto native_file::write_bytes(const char *buffer, std::size_t write_size,
auto native_file::write_bytes(const unsigned char *buffer,
std::size_t write_size,
std::uint64_t write_offset,
std::size_t &bytes_written) -> bool {
recur_mutex_lock l(read_write_mutex_);
@ -295,7 +298,8 @@ auto native_file::write_bytes(const char *buffer, std::size_t write_size,
return ret;
}
#else
auto native_file::write_bytes(const char *buffer, std::size_t write_size,
auto native_file::write_bytes(const unsigned char *buffer,
std::size_t write_size,
std::uint64_t write_offset,
std::size_t &bytes_written) -> bool {
bytes_written = 0U;

View File

@ -1,204 +0,0 @@
/*
Copyright <2018-2024> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "utils/path_utils.hpp"
#include "types/repertory.hpp"
#include "utils/error_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/utils.hpp"
namespace repertory::utils::path {
auto absolute(std::string path) -> std::string {
path = finalize(path);
#if defined(_WIN32)
if (not path.empty() && ::PathIsRelative(path.c_str())) {
std::string temp;
temp.resize(MAX_PATH + 1);
path = _fullpath(temp.data(), path.c_str(), MAX_PATH);
}
#else
if (not path.empty() && (path[0U] != '/')) {
auto found = false;
auto tmp = path;
do {
auto *res = realpath(&tmp[0U], nullptr);
if (res) {
path = combine(res, {path.substr(tmp.size())});
free(res);
found = true;
} else if (tmp == ".") {
found = true;
} else {
tmp = dirname(&tmp[0U]);
}
} while (not found);
}
#endif
return path;
}
auto combine(std::string path,
const std::vector<std::string> &paths) -> std::string {
return absolute(
std::accumulate(paths.begin(), paths.end(), path,
[](std::string next_path, const auto &path_part) {
if (next_path.empty()) {
return path_part;
}
return next_path + (directory_seperator + path_part);
}));
}
auto create_api_path(std::string path) -> std::string {
if (path.empty() || (path == ".") || (path == "/")) {
return "/";
}
format_path(path, "/", "\\");
if (path.find("./") == 0) {
path = path.substr(1);
}
if (path[0U] != '/') {
path = "/" + path;
}
if ((path != "/") && utils::string::ends_with(path, "/")) {
utils::string::right_trim(path, '/');
}
return path;
}
auto finalize(std::string path) -> std::string {
format_path(path, not_directory_seperator, directory_seperator);
format_path(path, directory_seperator, not_directory_seperator);
if ((path.size() > 1U) &&
(path[path.size() - 1U] == directory_seperator[0U])) {
path = path.substr(0U, path.size() - 1U);
}
#if defined(_WIN32)
if ((path.size() >= 2u) && (path[1U] == ':')) {
path[0U] = utils::string::to_lower(std::string(1U, path[0U]))[0U];
}
#endif
return path;
}
auto format_path(std::string &path, const std::string &sep,
const std::string &not_sep) -> std::string & {
std::replace(path.begin(), path.end(), not_sep[0U], sep[0U]);
while (utils::string::contains(path, sep + sep)) {
utils::string::replace(path, sep + sep, sep);
}
return path;
}
auto get_parent_api_path(const std::string &path) -> std::string {
std::string ret;
if (path != "/") {
ret = path.substr(0, path.rfind('/') + 1);
if (ret != "/") {
ret = utils::string::right_trim(ret, '/');
}
}
return ret;
}
#if !defined(_WIN32)
auto get_parent_directory(std::string path) -> std::string {
auto ret = std::string(dirname(&path[0U]));
if (ret == ".") {
ret = "/";
}
return ret;
}
#endif
auto is_ads_file_path([[maybe_unused]] const std::string &path) -> bool {
#if defined(_WIN32)
return utils::string::contains(path, ":");
#else
return false;
#endif
}
auto is_trash_directory(std::string path) -> bool {
path = create_api_path(utils::string::to_lower(path));
if (utils::string::begins_with(path, "/.trash-") ||
utils::string::begins_with(path, "/.trashes") ||
utils::string::begins_with(path, "/$recycle.bin")) {
return true;
}
return false;
}
auto remove_file_name(std::string path) -> std::string {
path = absolute(path);
#if defined(_WIN32)
::PathRemoveFileSpec(&path[0U]);
path = path.c_str();
#else
if (path != "/") {
auto i = path.size() - 1;
while ((i != 0) && (path[i] != '/')) {
i--;
}
path = (i > 0) ? absolute(path.substr(0, i)) : "/";
}
#endif
return path;
}
#if !defined(_WIN32)
auto resolve(std::string path) -> std::string {
std::string home{};
use_getpwuid(getuid(), [&home](struct passwd *pw) {
home = (pw->pw_dir ? pw->pw_dir : "");
if (home.empty() || ((home == "/") && (getuid() != 0))) {
home = combine("/home", {pw->pw_name});
}
});
return absolute(utils::string::replace(path, "~", home));
}
#endif
auto strip_to_file_name(std::string path) -> std::string {
#if defined(_WIN32)
return ::PathFindFileName(path.c_str());
#else
return utils::string::contains(path, "/") ? basename(&path[0U]) : path;
#endif
}
} // namespace repertory::utils::path

View File

@ -1,230 +0,0 @@
/*
Copyright <2018-2024> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "utils/string_utils.hpp"
namespace repertory::utils::string {
/* constexpr c++20 */ auto ends_with(std::string_view str, std::string_view val)
-> bool {
if (val.size() > str.size()) {
return false;
}
return std::equal(val.rbegin(), val.rend(), str.rbegin());
}
auto from_bool(bool val) -> std::string {
return std::to_string(static_cast<int>(val));
}
auto from_dynamic_bitset(const boost::dynamic_bitset<> &bitset) -> std::string {
std::stringstream stream;
boost::archive::text_oarchive archive(stream);
archive << bitset;
return stream.str();
}
auto from_utf8(const std::string &str) -> std::wstring {
return str.empty()
? L""
: std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>()
.from_bytes(str);
}
/* constexpr c++20 */ auto is_numeric(std::string_view str) -> bool {
if ((str.length() > 1U) && (str[0U] == '+' || str[0U] == '-')) {
str = str.substr(1U);
}
if (str.empty()) {
return false;
}
auto has_decimal = false;
return std::find_if(str.begin(), str.end(),
[&has_decimal](
const std::string_view::value_type &cur_ch) -> bool {
if (has_decimal && cur_ch == '.') {
return true;
}
has_decimal = has_decimal || cur_ch == '.';
if (has_decimal) {
return false;
}
return std::isdigit(cur_ch) == 0;
}) == str.end();
}
auto join(const std::vector<std::string> &arr, const char &delim)
-> std::string {
if (arr.empty()) {
return "";
}
return std::accumulate(
std::next(arr.begin()), arr.end(), arr[0U],
[&delim](auto str, const auto &cur) { return str + delim + cur; });
}
auto left_trim(std::string &str) -> std::string & {
return left_trim(str, ' ');
}
auto left_trim(std::string &str, const char &trim_ch) -> std::string & {
str.erase(0, str.find_first_not_of(trim_ch));
return str;
}
auto replace(std::string &src, const char &character, const char &with)
-> std::string & {
std::replace(src.begin(), src.end(), character, with);
return src;
}
auto replace(std::string &src, const std::string &find, const std::string &with,
size_t start_pos) -> std::string & {
if (!src.empty() && (start_pos < src.size())) {
while ((start_pos = src.find(find, start_pos)) != std::string::npos) {
src.replace(start_pos, find.size(), with);
start_pos += with.size();
}
}
return src;
}
auto replace_copy(std::string src, const char &character, const char &with)
-> std::string {
std::replace(src.begin(), src.end(), character, with);
return src;
}
auto replace_copy(std::string src, const std::string &find,
const std::string &with, size_t start_pos) -> std::string {
return replace(src, find, with, start_pos);
}
auto right_trim(std::string &str) -> std::string & {
return right_trim(str, ' ');
}
auto right_trim(std::string &str, const char &trim_ch) -> std::string & {
str.erase(str.find_last_not_of(trim_ch) + 1);
return str;
}
auto split(const std::string &str, const char &delim, bool should_trim)
-> std::vector<std::string> {
std::vector<std::string> ret;
std::stringstream stream(str);
std::string item;
while (std::getline(stream, item, delim)) {
ret.push_back(should_trim ? trim(item) : item);
}
return ret;
}
auto to_bool(std::string val) -> bool {
auto ret = false;
trim(val);
if (is_numeric(val)) {
if (contains(val, ".")) {
ret = (to_double(val) != 0.0);
} else {
std::istringstream(val) >> ret;
}
} else {
std::istringstream(to_lower(val)) >> std::boolalpha >> ret;
}
return ret;
}
auto to_double(const std::string &str) -> double { return std::stod(str); }
auto to_dynamic_bitset(const std::string &val) -> boost::dynamic_bitset<> {
std::stringstream stream(val);
boost::dynamic_bitset<> bitset;
boost::archive::text_iarchive archive(stream);
archive >> bitset;
return bitset;
}
auto to_int32(const std::string &val) -> std::int32_t { return std::stoi(val); }
auto to_int64(const std::string &val) -> std::int64_t {
return std::stoll(val);
}
auto to_lower(std::string str) -> std::string {
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
return str;
}
auto to_size_t(const std::string &val) -> std::size_t {
return static_cast<std::size_t>(std::stoull(val));
}
auto to_uint8(const std::string &val) -> std::uint8_t {
return static_cast<std::uint8_t>(std::stoul(val));
}
auto to_uint16(const std::string &val) -> std::uint16_t {
return static_cast<std::uint16_t>(std::stoul(val));
}
auto to_uint32(const std::string &val) -> std::uint32_t {
return static_cast<std::uint32_t>(std::stoul(val));
}
auto to_uint64(const std::string &val) -> std::uint64_t {
return std::stoull(val);
}
auto to_upper(std::string str) -> std::string {
std::transform(str.begin(), str.end(), str.begin(), ::toupper);
return str;
}
auto to_utf8(std::string str) -> std::string { return str; }
auto to_utf8(const std::wstring &str) -> std::string {
return str.empty()
? ""
: std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>()
.to_bytes(str);
}
auto trim(std::string &str) -> std::string & {
return right_trim(left_trim(str));
}
auto trim(std::string &str, const char &trim_ch) -> std::string & {
return right_trim(left_trim(str, trim_ch), trim_ch);
}
auto trim_copy(std::string str) -> std::string {
return right_trim(left_trim(str));
}
auto trim_copy(std::string str, const char &trim_ch) -> std::string {
return right_trim(left_trim(str, trim_ch), trim_ch);
}
} // namespace repertory::utils::string

View File

@ -24,15 +24,8 @@
#include "utils/unix/unix_utils.hpp"
#include "utils/error_utils.hpp"
#include "utils/utils.hpp"
namespace repertory::utils {
#if !defined(__APPLE__)
auto convert_to_uint64(const pthread_t &thread) -> std::uint64_t {
return static_cast<std::uint64_t>(thread);
}
#endif
auto from_api_error(const api_error &err) -> int {
switch (err) {
case api_error::access_denied:
@ -100,30 +93,6 @@ auto from_api_error(const api_error &err) -> int {
}
}
auto get_last_error_code() -> int { return errno; }
auto get_thread_id() -> std::uint64_t {
return convert_to_uint64(pthread_self());
}
auto is_uid_member_of_group(const uid_t &uid, const gid_t &gid) -> bool {
std::vector<gid_t> groups{};
use_getpwuid(uid, [&groups](struct passwd *pass) {
int group_count{};
if (getgrouplist(pass->pw_name, pass->pw_gid, nullptr, &group_count) < 0) {
groups.resize(static_cast<std::size_t>(group_count));
#if defined(__APPLE__)
getgrouplist(pass->pw_name, pass->pw_gid,
reinterpret_cast<int *>(groups.data()), &group_count);
#else
getgrouplist(pass->pw_name, pass->pw_gid, groups.data(), &group_count);
#endif
}
});
return collection_includes(groups, gid);
}
auto to_api_error(int err) -> api_error {
switch (abs(err)) {
case 0:
@ -192,8 +161,6 @@ auto to_api_error(int err) -> api_error {
}
}
void set_last_error_code(int error_code) { errno = error_code; }
auto unix_error_to_windows(int err) -> std::int32_t {
switch (err) {
case 0:
@ -238,21 +205,6 @@ auto unix_time_to_windows_time(const remote::file_time &file_time) -> UINT64 {
return (file_time / 100ULL) + 116444736000000000ULL;
}
void use_getpwuid(uid_t uid,
std::function<void(struct passwd *pass)> callback) {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
static std::mutex mtx{};
mutex_lock lock{mtx};
auto *temp_pw = getpwuid(uid);
if (temp_pw == nullptr) {
utils::error::raise_error(function_name, "'getpwuid' returned nullptr");
return;
}
callback(temp_pw);
}
void windows_create_to_unix(const UINT32 &create_options,
const UINT32 &granted_access, std::uint32_t &flags,
remote::file_mode &mode) {

View File

@ -27,9 +27,10 @@
#include "providers/i_provider.hpp"
#include "types/startup_exception.hpp"
#include "utils/com_init_wrapper.hpp"
#include "utils/common.hpp"
#include "utils/native_file.hpp"
#include "utils/path_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp"
namespace repertory::utils {
void calculate_allocation_size(bool directory, std::uint64_t file_size,
@ -51,53 +52,12 @@ void calculate_allocation_size(bool directory, std::uint64_t file_size,
allocation_meta_size = std::to_string(allocation_size);
}
auto calculate_read_size(const uint64_t &total_size, std::size_t read_size,
const uint64_t &offset) -> std::size_t {
return static_cast<std::size_t>(
((offset + read_size) > total_size)
? ((offset < total_size) ? total_size - offset : 0U)
: read_size);
}
auto compare_version_strings(std::string version1,
std::string version2) -> int {
if (utils::string::contains(version1, "-")) {
version1 = utils::string::split(version1, '-')[0U];
}
if (utils::string::contains(version2, "-")) {
version2 = utils::string::split(version2, '-')[0U];
}
auto nums1 = utils::string::split(version1, '.');
auto nums2 = utils::string::split(version2, '.');
while (nums1.size() > nums2.size()) {
nums2.emplace_back("0");
}
while (nums2.size() > nums1.size()) {
nums1.emplace_back("0");
}
for (std::size_t i = 0U; i < nums1.size(); i++) {
const auto int1 = utils::string::to_uint32(nums1[i]);
const auto int2 = utils::string::to_uint32(nums2[i]);
const auto res = std::memcmp(&int1, &int2, sizeof(int1));
if (res != 0) {
return res;
}
}
return 0;
}
auto convert_api_date(const std::string &date) -> std::uint64_t {
// 2009-10-12T17:50:30.000Z
const auto date_parts = utils::string::split(date, '.');
const auto date_parts = utils::string::split(date, '.', true);
const auto date_time = date_parts[0U];
const auto nanos =
utils::string::to_uint64(utils::string::split(date_parts[1U], 'Z')[0U]);
const auto nanos = utils::string::to_uint64(
utils::string::split(date_parts[1U], 'Z', true)[0U]);
struct tm tm1 {};
#if defined(_WIN32)
@ -118,165 +78,14 @@ auto create_curl() -> CURL * {
return reset_curl(curl_easy_init());
}
auto create_uuid_string() -> std::string {
std::random_device random_device;
auto seed_data = std::array<int, std::mt19937::state_size>{};
std::generate(std::begin(seed_data), std::end(seed_data),
std::ref(random_device));
std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
std::mt19937 generator(seq);
uuids::uuid_random_generator gen{generator};
return uuids::to_string(gen());
}
auto create_volume_label(const provider_type &prov) -> std::string {
return "repertory_" + app_config::get_provider_name(prov);
}
auto download_type_from_string(
std::string type, const download_type &default_type) -> download_type {
type = utils::string::to_lower(utils::string::trim(type));
if (type == "direct") {
return download_type::direct;
}
if (type == "fallback") {
return download_type::fallback;
}
if (type == "ring_buffer") {
return download_type::ring_buffer;
}
return default_type;
}
auto download_type_to_string(const download_type &type) -> std::string {
switch (type) {
case download_type::direct:
return "direct";
case download_type::fallback:
return "fallback";
case download_type::ring_buffer:
return "ring_buffer";
default:
return "fallback";
}
}
#if defined(_WIN32)
// https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/
auto filetime_to_unix_time(const FILETIME &ft) -> remote::file_time {
LARGE_INTEGER date{};
date.HighPart = static_cast<LONG>(ft.dwHighDateTime);
date.LowPart = ft.dwLowDateTime;
date.QuadPart -= 116444736000000000LL;
return static_cast<remote::file_time>(date.QuadPart) * 100ULL;
}
void unix_time_to_filetime(const remote::file_time &ts, FILETIME &ft) {
const auto win_time = (ts / 100ULL) + 116444736000000000ULL;
ft.dwHighDateTime = static_cast<DWORD>(win_time >> 32U);
ft.dwLowDateTime = win_time & 0xFFFFFFFF;
}
#endif
auto generate_random_string(std::uint16_t length) -> std::string {
std::string ret;
ret.resize(length);
for (std::uint16_t i = 0U; i < length; i++) {
do {
ret[i] = static_cast<char>(repertory_rand<std::uint8_t>() % 74 + 48);
} while (((ret[i] >= 91) && (ret[i] <= 96)) ||
((ret[i] >= 58) && (ret[i] <= 64)));
}
return ret;
}
auto get_attributes_from_meta(const api_meta_map &meta) -> DWORD {
return static_cast<DWORD>(utils::string::to_uint32(meta.at(META_ATTRIBUTES)));
}
auto get_environment_variable(const std::string &variable) -> std::string {
static std::mutex mtx{};
mutex_lock lock{mtx};
const auto *val = std::getenv(variable.c_str());
auto ret = std::string(val == nullptr ? "" : val);
return ret;
}
auto get_file_time_now() -> std::uint64_t {
#if defined(_WIN32)
SYSTEMTIME st{};
::GetSystemTime(&st);
FILETIME ft{};
::SystemTimeToFileTime(&st, &ft);
return static_cast<std::uint64_t>(
(reinterpret_cast<LARGE_INTEGER *>(&ft))->QuadPart);
#else
return get_time_now();
#endif
}
void get_local_time_now(struct tm &local_time) {
memset(&local_time, 0, sizeof(local_time));
const auto now =
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
#if defined(_WIN32)
localtime_s(&local_time, &now);
#else
localtime_r(&now, &local_time);
#endif
}
auto get_next_available_port(std::uint16_t first_port,
std::uint16_t &available_port) -> bool {
using namespace boost::asio;
using ip::tcp;
boost::system::error_code error_code{};
while (first_port != 0U) {
io_service svc{};
tcp::acceptor acceptor(svc);
acceptor.open(tcp::v4(), error_code) ||
acceptor.bind({tcp::v4(), first_port}, error_code);
if (not error_code) {
break;
}
++first_port;
}
if (not error_code) {
available_port = first_port;
}
return not error_code;
}
auto get_time_now() -> std::uint64_t {
#if defined(_WIN32)
return static_cast<std::uint64_t>(
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()));
#else
#if defined(__APPLE__)
return std::chrono::nanoseconds(
std::chrono::system_clock::now().time_since_epoch())
.count();
#else
return static_cast<std::uint64_t>(
std::chrono::nanoseconds(
std::chrono::high_resolution_clock::now().time_since_epoch())
.count());
#endif
#endif
}
auto reset_curl(CURL *curl_handle) -> CURL * {
curl_easy_reset(curl_handle);
#if defined(__APPLE__)

View File

@ -25,7 +25,7 @@
#include "types/startup_exception.hpp"
#include "utils/com_init_wrapper.hpp"
#include "utils/string_utils.hpp"
#include "utils/string.hpp"
#if !defined(STATUS_DEVICE_INSUFFICIENT_RESOURCES)
#define STATUS_DEVICE_INSUFFICIENT_RESOURCES static_cast<NTSTATUS>(0xC0000468L)
@ -232,10 +232,6 @@ auto unix_open_flags_to_flags_and_perms(const remote::file_mode & /*mode*/,
return ret;
}
auto time64_to_unix_time(const __time64_t &t) -> remote::file_time {
return static_cast<remote::file_time>(t * NANOS_PER_SECOND);
}
} // namespace repertory::utils
#endif // _WIN32

View File

@ -30,7 +30,7 @@
#include "utils/cli_utils.hpp"
#include "utils/com_init_wrapper.hpp"
#include "utils/file_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/string.hpp"
#if defined(_WIN32)
#include "drives/winfsp/remotewinfsp/remote_client.hpp"

View File

@ -77,7 +77,7 @@ auto main(int argc, char **argv) -> int {
res = utils::cli::parse_string_option(
args, utils::cli::options::remote_mount_option, data);
if (res == exit_code::success) {
const auto parts = utils::string::split(data, ':');
const auto parts = utils::string::split(data, ':', false);
if (parts.size() != 2) {
std::cerr << "Invalid syntax for host/port '-rm "
"host:port,--remote_mount host:port'"

View File

@ -29,7 +29,8 @@
#include "types/remote.hpp"
#include "types/repertory.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -67,10 +68,10 @@ public:
dir_item.size = 0;
dir_item.meta = {
{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::get_file_time_now())},
{META_CREATION, std::to_string(utils::get_file_time_now())}};
{META_MODIFIED, std::to_string(utils::time::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::time::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::time::get_file_time_now())},
{META_CREATION, std::to_string(utils::time::get_file_time_now())}};
list.emplace_back(dir_item);
dir_item.api_path = "..";

View File

@ -27,7 +27,8 @@
#include "drives/winfsp/i_winfsp_drive.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -53,11 +54,12 @@ public:
di.api_path = ".";
di.directory = true;
di.size = 0u;
di.meta = {{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::get_file_time_now())},
{META_CREATION, std::to_string(utils::get_file_time_now())}};
di.meta = {
{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::time::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::time::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::time::get_file_time_now())},
{META_CREATION, std::to_string(utils::time::get_file_time_now())}};
list.emplace_back(di);
di.api_path = "..";

View File

@ -34,7 +34,7 @@ REPERTORY_IGNORE_WARNINGS_DISABLE()
#include "events/consumers/console_consumer.hpp"
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "utils/encryption.hpp"
#include "utils/encrypt.hpp"
#include "utils/file_utils.hpp"
#include "utils/native_file.hpp"

View File

@ -24,6 +24,7 @@
#include "test_common.hpp"
#include "utils/collection.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -59,7 +60,7 @@ private:
public:
void process_event(const event &event) {
unique_mutex_lock l(mutex_);
utils::remove_element_from(event_names_, event.get_name());
utils::collection::remove_element(event_names_, event.get_name());
fired_event_names_.emplace_back(event.get_name());
notify_.notify_all();
l.unlock();

View File

@ -23,8 +23,8 @@
#include "app_config.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp"
namespace repertory {
class config_test : public ::testing::Test {

View File

@ -24,7 +24,7 @@
#include "database/db_common.hpp"
#include "database/db_insert.hpp"
#include "database/db_select.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
namespace repertory {
TEST(database, db_insert) {

View File

@ -24,7 +24,7 @@
#include "types/repertory.hpp"
#include "utils/encrypting_reader.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
namespace repertory {
static auto get_source_file_name() -> std::string {
@ -75,10 +75,11 @@ TEST(encrypting_reader, file_data) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size());
for (std::uint8_t j = 0U; j < 2U; j++) {
EXPECT_EQ(buffer.size() / 2U,
utils::encryption::encrypting_reader::reader_function(
&buffer[(buffer.size() / 2U) * j], buffer.size() / 2U, 1U,
&reader));
EXPECT_EQ(
buffer.size() / 2U,
utils::encryption::encrypting_reader::reader_function(
reinterpret_cast<char *>(&buffer[(buffer.size() / 2U) * j]),
buffer.size() / 2U, 1U, &reader));
}
data_buffer decrypted_data;
@ -123,7 +124,8 @@ TEST(encrypting_reader, file_data_in_multiple_chunks) {
2U);
EXPECT_EQ(buffer.size(),
utils::encryption::encrypting_reader::reader_function(
buffer.data(), buffer.size(), 1U, &reader));
reinterpret_cast<char *>(buffer.data()), buffer.size(), 1U,
&reader));
for (std::uint8_t j = 0U; j < 2U; j++) {
data_buffer decrypted_data;
@ -189,8 +191,9 @@ TEST(encrypting_reader, file_data_as_stream) {
for (std::uint8_t j = 0U; j < 2U; j++) {
EXPECT_FALSE(
io_stream
->read(&buffer[(buffer.size() / 2U) * j],
static_cast<std::streamsize>(buffer.size()) / 2U)
->read(
reinterpret_cast<char *>(&buffer[(buffer.size() / 2U) * j]),
static_cast<std::streamsize>(buffer.size()) / 2U)
.fail());
EXPECT_TRUE(io_stream->good());
}
@ -242,10 +245,10 @@ TEST(encrypting_reader, file_data_in_multiple_chunks_as_stream) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size() *
2U);
EXPECT_FALSE(
io_stream
->read(buffer.data(), static_cast<std::streamsize>(buffer.size()))
.fail());
EXPECT_FALSE(io_stream
->read(reinterpret_cast<char *>(buffer.data()),
static_cast<std::streamsize>(buffer.size()))
.fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t j = 0U; j < 2U; j++) {

View File

@ -22,8 +22,10 @@
#include "test_common.hpp"
#include "types/repertory.hpp"
#include "utils/encryption.hpp"
#include "utils/collection.hpp"
#include "utils/encrypt.hpp"
#include "utils/file_utils.hpp"
#include "utils/string.hpp"
namespace repertory {
static const std::string buffer = "cow moose dog chicken";
@ -41,7 +43,7 @@ static void test_encrypted_result(const data_buffer &result) {
TEST(encryption, generate_key) {
const auto key = utils::encryption::generate_key(token);
const auto str = utils::to_hex_string(key);
const auto str = utils::collection::to_hex_string(key);
EXPECT_STREQ(
"182072537ada59e4d6b18034a80302ebae935f66adbdf0f271d3d36309c2d481",
str.c_str());
@ -62,25 +64,31 @@ TEST(encryption, encrypt_data_buffer_with_key) {
TEST(encryption, encrypt_data_pointer) {
data_buffer result;
utils::encryption::encrypt_data(token, &buffer[0u], buffer.size(), result);
utils::encryption::encrypt_data(
token, reinterpret_cast<const unsigned char *>(buffer.data()),
buffer.size(), result);
test_encrypted_result(result);
}
TEST(encryption, encrypt_data_pointer_with_key) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
utils::encryption::encrypt_data(
key, reinterpret_cast<const unsigned char *>(buffer.data()),
buffer.size(), result);
test_encrypted_result(result);
}
TEST(encryption, decrypt_data_pointer) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
utils::encryption::encrypt_data(
key, reinterpret_cast<const unsigned char *>(buffer.data()),
buffer.size(), result);
std::string data;
EXPECT_TRUE(
utils::encryption::decrypt_data(token, &result[0u], result.size(), data));
EXPECT_TRUE(utils::encryption::decrypt_data(token, result.data(),
result.size(), data));
EXPECT_EQ(buffer.size(), data.size());
EXPECT_STREQ(buffer.c_str(), data.c_str());
@ -89,7 +97,9 @@ TEST(encryption, decrypt_data_pointer) {
TEST(encryption, decrypt_data_buffer_with_key) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
utils::encryption::encrypt_data(
key, reinterpret_cast<const unsigned char *>(buffer.data()),
buffer.size(), result);
std::string data;
EXPECT_TRUE(utils::encryption::decrypt_data(key, result, data));
@ -101,11 +111,13 @@ TEST(encryption, decrypt_data_buffer_with_key) {
TEST(encryption, decrypt_data_pointer_with_key) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
utils::encryption::encrypt_data(
key, reinterpret_cast<const unsigned char *>(buffer.data()),
buffer.size(), result);
std::string data;
EXPECT_TRUE(
utils::encryption::decrypt_data(key, &result[0u], result.size(), data));
utils::encryption::decrypt_data(key, result.data(), result.size(), data));
EXPECT_EQ(buffer.size(), data.size());
EXPECT_STREQ(buffer.c_str(), data.c_str());
@ -114,10 +126,12 @@ TEST(encryption, decrypt_data_pointer_with_key) {
TEST(encryption, decryption_failure) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
result[0u] = 0u;
result[1u] = 1u;
result[2u] = 2u;
utils::encryption::encrypt_data(
key, reinterpret_cast<const unsigned char *>(buffer.data()),
buffer.size(), result);
result[0U] = 0U;
result[1U] = 1U;
result[2U] = 2U;
std::string data;
EXPECT_FALSE(utils::encryption::decrypt_data(key, result, data));

View File

@ -26,7 +26,7 @@
#include "mocks/mock_upload_manager.hpp"
#include "types/repertory.hpp"
#include "utils/event_capture.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
namespace repertory {
static constexpr const std::size_t test_chunk_size = 1024u;

View File

@ -25,7 +25,7 @@
#include "mocks/mock_provider.hpp"
#include "mocks/mock_upload_manager.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/unix/unix_utils.hpp"
namespace repertory {

View File

@ -33,9 +33,10 @@
#include "utils/event_capture.hpp"
#include "utils/file_utils.hpp"
#include "utils/native_file.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/polling.hpp"
#include "utils/string_utils.hpp"
#include "utils/string.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -115,7 +116,7 @@ TEST(file_manager, can_create_and_close_file) {
{
std::shared_ptr<i_open_file> f;
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
@ -230,7 +231,7 @@ TEST(file_manager, can_open_and_close_file) {
std::uint64_t handle{};
{
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
@ -337,7 +338,7 @@ TEST(file_manager, can_open_and_close_multiple_handles_for_same_file) {
const auto source_path = utils::path::combine(
cfg.get_cache_directory(), {utils::create_uuid_string()});
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
@ -417,7 +418,7 @@ TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
event_capture ec({"download_stored"},
{"file_upload_completed", "file_upload_queued"});
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u,
@ -580,7 +581,7 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
});
event_capture ec({"download_end"});
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u,
@ -691,7 +692,7 @@ TEST(file_manager, can_evict_file) {
const auto source_path = utils::path::combine(
cfg.get_cache_directory(), {utils::create_uuid_string()});
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
@ -957,7 +958,7 @@ TEST(file_manager, evict_file_fails_if_file_is_uploading) {
const auto source_path = utils::path::combine(
cfg.get_cache_directory(), {utils::create_uuid_string()});
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
@ -1189,7 +1190,7 @@ TEST(file_manager, file_is_not_opened_if_provider_create_file_fails) {
EXPECT_CALL(mp, is_direct_only()).WillRepeatedly(Return(false));
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "", 2, now + 3u, 3u, 4u, 0u, "/test_create.src", 10,
@ -1741,7 +1742,7 @@ TEST(file_manager, file_is_closed_after_download_timeout) {
ee.get_api_path().get<std::string>().c_str());
});
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u,

View File

@ -25,7 +25,7 @@
#include "mocks/mock_provider.hpp"
#include "mocks/mock_upload_manager.hpp"
#include "utils/event_capture.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
namespace repertory {
static constexpr const std::size_t test_chunk_size = 1024u;

View File

@ -21,7 +21,7 @@
*/
#include "test_common.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
namespace repertory {
TEST(path_utils, combine) {

View File

@ -29,11 +29,12 @@
#include "providers/i_provider.hpp"
#include "providers/s3/s3_provider.hpp"
#include "providers/sia/sia_provider.hpp"
#include "utils/collection.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
#include "gtest/gtest.h"
namespace {
#if defined(_WIN32)
@ -56,7 +57,7 @@ const auto check_forced_dirs = [](const repertory::directory_item_list &list) {
const auto create_directory = [](repertory::i_provider &provider,
const std::string &api_path) {
auto date = repertory::utils::get_file_time_now();
auto date = repertory::utils::time::get_file_time_now();
auto meta = repertory::create_meta_attributes(
date, 1U, date + 1U, date + 2U, true, getgid(), "", 0700, date + 3U, 2U,
3U, 0U, api_path + "_src", getuid(), date + 4U);
@ -109,7 +110,7 @@ const auto create_file = [](repertory::i_provider &provider,
auto source_path = repertory::generate_test_file_name(
repertory::get_test_dir(), "providers_test");
auto date = repertory::utils::get_file_time_now();
auto date = repertory::utils::time::get_file_time_now();
auto meta = repertory::create_meta_attributes(
date, 1U, date + 1U, date + 2U, false, getgid(), "", 0700, date + 3U, 2U,
3U, 0U, source_path, getuid(), date + 4U);
@ -562,8 +563,8 @@ static void get_file_list(const app_config &cfg, i_provider &provider) {
for (auto &file : list) {
decrypt_parts(cfg, file.api_parent);
decrypt_parts(cfg, file.api_path);
utils::remove_element_from(expected_parents, file.api_parent);
utils::remove_element_from(expected_paths, file.api_path);
utils::collection::remove_element(expected_parents, file.api_parent);
utils::collection::remove_element(expected_paths, file.api_path);
}
EXPECT_TRUE(expected_parents.empty());
EXPECT_TRUE(expected_paths.empty());

View File

@ -34,6 +34,7 @@
#endif
#include "drives/fuse/remotefuse/remote_client.hpp"
#include "types/repertory.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
using namespace repertory;
@ -508,9 +509,10 @@ static void read_and_write_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(10,
client.fuse_write(api_path.c_str(), "1234567890", 10, 0, handle));
data_buffer buffer(10);
EXPECT_EQ(10,
client.fuse_read(api_path.c_str(), &buffer[0], 10, 0, handle));
EXPECT_EQ(0, memcmp("1234567890", &buffer[0], 10));
EXPECT_EQ(10, client.fuse_read(api_path.c_str(),
reinterpret_cast<char *>(buffer.data()), 10,
0, handle));
EXPECT_EQ(0, std::memcmp("1234567890", buffer.data(), 10));
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
}
@ -534,9 +536,10 @@ read_and_write_base64_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(10, client.fuse_write_base64(api_path.c_str(), &data[0],
data.size(), 0, handle));
data_buffer buffer(10);
EXPECT_EQ(10,
client.fuse_read(api_path.c_str(), &buffer[0], 10, 0, handle));
EXPECT_EQ(0, memcmp("1234567890", &buffer[0], 10));
EXPECT_EQ(10, client.fuse_read(api_path.c_str(),
reinterpret_cast<char *>(buffer.data()), 10,
0, handle));
EXPECT_EQ(0, std::memcmp("1234567890", buffer.data(), 10));
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
}
@ -683,7 +686,7 @@ static void setbkuptime_test(repertory::remote_fuse::remote_client &client) {
if (ret == 0) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
remote::file_time ts = utils::get_file_time_now();
remote::file_time ts = utils::time::get_file_time_now();
#if defined(_WIN32)
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_setbkuptime(api_path.c_str(), ts));
#else
@ -708,7 +711,7 @@ static void setchgtime_test(repertory::remote_fuse::remote_client &client) {
if (ret == 0) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
remote::file_time ts = utils::get_file_time_now();
remote::file_time ts = utils::time::get_file_time_now();
#if defined(_WIN32)
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_setchgtime(api_path.c_str(), ts));
#else
@ -733,7 +736,7 @@ static void setcrtime_test(repertory::remote_fuse::remote_client &client) {
if (ret == 0) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
remote::file_time ts = utils::get_file_time_now();
remote::file_time ts = utils::time::get_file_time_now();
#if defined(_WIN32)
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_setcrtime(api_path.c_str(), ts));
#else

View File

@ -32,6 +32,7 @@
#include "mocks/mock_fuse_drive.hpp"
#endif
#include "types/repertory.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
using namespace repertory;
@ -429,7 +430,7 @@ static void set_basic_info_test(remote_client &client) {
const auto change_time = last_write_time;
#else
const auto creation_time =
utils::unix_time_to_windows_time(utils::get_time_now());
utils::unix_time_to_windows_time(utils::time::get_time_now());
const auto last_access_time = creation_time + 1;
const auto last_write_time = creation_time + 2;
const auto change_time = last_write_time;

View File

@ -21,7 +21,7 @@
*/
#include "test_common.hpp"
#include "utils/string_utils.hpp"
#include "utils/string.hpp"
namespace repertory {
TEST(string_utils, is_numeric) {

View File

@ -22,7 +22,7 @@
#include "test_common.hpp"
#include "types/repertory.hpp"
#include "utils/path_utils.hpp"
#include "utils/path.hpp"
#include "utils/utils.hpp"
namespace repertory {

View File

@ -22,8 +22,8 @@
#include "test_common.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp"
#include "utils/utils.hpp"
namespace repertory {

View File

@ -23,6 +23,10 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libboost*.dll)
fi
if [ "${PROJECT_ENABLE_BACKWARD_CPP}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/msvcr90.dll)
fi
if [ "${PROJECT_ENABLE_CLI11}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libcli11*.dll)
fi
@ -31,11 +35,14 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libFLAC*.dll)
fi
if [ "${PROJECT_ENABLE_FMT}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libfmt*.dll)
fi
if [ "${PROJECT_ENABLE_FONTCONFIG}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(
/mingw64/bin/libexpat*.dll
/mingw64/bin/libfontconfig*.dll
/mingw64/bin/libpng*.dll
)
fi
@ -47,6 +54,11 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libcurl*.dll)
fi
if [ "${PROJECT_ENABLE_LIBJPEG_TURBO}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libjpeg*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libturbo*.dll)
fi
if [ "${PROJECT_ENABLE_LIBSODIUM}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libsodium*.dll)
fi
@ -70,6 +82,14 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libopenal*.dll)
fi
if [ "${PROJECT_ENABLE_LIBPNG}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libpng*.dll)
fi
if [ "${PROJECT_ENABLE_NANA}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libnana*.dll)
fi
if [ "${PROJECT_ENABLE_PUGIXML}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libpugi*.dll)
fi
@ -82,11 +102,15 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libsecp256k1*.dll)
fi
if [ "${PROJECT_ENABLE_SDL}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/SDL*.dll)
fi
if [ "${PROJECT_ENABLE_SFML}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libsfml*.dll)
fi
if [ "${PROJECT_ENABLE_SFML}" == "ON" ]; then
if [ "${PROJECT_ENABLE_SPDLOG}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libspdlog*.dll)
fi

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