33 Commits

Author SHA1 Message Date
46490f9930 refactor
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
2024-08-23 14:55:08 -05:00
9ede9f5cf5 refactor 2024-08-23 14:54:17 -05:00
00a5f155ad refactor 2024-08-23 14:51:50 -05:00
b6eab4a932 fix 2024-08-23 14:49:27 -05:00
d5d2b6a889 fix 2024-08-23 14:46:26 -05:00
51320f9a09 refactor 2024-08-23 14:39:27 -05:00
31e0b4c5d9 refactor 2024-08-23 14:32:20 -05:00
bc0901f6a2 refactor 2024-08-23 14:25:14 -05:00
3b4c590404 spelling 2024-08-23 14:15:08 -05:00
953684f5a6 fix 2024-08-23 14:13:46 -05:00
989c90bc8d fix 2024-08-23 14:12:29 -05:00
776862d474 updated build system 2024-08-23 14:12:02 -05:00
1ec287f41a refactor 2024-08-23 13:04:03 -05:00
01ed0c65bb refactor 2024-08-23 13:01:57 -05:00
9bed5e961f refactor 2024-08-23 12:54:48 -05:00
f8e7e8f0e3 time fixes 2024-08-23 12:52:42 -05:00
9e9d46a9cd time fixes 2024-08-23 12:41:35 -05:00
f654d269a7 updated build system 2024-08-23 12:35:48 -05:00
c8929fed0b fix 2024-08-23 12:12:05 -05:00
81fbe7a962 updates 2024-08-23 12:08:40 -05:00
3bce0e9c70 refactor 2024-08-23 12:03:40 -05:00
d4f0431cd5 updated build system 2024-08-23 12:01:46 -05:00
52f2b5b118 refactor 2024-08-23 11:35:51 -05:00
dfc8742fcb spelling 2024-08-23 10:23:51 -05:00
cf516d8663 spelling 2024-08-23 10:20:46 -05:00
e8af147805 spelling 2024-08-23 10:19:41 -05:00
2835809e5e refactor 2024-08-23 10:19:01 -05:00
bc0d299b85 refactor 2024-08-23 10:13:32 -05:00
13c136d01e refactor 2024-08-23 10:12:33 -05:00
218326f812 refactor 2024-08-23 10:12:02 -05:00
6dc10d2a11 updated build system 2024-08-23 10:01:31 -05:00
4eff7aae64 updated build system 2024-08-23 09:34:41 -05:00
bc85e34310 updated build system 2024-08-23 08:58:46 -05:00
55 changed files with 994 additions and 966 deletions

View File

@ -1,4 +1,7 @@
_lseeki64 _lseeki64
_sh_denyno
_sh_denyrd
_sh_denyrw
aarch64 aarch64
advapi32 advapi32
armv8 armv8
@ -86,6 +89,8 @@ ecdh
endforeach endforeach
endfunction endfunction
eventlib eventlib
expect_streq
fallocate_impl
fext fext
fgetattr fgetattr
flac_version flac_version
@ -123,14 +128,18 @@ libsfml
libsodium_type libsodium_type
libuuid libuuid
libuuid_include_dirs libuuid_include_dirs
libvlc
linkflags linkflags
mbig mbig
msvc msvc
msvcr120 msvcr120
mtune mtune
nana
ncrypt ncrypt
nlohmann_json nlohmann_json
nmakeprg nmakeprg
nominmax
ntstatus
nuspell_version nuspell_version
oleaut32 oleaut32
openal_version openal_version
@ -138,13 +147,20 @@ openssldir
pkgconfig pkgconfig
project_enable_fontconfig project_enable_fontconfig
project_enable_gtkmm project_enable_gtkmm
project_enable_libdsm
project_enable_nana
propgrid propgrid
psecurity_descriptor
pugi pugi
pugixml_project pugixml_project
puint32
pvoid
pwstr
remote_winfsp remote_winfsp
richtext richtext
rocksdb_library rocksdb_library
rpcrt4 rpcrt4
sddl_revision_1
secp256k1 secp256k1
secur32 secur32
sfml_project sfml_project
@ -152,13 +168,17 @@ shlwapi
source_subdir source_subdir
spdlog spdlog
spdlog_project spdlog_project
st_ctim
static-libgcc static-libgcc
static-libstdc++ static-libstdc++
stbuf
stduuid_project stduuid_project
strequal strequal
uring uring
userenv userenv
utimens_impl
vorbis_version vorbis_version
waggressive
wall wall
wcast-align wcast-align
wconversion wconversion
@ -166,6 +186,7 @@ wdouble-promotion
wduplicated-branches wduplicated-branches
wduplicated-cond wduplicated-cond
wextra wextra
wfloat
wformat=2 wformat=2
winfsp winfsp
winhttp winhttp
@ -183,5 +204,6 @@ wserialization
wshadow wshadow
wsign-conversion wsign-conversion
wunused wunused
wuseless
wxwidgets_version wxwidgets_version
xattr xattr

View File

@ -42,8 +42,8 @@ private:
using write_callback = size_t (*)(char *, size_t, size_t, void *); using write_callback = size_t (*)(char *, size_t, size_t, void *);
struct read_write_info final { struct read_write_info final {
repertory::data_buffer data{}; data_buffer data{};
repertory::stop_type &stop_requested; stop_type &stop_requested;
}; };
static const write_callback write_data; static const write_callback write_data;
@ -56,6 +56,11 @@ private:
private: private:
bool use_s3_path_style_{false}; bool use_s3_path_style_{false};
public:
[[nodiscard]] static auto create_curl() -> CURL *;
[[nodiscard]] static auto reset_curl(CURL *curl_handle) -> CURL *;
public: public:
[[nodiscard]] static auto [[nodiscard]] static auto
construct_url(CURL *curl, const std::string &relative_path, construct_url(CURL *curl, const std::string &relative_path,
@ -139,7 +144,7 @@ public:
response_code = 0; response_code = 0;
auto *curl = utils::create_curl(); auto *curl = create_curl();
if (not request.set_method(curl, stop_requested)) { if (not request.set_method(curl, stop_requested)) {
return false; return false;
} }

View File

@ -62,13 +62,6 @@ inline constexpr const std::string_view REPERTORY_DATA_NAME = "repertory2";
inline constexpr const std::string_view REPERTORY_MIN_REMOTE_VERSION = "2.0.0"; inline constexpr const std::string_view REPERTORY_MIN_REMOTE_VERSION = "2.0.0";
#define REPERTORY_INVALID_HANDLE INVALID_HANDLE_VALUE #define REPERTORY_INVALID_HANDLE INVALID_HANDLE_VALUE
#if defined(_WIN32)
#define REPERTORY_API_INVALID_HANDLE static_cast<std::uint64_t>(-1)
#else
#define REPERTORY_API_INVALID_HANDLE REPERTORY_INVALID_HANDLE
#endif
inline constexpr const auto NANOS_PER_SECOND = 1000000000L;
#define WINFSP_ALLOCATION_UNIT UINT64(4096U) #define WINFSP_ALLOCATION_UNIT UINT64(4096U)

View File

@ -64,15 +64,15 @@ private:
struct fuse_operations fuse_ops_ {}; struct fuse_operations fuse_ops_ {};
private: private:
[[nodiscard]] auto execute_callback( [[nodiscard]] auto
std::string_view function_name, const char *from, const char *to, execute_callback(std::string_view function_name, const char *from,
const std::function<api_error(const std::string &, const std::string &)> const char *to,
&cb, const std::function<api_error(std::string, std::string)> &cb,
bool disable_logging = false) -> int; bool disable_logging = false) -> int;
[[nodiscard]] auto [[nodiscard]] auto
execute_callback(std::string_view function_name, const char *path, execute_callback(std::string_view function_name, const char *path,
const std::function<api_error(const std::string &)> &cb, const std::function<api_error(std::string)> &cb,
bool disable_logging = false) -> int; bool disable_logging = false) -> int;
static void execute_void_callback(std::string_view function_name, static void execute_void_callback(std::string_view function_name,
@ -83,7 +83,7 @@ private:
const std::function<void *()> &cb) -> void *; const std::function<void *()> &cb) -> void *;
void raise_fuse_event(std::string_view function_name, void raise_fuse_event(std::string_view function_name,
const std::string &api_path, int ret, std::string_view api_path, int ret,
bool disable_logging); bool disable_logging);
private: private:

View File

@ -42,9 +42,9 @@ private:
private: private:
#if defined(_WIN32) #if defined(_WIN32)
#define to_handle(x) (x) #define to_handle(x) (x)
#else #else // !defined(_WIN32)
static auto to_handle(PVOID file_desc) -> native_handle; static auto to_handle(PVOID file_desc) -> native_handle;
#endif #endif // defined(_WIN32)
public: public:
auto json_create_directory_snapshot(const std::string &path, json &json_data) auto json_create_directory_snapshot(const std::string &path, json &json_data)

View File

@ -95,6 +95,9 @@ protected:
stop_type &stop_requested) -> api_error override; stop_type &stop_requested) -> api_error override;
public: public:
[[nodiscard]] static auto
convert_api_date(std::string_view date) -> std::uint64_t;
[[nodiscard]] auto get_directory_item_count(const std::string &api_path) const [[nodiscard]] auto get_directory_item_count(const std::string &api_path) const
-> std::uint64_t override; -> std::uint64_t override;

View File

@ -22,14 +22,14 @@
#ifndef INCLUDE_TYPES_REMOTE_HPP_ #ifndef INCLUDE_TYPES_REMOTE_HPP_
#define INCLUDE_TYPES_REMOTE_HPP_ #define INCLUDE_TYPES_REMOTE_HPP_
#define PACKET_SERVICE_FUSE 1U inline constexpr const auto PACKET_SERVICE_FUSE{1U};
#define PACKET_SERVICE_WINFSP 2U inline constexpr const auto PACKET_SERVICE_WINFSP{2U};
#if defined(_WIN32) #if defined(_WIN32)
#define PACKET_SERVICE_FLAGS PACKET_SERVICE_WINFSP inline constexpr const auto PACKET_SERVICE_FLAGS{PACKET_SERVICE_WINFSP};
#else #else // !defined(_WIN32)
#define PACKET_SERVICE_FLAGS PACKET_SERVICE_FUSE inline constexpr const auto PACKET_SERVICE_FLAGS{PACKET_SERVICE_FUSE};
#endif #endif // defined(_WIN32)
namespace repertory::remote { namespace repertory::remote {
using block_count = std::uint64_t; using block_count = std::uint64_t;
@ -65,16 +65,19 @@ enum class open_flags : std::uint32_t {
dsync = 131072U, dsync = 131072U,
}; };
inline auto operator|(const open_flags &flag_1, #if defined(__GNUG__)
const open_flags &flag_2) -> open_flags { __attribute__((unused))
using t = std::underlying_type_t<open_flags>; #endif // defined(__GNUG__)
return static_cast<open_flags>(static_cast<t>(flag_1) | [[nodiscard]] inline auto
static_cast<t>(flag_2)); operator|(const open_flags &flag_1, const open_flags &flag_2) -> open_flags {
using flag_t = std::underlying_type_t<open_flags>;
return static_cast<open_flags>(static_cast<flag_t>(flag_1) |
static_cast<flag_t>(flag_2));
} }
#if defined(__GNUG__) #if defined(__GNUG__)
__attribute__((unused)) __attribute__((unused))
#endif #endif // defined(__GNUG__)
inline auto inline auto
operator|=(open_flags &flag_1, const open_flags &flag_2) -> open_flags & { operator|=(open_flags &flag_1, const open_flags &flag_2) -> open_flags & {
flag_1 = flag_1 | flag_2; flag_1 = flag_1 | flag_2;
@ -83,69 +86,69 @@ operator|=(open_flags &flag_1, const open_flags &flag_2) -> open_flags & {
#if defined(__GNUG__) #if defined(__GNUG__)
__attribute__((unused)) __attribute__((unused))
#endif #endif // defined(__GNUG__)
inline auto [[nodiscard]] inline auto
operator&(const open_flags &flag_1, const open_flags &flag_2) -> open_flags { operator&(const open_flags &flag_1, const open_flags &flag_2) -> open_flags {
using t = std::underlying_type_t<open_flags>; using flag_t = std::underlying_type_t<open_flags>;
return static_cast<open_flags>(static_cast<t>(flag_1) & return static_cast<open_flags>(static_cast<flag_t>(flag_1) &
static_cast<t>(flag_2)); static_cast<flag_t>(flag_2));
} }
#pragma pack(1) #pragma pack(1)
struct file_info { struct file_info final {
UINT32 FileAttributes; UINT32 FileAttributes{};
UINT32 ReparseTag; UINT32 ReparseTag{};
UINT64 AllocationSize; UINT64 AllocationSize{};
UINT64 FileSize; UINT64 FileSize{};
UINT64 CreationTime; UINT64 CreationTime{};
UINT64 LastAccessTime; UINT64 LastAccessTime{};
UINT64 LastWriteTime; UINT64 LastWriteTime{};
UINT64 ChangeTime; UINT64 ChangeTime{};
UINT64 IndexNumber; UINT64 IndexNumber{};
UINT32 HardLinks; UINT32 HardLinks{};
UINT32 EaSize; UINT32 EaSize{};
}; };
struct setattr_x { struct setattr_x final {
std::int32_t valid; std::int32_t valid{};
file_mode mode; file_mode mode{};
user_id uid; user_id uid{};
group_id gid; group_id gid{};
file_size size; file_size size{};
file_time acctime; file_time acctime{};
file_time modtime; file_time modtime{};
file_time crtime; file_time crtime{};
file_time chgtime; file_time chgtime{};
file_time bkuptime; file_time bkuptime{};
std::uint32_t flags; std::uint32_t flags{};
}; };
struct stat { struct stat final {
file_mode st_mode; file_mode st_mode{};
file_nlink st_nlink; file_nlink st_nlink{};
user_id st_uid; user_id st_uid{};
group_id st_gid; group_id st_gid{};
file_time st_atimespec; file_time st_atimespec{};
file_time st_mtimespec; file_time st_mtimespec{};
file_time st_ctimespec; file_time st_ctimespec{};
file_time st_birthtimespec; file_time st_birthtimespec{};
file_size st_size; file_size st_size{};
block_count st_blocks; block_count st_blocks{};
block_size st_blksize; block_size st_blksize{};
std::uint32_t st_flags; std::uint32_t st_flags{};
}; };
struct statfs { struct statfs {
std::uint64_t f_bavail; std::uint64_t f_bavail{};
std::uint64_t f_bfree; std::uint64_t f_bfree{};
std::uint64_t f_blocks; std::uint64_t f_blocks{};
std::uint64_t f_favail; std::uint64_t f_favail{};
std::uint64_t f_ffree; std::uint64_t f_ffree{};
std::uint64_t f_files; std::uint64_t f_files{};
}; };
struct statfs_x : public statfs { struct statfs_x final : public statfs {
char f_mntfromname[1024]; std::array<char, 1024U> f_mntfromname{};
}; };
#pragma pack() #pragma pack()
@ -154,7 +157,7 @@ struct statfs_x : public statfs {
[[nodiscard]] auto [[nodiscard]] auto
create_os_open_flags(const open_flags &flags) -> std::uint32_t; create_os_open_flags(const open_flags &flags) -> std::uint32_t;
#endif #endif // !defined(_WIN32)
} // namespace repertory::remote } // namespace repertory::remote
#endif // INCLUDE_TYPES_REMOTE_HPP_ #endif // INCLUDE_TYPES_REMOTE_HPP_

View File

@ -23,26 +23,26 @@
#define INCLUDE_TYPES_REPERTORY_HPP_ #define INCLUDE_TYPES_REPERTORY_HPP_
namespace repertory { namespace repertory {
constexpr const auto max_time = 0xFFFFFFFFFFFFFFFFULL; inline constexpr const auto max_time{std::numeric_limits<std::uint64_t>::max()};
const std::string META_ACCESSED = "accessed"; inline constexpr const std::string META_ACCESSED{"accessed"};
const std::string META_ATTRIBUTES = "attributes"; inline constexpr const std::string META_ATTRIBUTES{"attributes"};
const std::string META_BACKUP = "backup"; inline constexpr const std::string META_BACKUP{"backup"};
const std::string META_CHANGED = "changed"; inline constexpr const std::string META_CHANGED{"changed"};
const std::string META_CREATION = "creation"; inline constexpr const std::string META_CREATION{"creation"};
const std::string META_DIRECTORY = "directory"; inline constexpr const std::string META_DIRECTORY{"directory"};
const std::string META_GID = "gid"; inline constexpr const std::string META_GID{"gid"};
const std::string META_KEY = "key"; inline constexpr const std::string META_KEY{"key"};
const std::string META_MODE = "mode"; inline constexpr const std::string META_MODE{"mode"};
const std::string META_MODIFIED = "modified"; inline constexpr const std::string META_MODIFIED{"modified"};
const std::string META_OSXFLAGS = "flags"; inline constexpr const std::string META_OSXFLAGS{"flags"};
const std::string META_PINNED = "pinned"; inline constexpr const std::string META_PINNED{"pinned"};
const std::string META_SIZE = "size"; inline constexpr const std::string META_SIZE{"size"};
const std::string META_SOURCE = "source"; inline constexpr const std::string META_SOURCE{"source"};
const std::string META_UID = "uid"; inline constexpr const std::string META_UID{"uid"};
const std::string META_WRITTEN = "written"; inline constexpr const std::string META_WRITTEN{"written"};
const std::vector<std::string> META_USED_NAMES = { inline constexpr const std::array<std::string, 16U> META_USED_NAMES = {
META_ACCESSED, META_ATTRIBUTES, META_BACKUP, META_CHANGED, META_ACCESSED, META_ATTRIBUTES, META_BACKUP, META_CHANGED,
META_CREATION, META_DIRECTORY, META_GID, META_KEY, META_CREATION, META_DIRECTORY, META_GID, META_KEY,
META_MODE, META_MODIFIED, META_OSXFLAGS, META_PINNED, META_MODE, META_MODIFIED, META_OSXFLAGS, META_PINNED,

View File

@ -79,8 +79,8 @@ struct head_object_result {
#else #else
strptime(date.c_str(), "%a, %d %b %Y %H:%M:%S %Z", &tm1); strptime(date.c_str(), "%a, %d %b %Y %H:%M:%S %Z", &tm1);
#endif #endif
last_modified = last_modified = static_cast<std::uint64_t>(mktime(&tm1)) *
static_cast<std::uint64_t>(mktime(&tm1)) * NANOS_PER_SECOND; utils::time::NANOS_PER_SECOND;
} }
return *this; return *this;
} }

View File

@ -26,10 +26,6 @@
#include "utils/file.hpp" #include "utils/file.hpp"
namespace repertory::utils::file { namespace repertory::utils::file {
// Prototypes
[[nodiscard]] auto calculate_used_space(std::string path,
bool recursive) -> std::uint64_t;
void change_to_process_directory(); void change_to_process_directory();
[[nodiscard]] auto copy_directory_recursively(std::string from_path, [[nodiscard]] auto copy_directory_recursively(std::string from_path,
@ -38,11 +34,6 @@ void change_to_process_directory();
[[nodiscard]] auto copy_file(std::string from_path, [[nodiscard]] auto copy_file(std::string from_path,
std::string to_path) -> bool; std::string to_path) -> bool;
[[nodiscard]] auto generate_sha256(const std::string &file_path) -> std::string;
[[nodiscard]] auto get_accessed_time(const std::string &path,
std::uint64_t &accessed) -> bool;
[[nodiscard]] auto [[nodiscard]] auto
get_directory_files(std::string path, bool oldest_first, get_directory_files(std::string path, bool oldest_first,
bool recursive = false) -> std::deque<std::string>; bool recursive = false) -> std::deque<std::string>;
@ -53,11 +44,8 @@ get_free_drive_space(const std::string &path) -> std::uint64_t;
[[nodiscard]] auto [[nodiscard]] auto
get_total_drive_space(const std::string &path) -> std::uint64_t; 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 [[nodiscard]] auto
is_modified_date_older_than(const std::string &path, is_modified_date_older_than(std::string_view path,
const std::chrono::hours &hours) -> bool; const std::chrono::hours &hours) -> bool;
[[nodiscard]] auto move_file(std::string from, std::string to) -> bool; [[nodiscard]] auto move_file(std::string from, std::string to) -> bool;
@ -66,10 +54,6 @@ is_modified_date_older_than(const std::string &path,
read_file_lines(const std::string &path) -> std::vector<std::string>; read_file_lines(const std::string &path) -> std::vector<std::string>;
[[nodiscard]] auto reset_modified_time(const std::string &path) -> bool; [[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;
} // namespace repertory::utils::file } // namespace repertory::utils::file
#endif // INCLUDE_UTILS_FILE_UTILS_HPP_ #endif // INCLUDE_UTILS_FILE_UTILS_HPP_

View File

@ -43,15 +43,9 @@ inline const std::array<std::string, 4U> attribute_namespaces = {
[[nodiscard]] auto unix_error_to_windows(int err) -> std::uint32_t; [[nodiscard]] auto unix_error_to_windows(int err) -> std::uint32_t;
[[nodiscard]] auto
unix_time_to_windows_time(const remote::file_time &file_time) -> UINT64;
void windows_create_to_unix(const UINT32 &create_options, void windows_create_to_unix(const UINT32 &create_options,
const UINT32 &granted_access, std::uint32_t &flags, const UINT32 &granted_access, std::uint32_t &flags,
remote::file_mode &mode); remote::file_mode &mode);
[[nodiscard]] auto
windows_time_to_unix_time(std::uint64_t win_time) -> remote::file_time;
} // namespace repertory::utils } // namespace repertory::utils
#endif // !_WIN32 #endif // !_WIN32

View File

@ -29,27 +29,10 @@ void calculate_allocation_size(bool directory, std::uint64_t file_size,
UINT64 allocation_size, UINT64 allocation_size,
std::string &allocation_meta_size); std::string &allocation_meta_size);
[[nodiscard]] auto convert_api_date(const std::string &date) -> std::uint64_t;
[[nodiscard]] auto create_curl() -> CURL *;
[[nodiscard]] auto [[nodiscard]] auto
create_volume_label(const provider_type &prov) -> std::string; create_volume_label(const provider_type &prov) -> std::string;
[[nodiscard]] auto get_attributes_from_meta(const api_meta_map &meta) -> DWORD; [[nodiscard]] auto get_attributes_from_meta(const api_meta_map &meta) -> DWORD;
[[nodiscard]] auto reset_curl(CURL *curl_handle) -> CURL *;
[[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,
const std::string &text = "");
void spin_wait_for_mutex(bool &complete, std::condition_variable &cond,
std::mutex &mtx, const std::string &text = "");
} // namespace repertory::utils } // namespace repertory::utils
#endif // INCLUDE_UTILS_UTILS_HPP_ #endif // INCLUDE_UTILS_UTILS_HPP_

View File

@ -92,6 +92,16 @@ auto curl_comm::construct_url(CURL *curl, const std::string &relative_path,
relative_path, url); relative_path, url);
} }
auto curl_comm::create_curl() -> CURL * { return reset_curl(curl_easy_init()); }
auto curl_comm::reset_curl(CURL *curl_handle) -> CURL * {
curl_easy_reset(curl_handle);
#if defined(__APPLE__)
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
#endif // defined(__APPLE__)
return curl_handle;
}
auto curl_comm::create_host_config(const s3_config &cfg, auto curl_comm::create_host_config(const s3_config &cfg,
bool use_s3_path_style) -> host_config { bool use_s3_path_style) -> host_config {
host_config host_cfg{}; host_config host_cfg{};

View File

@ -194,7 +194,7 @@ auto packet::decode(remote::statfs &val) -> packet::error_type {
auto packet::decode(remote::statfs_x &val) -> packet::error_type { auto packet::decode(remote::statfs_x &val) -> packet::error_type {
auto ret = decode(*dynamic_cast<remote::statfs *>(&val)); auto ret = decode(*dynamic_cast<remote::statfs *>(&val));
if (ret == 0) { if (ret == 0) {
ret = decode(&val.f_mntfromname[0U], sizeof(val.f_mntfromname)); ret = decode(val.f_mntfromname.data(), val.f_mntfromname.size());
} }
return ret; return ret;
} }
@ -372,9 +372,9 @@ void packet::encode(remote::statfs val, bool should_reserve) {
void packet::encode(remote::statfs_x val) { void packet::encode(remote::statfs_x val) {
buffer_.reserve(buffer_.size() + sizeof(remote::statfs) + buffer_.reserve(buffer_.size() + sizeof(remote::statfs) +
sizeof(val.f_mntfromname)); val.f_mntfromname.size());
encode(*dynamic_cast<remote::statfs *>(&val), false); encode(*dynamic_cast<remote::statfs *>(&val), false);
encode(&val.f_mntfromname[0], sizeof(val.f_mntfromname), false); encode(val.f_mntfromname.data(), val.f_mntfromname.size(), false);
} }
void packet::encode(remote::file_info val) { void packet::encode(remote::file_info val) {
@ -501,8 +501,8 @@ void packet::encode_top(remote::statfs val, bool should_reserve) {
void packet::encode_top(remote::statfs_x val) { void packet::encode_top(remote::statfs_x val) {
buffer_.reserve(buffer_.size() + sizeof(remote::statfs) + buffer_.reserve(buffer_.size() + sizeof(remote::statfs) +
sizeof(val.f_mntfromname)); val.f_mntfromname.size());
encode_top(&val.f_mntfromname[0], sizeof(val.f_mntfromname), false); encode_top(val.f_mntfromname.data(), val.f_mntfromname.size(), false);
encode_top(*dynamic_cast<remote::statfs *>(&val), false); encode_top(*dynamic_cast<remote::statfs *>(&val), false);
} }

View File

@ -46,30 +46,19 @@ auto eviction::check_minimum_requirements(const std::string &file_path)
} }
auto file_size{opt_size.value()}; auto file_size{opt_size.value()};
auto ret{false}; if (file_size == 0U) {
if (file_size != 0U) { return false;
std::uint64_t reference_time{};
ret = config_.get_eviction_uses_accessed_time()
? utils::file::get_accessed_time(file_path, reference_time)
: utils::file::get_modified_time(file_path, reference_time);
if (ret) {
#if defined(_WIN32)
const auto now = std::chrono::system_clock::now();
const auto delay =
std::chrono::minutes(config_.get_eviction_delay_mins());
ret = ((std::chrono::system_clock::from_time_t(
static_cast<time_t>(reference_time)) +
delay) <= now);
#else
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);
#endif
}
} }
return ret; auto reference_time = utils::file::file{file_path}.get_time(
config_.get_eviction_uses_accessed_time()
? utils::file::file::time_types::access
: utils::file::file::time_types::modified);
auto delay = (config_.get_eviction_delay_mins() * 60UL) *
utils::time::NANOS_PER_SECOND;
return ((reference_time + static_cast<std::uint64_t>(delay)) <=
utils::time::get_time_now());
} }
auto eviction::get_filtered_cached_files() -> std::deque<std::string> { auto eviction::get_filtered_cached_files() -> std::deque<std::string> {
@ -92,7 +81,7 @@ void eviction::service_function() {
// Handle maximum cache size eviction // Handle maximum cache size eviction
auto used_bytes = auto used_bytes =
utils::file::calculate_used_space(config_.get_cache_directory(), false); utils::file::directory{config_.get_cache_directory()}.size();
if (config_.get_enable_max_cache_size()) { if (config_.get_enable_max_cache_size()) {
should_evict = (used_bytes > config_.get_max_cache_size_bytes()); should_evict = (used_bytes > config_.get_max_cache_size_bytes());
} }

View File

@ -106,8 +106,8 @@ auto fuse_base::access_(const char *path, int mask) -> int {
}; };
return instance().instance().execute_callback( return instance().instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().access_impl(api_path, mask); return instance().access_impl(std::move(api_path), mask);
}); });
} }
@ -118,8 +118,8 @@ auto fuse_base::chflags_(const char *path, uint32_t flags) -> int {
}; };
return instance().instance().execute_callback( return instance().instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().chflags_impl(api_path, flags); return instance().chflags_impl(std::move(api_path), flags);
}); });
} }
#endif // __APPLE__ #endif // __APPLE__
@ -132,8 +132,8 @@ auto fuse_base::chmod_(const char *path, mode_t mode,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().chmod_impl(api_path, mode, fi); return instance().chmod_impl(std::move(api_path) mode, fi);
}); });
} }
#else #else
@ -143,8 +143,8 @@ auto fuse_base::chmod_(const char *path, mode_t mode) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().chmod_impl(api_path, mode); return instance().chmod_impl(std::move(api_path), mode);
}); });
} }
#endif #endif
@ -157,8 +157,8 @@ auto fuse_base::chown_(const char *path, uid_t uid, gid_t gid,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().chown_impl(api_path, uid, gid, fi); return instance().chown_impl(std::move(api_path), uid, gid, fi);
}); });
} }
#else #else
@ -168,8 +168,8 @@ auto fuse_base::chown_(const char *path, uid_t uid, gid_t gid) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().chown_impl(api_path, uid, gid); return instance().chown_impl(std::move(api_path), uid, gid);
}); });
} }
#endif #endif
@ -181,8 +181,8 @@ auto fuse_base::create_(const char *path, mode_t mode,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().create_impl(api_path, mode, fi); return instance().create_impl(std::move(api_path), mode, fi);
}); });
} }
@ -237,7 +237,7 @@ auto fuse_base::execute_callback(
auto fuse_base::execute_callback( auto fuse_base::execute_callback(
std::string_view function_name, const char *path, std::string_view function_name, const char *path,
const std::function<api_error(const std::string &api_path)> &cb, const std::function<api_error(std::string api_path)> &cb,
bool disable_logging) -> int { bool disable_logging) -> int {
const auto api_path = utils::path::create_api_path(path ? path : ""); const auto api_path = utils::path::create_api_path(path ? path : "");
const auto res = utils::from_api_error(cb(api_path)); const auto res = utils::from_api_error(cb(api_path));
@ -269,8 +269,9 @@ auto fuse_base::fallocate_(const char *path, int mode, off_t offset,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().fallocate_impl(api_path, mode, offset, length, fi); return instance().fallocate_impl(std::move(api_path), mode, offset,
length, fi);
}); });
} }
@ -282,8 +283,8 @@ auto fuse_base::fgetattr_(const char *path, struct stat *st,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().fgetattr_impl(api_path, st, fi); return instance().fgetattr_impl(std::move(api_path), st, fi);
}); });
} }
#endif #endif
@ -296,8 +297,8 @@ auto fuse_base::fsetattr_x_(const char *path, struct setattr_x *attr,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().fsetattr_x_impl(api_path, attr, fi); return instance().fsetattr_x_impl(std::move(api_path), attr, fi);
}); });
} }
#endif // __APPLE__ #endif // __APPLE__
@ -309,8 +310,8 @@ auto fuse_base::fsync_(const char *path, int datasync,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().fsync_impl(api_path, datasync, fi); return instance().fsync_impl(std::move(api_path), datasync, fi);
}); });
} }
@ -322,8 +323,8 @@ auto fuse_base::ftruncate_(const char *path, off_t size,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().ftruncate_impl(api_path, size, fi); return instance().ftruncate_impl(std::move(api_path), size, fi);
}); });
} }
#endif #endif
@ -336,8 +337,8 @@ auto fuse_base::getattr_(const char *path, struct stat *st,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().getattr_impl(api_path, st, fi); return instance().getattr_impl(std::move(api_path), st, fi);
}); });
} }
#else #else
@ -347,8 +348,8 @@ auto fuse_base::getattr_(const char *path, struct stat *st) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().getattr_impl(api_path, st); return instance().getattr_impl(std::move(api_path), st);
}); });
} }
#endif #endif
@ -361,8 +362,8 @@ auto fuse_base::getxtimes_(const char *path, struct timespec *bkuptime,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().getxtimes_impl(api_path, bkuptime, crtime); return instance().getxtimes_impl(std::move(api_path), bkuptime, crtime);
}); });
} }
#endif // __APPLE__ #endif // __APPLE__
@ -427,8 +428,8 @@ auto fuse_base::mkdir_(const char *path, mode_t mode) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().mkdir_impl(api_path, mode); return instance().mkdir_impl(std::move(api_path), mode);
}); });
} }
@ -486,8 +487,8 @@ auto fuse_base::open_(const char *path, struct fuse_file_info *fi) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().open_impl(api_path, fi); return instance().open_impl(std::move(api_path), fi);
}); });
} }
@ -497,8 +498,8 @@ auto fuse_base::opendir_(const char *path, struct fuse_file_info *fi) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().opendir_impl(api_path, fi); return instance().opendir_impl(std::move(api_path), fi);
}); });
} }
@ -511,9 +512,9 @@ auto fuse_base::read_(const char *path, char *buffer, size_t read_size,
std::size_t bytes_read{}; std::size_t bytes_read{};
const auto res = instance().execute_callback( const auto res = instance().execute_callback(
function_name, path, function_name, path,
[&](const std::string &api_path) -> api_error { [&](std::string api_path) -> api_error {
return instance().read_impl(api_path, buffer, read_size, read_offset, return instance().read_impl(std::move(api_path), buffer, read_size,
fi, bytes_read); read_offset, fi, bytes_read);
}, },
true); true);
return (res == 0) ? static_cast<int>(bytes_read) : res; return (res == 0) ? static_cast<int>(bytes_read) : res;
@ -529,9 +530,9 @@ auto fuse_base::readdir_(const char *path, void *buf,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().readdir_impl(api_path, buf, fuse_fill_dir, offset, fi, return instance().readdir_impl(std::move(api_path), buf, fuse_fill_dir,
flags); offset, fi, flags);
}); });
} }
#else #else
@ -543,9 +544,9 @@ auto fuse_base::readdir_(const char *path, void *buf,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().readdir_impl(api_path, buf, fuse_fill_dir, offset, return instance().readdir_impl(std::move(api_path), buf, fuse_fill_dir,
fi); offset, fi);
}); });
} }
#endif #endif
@ -556,8 +557,8 @@ auto fuse_base::release_(const char *path, struct fuse_file_info *fi) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().release_impl(api_path, fi); return instance().release_impl(std::move(api_path), fi);
}); });
} }
@ -568,8 +569,8 @@ auto fuse_base::releasedir_(const char *path,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().releasedir_impl(api_path, fi); return instance().releasedir_impl(std::move(api_path), fi);
}); });
} }
@ -608,8 +609,8 @@ auto fuse_base::rmdir_(const char *path) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().rmdir_impl(api_path); return instance().rmdir_impl(std::move(api_path));
}); });
} }
@ -623,9 +624,9 @@ auto fuse_base::getxattr_(const char *path, const char *name, char *value,
int attribute_size = 0; int attribute_size = 0;
const auto res = instance().execute_callback( const auto res = instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().getxattr_impl(api_path, name, value, size, position, return instance().getxattr_impl(std::move(api_path), name, value, size,
attribute_size); position, attribute_size);
}); });
return res == 0 ? attribute_size : res; return res == 0 ? attribute_size : res;
@ -639,8 +640,8 @@ auto fuse_base::getxattr_(const char *path, const char *name, char *value,
int attribute_size = 0; int attribute_size = 0;
const auto res = instance().execute_callback( const auto res = instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().getxattr_impl(api_path, name, value, size, return instance().getxattr_impl(std::move(api_path), name, value, size,
attribute_size); attribute_size);
}); });
@ -657,9 +658,9 @@ auto fuse_base::listxattr_(const char *path, char *buffer, size_t size) -> int {
bool return_size = false; bool return_size = false;
const auto res = instance().execute_callback( const auto res = instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().listxattr_impl(api_path, buffer, size, required_size, return instance().listxattr_impl(std::move(api_path), buffer, size,
return_size); required_size, return_size);
}); });
return return_size ? required_size : res; return return_size ? required_size : res;
@ -752,7 +753,7 @@ auto fuse_base::parse_args(std::vector<std::string> &args) -> int {
} }
void fuse_base::raise_fuse_event(std::string_view function_name, void fuse_base::raise_fuse_event(std::string_view function_name,
const std::string &api_path, int ret, std::string_view api_path, int ret,
bool disable_logging) { bool disable_logging) {
if ((ret >= 0) && disable_logging) { if ((ret >= 0) && disable_logging) {
return; return;
@ -766,7 +767,7 @@ void fuse_base::raise_fuse_event(std::string_view function_name,
(config_.get_event_level() >= event_level::trace)) { (config_.get_event_level() >= event_level::trace)) {
std::string func{function_name}; std::string func{function_name};
event_system::instance().raise<fuse_event>( event_system::instance().raise<fuse_event>(
utils::string::right_trim(func, '_'), api_path, ret); utils::string::right_trim(func, '_'), std::string{api_path}, ret);
} }
} }
@ -776,8 +777,8 @@ auto fuse_base::removexattr_(const char *path, const char *name) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().removexattr_impl(api_path, name); return instance().removexattr_impl(std::move(api_path), name);
}); });
} }
@ -789,9 +790,9 @@ auto fuse_base::setxattr_(const char *path, const char *name, const char *value,
}; };
const auto res = instance().execute_callback( const auto res = instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().setxattr_impl(api_path, name, value, size, flags, return instance().setxattr_impl(std::move(api_path), name, value, size,
position); flags, position);
}); });
if (res != 0) { if (res != 0) {
errno = std::abs(res); errno = std::abs(res);
@ -807,8 +808,9 @@ auto fuse_base::setxattr_(const char *path, const char *name, const char *value,
}; };
const auto res = instance().execute_callback( const auto res = instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().setxattr_impl(api_path, name, value, size, flags); return instance().setxattr_impl(std::move(api_path), name, value, size,
flags);
}); });
if (res != 0) { if (res != 0) {
errno = std::abs(res); errno = std::abs(res);
@ -832,8 +834,8 @@ auto fuse_base::setattr_x_(const char *path, struct setattr_x *attr) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().setattr_x_impl(api_path, attr); return instance().setattr_x_impl(std::move(api_path), attr);
}); });
} }
@ -844,8 +846,8 @@ auto fuse_base::setbkuptime_(const char *path,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().setbkuptime_impl(api_path, bkuptime); return instance().setbkuptime_impl(std::move(api_path), bkuptime);
}); });
} }
@ -856,8 +858,8 @@ auto fuse_base::setchgtime_(const char *path,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().setchgtime_impl(api_path, chgtime); return instance().setchgtime_impl(std::move(api_path), chgtime);
}); });
} }
@ -868,8 +870,8 @@ auto fuse_base::setcrtime_(const char *path,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().setcrtime_impl(api_path, crtime); return instance().setcrtime_impl(std::move(api_path), crtime);
}); });
} }
@ -879,8 +881,8 @@ auto fuse_base::setvolname_(const char *volname) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, volname, [&](const std::string &api_path) -> api_error { function_name, volname, [&](std::string api_path) -> api_error {
return instance().setvolname_impl(volname); return instance().setvolname_impl(std::move(volname));
}); });
} }
@ -890,8 +892,8 @@ auto fuse_base::statfs_x_(const char *path, struct statfs *stbuf) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().statfs_x_impl(api_path, stbuf); return instance().statfs_x_impl(std::move(api_path), stbuf);
}); });
} }
#else // __APPLE__ #else // __APPLE__
@ -901,8 +903,8 @@ auto fuse_base::statfs_(const char *path, struct statvfs *stbuf) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().statfs_impl(api_path, stbuf); return instance().statfs_impl(std::move(api_path), stbuf);
}); });
} }
#endif // __APPLE__ #endif // __APPLE__
@ -915,8 +917,8 @@ auto fuse_base::truncate_(const char *path, off_t size,
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().truncate_impl(api_path, size, fi); return instance().truncate_impl(std::move(api_path), size, fi);
}); });
} }
#else #else
@ -926,8 +928,8 @@ auto fuse_base::truncate_(const char *path, off_t size) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().truncate_impl(api_path, size); return instance().truncate_impl(std::move(api_path), size);
}); });
} }
#endif #endif
@ -938,8 +940,8 @@ auto fuse_base::unlink_(const char *path) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().unlink_impl(api_path); return instance().unlink_impl(std::move(api_path));
}); });
} }
@ -965,8 +967,8 @@ auto fuse_base::utimens_(const char *path, const struct timespec tv[2],
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().utimens_impl(api_path, tv, fi); return instance().utimens_impl(std::move(api_path), tv, fi);
}); });
} }
#else #else
@ -976,8 +978,8 @@ auto fuse_base::utimens_(const char *path, const struct timespec tv[2]) -> int {
}; };
return instance().execute_callback( return instance().execute_callback(
function_name, path, [&](const std::string &api_path) -> api_error { function_name, path, [&](std::string api_path) -> api_error {
return instance().utimens_impl(api_path, tv); return instance().utimens_impl(std::move(api_path), tv);
}); });
} }
#endif #endif
@ -992,9 +994,9 @@ auto fuse_base::write_(const char *path, const char *buffer, size_t write_size,
const auto res = instance().execute_callback( const auto res = instance().execute_callback(
function_name, path, function_name, path,
[&](const std::string &api_path) -> api_error { [&](std::string api_path) -> api_error {
return instance().write_impl(api_path, buffer, write_size, write_offset, return instance().write_impl(std::move(api_path), buffer, write_size,
fi, bytes_written); write_offset, fi, bytes_written);
}, },
true); true);
return (res == 0) ? static_cast<int>(bytes_written) : res; return (res == 0) ? static_cast<int>(bytes_written) : res;

View File

@ -299,7 +299,7 @@ void fuse_drive_base::populate_stat(const std::string &api_path,
std::uint64_t size_or_count, std::uint64_t size_or_count,
const api_meta_map &meta, bool directory, const api_meta_map &meta, bool directory,
i_provider &provider, struct stat *st) { i_provider &provider, struct stat *st) {
memset(st, 0, sizeof(struct stat)); std::memset(st, 0, sizeof(struct stat));
st->st_nlink = static_cast<nlink_t>( st->st_nlink = static_cast<nlink_t>(
directory ? 2 + (size_or_count == 0U directory ? 2 + (size_or_count == 0U
? provider.get_directory_item_count(api_path) ? provider.get_directory_item_count(api_path)

View File

@ -36,6 +36,7 @@
#include "utils/error_utils.hpp" #include "utils/error_utils.hpp"
#include "utils/file_utils.hpp" #include "utils/file_utils.hpp"
#include "utils/path.hpp" #include "utils/path.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp" #include "utils/utils.hpp"
namespace repertory::remote_fuse { namespace repertory::remote_fuse {
@ -142,16 +143,17 @@ api_error remote_fuse_drive::fsetattr_x_impl(std::string api_path,
attributes.uid = attr->uid; attributes.uid = attr->uid;
attributes.gid = attr->gid; attributes.gid = attr->gid;
attributes.size = attr->size; attributes.size = attr->size;
attributes.acctime = attributes.acctime = ((attr->acctime.tv_sec * utils::time::NANOS_PER_SECOND) +
((attr->acctime.tv_sec * NANOS_PER_SECOND) + attr->acctime.tv_nsec); attr->acctime.tv_nsec);
attributes.modtime = attributes.modtime = ((attr->modtime.tv_sec * utils::time::NANOS_PER_SECOND) +
((attr->modtime.tv_sec * NANOS_PER_SECOND) + attr->modtime.tv_nsec); attr->modtime.tv_nsec);
attributes.crtime = attributes.crtime = ((attr->crtime.tv_sec * utils::time::NANOS_PER_SECOND) +
((attr->crtime.tv_sec * NANOS_PER_SECOND) + attr->crtime.tv_nsec); attr->crtime.tv_nsec);
attributes.chgtime = attributes.chgtime = ((attr->chgtime.tv_sec * utils::time::NANOS_PER_SECOND) +
((attr->chgtime.tv_sec * NANOS_PER_SECOND) + attr->chgtime.tv_nsec); attr->chgtime.tv_nsec);
attributes.bkuptime = attributes.bkuptime =
((attr->bkuptime.tv_sec * NANOS_PER_SECOND) + attr->bkuptime.tv_nsec); ((attr->bkuptime.tv_sec * utils::time::NANOS_PER_SECOND) +
attr->bkuptime.tv_nsec);
attributes.flags = attr->flags; attributes.flags = attr->flags;
return utils::to_api_error(remote_instance_->fuse_fsetattr_x( return utils::to_api_error(remote_instance_->fuse_fsetattr_x(
api_path.c_str(), attributes, f_info->fh)); api_path.c_str(), attributes, f_info->fh));
@ -208,10 +210,11 @@ api_error remote_fuse_drive::getxtimes_impl(std::string api_path,
api_path.c_str(), repertory_bkuptime, repertory_crtime); api_path.c_str(), repertory_bkuptime, repertory_crtime);
if (res == 0) { if (res == 0) {
bkuptime->tv_nsec = bkuptime->tv_nsec =
static_cast<long>(repertory_bkuptime % NANOS_PER_SECOND); static_cast<long>(repertory_bkuptime % utils::time::NANOS_PER_SECOND);
bkuptime->tv_sec = repertory_bkuptime / NANOS_PER_SECOND; bkuptime->tv_sec = repertory_bkuptime / utils::time::NANOS_PER_SECOND;
crtime->tv_nsec = static_cast<long>(repertory_crtime % NANOS_PER_SECOND); crtime->tv_nsec =
crtime->tv_sec = repertory_crtime / NANOS_PER_SECOND; static_cast<long>(repertory_crtime % utils::time::NANOS_PER_SECOND);
crtime->tv_sec = repertory_crtime / utils::time::NANOS_PER_SECOND;
} }
return utils::to_api_error(res); return utils::to_api_error(res);
@ -296,42 +299,51 @@ auto remote_fuse_drive::opendir_impl(
void remote_fuse_drive::populate_stat(const remote::stat &r_stat, void remote_fuse_drive::populate_stat(const remote::stat &r_stat,
bool directory, struct stat &unix_st) { bool directory, struct stat &unix_st) {
memset(&unix_st, 0, sizeof(struct stat)); std::memset(&unix_st, 0, sizeof(struct stat));
#if defined(__APPLE__) #if defined(__APPLE__)
unix_st.st_blksize = 0; unix_st.st_blksize = 0;
unix_st.st_atimespec.tv_nsec = r_stat.st_atimespec % NANOS_PER_SECOND; unix_st.st_atimespec.tv_nsec =
unix_st.st_atimespec.tv_sec = r_stat.st_atimespec / NANOS_PER_SECOND; r_stat.st_atimespec % utils::time::NANOS_PER_SECOND;
unix_st.st_atimespec.tv_sec =
r_stat.st_atimespec / utils::time::NANOS_PER_SECOND;
unix_st.st_birthtimespec.tv_nsec = r_stat.st_birthtimespec % NANOS_PER_SECOND; unix_st.st_birthtimespec.tv_nsec =
unix_st.st_birthtimespec.tv_sec = r_stat.st_birthtimespec / NANOS_PER_SECOND; r_stat.st_birthtimespec % utils::time::NANOS_PER_SECOND;
unix_st.st_birthtimespec.tv_sec =
r_stat.st_birthtimespec / utils::time::NANOS_PER_SECOND;
unix_st.st_ctimespec.tv_nsec = r_stat.st_ctimespec % NANOS_PER_SECOND; unix_st.st_ctimespec.tv_nsec =
unix_st.st_ctimespec.tv_sec = r_stat.st_ctimespec / NANOS_PER_SECOND; r_stat.st_ctimespec % utils::time::NANOS_PER_SECOND;
unix_st.st_ctimespec.tv_sec =
r_stat.st_ctimespec / utils::time::NANOS_PER_SECOND;
unix_st.st_mtimespec.tv_nsec = r_stat.st_mtimespec % NANOS_PER_SECOND; unix_st.st_mtimespec.tv_nsec =
unix_st.st_mtimespec.tv_sec = r_stat.st_mtimespec / NANOS_PER_SECOND; r_stat.st_mtimespec % utils::time::NANOS_PER_SECOND;
unix_st.st_mtimespec.tv_sec =
r_stat.st_mtimespec / utils::time::NANOS_PER_SECOND;
unix_st.st_flags = r_stat.st_flags; unix_st.st_flags = r_stat.st_flags;
#else #else // !defined(__APPLE__)
unix_st.st_blksize = 4096; unix_st.st_blksize = 4096;
unix_st.st_atim.tv_nsec = unix_st.st_atim.tv_nsec = static_cast<suseconds_t>(
static_cast<suseconds_t>(r_stat.st_atimespec % NANOS_PER_SECOND); r_stat.st_atimespec % utils::time::NANOS_PER_SECOND);
unix_st.st_atim.tv_sec = unix_st.st_atim.tv_sec = static_cast<suseconds_t>(
static_cast<suseconds_t>(r_stat.st_atimespec / NANOS_PER_SECOND); r_stat.st_atimespec / utils::time::NANOS_PER_SECOND);
unix_st.st_ctim.tv_nsec = unix_st.st_ctim.tv_nsec = static_cast<suseconds_t>(
static_cast<suseconds_t>(r_stat.st_ctimespec % NANOS_PER_SECOND); r_stat.st_ctimespec % utils::time::NANOS_PER_SECOND);
unix_st.st_ctim.tv_sec = unix_st.st_ctim.tv_sec = static_cast<suseconds_t>(
static_cast<suseconds_t>(r_stat.st_ctimespec / NANOS_PER_SECOND); r_stat.st_ctimespec / utils::time::NANOS_PER_SECOND);
unix_st.st_mtim.tv_nsec = static_cast<suseconds_t>(
r_stat.st_mtimespec % utils::time::NANOS_PER_SECOND);
unix_st.st_mtim.tv_sec = static_cast<suseconds_t>(
r_stat.st_mtimespec / utils::time::NANOS_PER_SECOND);
#endif // defined(__APPLE__)
unix_st.st_mtim.tv_nsec =
static_cast<suseconds_t>(r_stat.st_mtimespec % NANOS_PER_SECOND);
unix_st.st_mtim.tv_sec =
static_cast<suseconds_t>(r_stat.st_mtimespec / NANOS_PER_SECOND);
#endif
if (not directory) { if (not directory) {
const auto block_size_stat = static_cast<std::uint64_t>(512U); const auto block_size_stat = static_cast<std::uint64_t>(512U);
const auto block_size = static_cast<std::uint64_t>(4096U); const auto block_size = static_cast<std::uint64_t>(4096U);
@ -440,16 +452,17 @@ api_error remote_fuse_drive::setattr_x_impl(std::string api_path,
attributes.uid = attr->uid; attributes.uid = attr->uid;
attributes.gid = attr->gid; attributes.gid = attr->gid;
attributes.size = attr->size; attributes.size = attr->size;
attributes.acctime = attributes.acctime = ((attr->acctime.tv_sec * utils::time::NANOS_PER_SECOND) +
((attr->acctime.tv_sec * NANOS_PER_SECOND) + attr->acctime.tv_nsec); attr->acctime.tv_nsec);
attributes.modtime = attributes.modtime = ((attr->modtime.tv_sec * utils::time::NANOS_PER_SECOND) +
((attr->modtime.tv_sec * NANOS_PER_SECOND) + attr->modtime.tv_nsec); attr->modtime.tv_nsec);
attributes.crtime = attributes.crtime = ((attr->crtime.tv_sec * utils::time::NANOS_PER_SECOND) +
((attr->crtime.tv_sec * NANOS_PER_SECOND) + attr->crtime.tv_nsec); attr->crtime.tv_nsec);
attributes.chgtime = attributes.chgtime = ((attr->chgtime.tv_sec * utils::time::NANOS_PER_SECOND) +
((attr->chgtime.tv_sec * NANOS_PER_SECOND) + attr->chgtime.tv_nsec); attr->chgtime.tv_nsec);
attributes.bkuptime = attributes.bkuptime =
((attr->bkuptime.tv_sec * NANOS_PER_SECOND) + attr->bkuptime.tv_nsec); ((attr->bkuptime.tv_sec * utils::time::NANOS_PER_SECOND) +
attr->bkuptime.tv_nsec);
attributes.flags = attr->flags; attributes.flags = attr->flags;
return utils::to_api_error( return utils::to_api_error(
remote_instance_->fuse_setattr_x(api_path.c_str(), attributes)); remote_instance_->fuse_setattr_x(api_path.c_str(), attributes));
@ -458,7 +471,7 @@ api_error remote_fuse_drive::setattr_x_impl(std::string api_path,
api_error remote_fuse_drive::setbkuptime_impl(std::string api_path, api_error remote_fuse_drive::setbkuptime_impl(std::string api_path,
const struct timespec *bkuptime) { const struct timespec *bkuptime) {
remote::file_time repertory_bkuptime = remote::file_time repertory_bkuptime =
((bkuptime->tv_sec * NANOS_PER_SECOND) + bkuptime->tv_nsec); ((bkuptime->tv_sec * utils::time::NANOS_PER_SECOND) + bkuptime->tv_nsec);
return utils::to_api_error( return utils::to_api_error(
remote_instance_->fuse_setbkuptime(api_path.c_str(), repertory_bkuptime)); remote_instance_->fuse_setbkuptime(api_path.c_str(), repertory_bkuptime));
} }
@ -466,7 +479,7 @@ api_error remote_fuse_drive::setbkuptime_impl(std::string api_path,
api_error remote_fuse_drive::setchgtime_impl(std::string api_path, api_error remote_fuse_drive::setchgtime_impl(std::string api_path,
const struct timespec *chgtime) { const struct timespec *chgtime) {
remote::file_time repertory_chgtime = remote::file_time repertory_chgtime =
((chgtime->tv_sec * NANOS_PER_SECOND) + chgtime->tv_nsec); ((chgtime->tv_sec * utils::time::NANOS_PER_SECOND) + chgtime->tv_nsec);
return utils::to_api_error( return utils::to_api_error(
remote_instance_->fuse_setchgtime(api_path.c_str(), repertory_chgtime)); remote_instance_->fuse_setchgtime(api_path.c_str(), repertory_chgtime));
} }
@ -474,7 +487,7 @@ api_error remote_fuse_drive::setchgtime_impl(std::string api_path,
api_error remote_fuse_drive::setcrtime_impl(std::string api_path, api_error remote_fuse_drive::setcrtime_impl(std::string api_path,
const struct timespec *crtime) { const struct timespec *crtime) {
remote::file_time repertory_crtime = remote::file_time repertory_crtime =
((crtime->tv_sec * NANOS_PER_SECOND) + crtime->tv_nsec); ((crtime->tv_sec * utils::time::NANOS_PER_SECOND) + crtime->tv_nsec);
return utils::to_api_error( return utils::to_api_error(
remote_instance_->fuse_setcrtime(api_path.c_str(), repertory_crtime)); remote_instance_->fuse_setcrtime(api_path.c_str(), repertory_crtime));
} }
@ -556,9 +569,9 @@ auto remote_fuse_drive::utimens_impl(std::string api_path,
remote::file_time rtv[2U] = {0}; remote::file_time rtv[2U] = {0};
if (tv != nullptr) { if (tv != nullptr) {
rtv[0U] = static_cast<remote::file_time>( rtv[0U] = static_cast<remote::file_time>(
tv[0U].tv_nsec + (tv[0U].tv_sec * NANOS_PER_SECOND)); tv[0U].tv_nsec + (tv[0U].tv_sec * utils::time::NANOS_PER_SECOND));
rtv[1U] = static_cast<remote::file_time>( rtv[1U] = static_cast<remote::file_time>(
tv[1U].tv_nsec + (tv[1U].tv_sec * NANOS_PER_SECOND)); tv[1U].tv_nsec + (tv[1U].tv_sec * utils::time::NANOS_PER_SECOND));
} }
return utils::to_api_error(remote_instance_->fuse_utimens( return utils::to_api_error(remote_instance_->fuse_utimens(

View File

@ -125,18 +125,18 @@ void remote_server::populate_file_info(const std::string &api_path,
file_info.AllocationSize = file_info.AllocationSize =
utils::divide_with_ceiling(file_size, WINFSP_ALLOCATION_UNIT) * utils::divide_with_ceiling(file_size, WINFSP_ALLOCATION_UNIT) *
WINFSP_ALLOCATION_UNIT; WINFSP_ALLOCATION_UNIT;
file_info.ChangeTime = utils::unix_time_to_windows_time( file_info.ChangeTime = utils::time::unix_time_to_windows_time(
utils::string::to_uint64(empty_as_zero(meta[META_MODIFIED]))); utils::string::to_uint64(empty_as_zero(meta[META_MODIFIED])));
file_info.CreationTime = utils::unix_time_to_windows_time( file_info.CreationTime = utils::time::unix_time_to_windows_time(
utils::string::to_uint64(empty_as_zero(meta[META_CREATION]))); utils::string::to_uint64(empty_as_zero(meta[META_CREATION])));
file_info.EaSize = 0; file_info.EaSize = 0;
file_info.FileAttributes = attributes; file_info.FileAttributes = attributes;
file_info.FileSize = file_size; file_info.FileSize = file_size;
file_info.HardLinks = 0; file_info.HardLinks = 0;
file_info.IndexNumber = 0; file_info.IndexNumber = 0;
file_info.LastAccessTime = utils::unix_time_to_windows_time( file_info.LastAccessTime = utils::time::unix_time_to_windows_time(
utils::string::to_uint64(empty_as_zero(meta[META_ACCESSED]))); utils::string::to_uint64(empty_as_zero(meta[META_ACCESSED])));
file_info.LastWriteTime = utils::unix_time_to_windows_time( file_info.LastWriteTime = utils::time::unix_time_to_windows_time(
utils::string::to_uint64(empty_as_zero(meta[META_WRITTEN]))); utils::string::to_uint64(empty_as_zero(meta[META_WRITTEN])));
if (meta[META_WRITTEN].empty() || (meta[META_WRITTEN] == "0") || if (meta[META_WRITTEN].empty() || (meta[META_WRITTEN] == "0") ||
(meta[META_WRITTEN] == "116444736000000000")) { (meta[META_WRITTEN] == "116444736000000000")) {
@ -148,30 +148,38 @@ void remote_server::populate_file_info(const std::string &api_path,
void remote_server::populate_stat(const struct stat64 &unix_st, void remote_server::populate_stat(const struct stat64 &unix_st,
remote::stat &r_stat) { remote::stat &r_stat) {
memset(&r_stat, 0, sizeof(r_stat)); r_stat = {};
#if defined(__APPLE__) #if defined(__APPLE__)
r_stat.st_flags = unix_st.st_flags; r_stat.st_flags = unix_st.st_flags;
r_stat.st_atimespec = unix_st.st_atimespec.tv_nsec + r_stat.st_atimespec =
(unix_st.st_atimespec.tv_sec * NANOS_PER_SECOND); unix_st.st_atimespec.tv_nsec +
(unix_st.st_atimespec.tv_sec * utils::time::NANOS_PER_SECOND);
r_stat.st_birthtimespec = r_stat.st_birthtimespec =
unix_st.st_birthtimespec.tv_nsec + unix_st.st_birthtimespec.tv_nsec +
(unix_st.st_birthtimespec.tv_sec * NANOS_PER_SECOND); (unix_st.st_birthtimespec.tv_sec * utils::time::NANOS_PER_SECOND);
r_stat.st_ctimespec = unix_st.st_ctimespec.tv_nsec + r_stat.st_ctimespec =
(unix_st.st_ctimespec.tv_sec * NANOS_PER_SECOND); unix_st.st_ctimespec.tv_nsec +
r_stat.st_mtimespec = unix_st.st_mtimespec.tv_nsec + (unix_st.st_ctimespec.tv_sec * utils::time::NANOS_PER_SECOND);
(unix_st.st_mtimespec.tv_sec * NANOS_PER_SECOND); r_stat.st_mtimespec =
unix_st.st_mtimespec.tv_nsec +
(unix_st.st_mtimespec.tv_sec * utils::time::NANOS_PER_SECOND);
#else // !defined(__APPLE__) #else // !defined(__APPLE__)
r_stat.st_flags = 0; r_stat.st_flags = 0;
r_stat.st_atimespec = static_cast<remote::file_time>( r_stat.st_atimespec = static_cast<remote::file_time>(
unix_st.st_atim.tv_nsec + (unix_st.st_atim.tv_sec * NANOS_PER_SECOND)); unix_st.st_atim.tv_nsec +
(unix_st.st_atim.tv_sec * utils::time::NANOS_PER_SECOND));
r_stat.st_birthtimespec = static_cast<remote::file_time>( r_stat.st_birthtimespec = static_cast<remote::file_time>(
unix_st.st_ctim.tv_nsec + (unix_st.st_ctim.tv_sec * NANOS_PER_SECOND)); unix_st.st_ctim.tv_nsec +
(unix_st.st_ctim.tv_sec * utils::time::NANOS_PER_SECOND));
r_stat.st_ctimespec = static_cast<remote::file_time>( r_stat.st_ctimespec = static_cast<remote::file_time>(
unix_st.st_ctim.tv_nsec + (unix_st.st_ctim.tv_sec * NANOS_PER_SECOND)); unix_st.st_ctim.tv_nsec +
(unix_st.st_ctim.tv_sec * utils::time::NANOS_PER_SECOND));
r_stat.st_mtimespec = static_cast<remote::file_time>( r_stat.st_mtimespec = static_cast<remote::file_time>(
unix_st.st_mtim.tv_nsec + (unix_st.st_mtim.tv_sec * NANOS_PER_SECOND)); unix_st.st_mtim.tv_nsec +
(unix_st.st_mtim.tv_sec * utils::time::NANOS_PER_SECOND));
#endif // defined(__APPLE__) #endif // defined(__APPLE__)
r_stat.st_blksize = static_cast<remote::block_size>(unix_st.st_blksize); r_stat.st_blksize = static_cast<remote::block_size>(unix_st.st_blksize);
r_stat.st_blocks = static_cast<remote::block_count>(unix_st.st_blocks); r_stat.st_blocks = static_cast<remote::block_count>(unix_st.st_blocks);
@ -320,8 +328,9 @@ auto remote_server::fuse_fgetattr(
static_cast<const char *>(__FUNCTION__), static_cast<const char *>(__FUNCTION__),
}; };
r_stat = {};
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
memset(&r_stat, 0, sizeof(remote::stat));
auto res = has_open_info(static_cast<native_handle>(handle), EBADF); auto res = has_open_info(static_cast<native_handle>(handle), EBADF);
if (res == 0) { if (res == 0) {
@ -406,16 +415,18 @@ auto remote_server::fuse_fsetattr_x(
if (SETATTR_WANTS_MODTIME(&attr)) { if (SETATTR_WANTS_MODTIME(&attr)) {
struct timeval val[2]; struct timeval val[2];
if (SETATTR_WANTS_ACCTIME(&attr)) { if (SETATTR_WANTS_ACCTIME(&attr)) {
val[0U].tv_sec = static_cast<time_t>(attr.acctime / NANOS_PER_SECOND); val[0U].tv_sec =
val[0U].tv_usec = static_cast<time_t>(attr.acctime / utils::time::NANOS_PER_SECOND);
static_cast<time_t>((attr.acctime % NANOS_PER_SECOND) / 1000); val[0U].tv_usec = static_cast<time_t>(
(attr.acctime % utils::time::NANOS_PER_SECOND) / 1000);
} else { } else {
gettimeofday(&val[0U], nullptr); gettimeofday(&val[0U], nullptr);
} }
val[1U].tv_sec = static_cast<time_t>(attr.modtime / NANOS_PER_SECOND); val[1U].tv_sec =
val[1U].tv_usec = static_cast<time_t>(attr.modtime / utils::time::NANOS_PER_SECOND);
static_cast<time_t>((attr.modtime % NANOS_PER_SECOND) / 1000); val[1U].tv_usec = static_cast<time_t>(
(attr.modtime % utils::time::NANOS_PER_SECOND) / 1000);
res = utimes(file_path.c_str(), &val[0U]); res = utimes(file_path.c_str(), &val[0U]);
} }
@ -487,7 +498,8 @@ auto remote_server::fuse_getattr(const char *path, remote::stat &r_stat,
const auto api_path = utils::path::create_api_path(path); const auto api_path = utils::path::create_api_path(path);
const auto file_path = construct_path(api_path); const auto file_path = construct_path(api_path);
const auto parent_api_path = utils::path::get_parent_api_path(api_path); const auto parent_api_path = utils::path::get_parent_api_path(api_path);
memset(&r_stat, 0, sizeof(remote::stat));
r_stat = {};
directory = utils::file::directory(file_path).exists(); directory = utils::file::directory(file_path).exists();
@ -950,10 +962,10 @@ auto remote_server::fuse_statfs_x(const char *path, std::uint64_t bsize,
r_stat.f_blocks ? (r_stat.f_blocks - used_blocks) : 0; r_stat.f_blocks ? (r_stat.f_blocks - used_blocks) : 0;
r_stat.f_ffree = r_stat.f_favail = r_stat.f_ffree = r_stat.f_favail =
r_stat.f_files - drive_.get_total_item_count(); r_stat.f_files - drive_.get_total_item_count();
std::memset(&r_stat.f_mntfromname[0U], 0, sizeof(r_stat.f_mntfromname)); std::memset(r_stat.f_mntfromname.data(), 0, r_stat.f_mntfromname.size());
strncpy(&r_stat.f_mntfromname[0U], strncpy(r_stat.f_mntfromname.data(),
(utils::create_volume_label(config_.get_provider_type())).c_str(), (utils::create_volume_label(config_.get_provider_type())).c_str(),
sizeof(r_stat.f_mntfromname) - 1U); r_stat.f_mntfromname.size() - 1U);
RAISE_REMOTE_FUSE_SERVER_EVENT(function_name, file_path, 0); RAISE_REMOTE_FUSE_SERVER_EVENT(function_name, file_path, 0);
return 0; return 0;
@ -998,16 +1010,20 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
tv2[0U].tv_nsec = static_cast<time_t>(op0); tv2[0U].tv_nsec = static_cast<time_t>(op0);
tv2[0U].tv_sec = 0; tv2[0U].tv_sec = 0;
} else { } else {
tv2[0U].tv_nsec = static_cast<time_t>(tv[0U] % NANOS_PER_SECOND); tv2[0U].tv_nsec =
tv2[0U].tv_sec = static_cast<time_t>(tv[0U] / NANOS_PER_SECOND); static_cast<time_t>(tv[0U] % utils::time::NANOS_PER_SECOND);
tv2[0U].tv_sec =
static_cast<time_t>(tv[0U] / utils::time::NANOS_PER_SECOND);
} }
if ((op1 == UTIME_NOW) || (op1 == UTIME_OMIT)) { if ((op1 == UTIME_NOW) || (op1 == UTIME_OMIT)) {
tv2[1U].tv_nsec = static_cast<time_t>(op1); tv2[1U].tv_nsec = static_cast<time_t>(op1);
tv2[1U].tv_sec = 0; tv2[1U].tv_sec = 0;
} else { } else {
tv2[1U].tv_nsec = static_cast<time_t>(tv[1U] % NANOS_PER_SECOND); tv2[1U].tv_nsec =
tv2[1U].tv_sec = static_cast<time_t>(tv[1U] / NANOS_PER_SECOND); static_cast<time_t>(tv[1U] % utils::time::NANOS_PER_SECOND);
tv2[1U].tv_sec =
static_cast<time_t>(tv[1U] / utils::time::NANOS_PER_SECOND);
} }
const auto res = const auto res =
@ -1543,25 +1559,28 @@ auto remote_server::winfsp_set_basic_info(
if ((creation_time != 0U) && (creation_time != max_time)) { if ((creation_time != 0U) && (creation_time != max_time)) {
drive_.set_item_meta( drive_.set_item_meta(
api_path, META_CREATION, api_path, META_CREATION,
std::to_string(utils::windows_time_to_unix_time(creation_time))); std::to_string(
utils::time::windows_time_to_unix_time(creation_time)));
} }
if ((last_access_time != 0U) && (last_access_time != max_time)) { if ((last_access_time != 0U) && (last_access_time != max_time)) {
drive_.set_item_meta( drive_.set_item_meta(
api_path, META_ACCESSED, api_path, META_ACCESSED,
std::to_string(utils::windows_time_to_unix_time(last_access_time))); std::to_string(
utils::time::windows_time_to_unix_time(last_access_time)));
} }
if ((last_write_time != 0U) && (last_write_time != max_time)) { if ((last_write_time != 0U) && (last_write_time != max_time)) {
drive_.set_item_meta( drive_.set_item_meta(
api_path, META_WRITTEN, api_path, META_WRITTEN,
std::to_string(utils::windows_time_to_unix_time(last_write_time))); std::to_string(
utils::time::windows_time_to_unix_time(last_write_time)));
} }
if ((change_time != 0U) && (change_time != max_time)) { if ((change_time != 0U) && (change_time != max_time)) {
drive_.set_item_meta( drive_.set_item_meta(
api_path, META_MODIFIED, api_path, META_MODIFIED,
std::to_string(utils::windows_time_to_unix_time(change_time))); std::to_string(utils::time::windows_time_to_unix_time(change_time)));
} }
ret = populate_file_info(api_path, *file_info); ret = populate_file_info(api_path, *file_info);
@ -1746,12 +1765,22 @@ auto remote_server::json_release_directory_snapshot(
auto remote_server::update_to_windows_format(json &item) -> json & { auto remote_server::update_to_windows_format(json &item) -> json & {
const auto api_path = item["path"].get<std::string>(); const auto api_path = item["path"].get<std::string>();
item["meta"][META_MODIFIED] = std::to_string(utils::unix_time_to_windows_time( item["meta"][META_ACCESSED] = std::to_string(
utils::string::to_uint64(empty_as_zero(item["meta"][META_MODIFIED])))); utils::string::to_uint64(empty_as_zero(item["meta"][META_ACCESSED])));
item["meta"][META_CREATION] = std::to_string(utils::unix_time_to_windows_time( item["meta"][META_CREATION] = std::to_string(
utils::string::to_uint64(empty_as_zero(item["meta"][META_CREATION])))); utils::string::to_uint64(empty_as_zero(item["meta"][META_CREATION])));
item["meta"][META_ACCESSED] = std::to_string(utils::unix_time_to_windows_time( item["meta"][META_MODIFIED] = std::to_string(
utils::string::to_uint64(empty_as_zero(item["meta"][META_ACCESSED])))); utils::string::to_uint64(empty_as_zero(item["meta"][META_MODIFIED])));
if (item["meta"][META_WRITTEN].empty() ||
(item["meta"][META_WRITTEN].get<std::string>() == "0") ||
(item["meta"][META_WRITTEN].get<std::string>() ==
std::to_string(WIN32_TIME_CONVERSION))) {
drive_.set_item_meta(api_path, META_WRITTEN,
item["meta"][META_MODIFIED].get<std::string>());
item["meta"][META_WRITTEN] = item["meta"][META_MODIFIED];
}
if (item["meta"][META_ATTRIBUTES].empty()) { if (item["meta"][META_ATTRIBUTES].empty()) {
item["meta"][META_ATTRIBUTES] = item["meta"][META_ATTRIBUTES] =
item["directory"].get<bool>() ? std::to_string(FILE_ATTRIBUTE_DIRECTORY) item["directory"].get<bool>() ? std::to_string(FILE_ATTRIBUTE_DIRECTORY)
@ -1760,19 +1789,6 @@ auto remote_server::update_to_windows_format(json &item) -> json & {
item["meta"][META_ATTRIBUTES].get<std::string>()); item["meta"][META_ATTRIBUTES].get<std::string>());
} }
if (item["meta"][META_WRITTEN].empty() ||
(item["meta"][META_WRITTEN].get<std::string>() == "0") ||
(item["meta"][META_WRITTEN].get<std::string>() == "116444736000000000")) {
drive_.set_item_meta(api_path, META_WRITTEN,
item["meta"][META_MODIFIED].get<std::string>());
item["meta"][META_WRITTEN] = std::to_string(
utils::unix_time_to_windows_time(utils::string::to_uint64(
empty_as_zero(item["meta"][META_MODIFIED]))));
} else {
item["meta"][META_WRITTEN] = std::to_string(
utils::unix_time_to_windows_time(utils::string::to_uint64(
empty_as_zero(item["meta"][META_WRITTEN]))));
}
return item; return item;
} }
} // namespace repertory::remote_fuse } // namespace repertory::remote_fuse

View File

@ -65,7 +65,10 @@ auto remote_client::winfsp_can_delete(PVOID file_desc,
request.encode(file_name); request.encode(file_name);
std::uint32_t service_flags{}; std::uint32_t service_flags{};
const auto ret = packet_client_.send(function_name, request, service_flags); auto ret{
packet_client_.send(function_name, request, service_flags),
};
RAISE_REMOTE_WINFSP_CLIENT_EVENT( RAISE_REMOTE_WINFSP_CLIENT_EVENT(
function_name, function_name,
utils::path::create_api_path(utils::string::to_utf8(file_name)), ret); utils::path::create_api_path(utils::string::to_utf8(file_name)), ret);
@ -83,8 +86,9 @@ auto remote_client::json_create_directory_snapshot(
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
if (ret == 0) { if (ret == 0) {
ret = packet::decode_json(response, json_data); ret = packet::decode_json(response, json_data);
} }
@ -107,8 +111,9 @@ auto remote_client::json_read_directory_snapshot(
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
if (ret == 0) { if (ret == 0) {
ret = packet::decode_json(response, json_data); ret = packet::decode_json(response, json_data);
} }
@ -129,7 +134,9 @@ auto remote_client::json_release_directory_snapshot(
request.encode(handle); request.encode(handle);
std::uint32_t service_flags{}; std::uint32_t service_flags{};
const auto ret = packet_client_.send(function_name, request, service_flags); auto ret{
packet_client_.send(function_name, request, service_flags),
};
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, path, ret); RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, path, ret);
return ret; return ret;
@ -142,8 +149,14 @@ auto remote_client::winfsp_cleanup(PVOID file_desc, PWSTR file_name,
static_cast<const char *>(__FUNCTION__), static_cast<const char *>(__FUNCTION__),
}; };
auto handle = to_handle(file_desc); auto handle{
const auto file_path = get_open_file_path(handle); to_handle(file_desc),
};
auto file_path{
get_open_file_path(handle),
};
was_closed = 0; was_closed = 0;
packet request; packet request;
@ -153,8 +166,9 @@ auto remote_client::winfsp_cleanup(PVOID file_desc, PWSTR file_name,
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
DECODE_OR_IGNORE(&response, was_closed); DECODE_OR_IGNORE(&response, was_closed);
if (was_closed != 0U) { if (was_closed != 0U) {
remove_all(file_path); remove_all(file_path);
@ -168,15 +182,21 @@ auto remote_client::winfsp_close(PVOID file_desc) -> packet::error_type {
static_cast<const char *>(__FUNCTION__), static_cast<const char *>(__FUNCTION__),
}; };
auto handle = to_handle(file_desc); auto handle{
to_handle(file_desc),
};
if (has_open_info(handle, STATUS_INVALID_HANDLE) == STATUS_SUCCESS) { if (has_open_info(handle, STATUS_INVALID_HANDLE) == STATUS_SUCCESS) {
const auto file_path = get_open_file_path(handle); auto file_path{
get_open_file_path(handle),
};
packet request; packet request;
request.encode(file_desc); request.encode(file_desc);
std::uint32_t service_flags{}; std::uint32_t service_flags{};
const auto ret = packet_client_.send(function_name, request, service_flags); auto ret{
packet_client_.send(function_name, request, service_flags),
};
if ((ret == STATUS_SUCCESS) || if ((ret == STATUS_SUCCESS) ||
(ret == static_cast<packet::error_type>(STATUS_INVALID_HANDLE))) { (ret == static_cast<packet::error_type>(STATUS_INVALID_HANDLE))) {
remove_open_info(handle); remove_open_info(handle);
@ -206,8 +226,9 @@ auto remote_client::winfsp_create(PWSTR file_name, UINT32 create_options,
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
if (ret == STATUS_SUCCESS) { if (ret == STATUS_SUCCESS) {
HANDLE handle{}; HANDLE handle{};
DECODE_OR_IGNORE(&response, handle); DECODE_OR_IGNORE(&response, handle);
@ -243,8 +264,9 @@ auto remote_client::winfsp_flush(PVOID file_desc, remote::file_info *file_info)
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
DECODE_OR_IGNORE(&response, *file_info); DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT( RAISE_REMOTE_WINFSP_CLIENT_EVENT(
@ -274,8 +296,9 @@ auto remote_client::winfsp_get_file_info(
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
DECODE_OR_IGNORE(&response, *file_info); DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT( RAISE_REMOTE_WINFSP_CLIENT_EVENT(
@ -298,8 +321,9 @@ auto remote_client::winfsp_get_security_by_name(
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
string_descriptor.clear(); string_descriptor.clear();
DECODE_OR_IGNORE(&response, string_descriptor); DECODE_OR_IGNORE(&response, string_descriptor);
@ -326,8 +350,9 @@ auto remote_client::winfsp_get_volume_info(
packet request; packet request;
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
DECODE_OR_IGNORE(&response, total_size); DECODE_OR_IGNORE(&response, total_size);
DECODE_OR_IGNORE(&response, free_size); DECODE_OR_IGNORE(&response, free_size);
DECODE_OR_IGNORE(&response, volume_label); DECODE_OR_IGNORE(&response, volume_label);
@ -346,8 +371,13 @@ auto remote_client::winfsp_mounted(const std::wstring &location)
request.encode(location); request.encode(location);
std::uint32_t service_flags{}; std::uint32_t service_flags{};
const auto ret = packet_client_.send(function_name, request, service_flags); auto ret{
const auto mount_location = utils::string::to_utf8(location); packet_client_.send(function_name, request, service_flags),
};
auto mount_location{
utils::string::to_utf8(location),
};
event_system::instance().raise<drive_mounted>(mount_location); event_system::instance().raise<drive_mounted>(mount_location);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, mount_location, ret); RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, mount_location, ret);
@ -369,8 +399,9 @@ auto remote_client::winfsp_open(
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
if (ret == STATUS_SUCCESS) { if (ret == STATUS_SUCCESS) {
HANDLE handle{}; HANDLE handle{};
DECODE_OR_IGNORE(&response, handle); DECODE_OR_IGNORE(&response, handle);
@ -406,8 +437,9 @@ auto remote_client::winfsp_overwrite(
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
DECODE_OR_IGNORE(&response, *file_info); DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT( RAISE_REMOTE_WINFSP_CLIENT_EVENT(
@ -429,8 +461,9 @@ auto remote_client::winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
DECODE_OR_IGNORE(&response, *bytes_transferred); DECODE_OR_IGNORE(&response, *bytes_transferred);
if (ret == STATUS_SUCCESS) { if (ret == STATUS_SUCCESS) {
ret = response.decode(buffer, *bytes_transferred); ret = response.decode(buffer, *bytes_transferred);
@ -464,8 +497,9 @@ auto remote_client::winfsp_read_directory(PVOID file_desc, PWSTR pattern,
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
if (ret == STATUS_SUCCESS) { if (ret == STATUS_SUCCESS) {
ret = packet::decode_json(response, item_list); ret = packet::decode_json(response, item_list);
} }
@ -489,7 +523,10 @@ auto remote_client::winfsp_rename(
request.encode(replace_if_exists); request.encode(replace_if_exists);
std::uint32_t service_flags{}; std::uint32_t service_flags{};
const auto ret = packet_client_.send(function_name, request, service_flags); auto ret{
packet_client_.send(function_name, request, service_flags),
};
RAISE_REMOTE_WINFSP_CLIENT_EVENT( RAISE_REMOTE_WINFSP_CLIENT_EVENT(
function_name, function_name,
utils::path::create_api_path(utils::string::to_utf8(file_name)) + "|" + utils::path::create_api_path(utils::string::to_utf8(file_name)) + "|" +
@ -516,8 +553,9 @@ auto remote_client::winfsp_set_basic_info(
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
DECODE_OR_IGNORE(&response, *file_info); DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT( RAISE_REMOTE_WINFSP_CLIENT_EVENT(
@ -539,8 +577,9 @@ auto remote_client::winfsp_set_file_size(
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
DECODE_OR_IGNORE(&response, *file_info); DECODE_OR_IGNORE(&response, *file_info);
RAISE_REMOTE_WINFSP_CLIENT_EVENT( RAISE_REMOTE_WINFSP_CLIENT_EVENT(
@ -554,13 +593,17 @@ auto remote_client::winfsp_unmounted(const std::wstring &location)
static_cast<const char *>(__FUNCTION__), static_cast<const char *>(__FUNCTION__),
}; };
const auto mount_location = utils::string::to_utf8(location); auto mount_location{
utils::string::to_utf8(location),
};
event_system::instance().raise<drive_unmount_pending>(mount_location); event_system::instance().raise<drive_unmount_pending>(mount_location);
packet request; packet request;
request.encode(location); request.encode(location);
std::uint32_t service_flags{}; std::uint32_t service_flags{};
const auto ret = packet_client_.send(function_name, request, service_flags); auto ret{
packet_client_.send(function_name, request, service_flags),
};
event_system::instance().raise<drive_unmounted>(mount_location); event_system::instance().raise<drive_unmounted>(mount_location);
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, mount_location, ret); RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, mount_location, ret);
@ -587,8 +630,9 @@ auto remote_client::winfsp_write(
packet response; packet response;
std::uint32_t service_flags{}; std::uint32_t service_flags{};
auto ret = auto ret{
packet_client_.send(function_name, request, response, service_flags); packet_client_.send(function_name, request, response, service_flags),
};
DECODE_OR_IGNORE(&response, *bytes_transferred); DECODE_OR_IGNORE(&response, *bytes_transferred);
DECODE_OR_IGNORE(&response, *file_info); DECODE_OR_IGNORE(&response, *file_info);
@ -603,5 +647,5 @@ auto remote_client::winfsp_write(
auto remote_client::to_handle(PVOID file_desc) -> native_handle { auto remote_client::to_handle(PVOID file_desc) -> native_handle {
return static_cast<native_handle>(reinterpret_cast<std::uint64_t>(file_desc)); return static_cast<native_handle>(reinterpret_cast<std::uint64_t>(file_desc));
} }
#endif #endif // !defined(_WIN32)
} // namespace repertory::remote_winfsp } // namespace repertory::remote_winfsp

View File

@ -92,10 +92,14 @@ void remote_server::populate_stat(const char *path, bool directory,
directory ? 2 + drive_.get_directory_item_count( directory ? 2 + drive_.get_directory_item_count(
utils::path::create_api_path(path)) utils::path::create_api_path(path))
: 1); : 1);
r_stat.st_atimespec = utils::time::time64_to_unix_time(unix_st.st_atime); r_stat.st_atimespec = utils::time::windows_time_to_unix_time(
r_stat.st_birthtimespec = utils::time::time64_to_unix_time(unix_st.st_ctime); static_cast<std::uint64_t>(unix_st.st_atime));
r_stat.st_ctimespec = utils::time::time64_to_unix_time(unix_st.st_ctime); r_stat.st_birthtimespec = utils::time::windows_time_to_unix_time(
r_stat.st_mtimespec = utils::time::time64_to_unix_time(unix_st.st_mtime); static_cast<std::uint64_t>(unix_st.st_ctime));
r_stat.st_ctimespec = utils::time::windows_time_to_unix_time(
static_cast<std::uint64_t>(unix_st.st_ctime));
r_stat.st_mtimespec = utils::time::windows_time_to_unix_time(
static_cast<std::uint64_t>(unix_st.st_mtime));
r_stat.st_size = static_cast<remote::file_size>(unix_st.st_size); r_stat.st_size = static_cast<remote::file_size>(unix_st.st_size);
r_stat.st_mode = unix_st.st_mode; r_stat.st_mode = unix_st.st_mode;
} }
@ -107,10 +111,22 @@ auto remote_server::fuse_access(const char *path, const std::int32_t &mask)
static_cast<const char *>(__FUNCTION__), static_cast<const char *>(__FUNCTION__),
}; };
const auto file_path = construct_path(path); auto file_path{
const auto windows_mask = utils::unix_access_mask_to_windows(mask); construct_path(path),
const auto res = _access(file_path.c_str(), windows_mask); };
const auto ret = ((res < 0) ? -errno : 0);
auto windows_mask{
utils::unix_access_mask_to_windows(mask),
};
auto res{
_access(file_path.c_str(), windows_mask),
};
auto ret{
((res < 0) ? -errno : 0),
};
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret); RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret; return ret;
} }
@ -181,10 +197,13 @@ auto remote_server::fuse_fgetattr(
static_cast<const char *>(__FUNCTION__), static_cast<const char *>(__FUNCTION__),
}; };
const auto file_path = construct_path(path); r_stat = {};
memset(&r_stat, 0, sizeof(remote::stat));
auto res = has_compat_open_info(handle, EBADF); const auto file_path = construct_path(path);
auto res{
has_compat_open_info(handle, EBADF),
};
if (res == 0) { if (res == 0) {
directory = utils::file::directory(file_path).exists(); directory = utils::file::directory(file_path).exists();
struct _stat64 unix_st {}; struct _stat64 unix_st {};
@ -221,7 +240,9 @@ auto remote_server::fuse_fsync(
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
auto res = has_compat_open_info(handle, EBADF); auto res{
has_compat_open_info(handle, EBADF),
};
if (res == 0) { if (res == 0) {
res = -1; res = -1;
errno = EBADF; errno = EBADF;
@ -250,7 +271,9 @@ auto remote_server::fuse_ftruncate(
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
auto res = has_compat_open_info(handle, EBADF); auto res{
has_compat_open_info(handle, EBADF),
};
if (res == 0) { if (res == 0) {
res = -1; res = -1;
errno = EBADF; errno = EBADF;
@ -279,13 +302,16 @@ auto remote_server::fuse_getattr(const char *path, remote::stat &r_st,
static_cast<const char *>(__FUNCTION__), static_cast<const char *>(__FUNCTION__),
}; };
r_st = {};
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
memset(&r_st, 0, sizeof(remote::stat));
directory = utils::file::directory(file_path).exists(); directory = utils::file::directory(file_path).exists();
struct _stat64 st1 {}; struct _stat64 st1 {};
const auto res = _stat64(file_path.c_str(), &st1); auto res{
_stat64(file_path.c_str(), &st1),
};
if (res == 0) { if (res == 0) {
populate_stat(path, directory, r_st, st1); populate_stat(path, directory, r_st, st1);
} }
@ -345,7 +371,9 @@ auto remote_server::fuse_mkdir(const char *path,
}; };
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
const auto res = _mkdir(file_path.c_str()); auto res{
_mkdir(file_path.c_str()),
};
const auto ret = ((res < 0) ? -errno : 0); const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret); RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret; return ret;
@ -359,7 +387,7 @@ auto remote_server::fuse_opendir(const char *path, remote::file_handle &handle)
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
const auto unicode_file_path = utils::string::from_utf8(file_path); const auto unicode_file_path = utils::string::from_utf8(file_path);
auto res = -1; auto res{-1};
errno = ENOENT; errno = ENOENT;
if (::PathIsDirectoryW(unicode_file_path.c_str()) != 0) { if (::PathIsDirectoryW(unicode_file_path.c_str()) != 0) {
@ -402,8 +430,9 @@ auto remote_server::fuse_create(const char *path, const remote::file_mode &mode,
ret = -EACCES; ret = -EACCES;
} else { } else {
int file = -1; int file = -1;
const auto res = auto res{
_sopen_s(&file, file_path.c_str(), open_flags, _SH_DENYNO, perms); _sopen_s(&file, file_path.c_str(), open_flags, _SH_DENYNO, perms),
};
if (res == 0) { if (res == 0) {
handle = static_cast<remote::file_handle>(file); handle = static_cast<remote::file_handle>(file);
ret = 0; ret = 0;
@ -425,7 +454,7 @@ auto remote_server::fuse_open(const char *path, const remote::open_flags &flags,
}; };
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
auto res = -1; auto res{-1};
if ((flags & remote::open_flags::directory) == if ((flags & remote::open_flags::directory) ==
remote::open_flags::directory) { remote::open_flags::directory) {
@ -460,13 +489,13 @@ auto remote_server::fuse_read(
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
auto &data = *reinterpret_cast<data_buffer *>(buffer); auto &data = *reinterpret_cast<data_buffer *>(buffer);
auto res = 0; auto res{0};
if (read_size > std::numeric_limits<std::size_t>::max()) { if (read_size > std::numeric_limits<std::size_t>::max()) {
res = -1; res = -1;
errno = ERANGE; errno = ERANGE;
} else if ((res = has_compat_open_info(handle, EBADF)) == 0) { } else if ((res = has_compat_open_info(handle, EBADF)) == 0) {
res = _lseeki64(static_cast<int>(handle), static_cast<__int64>(read_offset), res = static_cast<std::decay_t<decltype(res)>>(_lseeki64(
SEEK_SET); static_cast<int>(handle), static_cast<__int64>(read_offset), SEEK_SET));
if (res != -1) { if (res != -1) {
data.resize(read_size); data.resize(read_size);
res = read(static_cast<int>(handle), data.data(), res = read(static_cast<int>(handle), data.data(),
@ -494,7 +523,9 @@ auto remote_server::fuse_rename(const char *from,
const auto from_path = utils::path::combine(mount_location_, {from}); const auto from_path = utils::path::combine(mount_location_, {from});
const auto to_path = utils::path::combine(mount_location_, {to}); const auto to_path = utils::path::combine(mount_location_, {to});
const auto res = rename(from_path.c_str(), to_path.c_str()); auto res{
rename(from_path.c_str(), to_path.c_str()),
};
const auto ret = ((res < 0) ? -errno : 0); const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, from + std::string("|") + to, RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, from + std::string("|") + to,
@ -512,15 +543,16 @@ auto remote_server::fuse_write(
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
std::size_t bytes_written{}; std::size_t bytes_written{};
auto res = 0; auto res{0};
if (write_size > std::numeric_limits<std::size_t>::max()) { if (write_size > std::numeric_limits<std::size_t>::max()) {
res = -1; res = -1;
errno = ERANGE; errno = ERANGE;
} else { } else {
res = has_compat_open_info(handle, EBADF); res = has_compat_open_info(handle, EBADF);
if (res == 0) { if (res == 0) {
res = _lseeki64(static_cast<int>(handle), res = static_cast<std::decay_t<decltype(res)>>(
static_cast<__int64>(write_offset), SEEK_SET); _lseeki64(static_cast<int>(handle),
static_cast<__int64>(write_offset), SEEK_SET));
if (res != -1) { if (res != -1) {
res = write(static_cast<int>(handle), buffer, res = write(static_cast<int>(handle), buffer,
static_cast<unsigned int>(write_size)); static_cast<unsigned int>(write_size));
@ -556,7 +588,7 @@ auto remote_server::fuse_readdir(const char *path,
}; };
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
auto res = 0; auto res{0};
if (offset > std::numeric_limits<std::size_t>::max()) { if (offset > std::numeric_limits<std::size_t>::max()) {
errno = ERANGE; errno = ERANGE;
res = -1; res = -1;
@ -584,7 +616,9 @@ auto remote_server::fuse_release(
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
remove_compat_open_info(handle); remove_compat_open_info(handle);
const auto res = _close(static_cast<int>(handle)); auto res{
_close(static_cast<int>(handle)),
};
const auto ret = ((res < 0) ? -errno : 0); const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret); RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
@ -616,7 +650,9 @@ auto remote_server::fuse_rmdir(const char *path) -> packet::error_type {
}; };
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
const auto res = _rmdir(file_path.c_str()); auto res{
_rmdir(file_path.c_str()),
};
const auto ret = ((res < 0) ? -errno : 0); const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret); RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret; return ret;
@ -741,9 +777,9 @@ auto remote_server::fuse_statfs_x(const char *path, std::uint64_t bsize,
r_stat.f_files = 4294967295; r_stat.f_files = 4294967295;
r_stat.f_ffree = r_stat.f_favail = r_stat.f_ffree = r_stat.f_favail =
r_stat.f_files - drive_.get_total_item_count(); r_stat.f_files - drive_.get_total_item_count();
strncpy(&r_stat.f_mntfromname[0U], strncpy(r_stat.f_mntfromname.data(),
(utils::create_volume_label(config_.get_provider_type())).c_str(), (utils::create_volume_label(config_.get_provider_type())).c_str(),
sizeof(r_stat.f_mntfromname) - 1U); r_stat.f_mntfromname.size() - 1U);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, 0); RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, 0);
return 0; return 0;
@ -757,7 +793,7 @@ auto remote_server::fuse_truncate(
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
const auto unicode_file_path = utils::string::from_utf8(file_path); const auto unicode_file_path = utils::string::from_utf8(file_path);
auto res = -1; auto res{-1};
errno = ENOENT; errno = ENOENT;
const auto flags_and_attributes = const auto flags_and_attributes =
@ -792,7 +828,9 @@ auto remote_server::fuse_unlink(const char *path) -> packet::error_type {
}; };
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
const auto res = _unlink(file_path.c_str()); auto res{
_unlink(file_path.c_str()),
};
const auto ret = ((res < 0) ? -errno : 0); const auto ret = ((res < 0) ? -errno : 0);
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret); RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
return ret; return ret;
@ -808,7 +846,7 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
const auto unicode_file_path = utils::string::from_utf8(file_path); const auto unicode_file_path = utils::string::from_utf8(file_path);
auto res = -1; auto res{-1};
errno = ENOENT; errno = ENOENT;
const auto flags_and_attributes = const auto flags_and_attributes =
@ -870,7 +908,7 @@ auto remote_server::json_create_directory_snapshot(
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
auto res = -1; auto res{-1};
errno = ENOENT; errno = ENOENT;
if (utils::file::directory(file_path).exists()) { if (utils::file::directory(file_path).exists()) {
@ -1477,4 +1515,4 @@ auto remote_server::winfsp_get_dir_buffer(PVOID /*file_desc*/, PVOID *& /*ptr*/)
} }
} // namespace repertory::remote_winfsp } // namespace repertory::remote_winfsp
#endif // _WIN32 #endif // defined(_WIN32)

View File

@ -373,7 +373,7 @@ auto remote_winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
::ZeroMemory(directory_info, sizeof(*directory_info)); ::ZeroMemory(directory_info, sizeof(*directory_info));
directory_info->Size = static_cast<UINT16>( directory_info->Size = static_cast<UINT16>(
FIELD_OFFSET(FSP_FSCTL_DIR_INFO, FileNameBuf) + FIELD_OFFSET(FSP_FSCTL_DIR_INFO, FileNameBuf) +
(std::min((size_t)MAX_PATH, display_name.size()) * (std::min(static_cast<size_t>(MAX_PATH), display_name.size()) *
sizeof(WCHAR))); sizeof(WCHAR)));
if (not item["meta"].empty() || if (not item["meta"].empty() ||

View File

@ -238,8 +238,10 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
if ((flags & FspCleanupSetChangeTime) != 0U) { if ((flags & FspCleanupSetChangeTime) != 0U) {
auto res = provider_.set_item_meta( auto res = provider_.set_item_meta(
api_path, {{META_CHANGED, std::to_string(now)}, api_path, {
{META_MODIFIED, std::to_string(now)}}); {META_CHANGED, std::to_string(now)},
{META_MODIFIED, std::to_string(now)},
});
if (res != api_error::success) { if (res != api_error::success) {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
function_name, api_path, res, function_name, api_path, res,
@ -1058,17 +1060,22 @@ auto winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
meta[META_ATTRIBUTES] = std::to_string(attributes); meta[META_ATTRIBUTES] = std::to_string(attributes);
} }
if ((creation_time != 0U) && (creation_time != max_time)) { if ((creation_time != 0U) && (creation_time != max_time)) {
meta[META_CREATION] = std::to_string(creation_time); meta[META_CREATION] = std::to_string(
utils::time::windows_time_to_unix_time(creation_time));
} }
if ((last_access_time != 0U) && (last_access_time != max_time)) { if ((last_access_time != 0U) && (last_access_time != max_time)) {
meta[META_ACCESSED] = std::to_string(last_access_time); meta[META_ACCESSED] = std::to_string(
utils::time::windows_time_to_unix_time(last_access_time));
} }
if ((last_write_time != 0U) && (last_write_time != max_time)) { if ((last_write_time != 0U) && (last_write_time != max_time)) {
meta[META_WRITTEN] = std::to_string(last_write_time); meta[META_WRITTEN] = std::to_string(
utils::time::windows_time_to_unix_time(last_write_time));
} }
if ((change_time != 0U) && (change_time != max_time)) { if ((change_time != 0U) && (change_time != max_time)) {
meta[META_CHANGED] = std::to_string(change_time); meta[META_CHANGED] =
meta[META_MODIFIED] = std::to_string(change_time); std::to_string(utils::time::windows_time_to_unix_time(change_time));
meta[META_MODIFIED] =
std::to_string(utils::time::windows_time_to_unix_time(change_time));
} }
error = provider_.set_item_meta(api_path, meta); error = provider_.set_item_meta(api_path, meta);

View File

@ -244,7 +244,7 @@ auto file_manager::evict_file(const std::string &api_path) -> bool {
open_file_lookup_.erase(api_path); open_file_lookup_.erase(api_path);
auto removed = utils::file::retry_delete_file(source_path); auto removed = utils::file::file(source_path).remove();
if (removed) { if (removed) {
event_system::instance().raise<filesystem_item_evicted>(api_path, event_system::instance().raise<filesystem_item_evicted>(api_path,
source_path); source_path);
@ -513,8 +513,8 @@ void file_manager::queue_upload(const std::string &api_path,
db::db_insert{*db_.get(), upload_table} db::db_insert{*db_.get(), upload_table}
.or_replace() .or_replace()
.column_value("api_path", api_path) .column_value("api_path", api_path)
.column_value("date_time", static_cast<std::int64_t>( .column_value("date_time",
utils::time::get_time_now())) static_cast<std::int64_t>(utils::time::get_time_now()))
.column_value("source_path", source_path) .column_value("source_path", source_path)
.go(); .go();
if (result.ok()) { if (result.ok()) {
@ -557,7 +557,7 @@ auto file_manager::remove_file(const std::string &api_path) -> api_error {
return res; return res;
} }
if (not utils::file::retry_delete_file(fsi.source_path)) { if (not utils::file::file(fsi.source_path).remove()) {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
function_name, fsi.api_path, fsi.source_path, function_name, fsi.api_path, fsi.source_path,
utils::get_last_error_code(), "failed to delete source"); utils::get_last_error_code(), "failed to delete source");
@ -780,7 +780,7 @@ auto file_manager::rename_file(const std::string &from_api_path,
res = remove_file(to_api_path); res = remove_file(to_api_path);
if ((res == api_error::success) || (res == api_error::item_not_found)) { if ((res == api_error::success) || (res == api_error::item_not_found)) {
if (not utils::file::retry_delete_file(fsi.source_path)) { if (not utils::file::file(fsi.source_path).remove()) {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
function_name, fsi.api_path, fsi.source_path, function_name, fsi.api_path, fsi.source_path,
utils::get_last_error_code(), "failed to delete source path"); utils::get_last_error_code(), "failed to delete source path");

View File

@ -458,7 +458,7 @@ auto file_manager::open_file::close() -> bool {
mgr_.store_resume(*this); mgr_.store_resume(*this);
} else if (get_api_error() != api_error::success) { } else if (get_api_error() != api_error::success) {
mgr_.remove_resume(get_api_path(), get_source_path()); mgr_.remove_resume(get_api_path(), get_source_path());
if (not utils::file::retry_delete_file(fsi_.source_path)) { if (not utils::file::file(fsi_.source_path).remove()) {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
function_name, get_api_path(), fsi_.source_path, function_name, get_api_path(), fsi_.source_path,
utils::get_last_error_code(), "failed to delete file"); utils::get_last_error_code(), "failed to delete file");

View File

@ -93,7 +93,7 @@ file_manager::ring_buffer_open_file::~ring_buffer_open_file() {
close(); close();
nf_->close(); nf_->close();
if (not utils::file::retry_delete_file(fsi_.source_path)) { if (not utils::file::file(fsi_.source_path).remove()) {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
function_name, fsi_.api_path, fsi_.source_path, function_name, fsi_.api_path, fsi_.source_path,
utils::get_last_error_code(), "failed to delete file"); utils::get_last_error_code(), "failed to delete file");

View File

@ -506,7 +506,7 @@ void base_provider::remove_deleted_files() {
} else { } else {
utils::error::raise_error( utils::error::raise_error(
function_name, std::to_string(utils::get_last_error_code()), function_name, std::to_string(utils::get_last_error_code()),
"failed to create orphaned director|sp|" + orphaned_directory); "failed to create orphaned directory|sp|" + orphaned_directory);
continue; continue;
} }
} }

View File

@ -90,44 +90,40 @@ auto encrypt_provider::create_api_file(
source_path); source_path);
file.source_path = source_path; file.source_path = source_path;
#if defined(__APPLE__) #if defined(__APPLE__)
file.changed_date = file.changed_date = buf.st_ctimespec.tv_nsec +
buf.st_ctimespec.tv_nsec + (buf.st_ctimespec.tv_sec * NANOS_PER_SECOND); (buf.st_ctimespec.tv_sec * utils::time::NANOS_PER_SECOND);
file.accessed_date = file.accessed_date =
buf.st_atimespec.tv_nsec + (buf.st_atimespec.tv_sec * NANOS_PER_SECOND); buf.st_atimespec.tv_nsec +
file.creation_date = buf.st_birthtimespec.tv_nsec + (buf.st_atimespec.tv_sec * utils::time::NANOS_PER_SECOND);
(buf.st_birthtimespec.tv_sec * NANOS_PER_SECOND);
file.modified_date =
buf.st_mtimespec.tv_nsec + (buf.st_mtimespec.tv_sec * NANOS_PER_SECOND);
#elif defined(_WIN32)
auto ft = utils::time::unix_time_to_filetime(
utils::time::time64_to_unix_time(buf.st_atime));
file.accessed_date =
(static_cast<std::uint64_t>(ft.dwHighDateTime) << 32U) | ft.dwLowDateTime;
ft = utils::time::unix_time_to_filetime(
utils::time::time64_to_unix_time(buf.st_mtime));
file.changed_date =
(static_cast<std::uint64_t>(ft.dwHighDateTime) << 32U) | ft.dwLowDateTime;
ft = utils::time::unix_time_to_filetime(
utils::time::time64_to_unix_time(buf.st_ctime));
file.creation_date = file.creation_date =
(static_cast<std::uint64_t>(ft.dwHighDateTime) << 32U) | ft.dwLowDateTime; buf.st_birthtimespec.tv_nsec +
(buf.st_birthtimespec.tv_sec * utils::time::NANOS_PER_SECOND);
ft = utils::time::unix_time_to_filetime(
utils::time::time64_to_unix_time(buf.st_mtime));
file.modified_date = file.modified_date =
(static_cast<std::uint64_t>(ft.dwHighDateTime) << 32U) | ft.dwLowDateTime; buf.st_mtimespec.tv_nsec +
#else (buf.st_mtimespec.tv_sec * utils::time::NANOS_PER_SECOND);
#elif defined(_WIN32)
file.accessed_date = utils::time::windows_time_to_unix_time(
static_cast<std::uint64_t>(buf.st_atime));
file.changed_date = utils::time::windows_time_to_unix_time(
static_cast<std::uint64_t>(buf.st_mtime));
file.creation_date = utils::time::windows_time_to_unix_time(
static_cast<std::uint64_t>(buf.st_ctime));
file.modified_date = utils::time::windows_time_to_unix_time(
static_cast<std::uint64_t>(buf.st_mtime));
#else // !defined(_WIN32)
file.changed_date = static_cast<std::uint64_t>( file.changed_date = static_cast<std::uint64_t>(
buf.st_mtim.tv_nsec + (buf.st_mtim.tv_sec * NANOS_PER_SECOND)); buf.st_mtim.tv_nsec +
(buf.st_mtim.tv_sec * utils::time::NANOS_PER_SECOND));
file.accessed_date = static_cast<std::uint64_t>( file.accessed_date = static_cast<std::uint64_t>(
buf.st_atim.tv_nsec + (buf.st_atim.tv_sec * NANOS_PER_SECOND)); buf.st_atim.tv_nsec +
(buf.st_atim.tv_sec * utils::time::NANOS_PER_SECOND));
file.creation_date = static_cast<std::uint64_t>( file.creation_date = static_cast<std::uint64_t>(
buf.st_ctim.tv_nsec + (buf.st_ctim.tv_sec * NANOS_PER_SECOND)); buf.st_ctim.tv_nsec +
(buf.st_ctim.tv_sec * utils::time::NANOS_PER_SECOND));
file.modified_date = static_cast<std::uint64_t>( file.modified_date = static_cast<std::uint64_t>(
buf.st_mtim.tv_nsec + (buf.st_mtim.tv_sec * NANOS_PER_SECOND)); buf.st_mtim.tv_nsec +
#endif (buf.st_mtim.tv_sec * utils::time::NANOS_PER_SECOND));
#endif // defined(__APPLE__)
return file; return file;
} }

View File

@ -60,6 +60,24 @@ auto s3_provider::add_if_not_found(
return api_error::success; return api_error::success;
} }
auto s3_provider::convert_api_date(std::string_view date) -> std::uint64_t {
// 2009-10-12T17:50:30.000Z
auto date_parts = utils::string::split(date, '.', true);
auto date_time = date_parts.at(0U);
auto nanos = utils::string::to_uint64(
utils::string::split(date_parts.at(1U), 'Z', true).at(0U));
struct tm tm1 {};
#if defined(_WIN32)
utils::time::strptime(date_time.c_str(), "%Y-%m-%dT%T", &tm1);
#else
strptime(date_time.c_str(), "%Y-%m-%dT%T", &tm1);
#endif
return nanos + (static_cast<std::uint64_t>(mktime(&tm1)) *
utils::time::NANOS_PER_SECOND);
}
auto s3_provider::create_directory_impl(const std::string &api_path, auto s3_provider::create_directory_impl(const std::string &api_path,
api_meta_map &meta) -> api_error { api_meta_map &meta) -> api_error {
static constexpr const std::string_view function_name{ static constexpr const std::string_view function_name{
@ -448,7 +466,7 @@ auto s3_provider::get_file_list(api_file_list &list) const -> api_error {
file.api_path = utils::path::create_api_path(api_path); file.api_path = utils::path::create_api_path(api_path);
file.api_parent = utils::path::get_parent_api_path(file.api_path); file.api_parent = utils::path::get_parent_api_path(file.api_path);
file.accessed_date = utils::time::get_time_now(); file.accessed_date = utils::time::get_time_now();
file.changed_date = utils::convert_api_date( file.changed_date = convert_api_date(
node.node().select_node("LastModified").node().text().as_string()); node.node().select_node("LastModified").node().text().as_string());
file.creation_date = file.changed_date; file.creation_date = file.changed_date;
file.file_size = file.file_size =

View File

@ -22,12 +22,11 @@
#include "rpc/server/full_server.hpp" #include "rpc/server/full_server.hpp"
#include "app_config.hpp" #include "app_config.hpp"
#include "drives/directory_iterator.hpp"
#include "file_manager/i_file_manager.hpp" #include "file_manager/i_file_manager.hpp"
#include "providers/i_provider.hpp" #include "providers/i_provider.hpp"
#include "types/repertory.hpp" #include "types/repertory.hpp"
#include "types/rpc.hpp" #include "types/rpc.hpp"
#include "utils/file_utils.hpp" #include "utils/file.hpp"
#include "utils/path.hpp" #include "utils/path.hpp"
namespace repertory { namespace repertory {
@ -51,11 +50,11 @@ void full_server::handle_get_directory_items(const httplib::Request &req,
void full_server::handle_get_drive_information(const httplib::Request & /*req*/, void full_server::handle_get_drive_information(const httplib::Request & /*req*/,
httplib::Response &res) { httplib::Response &res) {
auto dir_size =
utils::file::directory(get_config().get_cache_directory()).size();
res.set_content( res.set_content(
json({ json({
{"cache_space_used", {"cache_space_used", dir_size},
utils::file::calculate_used_space(
get_config().get_cache_directory(), false)},
{"drive_space_total", provider_.get_total_drive_space()}, {"drive_space_total", provider_.get_total_drive_space()},
{"drive_space_used", provider_.get_used_drive_space()}, {"drive_space_used", provider_.get_used_drive_space()},
{"item_count", provider_.get_total_item_count()}, {"item_count", provider_.get_total_item_count()},

View File

@ -23,7 +23,8 @@
#include "app_config.hpp" #include "app_config.hpp"
#include "utils/collection.hpp" #include "utils/collection.hpp"
#include "utils/file_utils.hpp" #include "utils/common.hpp"
#include "utils/file.hpp"
#include "utils/path.hpp" #include "utils/path.hpp"
#include "utils/string.hpp" #include "utils/string.hpp"
#include "utils/utils.hpp" #include "utils/utils.hpp"
@ -38,7 +39,7 @@ void get_api_authentication_data(std::string &user, std::string &password,
{"config.json"}); {"config.json"});
json data; json data;
const auto success = utils::retryable_action([&]() -> bool { const auto success = utils::retry_action([&]() -> bool {
return utils::file::read_json_file(cfg_file_path, data); return utils::file::read_json_file(cfg_file_path, data);
}); });

View File

@ -30,56 +30,6 @@
#include "utils/utils.hpp" #include "utils/utils.hpp"
namespace repertory::utils::file { namespace repertory::utils::file {
auto calculate_used_space(std::string path, bool recursive) -> std::uint64_t {
path = utils::path::absolute(path);
std::uint64_t ret{};
#if defined(_WIN32)
WIN32_FIND_DATA fd{};
const auto search = utils::path::combine(path, {"*.*"});
auto find = ::FindFirstFile(search.c_str(), &fd);
if (find != INVALID_HANDLE_VALUE) {
do {
const auto file_name = std::string(fd.cFileName);
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
if (recursive && (file_name != ".") && (file_name != "..")) {
ret += calculate_used_space(utils::path::combine(path, {file_name}),
recursive);
}
} else {
std::uint64_t file_size{};
if (get_file_size(utils::path::combine(path, {file_name}), file_size)) {
ret += file_size;
}
}
} while (::FindNextFile(find, &fd) != 0);
::FindClose(find);
}
#else
auto *root = opendir(path.c_str());
if (root) {
struct dirent *de{};
while ((de = readdir(root)) != nullptr) {
if (de->d_type == DT_DIR) {
if (recursive && (strcmp(de->d_name, ".") != 0) &&
(strcmp(de->d_name, "..") != 0)) {
ret += calculate_used_space(utils::path::combine(path, {de->d_name}),
recursive);
}
} else {
std::uint64_t file_size{};
if (get_file_size(utils::path::combine(path, {de->d_name}),
file_size)) {
ret += file_size;
}
}
}
closedir(root);
}
#endif
return ret;
}
void change_to_process_directory() { void change_to_process_directory() {
#if defined(_WIN32) #if defined(_WIN32)
std::string file_name; std::string file_name;
@ -118,7 +68,7 @@ auto copy_directory_recursively(std::string from_path,
std::string to_path) -> bool { std::string to_path) -> bool {
from_path = utils::path::absolute(from_path); from_path = utils::path::absolute(from_path);
to_path = utils::path::absolute(to_path); to_path = utils::path::absolute(to_path);
auto ret = utils::file::directory(to_path).create_directory(); auto ret = utils::file::directory(to_path).create_directory() != nullptr;
if (ret) { if (ret) {
#if defined(_WIN32) #if defined(_WIN32)
WIN32_FIND_DATA fd{}; WIN32_FIND_DATA fd{};
@ -168,49 +118,6 @@ auto copy_directory_recursively(std::string from_path,
return ret; return ret;
} }
auto generate_sha256(const std::string &file_path) -> std::string {
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));
}
{
auto input_file = utils::file::file::open_file(file_path);
if (not *input_file) {
throw std::runtime_error("failed to open file|" + file_path);
}
data_buffer buffer(input_file->get_read_buffer_size());
std::uint64_t read_offset{0U};
std::size_t bytes_read{0U};
while (input_file->read(buffer, read_offset, &bytes_read)) {
if (not bytes_read) {
break;
}
read_offset += bytes_read;
res = crypto_hash_sha256_update(
&state, reinterpret_cast<const unsigned char *>(buffer.data()),
bytes_read);
if (res != 0) {
throw std::runtime_error("failed to update sha256|" +
std::to_string(res));
}
}
}
std::array<unsigned char, crypto_hash_sha256_BYTES> out{};
res = crypto_hash_sha256_final(&state, out.data());
if (res != 0) {
throw std::runtime_error("failed to finalize sha256|" +
std::to_string(res));
}
return utils::collection::to_hex_string(out);
}
auto get_free_drive_space(const std::string &path) -> std::uint64_t { auto get_free_drive_space(const std::string &path) -> std::uint64_t {
#if defined(_WIN32) #if defined(_WIN32)
ULARGE_INTEGER li{}; ULARGE_INTEGER li{};
@ -311,12 +218,13 @@ auto get_directory_files(std::string path, bool oldest_first,
stat(lookup_path.c_str(), &st); stat(lookup_path.c_str(), &st);
#if defined(__APPLE__) #if defined(__APPLE__)
lookup[lookup_path] = static_cast<std::uint64_t>( lookup[lookup_path] = static_cast<std::uint64_t>(
(st.st_mtimespec.tv_sec * NANOS_PER_SECOND) + (st.st_mtimespec.tv_sec * utils::time::NANOS_PER_SECOND) +
st.st_mtimespec.tv_nsec); st.st_mtimespec.tv_nsec);
#else #else // !defined(__APPLE__)
lookup[lookup_path] = static_cast<std::uint64_t>( lookup[lookup_path] = static_cast<std::uint64_t>(
(st.st_mtim.tv_sec * NANOS_PER_SECOND) + st.st_mtim.tv_nsec); (st.st_mtim.tv_sec * utils::time::NANOS_PER_SECOND) +
#endif st.st_mtim.tv_nsec);
#endif // defined(__APPLE__)
} }
}; };
@ -331,74 +239,13 @@ auto get_directory_files(std::string path, bool oldest_first,
return ret; return ret;
} }
auto get_accessed_time(const std::string &path, auto is_modified_date_older_than(std::string_view path,
std::uint64_t &accessed) -> bool {
auto ret = false;
accessed = 0;
#if defined(_WIN32)
struct _stat64 st {};
if (_stat64(path.c_str(), &st) != -1) {
accessed = static_cast<uint64_t>(st.st_atime);
#else
struct stat st {};
if (stat(path.c_str(), &st) != -1) {
#if defined(__APPLE__)
accessed = static_cast<uint64_t>(
st.st_atimespec.tv_nsec + (st.st_atimespec.tv_sec * NANOS_PER_SECOND));
#else
accessed = static_cast<uint64_t>(st.st_atim.tv_nsec +
(st.st_atim.tv_sec * NANOS_PER_SECOND));
#endif
#endif
ret = true;
}
return ret;
}
auto get_modified_time(const std::string &path,
std::uint64_t &modified) -> bool {
auto ret = false;
modified = 0U;
#if defined(_WIN32)
struct _stat64 st {};
if (_stat64(path.c_str(), &st) != -1) {
modified = static_cast<uint64_t>(st.st_mtime);
#else
struct stat st {};
if (stat(path.c_str(), &st) != -1) {
#if defined(__APPLE__)
modified = static_cast<uint64_t>(
st.st_mtimespec.tv_nsec + (st.st_mtimespec.tv_sec * NANOS_PER_SECOND));
#else
modified = static_cast<uint64_t>(st.st_mtim.tv_nsec +
(st.st_mtim.tv_sec * NANOS_PER_SECOND));
#endif
#endif
ret = true;
}
return ret;
}
auto is_modified_date_older_than(const std::string &path,
const std::chrono::hours &hours) -> bool { const std::chrono::hours &hours) -> bool {
auto ret = false; auto modified = file{path}.get_time(file::time_types::modified);
std::uint64_t modified{}; auto seconds = std::chrono::duration_cast<std::chrono::seconds>(hours);
if (get_modified_time(path, modified)) { return (modified + static_cast<std::uint64_t>(
const auto seconds = seconds.count() * utils::time::NANOS_PER_SECOND)) <
std::chrono::duration_cast<std::chrono::seconds>(hours); utils::time::get_time_now();
#if defined(_WIN32)
return (std::chrono::system_clock::from_time_t(
static_cast<time_t>(modified)) +
seconds) < std::chrono::system_clock::now();
#else
return (modified +
static_cast<std::uint64_t>(seconds.count() * NANOS_PER_SECOND)) <
utils::time::get_time_now();
#endif
}
return ret;
} }
auto move_file(std::string from, std::string to) -> bool { auto move_file(std::string from, std::string to) -> bool {
@ -459,24 +306,4 @@ auto reset_modified_time(const std::string &path) -> bool {
#endif #endif
return ret; return ret;
} }
auto retry_delete_directory(const std::string &dir) -> bool {
auto deleted = false;
for (std::uint8_t i = 0U;
not(deleted = directory(dir).remove()) && (i < 200U); i++) {
std::this_thread::sleep_for(10ms);
}
return deleted;
}
auto retry_delete_file(const std::string &file) -> bool {
auto deleted = false;
for (std::uint8_t i = 0U;
not(deleted = utils::file::file{file}.remove()) && (i < 200U); i++) {
std::this_thread::sleep_for(10ms);
}
return deleted;
}
} // namespace repertory::utils::file } // namespace repertory::utils::file

View File

@ -201,10 +201,6 @@ auto unix_error_to_windows(int err) -> std::uint32_t {
} }
} }
auto unix_time_to_windows_time(const remote::file_time &file_time) -> UINT64 {
return (file_time / 100ULL) + 116444736000000000ULL;
}
void windows_create_to_unix(const UINT32 &create_options, void windows_create_to_unix(const UINT32 &create_options,
const UINT32 &granted_access, std::uint32_t &flags, const UINT32 &granted_access, std::uint32_t &flags,
remote::file_mode &mode) { remote::file_mode &mode) {
@ -221,10 +217,6 @@ void windows_create_to_unix(const UINT32 &create_options,
mode |= (S_IXUSR); mode |= (S_IXUSR);
} }
} }
auto windows_time_to_unix_time(std::uint64_t win_time) -> remote::file_time {
return (win_time - 116444736000000000ULL) * 100ULL;
}
} // namespace repertory::utils } // namespace repertory::utils
#endif // !_WIN32 #endif // !_WIN32

View File

@ -22,15 +22,8 @@
#include "utils/utils.hpp" #include "utils/utils.hpp"
#include "app_config.hpp" #include "app_config.hpp"
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "providers/i_provider.hpp"
#include "types/startup_exception.hpp"
#include "utils/com_init_wrapper.hpp"
#include "utils/common.hpp" #include "utils/common.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp" #include "utils/string.hpp"
#include "utils/time.hpp"
namespace repertory::utils { namespace repertory::utils {
void calculate_allocation_size(bool directory, std::uint64_t file_size, void calculate_allocation_size(bool directory, std::uint64_t file_size,
@ -52,32 +45,6 @@ void calculate_allocation_size(bool directory, std::uint64_t file_size,
allocation_meta_size = std::to_string(allocation_size); allocation_meta_size = std::to_string(allocation_size);
} }
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, '.', true);
const auto date_time = date_parts[0U];
const auto nanos = utils::string::to_uint64(
utils::string::split(date_parts[1U], 'Z', true)[0U]);
struct tm tm1 {};
#if defined(_WIN32)
utils::time::strptime(date_time.c_str(), "%Y-%m-%dT%T", &tm1);
#else
strptime(date_time.c_str(), "%Y-%m-%dT%T", &tm1);
#endif
return nanos + (static_cast<std::uint64_t>(mktime(&tm1)) * NANOS_PER_SECOND);
}
auto create_curl() -> CURL * {
static std::recursive_mutex mtx;
unique_recur_mutex_lock lock(mtx);
curl_global_init(CURL_GLOBAL_DEFAULT);
lock.unlock();
return reset_curl(curl_easy_init());
}
auto create_volume_label(const provider_type &prov) -> std::string { auto create_volume_label(const provider_type &prov) -> std::string {
return "repertory_" + app_config::get_provider_name(prov); return "repertory_" + app_config::get_provider_name(prov);
} }
@ -85,54 +52,4 @@ auto create_volume_label(const provider_type &prov) -> std::string {
auto get_attributes_from_meta(const api_meta_map &meta) -> DWORD { auto get_attributes_from_meta(const api_meta_map &meta) -> DWORD {
return static_cast<DWORD>(utils::string::to_uint32(meta.at(META_ATTRIBUTES))); return static_cast<DWORD>(utils::string::to_uint32(meta.at(META_ATTRIBUTES)));
} }
auto reset_curl(CURL *curl_handle) -> CURL * {
curl_easy_reset(curl_handle);
#if defined(__APPLE__)
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
#endif
return curl_handle;
}
auto retryable_action(const std::function<bool()> &action) -> bool {
static constexpr const auto retry_count = 20U;
auto succeeded = false;
for (std::uint8_t i = 0U; not(succeeded = action()) && (i < retry_count);
i++) {
std::this_thread::sleep_for(100ms);
}
return succeeded;
}
void spin_wait_for_mutex(std::function<bool()> complete,
std::condition_variable &cond, std::mutex &mtx,
const std::string &text) {
while (not complete()) {
unique_mutex_lock lock(mtx);
if (not complete()) {
if (not text.empty()) {
/* event_system::instance().raise<DebugLog>(__FUNCTION__,
* "spin_wait_for_mutex", text); */
}
cond.wait_for(lock, 1s);
}
lock.unlock();
}
}
void spin_wait_for_mutex(bool &complete, std::condition_variable &cond,
std::mutex &mtx, const std::string &text) {
while (not complete) {
unique_mutex_lock lock(mtx);
if (not complete) {
if (not text.empty()) {
/* event_system::instance().raise<DebugLog>(__FUNCTION__,
* "spin_wait_for_mutex", text); */
}
cond.wait_for(lock, 1s);
}
lock.unlock();
}
}
} // namespace repertory::utils } // namespace repertory::utils

View File

@ -23,9 +23,8 @@
#include "utils/windows/windows_utils.hpp" #include "utils/windows/windows_utils.hpp"
#include "types/startup_exception.hpp"
#include "utils/com_init_wrapper.hpp"
#include "utils/string.hpp" #include "utils/string.hpp"
#include "utils/time.hpp"
#if !defined(STATUS_DEVICE_INSUFFICIENT_RESOURCES) #if !defined(STATUS_DEVICE_INSUFFICIENT_RESOURCES)
#define STATUS_DEVICE_INSUFFICIENT_RESOURCES static_cast<NTSTATUS>(0xC0000468L) #define STATUS_DEVICE_INSUFFICIENT_RESOURCES static_cast<NTSTATUS>(0xC0000468L)
@ -88,19 +87,23 @@ auto from_api_error(const api_error &e) -> NTSTATUS {
} }
auto get_accessed_time_from_meta(const api_meta_map &meta) -> std::uint64_t { auto get_accessed_time_from_meta(const api_meta_map &meta) -> std::uint64_t {
return utils::string::to_uint64(meta.at(META_ACCESSED)); return utils::time::unix_time_to_windows_time(
utils::string::to_uint64(meta.at(META_ACCESSED)));
} }
auto get_changed_time_from_meta(const api_meta_map &meta) -> std::uint64_t { auto get_changed_time_from_meta(const api_meta_map &meta) -> std::uint64_t {
return utils::string::to_uint64(meta.at(META_MODIFIED)); return utils::time::unix_time_to_windows_time(
utils::string::to_uint64(meta.at(META_MODIFIED)));
} }
auto get_creation_time_from_meta(const api_meta_map &meta) -> std::uint64_t { auto get_creation_time_from_meta(const api_meta_map &meta) -> std::uint64_t {
return utils::string::to_uint64(meta.at(META_CREATION)); return utils::time::unix_time_to_windows_time(
utils::string::to_uint64(meta.at(META_CREATION)));
} }
auto get_written_time_from_meta(const api_meta_map &meta) -> std::uint64_t { auto get_written_time_from_meta(const api_meta_map &meta) -> std::uint64_t {
return utils::string::to_uint64(meta.at(META_WRITTEN)); return utils::time::unix_time_to_windows_time(
utils::string::to_uint64(meta.at(META_WRITTEN)));
} }
auto unix_access_mask_to_windows(std::int32_t mask) -> int { auto unix_access_mask_to_windows(std::int32_t mask) -> int {

View File

@ -21,7 +21,7 @@
*/ */
#if defined(PROJECT_ENABLE_BACKWARD_CPP) #if defined(PROJECT_ENABLE_BACKWARD_CPP)
#include "backward.hpp" #include "backward.hpp"
#endif #endif // defined(PROJECT_ENABLE_BACKWARD_CPP)
#include "cli/actions.hpp" #include "cli/actions.hpp"
#include "initialize.hpp" #include "initialize.hpp"
@ -34,7 +34,7 @@ using namespace repertory;
auto main(int argc, char **argv) -> int { auto main(int argc, char **argv) -> int {
#if defined(PROJECT_ENABLE_BACKWARD_CPP) #if defined(PROJECT_ENABLE_BACKWARD_CPP)
static backward::SignalHandling sh; static backward::SignalHandling sh;
#endif #endif // defined(PROJECT_ENABLE_BACKWARD_CPP)
if (not repertory::project_initialize()) { if (not repertory::project_initialize()) {
std::cerr << "fatal: failed to initialize repertory" << std::endl; std::cerr << "fatal: failed to initialize repertory" << std::endl;

View File

@ -132,7 +132,7 @@ public:
utils::path::combine(mount_location_, {to_api_path}); utils::path::combine(mount_location_, {to_api_path});
if (overwrite) { if (overwrite) {
if (not utils::file::retry_delete_file(to_file_path)) { if (not utils::file::file(to_file_path).remove()) {
return -1; return -1;
} }
} else if (utils::file::directory(to_file_path).exists()) || } else if (utils::file::directory(to_file_path).exists()) ||

View File

@ -371,8 +371,14 @@ TEST(ring_buffer_open_file, read_full_file) {
nf2.close(); nf2.close();
nf.close(); nf.close();
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(), auto hash1 = utils::file::file(download_source_path).sha256();
utils::file::generate_sha256(dest_path).c_str()); auto hash2 = utils::file::file(dest_path).sha256();
EXPECT_TRUE(hash1.has_value());
EXPECT_TRUE(hash2.has_value());
if (hash1.has_value() && hash2.has_value()) {
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
}
} }
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
@ -430,8 +436,14 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
nf2.close(); nf2.close();
nf.close(); nf.close();
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(), auto hash1 = utils::file::file(download_source_path).sha256();
utils::file::generate_sha256(dest_path).c_str()); auto hash2 = utils::file::file(dest_path).sha256();
EXPECT_TRUE(hash1.has_value());
EXPECT_TRUE(hash2.has_value());
if (hash1.has_value() && hash2.has_value()) {
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
}
} }
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
@ -490,8 +502,14 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
nf2.close(); nf2.close();
nf.close(); nf.close();
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(), auto hash1 = utils::file::file(download_source_path).sha256();
utils::file::generate_sha256(dest_path).c_str()); auto hash2 = utils::file::file(dest_path).sha256();
EXPECT_TRUE(hash1.has_value());
EXPECT_TRUE(hash2.has_value());
if (hash1.has_value() && hash2.has_value()) {
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
}
} }
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
@ -555,8 +573,14 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
nf2.close(); nf2.close();
nf.close(); nf.close();
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(), auto hash1 = utils::file::file(download_source_path).sha256();
utils::file::generate_sha256(dest_path).c_str()); auto hash2 = utils::file::file(dest_path).sha256();
EXPECT_TRUE(hash1.has_value());
EXPECT_TRUE(hash2.has_value());
if (hash1.has_value() && hash2.has_value()) {
EXPECT_STREQ(hash1.value().c_str(), hash2.value().c_str());
}
} }
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());

View File

@ -738,7 +738,7 @@ TEST(file_manager, can_evict_file) {
fm.close(handle); fm.close(handle);
capture.wait_for_empty(); capture.wait_for_empty();
EXPECT_TRUE(utils::retryable_action( EXPECT_TRUE(utils::retry_action(
[&fm]() -> bool { return not fm.is_processing("/test_evict.txt"); })); [&fm]() -> bool { return not fm.is_processing("/test_evict.txt"); }));
EXPECT_CALL(mp, get_item_meta(_, META_SOURCE, _)) EXPECT_CALL(mp, get_item_meta(_, META_SOURCE, _))
@ -1009,7 +1009,7 @@ TEST(file_manager, evict_file_fails_if_file_is_uploading) {
fm.close(handle); fm.close(handle);
EXPECT_TRUE(utils::retryable_action( EXPECT_TRUE(utils::retry_action(
[&fm]() -> bool { return fm.is_processing("/test_evict.txt"); })); [&fm]() -> bool { return fm.is_processing("/test_evict.txt"); }));
EXPECT_FALSE(fm.evict_file("/test_evict.txt")); EXPECT_FALSE(fm.evict_file("/test_evict.txt"));
} }

View File

@ -431,8 +431,8 @@ namespace repertory {
// // utils::path::combine(mount_location, {"to_rename_file_test"}); // // utils::path::combine(mount_location, {"to_rename_file_test"});
// // test_rename_file(file_path, to_file_path, // // test_rename_file(file_path, to_file_path,
// // provider_ptr->is_rename_supported()); // // provider_ptr->is_rename_supported());
// // EXPECT_TRUE(utils::file::retry_delete_file(file_path)); // // EXPECT_TRUE(utils::file::file(file_path).remove());
// // EXPECT_TRUE(utils::file::retry_delete_file(to_file_path)); // // EXPECT_TRUE(utils::file::file(to_file_path).remove());
// // // //
// // file_path = // // file_path =
// // utils::path::combine(mount_location, // // utils::path::combine(mount_location,

View File

@ -52,7 +52,7 @@ static std::string fuse_remote_dir =
static void access_test(repertory::remote_fuse::remote_client &client) { static void access_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"access.txt"}); const auto test_file = utils::path::combine(fuse_remote_dir, {"access.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -64,13 +64,13 @@ static void access_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_access(api_path.c_str(), 0)); EXPECT_EQ(0, client.fuse_access(api_path.c_str(), 0));
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void chflags_test(repertory::remote_fuse::remote_client &client) { static void chflags_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"chflags.txt"}); const auto test_file = utils::path::combine(fuse_remote_dir, {"chflags.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -86,13 +86,13 @@ static void chflags_test(repertory::remote_fuse::remote_client &client) {
#endif #endif
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void chmod_test(repertory::remote_fuse::remote_client &client) { static void chmod_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"chmod.txt"}); const auto test_file = utils::path::combine(fuse_remote_dir, {"chmod.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -108,13 +108,13 @@ static void chmod_test(repertory::remote_fuse::remote_client &client) {
#endif #endif
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void chown_test(repertory::remote_fuse::remote_client &client) { static void chown_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"chown.txt"}); const auto test_file = utils::path::combine(fuse_remote_dir, {"chown.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -134,7 +134,7 @@ static void chown_test(repertory::remote_fuse::remote_client &client) {
#endif #endif
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void static void
@ -143,7 +143,7 @@ create_and_release_test(repertory::remote_fuse::remote_client &client,
const auto test_file = const auto test_file =
utils::path::combine(fuse_remote_dir, {"create_and_release.txt"}); utils::path::combine(fuse_remote_dir, {"create_and_release.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -156,7 +156,7 @@ create_and_release_test(repertory::remote_fuse::remote_client &client,
EXPECT_EQ(0u, server.get_open_file_count(test_file)); EXPECT_EQ(0u, server.get_open_file_count(test_file));
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void destroy_test(repertory::remote_fuse::remote_client &client) { static void destroy_test(repertory::remote_fuse::remote_client &client) {
@ -167,7 +167,7 @@ static void destroy_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, const auto test_file = utils::path::combine(fuse_remote_dir,
{"fallocate.txt"}); const auto api_path = {"fallocate.txt"}); const auto api_path =
test_file.substr(mount_location_.size()); test_file.substr(mount_location_.size());
utils::file::retry_delete_file(test_file); utils::file::file(test_file).remove();
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -181,14 +181,14 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
EXPECT_EQ(100, file_size); EXPECT_EQ(100, file_size);
} }
utils::file::retry_delete_file(test_file); utils::file::file(test_file).remove();
}*/ }*/
static void fgetattr_test(repertory::remote_fuse::remote_client &client) { static void fgetattr_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(fuse_remote_dir, {"fgetattr.txt"}); utils::path::combine(fuse_remote_dir, {"fgetattr.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -219,23 +219,23 @@ static void fgetattr_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(st1.st_nlink, st.st_nlink); EXPECT_EQ(st1.st_nlink, st.st_nlink);
EXPECT_EQ(st1.st_mode, st.st_mode); EXPECT_EQ(st1.st_mode, st.st_mode);
EXPECT_LE(static_cast<remote::file_time>(st1.st_atime), EXPECT_LE(static_cast<remote::file_time>(st1.st_atime),
st.st_atimespec / NANOS_PER_SECOND); st.st_atimespec / utils::time::NANOS_PER_SECOND);
EXPECT_EQ(static_cast<remote::file_time>(st1.st_mtime), EXPECT_EQ(static_cast<remote::file_time>(st1.st_mtime),
st.st_mtimespec / NANOS_PER_SECOND); st.st_mtimespec / utils::time::NANOS_PER_SECOND);
EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime), EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime),
st.st_ctimespec / NANOS_PER_SECOND); st.st_ctimespec / utils::time::NANOS_PER_SECOND);
EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime), EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime),
st.st_birthtimespec / NANOS_PER_SECOND); st.st_birthtimespec / utils::time::NANOS_PER_SECOND);
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void fsetattr_x_test(repertory::remote_fuse::remote_client &client) { static void fsetattr_x_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(fuse_remote_dir, {"fsetattr_x.txt"}); utils::path::combine(fuse_remote_dir, {"fsetattr_x.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -253,13 +253,13 @@ static void fsetattr_x_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle)); EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void fsync_test(repertory::remote_fuse::remote_client &client) { static void fsync_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"fsync.txt"}); const auto test_file = utils::path::combine(fuse_remote_dir, {"fsync.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -271,14 +271,14 @@ static void fsync_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle)); EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void ftruncate_test(repertory::remote_fuse::remote_client &client) { static void ftruncate_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(fuse_remote_dir, {"ftruncate.txt"}); utils::path::combine(fuse_remote_dir, {"ftruncate.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -294,13 +294,13 @@ static void ftruncate_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(100U, opt_size.value()); EXPECT_EQ(100U, opt_size.value());
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void getattr_test(repertory::remote_fuse::remote_client &client) { static void getattr_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"getattr.txt"}); const auto test_file = utils::path::combine(fuse_remote_dir, {"getattr.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -330,23 +330,23 @@ static void getattr_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(st1.st_nlink, st.st_nlink); EXPECT_EQ(st1.st_nlink, st.st_nlink);
EXPECT_EQ(st1.st_mode, st.st_mode); EXPECT_EQ(st1.st_mode, st.st_mode);
EXPECT_LE(static_cast<remote::file_time>(st1.st_atime), EXPECT_LE(static_cast<remote::file_time>(st1.st_atime),
st.st_atimespec / NANOS_PER_SECOND); st.st_atimespec / utils::time::NANOS_PER_SECOND);
EXPECT_EQ(static_cast<remote::file_time>(st1.st_mtime), EXPECT_EQ(static_cast<remote::file_time>(st1.st_mtime),
st.st_mtimespec / NANOS_PER_SECOND); st.st_mtimespec / utils::time::NANOS_PER_SECOND);
EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime), EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime),
st.st_ctimespec / NANOS_PER_SECOND); st.st_ctimespec / utils::time::NANOS_PER_SECOND);
EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime), EXPECT_EQ(static_cast<remote::file_time>(st1.st_ctime),
st.st_birthtimespec / NANOS_PER_SECOND); st.st_birthtimespec / utils::time::NANOS_PER_SECOND);
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
/*static void getxattr_test(repertory::remote_fuse::remote_client &client) { /*static void getxattr_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, const auto test_file = utils::path::combine(fuse_remote_dir,
{"getxattr.txt"}); const auto api_path = {"getxattr.txt"}); const auto api_path =
test_file.substr(mount_location_.size()); test_file.substr(mount_location_.size());
utils::file::retry_delete_file(test_file); utils::file::file(test_file).remove();
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -359,14 +359,14 @@ nullptr, 0)); #else EXPECT_EQ(-EACCES, client.fuse_getxattr(api_path.c_str(),
"test", nullptr, 0)); #endif "test", nullptr, 0)); #endif
} }
utils::file::retry_delete_file(test_file); utils::file::file(test_file).remove();
} }
static void getxattr_osx_test(repertory::remote_fuse::remote_client &client) { static void getxattr_osx_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, const auto test_file = utils::path::combine(fuse_remote_dir,
{"getxattr_osx.txt"}); const auto api_path = {"getxattr_osx.txt"}); const auto api_path =
test_file.substr(mount_location_.size()); test_file.substr(mount_location_.size());
utils::file::retry_delete_file(test_file); utils::file::file(test_file).remove();
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -377,14 +377,14 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
client.fuse_getxattrOSX(api_path.c_str(), "test", nullptr, 0, 0)); client.fuse_getxattrOSX(api_path.c_str(), "test", nullptr, 0, 0));
} }
utils::file::retry_delete_file(test_file); utils::file::file(test_file).remove();
}*/ }*/
static void getxtimes_test(repertory::remote_fuse::remote_client &client) { static void getxtimes_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(fuse_remote_dir, {"getxtimes.txt"}); utils::path::combine(fuse_remote_dir, {"getxtimes.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -403,7 +403,7 @@ static void getxtimes_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle)); EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void init_test(repertory::remote_fuse::remote_client &client) { static void init_test(repertory::remote_fuse::remote_client &client) {
@ -414,7 +414,7 @@ static void init_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, const auto test_file = utils::path::combine(fuse_remote_dir,
{"listxattr.txt"}); const auto api_path = {"listxattr.txt"}); const auto api_path =
test_file.substr(mount_location_.size()); test_file.substr(mount_location_.size());
utils::file::retry_delete_file(test_file); utils::file::file(test_file).remove();
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -427,7 +427,7 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
#endif #endif
} }
utils::file::retry_delete_file(test_file); utils::file::file(test_file).remove();
}*/ }*/
static void mkdir_test(repertory::remote_fuse::remote_client &client) { static void mkdir_test(repertory::remote_fuse::remote_client &client) {
@ -449,7 +449,7 @@ static void mkdir_test(repertory::remote_fuse::remote_client &client) {
static void open_test(repertory::remote_fuse::remote_client &client) { static void open_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"open.txt"}); const auto test_file = utils::path::combine(fuse_remote_dir, {"open.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
#if defined(_WIN32) #if defined(_WIN32)
@ -471,7 +471,7 @@ static void open_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle2)); EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle2));
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void static void
@ -499,7 +499,7 @@ static void read_and_write_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(fuse_remote_dir, {"read_and_write.txt"}); utils::path::combine(fuse_remote_dir, {"read_and_write.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -517,7 +517,7 @@ static void read_and_write_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle)); EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void static void
@ -525,7 +525,7 @@ read_and_write_base64_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(fuse_remote_dir, {"read_and_write_base64.txt"}); utils::path::combine(fuse_remote_dir, {"read_and_write_base64.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -544,7 +544,7 @@ read_and_write_base64_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle)); EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void readdir_test(repertory::remote_fuse::remote_client &client) { static void readdir_test(repertory::remote_fuse::remote_client &client) {
@ -579,7 +579,7 @@ static void readdir_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, const auto test_file = utils::path::combine(fuse_remote_dir,
{"removexattr.txt"}); const auto api_path = {"removexattr.txt"}); const auto api_path =
test_file.substr(mount_location_.size()); test_file.substr(mount_location_.size());
utils::file::retry_delete_file(test_file); utils::file::file(test_file).remove();
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -592,7 +592,7 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
"test")); #endif "test")); #endif
} }
utils::file::retry_delete_file(test_file); utils::file::file(test_file).remove();
}*/ }*/
static void rename_test(repertory::remote_fuse::remote_client &client) { static void rename_test(repertory::remote_fuse::remote_client &client) {
@ -602,8 +602,8 @@ static void rename_test(repertory::remote_fuse::remote_client &client) {
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
const auto renamed_api_path = const auto renamed_api_path =
renamed_test_file.substr(mount_location_.size()); renamed_test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
EXPECT_TRUE(utils::file::retry_delete_file(renamed_test_file)); EXPECT_TRUE(utils::file::file(renamed_test_file).remove());
remote::file_handle handle; remote::file_handle handle;
#if defined(_WIN32) #if defined(_WIN32)
@ -625,8 +625,8 @@ static void rename_test(repertory::remote_fuse::remote_client &client) {
EXPECT_TRUE(utils::file::file(renamed_test_file).exists()); EXPECT_TRUE(utils::file::file(renamed_test_file).exists());
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
EXPECT_TRUE(utils::file::retry_delete_file(renamed_test_file)); EXPECT_TRUE(utils::file::file(renamed_test_file).remove());
} }
static void rmdir_test(repertory::remote_fuse::remote_client &client) { static void rmdir_test(repertory::remote_fuse::remote_client &client) {
@ -652,7 +652,7 @@ static void setattr_x_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(fuse_remote_dir, {"setattr_x.txt"}); utils::path::combine(fuse_remote_dir, {"setattr_x.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -670,14 +670,14 @@ static void setattr_x_test(repertory::remote_fuse::remote_client &client) {
#endif #endif
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void setbkuptime_test(repertory::remote_fuse::remote_client &client) { static void setbkuptime_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(fuse_remote_dir, {"setbkuptime.txt"}); utils::path::combine(fuse_remote_dir, {"setbkuptime.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -695,14 +695,14 @@ static void setbkuptime_test(repertory::remote_fuse::remote_client &client) {
#endif #endif
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void setchgtime_test(repertory::remote_fuse::remote_client &client) { static void setchgtime_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(fuse_remote_dir, {"setchgtime.txt"}); utils::path::combine(fuse_remote_dir, {"setchgtime.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -720,14 +720,14 @@ static void setchgtime_test(repertory::remote_fuse::remote_client &client) {
#endif #endif
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void setcrtime_test(repertory::remote_fuse::remote_client &client) { static void setcrtime_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(fuse_remote_dir, {"setcrtime.txt"}); utils::path::combine(fuse_remote_dir, {"setcrtime.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -745,7 +745,7 @@ static void setcrtime_test(repertory::remote_fuse::remote_client &client) {
#endif #endif
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void setvolname_test(repertory::remote_fuse::remote_client &client) { static void setvolname_test(repertory::remote_fuse::remote_client &client) {
@ -756,7 +756,7 @@ static void setvolname_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, const auto test_file = utils::path::combine(fuse_remote_dir,
{"setxattr.txt"}); const auto api_path = {"setxattr.txt"}); const auto api_path =
test_file.substr(mount_location_.size()); test_file.substr(mount_location_.size());
utils::file::retry_delete_file(test_file); utils::file::file(test_file).remove();
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -771,14 +771,14 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
5, 0)); #endif 5, 0)); #endif
} }
utils::file::retry_delete_file(test_file); utils::file::file(test_file).remove();
} }
static void setxattr_osx_test(repertory::remote_fuse::remote_client &client) { static void setxattr_osx_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, const auto test_file = utils::path::combine(fuse_remote_dir,
{"setxattr_osx.txt"}); const auto api_path = {"setxattr_osx.txt"}); const auto api_path =
test_file.substr(mount_location_.size()); test_file.substr(mount_location_.size());
utils::file::retry_delete_file(test_file); utils::file::file(test_file).remove();
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -791,7 +791,7 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
0)); 0));
} }
utils::file::retry_delete_file(test_file); utils::file::file(test_file).remove();
}*/ }*/
#if defined(_WIN32) #if defined(_WIN32)
@ -832,7 +832,7 @@ static void statfs_x_test(repertory::remote_fuse::remote_client &client,
remote::statfs_x st{}; remote::statfs_x st{};
EXPECT_EQ(0, client.fuse_statfs_x(api_path.c_str(), 4096, st)); EXPECT_EQ(0, client.fuse_statfs_x(api_path.c_str(), 4096, st));
EXPECT_STREQ(&st.f_mntfromname[0], EXPECT_STREQ(st.f_mntfromname.data(),
utils::create_volume_label(provider_type::remote).c_str()); utils::create_volume_label(provider_type::remote).c_str());
const auto total_bytes = drive.get_total_drive_space(); const auto total_bytes = drive.get_total_drive_space();
@ -853,7 +853,7 @@ static void truncate_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(fuse_remote_dir, {"truncate.txt"}); utils::path::combine(fuse_remote_dir, {"truncate.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
#if defined(_WIN32) #if defined(_WIN32)
@ -876,13 +876,13 @@ static void truncate_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(100U, opt_size.value()); EXPECT_EQ(100U, opt_size.value());
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void unlink_test(repertory::remote_fuse::remote_client &client) { static void unlink_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"unlink.txt"}); const auto test_file = utils::path::combine(fuse_remote_dir, {"unlink.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -895,13 +895,13 @@ static void unlink_test(repertory::remote_fuse::remote_client &client) {
EXPECT_FALSE(utils::file::file(test_file).exists()); EXPECT_FALSE(utils::file::file(test_file).exists());
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void utimens_test(repertory::remote_fuse::remote_client &client) { static void utimens_test(repertory::remote_fuse::remote_client &client) {
const auto test_file = utils::path::combine(fuse_remote_dir, {"utimens.txt"}); const auto test_file = utils::path::combine(fuse_remote_dir, {"utimens.txt"});
const auto api_path = test_file.substr(mount_location_.size()); const auto api_path = test_file.substr(mount_location_.size());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
remote::file_handle handle; remote::file_handle handle;
const auto ret = client.fuse_create( const auto ret = client.fuse_create(
@ -915,7 +915,7 @@ static void utimens_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_utimens(api_path.c_str(), tv, 0, 0)); EXPECT_EQ(0, client.fuse_utimens(api_path.c_str(), tv, 0, 0));
} }
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
TEST(remote_fuse, all_tests) { TEST(remote_fuse, all_tests) {

View File

@ -33,6 +33,7 @@
#include "platform/platform.hpp" #include "platform/platform.hpp"
#include "types/repertory.hpp" #include "types/repertory.hpp"
#include "utils/common.hpp" #include "utils/common.hpp"
#include "utils/time.hpp"
using namespace repertory; using namespace repertory;
using namespace repertory::remote_winfsp; using namespace repertory::remote_winfsp;
@ -45,7 +46,7 @@ static std::string win_remote_dir =
static void can_delete_test(remote_client &client) { static void can_delete_test(remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(win_remote_dir, {"candelete.txt"}); utils::path::combine(win_remote_dir, {"candelete.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path = auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size()); utils::string::from_utf8(test_file).substr(mount_location_.size());
@ -58,14 +59,14 @@ static void can_delete_test(remote_client &client) {
api_path.data())); api_path.data()));
nf.close(); nf.close();
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
} }
template <typename t> template <typename t>
static void create_and_close_test(remote_client &client, t &server) { static void create_and_close_test(remote_client &client, t &server) {
const auto test_file = utils::path::combine(win_remote_dir, {"create.txt"}); const auto test_file = utils::path::combine(win_remote_dir, {"create.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path = auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size()); utils::string::from_utf8(test_file).substr(mount_location_.size());
@ -83,12 +84,12 @@ static void create_and_close_test(remote_client &client, t &server) {
EXPECT_EQ(0u, client.get_open_file_count(utils::string::to_utf8(api_path))); EXPECT_EQ(0u, client.get_open_file_count(utils::string::to_utf8(api_path)));
EXPECT_EQ(0u, server.get_open_file_count(test_file)); EXPECT_EQ(0u, server.get_open_file_count(test_file));
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void cleanup_test(remote_client &client) { static void cleanup_test(remote_client &client) {
const auto test_file = utils::path::combine(win_remote_dir, {"cleanup.txt"}); const auto test_file = utils::path::combine(win_remote_dir, {"cleanup.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path = auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size()); utils::string::from_utf8(test_file).substr(mount_location_.size());
@ -107,12 +108,12 @@ static void cleanup_test(remote_client &client) {
EXPECT_FALSE(was_closed); EXPECT_FALSE(was_closed);
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc)); EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void flush_test(remote_client &client) { static void flush_test(remote_client &client) {
const auto test_file = utils::path::combine(win_remote_dir, {"flush.txt"}); const auto test_file = utils::path::combine(win_remote_dir, {"flush.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path = auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size()); utils::string::from_utf8(test_file).substr(mount_location_.size());
@ -129,13 +130,13 @@ static void flush_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc)); EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void get_file_info_test(remote_client &client) { static void get_file_info_test(remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(win_remote_dir, {"get_file_info.txt"}); utils::path::combine(win_remote_dir, {"get_file_info.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path = auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size()); utils::string::from_utf8(test_file).substr(mount_location_.size());
@ -152,13 +153,13 @@ static void get_file_info_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc)); EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void get_security_by_name_test(remote_client &client) { static void get_security_by_name_test(remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(win_remote_dir, {"get_security_by_name.txt"}); utils::path::combine(win_remote_dir, {"get_security_by_name.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path = auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size()); utils::string::from_utf8(test_file).substr(mount_location_.size());
@ -181,7 +182,7 @@ static void get_security_by_name_test(remote_client &client) {
EXPECT_EQ(static_cast<UINT32>(FILE_ATTRIBUTE_NORMAL), attributes); EXPECT_EQ(static_cast<UINT32>(FILE_ATTRIBUTE_NORMAL), attributes);
EXPECT_FALSE(str_descriptor.empty()); EXPECT_FALSE(str_descriptor.empty());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void get_volume_info_test(remote_client &client) { static void get_volume_info_test(remote_client &client) {
@ -202,7 +203,7 @@ static void mounted_test(remote_client &client) {
static void open_test(remote_client &client) { static void open_test(remote_client &client) {
const auto test_file = utils::path::combine(win_remote_dir, {"open.txt"}); const auto test_file = utils::path::combine(win_remote_dir, {"open.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path = auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size()); utils::string::from_utf8(test_file).substr(mount_location_.size());
@ -229,13 +230,13 @@ static void open_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc)); EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc2)); EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc2));
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void overwrite_test(remote_client &client) { static void overwrite_test(remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(win_remote_dir, {"overwrite.txt"}); utils::path::combine(win_remote_dir, {"overwrite.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path = auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size()); utils::string::from_utf8(test_file).substr(mount_location_.size());
@ -259,7 +260,7 @@ static void overwrite_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc)); EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void create_and_read_directory_test(remote_client &client) { static void create_and_read_directory_test(remote_client &client) {
@ -329,7 +330,7 @@ static void open_and_read_directory_test(remote_client &client) {
static void read_and_write_test(remote_client &client) { static void read_and_write_test(remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(win_remote_dir, {"read_and_write.txt"}); utils::path::combine(win_remote_dir, {"read_and_write.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path = auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size()); utils::string::from_utf8(test_file).substr(mount_location_.size());
@ -365,14 +366,14 @@ static void read_and_write_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc)); EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void rename_test(remote_client &client) { static void rename_test(remote_client &client) {
const auto test_file = utils::path::combine(win_remote_dir, {"rename.txt"}); const auto test_file = utils::path::combine(win_remote_dir, {"rename.txt"});
const auto test_file2 = utils::path::combine(win_remote_dir, {"rename2.txt"}); const auto test_file2 = utils::path::combine(win_remote_dir, {"rename2.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
EXPECT_TRUE(utils::file::retry_delete_file(test_file2)); EXPECT_TRUE(utils::file::file(test_file2).remove());
auto api_path = auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size()); utils::string::from_utf8(test_file).substr(mount_location_.size());
auto api_path2 = auto api_path2 =
@ -394,15 +395,15 @@ static void rename_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc)); EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
EXPECT_TRUE(utils::file::retry_delete_file(test_file2)); EXPECT_TRUE(utils::file::file(test_file2).remove());
} }
static void set_basic_info_test(remote_client &client) { static void set_basic_info_test(remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(win_remote_dir, {"set_basic_info.txt"}); utils::path::combine(win_remote_dir, {"set_basic_info.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path = auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size()); utils::string::from_utf8(test_file).substr(mount_location_.size());
@ -429,7 +430,7 @@ static void set_basic_info_test(remote_client &client) {
const auto change_time = last_write_time; const auto change_time = last_write_time;
#else #else
const auto creation_time = const auto creation_time =
utils::unix_time_to_windows_time(utils::time::get_time_now()); utils::time::unix_time_to_windows_time(utils::time::get_time_now());
const auto last_access_time = creation_time + 1; const auto last_access_time = creation_time + 1;
const auto last_write_time = creation_time + 2; const auto last_write_time = creation_time + 2;
const auto change_time = last_write_time; const auto change_time = last_write_time;
@ -447,13 +448,13 @@ static void set_basic_info_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc)); EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void set_file_size_test(remote_client &client) { static void set_file_size_test(remote_client &client) {
const auto test_file = const auto test_file =
utils::path::combine(win_remote_dir, {"set_file_size.txt"}); utils::path::combine(win_remote_dir, {"set_file_size.txt"});
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
auto api_path = auto api_path =
utils::string::from_utf8(test_file).substr(mount_location_.size()); utils::string::from_utf8(test_file).substr(mount_location_.size());
@ -478,7 +479,7 @@ static void set_file_size_test(remote_client &client) {
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc)); EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
EXPECT_TRUE(utils::file::retry_delete_file(test_file)); EXPECT_TRUE(utils::file::file(test_file).remove());
} }
static void unmounted_test(remote_client &client) { static void unmounted_test(remote_client &client) {

View File

@ -50,8 +50,8 @@ TEST(utils, convert_api_date) {
} }
#endif #endif
TEST(utils, generate_sha256) { // TEST(utils, generate_sha256) {
const auto res = utils::file::generate_sha256(__FILE__); // const auto res = utils::file::generate_sha256(__FILE__);
std::cout << res << std::endl; // std::cout << res << std::endl;
} // }
} // namespace repertory } // namespace repertory

View File

@ -113,7 +113,7 @@ static auto create_test(winfsp_test *test, const std::string &mount_point) {
static void delete_file_test(const std::string &file) { static void delete_file_test(const std::string &file) {
TEST_HEADER(__FUNCTION__); TEST_HEADER(__FUNCTION__);
event_capture ec({"file_removed"}); event_capture ec({"file_removed"});
EXPECT_TRUE(utils::file::retry_delete_file(file)); EXPECT_TRUE(utils::file::file(file).remove());
EXPECT_FALSE(utils::file::file(file).exists()); EXPECT_FALSE(utils::file::file(file).exists());
} }

View File

@ -33,6 +33,8 @@ struct result final {
[[nodiscard]] operator bool() const { return ok; } [[nodiscard]] operator bool() const { return ok; }
}; };
using retryable_action_t = std::function<bool()>;
[[nodiscard]] inline constexpr auto [[nodiscard]] inline constexpr auto
calculate_read_size(std::uint64_t total_size, std::size_t read_size, calculate_read_size(std::uint64_t total_size, std::size_t read_size,
std::uint64_t offset) -> std::size_t { std::uint64_t offset) -> std::size_t {
@ -90,6 +92,11 @@ get_next_available_port(std::uint16_t first_port,
std::uint16_t &available_port) -> bool; std::uint16_t &available_port) -> bool;
#endif // defined(PROJECT_ENABLE_BOOST) #endif // defined(PROJECT_ENABLE_BOOST)
[[nodiscard]] auto retry_action(retryable_action_t action,
std::size_t retry_count = 200U,
std::chrono::milliseconds retry_wait =
std::chrono::milliseconds(10)) -> bool;
template <typename result_t, typename data_t> template <typename result_t, typename data_t>
inline constexpr auto divide_with_ceiling(result_t numerator, inline constexpr auto divide_with_ceiling(result_t numerator,
data_t denominator) -> result_t { data_t denominator) -> result_t {

View File

@ -283,6 +283,10 @@ public:
return read_buffer_size; return read_buffer_size;
} }
#if defined(PROJECT_ENABLE_LIBSODIUM)
[[nodiscard]] auto sha256() -> std::optional<std::string>;
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
[[nodiscard]] auto size() const -> std::optional<std::uint64_t> override; [[nodiscard]] auto size() const -> std::optional<std::uint64_t> override;
[[nodiscard]] auto truncate(std::size_t size) -> bool override; [[nodiscard]] auto truncate(std::size_t size) -> bool override;

View File

@ -25,7 +25,9 @@
#include "utils/config.hpp" #include "utils/config.hpp"
namespace repertory::utils::time { namespace repertory::utils::time {
inline constexpr const auto NANOS_PER_SECOND = 1000000000L; inline constexpr const auto NANOS_PER_SECOND{1000000000ULL};
inline constexpr const auto WIN32_TIME_CONVERSION{116444736000000000ULL};
inline constexpr const auto WIN32_TIME_NANOS_PER_TICK{100ULL};
#if defined(PROJECT_ENABLE_SPDLOG) || defined(PROJECT_ENABLE_FMT) #if defined(PROJECT_ENABLE_SPDLOG) || defined(PROJECT_ENABLE_FMT)
[[nodiscard]] inline auto convert_to_utc(time_t time) -> std::time_t { [[nodiscard]] inline auto convert_to_utc(time_t time) -> std::time_t {
@ -53,10 +55,14 @@ void get_local_time_now(struct tm &local_time);
#if defined(_WIN32) #if defined(_WIN32)
auto strptime(const char *s, const char *f, struct tm *tm) -> const char *; auto strptime(const char *s, const char *f, struct tm *tm) -> const char *;
[[nodiscard]] auto time64_to_unix_time(const __time64_t &time) -> std::uint64_t;
[[nodiscard]] auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME; [[nodiscard]] auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME;
#endif // defined(_WIN32) #endif // defined(_WIN32)
[[nodiscard]] auto
unix_time_to_windows_time(std::uint64_t unix_time) -> std::uint64_t;
[[nodiscard]] auto
windows_time_to_unix_time(std::uint64_t win_time) -> std::uint64_t;
} // namespace repertory::utils::time } // namespace repertory::utils::time
#endif // REPERTORY_INCLUDE_UTILS_TIME_HPP_ #endif // REPERTORY_INCLUDE_UTILS_TIME_HPP_

View File

@ -21,6 +21,7 @@
*/ */
#include "utils/common.hpp" #include "utils/common.hpp"
#include "utils/error.hpp"
#include "utils/string.hpp" #include "utils/string.hpp"
namespace repertory::utils { namespace repertory::utils {
@ -153,4 +154,27 @@ auto get_next_available_port(std::uint16_t first_port,
return not error_code; return not error_code;
} }
#endif // defined(PROJECT_ENABLE_BOOST) #endif // defined(PROJECT_ENABLE_BOOST)
auto retry_action(retryable_action_t action, std::size_t retry_count,
std::chrono::milliseconds retry_wait) -> bool {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
try {
for (std::size_t idx = 0U; idx < retry_count; ++idx) {
if (action()) {
return true;
}
std::this_thread::sleep_for(retry_wait);
}
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
return false;
}
} // namespace repertory::utils } // namespace repertory::utils

View File

@ -206,8 +206,7 @@ encrypting_reader::encrypting_reader(
throw std::runtime_error("failed to get file size|" + throw std::runtime_error("failed to get file size|" +
source_file_->get_path()); source_file_->get_path());
} }
auto file_size = opt_size.value();
auto file_size{opt_size.value()};
const auto total_chunks = utils::divide_with_ceiling( const auto total_chunks = utils::divide_with_ceiling(
file_size, static_cast<std::uint64_t>(data_chunk_size_)); file_size, static_cast<std::uint64_t>(data_chunk_size_));
@ -246,8 +245,7 @@ encrypting_reader::encrypting_reader(std::string_view encrypted_file_path,
throw std::runtime_error("failed to get file size|" + throw std::runtime_error("failed to get file size|" +
source_file_->get_path()); source_file_->get_path());
} }
auto file_size = opt_size.value();
auto file_size{opt_size.value()};
const auto total_chunks = utils::divide_with_ceiling( const auto total_chunks = utils::divide_with_ceiling(
file_size, static_cast<std::uint64_t>(data_chunk_size_)); file_size, static_cast<std::uint64_t>(data_chunk_size_));
@ -289,7 +287,6 @@ encrypting_reader::encrypting_reader(
source_file_->get_path() + '|' + source_file_->get_path() + '|' +
std::to_string(utils::get_last_error_code())); std::to_string(utils::get_last_error_code()));
} }
auto file_size{opt_size.value()}; auto file_size{opt_size.value()};
const auto total_chunks = utils::divide_with_ceiling( const auto total_chunks = utils::divide_with_ceiling(
@ -339,7 +336,6 @@ auto encrypting_reader::calculate_encrypted_size(std::string_view source_path)
std::string{source_path} + '|' + std::string{source_path} + '|' +
std::to_string(utils::get_last_error_code())); std::to_string(utils::get_last_error_code()));
} }
auto file_size{opt_size.value()}; auto file_size{opt_size.value()};
const auto total_chunks = utils::divide_with_ceiling( const auto total_chunks = utils::divide_with_ceiling(

View File

@ -25,6 +25,7 @@
#include "utils/error.hpp" #include "utils/error.hpp"
#include "utils/path.hpp" #include "utils/path.hpp"
#include "utils/string.hpp" #include "utils/string.hpp"
#include "utils/time.hpp"
namespace repertory::utils::file { namespace repertory::utils::file {
auto i_file::read_all(data_buffer &data, std::uint64_t offset, auto i_file::read_all(data_buffer &data, std::uint64_t offset,
@ -74,7 +75,8 @@ auto i_fs_item::get_time(time_types type) const -> std::uint64_t {
switch (type) { switch (type) {
case time_types::access: case time_types::access:
#if defined(_WIN32) #if defined(_WIN32)
return static_cast<std::uint64_t>(st.st_atime); return utils::time::windows_time_to_unix_time(
static_cast<std::uint64_t>(st.st_atime));
#else // !defined(_WIN32) #else // !defined(_WIN32)
return static_cast<std::uint64_t>(st.st_atim.tv_nsec + return static_cast<std::uint64_t>(st.st_atim.tv_nsec +
st.st_atim.tv_sec * st.st_atim.tv_sec *
@ -83,7 +85,8 @@ auto i_fs_item::get_time(time_types type) const -> std::uint64_t {
case time_types::creation: case time_types::creation:
#if defined(_WIN32) #if defined(_WIN32)
return static_cast<std::uint64_t>(st.st_ctime); return utils::time::windows_time_to_unix_time(
static_cast<std::uint64_t>(st.st_ctime));
#else // !defined(_WIN32) #else // !defined(_WIN32)
return static_cast<std::uint64_t>(st.st_ctim.tv_nsec + return static_cast<std::uint64_t>(st.st_ctim.tv_nsec +
st.st_ctim.tv_sec * st.st_ctim.tv_sec *
@ -92,7 +95,8 @@ auto i_fs_item::get_time(time_types type) const -> std::uint64_t {
case time_types::modified: case time_types::modified:
#if defined(_WIN32) #if defined(_WIN32)
return static_cast<std::uint64_t>(st.st_mtime); return utils::time::windows_time_to_unix_time(
static_cast<std::uint64_t>(st.st_mtime));
#else // !defined(_WIN32) #else // !defined(_WIN32)
return static_cast<std::uint64_t>(st.st_mtim.tv_nsec + return static_cast<std::uint64_t>(st.st_mtim.tv_nsec +
st.st_mtim.tv_sec * st.st_mtim.tv_sec *
@ -101,7 +105,8 @@ auto i_fs_item::get_time(time_types type) const -> std::uint64_t {
case time_types::write: case time_types::write:
#if defined(_WIN32) #if defined(_WIN32)
return static_cast<std::uint64_t>(st.st_mtime); return utils::time::windows_time_to_unix_time(
static_cast<std::uint64_t>(st.st_mtime));
#else // !defined(_WIN32) #else // !defined(_WIN32)
return static_cast<std::uint64_t>(st.st_mtim.tv_nsec + return static_cast<std::uint64_t>(st.st_mtim.tv_nsec +
st.st_mtim.tv_sec * st.st_mtim.tv_sec *

View File

@ -21,6 +21,7 @@
*/ */
#include "utils/file.hpp" #include "utils/file.hpp"
#include "utils/common.hpp"
#include "utils/error.hpp" #include "utils/error.hpp"
#include "utils/unix.hpp" #include "utils/unix.hpp"
#include "utils/windows.hpp" #include "utils/windows.hpp"
@ -329,19 +330,21 @@ auto directory::remove() -> bool {
static_cast<const char *>(__FUNCTION__), static_cast<const char *>(__FUNCTION__),
}; };
try { return utils::retry_action([this]() -> bool {
try {
#if defined(_WIN32) #if defined(_WIN32)
return (not exists() || ::RemoveDirectoryA(path_.c_str())); return (not exists() || ::RemoveDirectoryA(path_.c_str()));
#else // !defined(_WIN32) #else // !defined(_WIN32)
return not exists() || (rmdir(path_.c_str()) == 0); return not exists() || (rmdir(path_.c_str()) == 0);
#endif // defined(_WIN32) #endif // defined(_WIN32)
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::handle_exception(function_name, e); utils::error::handle_exception(function_name, e);
} catch (...) { } catch (...) {
utils::error::handle_exception(function_name); utils::error::handle_exception(function_name);
} }
return false; return false;
});
} }
auto directory::remove_recursively() -> bool { auto directory::remove_recursively() -> bool {

View File

@ -21,11 +21,14 @@
*/ */
#include "utils/file.hpp" #include "utils/file.hpp"
#include "utils/collection.hpp"
#include "utils/common.hpp"
#include "utils/encryption.hpp" #include "utils/encryption.hpp"
#include "utils/error.hpp" #include "utils/error.hpp"
#include "utils/path.hpp" #include "utils/path.hpp"
#include "utils/string.hpp" #include "utils/string.hpp"
#include "utils/time.hpp" #include "utils/time.hpp"
#include <optional>
namespace { namespace {
[[nodiscard]] auto get_file_size(std::string_view path, [[nodiscard]] auto get_file_size(std::string_view path,
@ -295,14 +298,15 @@ auto file::read(unsigned char *data, std::size_t to_read, std::uint64_t offset,
throw std::runtime_error("file is not open for reading"); throw std::runtime_error("file is not open for reading");
} }
auto res = fseeko(file_.get(), static_cast<std::int64_t>(offset), SEEK_SET); if (fseeko(file_.get(), static_cast<std::int64_t>(offset), SEEK_SET) ==
if (res == -1) { -1) {
throw std::runtime_error("failed to seek before read"); throw std::runtime_error("failed to seek before read");
} }
std::size_t bytes_read{0U}; std::size_t bytes_read{0U};
while (bytes_read != to_read) { while (bytes_read != to_read) {
res = fread(&data[bytes_read], 1U, to_read - bytes_read, file_.get()); auto res =
fread(&data[bytes_read], 1U, to_read - bytes_read, file_.get());
if (not feof(file_.get()) && ferror(file_.get())) { if (not feof(file_.get()) && ferror(file_.get())) {
throw std::runtime_error("failed to read file bytes"); throw std::runtime_error("failed to read file bytes");
} }
@ -328,6 +332,73 @@ auto file::read(unsigned char *data, std::size_t to_read, std::uint64_t offset,
return false; return false;
} }
#if defined(PROJECT_ENABLE_LIBSODIUM)
auto file::sha256() -> std::optional<std::string> {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
auto should_close{false};
auto read_only{read_only_};
std::optional<std::string> ret;
try {
if (file_ == nullptr) {
should_close = true;
read_only_ = true;
this->open();
}
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));
}
{
data_buffer buffer(get_read_buffer_size());
std::uint64_t read_offset{0U};
std::size_t bytes_read{0U};
while (i_file::read(buffer, read_offset, &bytes_read)) {
if (not bytes_read) {
break;
}
read_offset += bytes_read;
res = crypto_hash_sha256_update(
&state, reinterpret_cast<const unsigned char *>(buffer.data()),
bytes_read);
if (res != 0) {
throw std::runtime_error("failed to update sha256|" +
std::to_string(res));
}
}
}
std::array<unsigned char, crypto_hash_sha256_BYTES> out{};
res = crypto_hash_sha256_final(&state, out.data());
if (res != 0) {
throw std::runtime_error("failed to finalize sha256|" +
std::to_string(res));
}
ret = utils::collection::to_hex_string(out);
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
if (should_close) {
read_only_ = read_only;
close();
}
return ret;
}
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
auto file::remove() -> bool { auto file::remove() -> bool {
#if defined(_WIN32) #if defined(_WIN32)
recur_mutex_lock lock{*mtx_}; recur_mutex_lock lock{*mtx_};
@ -339,12 +410,14 @@ auto file::remove() -> bool {
return true; return true;
} }
return utils::retry_action([this]() -> bool {
#if defined(_WIN32) #if defined(_WIN32)
return !!::DeleteFileA(path_.c_str()); return !!::DeleteFileA(path_.c_str());
#else // !defined(_WIN32) #else // !defined(_WIN32)
std::error_code ec{}; std::error_code ec{};
return std::filesystem::remove(path_, ec); return std::filesystem::remove(path_, ec);
#endif // defined(_WIN32) #endif // defined(_WIN32)
});
} }
auto file::truncate(std::size_t size) -> bool { auto file::truncate(std::size_t size) -> bool {

View File

@ -21,6 +21,7 @@
*/ */
#include "utils/file.hpp" #include "utils/file.hpp"
#include "utils/common.hpp"
#include "utils/error.hpp" #include "utils/error.hpp"
#if defined(PROJECT_ENABLE_LIBDSM) #if defined(PROJECT_ENABLE_LIBDSM)
@ -490,14 +491,24 @@ auto smb_directory::remove() -> bool {
throw std::runtime_error("session not found|" + path_); throw std::runtime_error("session not found|" + path_);
} }
auto res = smb_directory_rm(session_.get(), tid_, return utils::retry_action([this]() -> bool {
smb_create_relative_path(path_).c_str()); try {
if (res != DSM_SUCCESS) { auto res = smb_directory_rm(session_.get(), tid_,
throw std::runtime_error("failed to remove directory|" + path_ + '|' + smb_create_relative_path(path_).c_str());
std::to_string(res)); if (res != DSM_SUCCESS) {
} throw std::runtime_error("failed to remove directory|" + path_ + '|' +
std::to_string(res));
}
return true; return true;
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
return false;
});
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::handle_exception(function_name, e); utils::error::handle_exception(function_name, e);
} catch (...) { } catch (...) {

View File

@ -21,6 +21,7 @@
*/ */
#include "utils/file.hpp" #include "utils/file.hpp"
#include "utils/common.hpp"
#include "utils/error.hpp" #include "utils/error.hpp"
#include "utils/string.hpp" #include "utils/string.hpp"
@ -273,22 +274,32 @@ auto smb_file::remove() -> bool {
try { try {
close(); close();
auto res = smb_tree_connect(session_.get(), share_name_.c_str(), &tid_); return utils::retry_action([this]() -> bool {
if (res != DSM_SUCCESS) { try {
throw std::runtime_error("failed to connect to share|" + share_name_ + auto res = smb_tree_connect(session_.get(), share_name_.c_str(), &tid_);
'|' + std::to_string(res)); if (res != DSM_SUCCESS) {
} throw std::runtime_error("failed to connect to share|" + share_name_ +
'|' + std::to_string(res));
}
auto rel_path = smb_create_relative_path(path_); auto rel_path = smb_create_relative_path(path_);
res = smb_file_rm(session_.get(), tid_, rel_path.c_str()); res = smb_file_rm(session_.get(), tid_, rel_path.c_str());
if (res != DSM_SUCCESS) { if (res != DSM_SUCCESS) {
throw std::runtime_error( throw std::runtime_error(
"failed to remove file|" + path_ + '|' + rel_path + '|' + "failed to remove file|" + path_ + '|' + rel_path + '|' +
std::to_string(res) + '|' + std::to_string(res) + '|' +
std::to_string(smb_session_get_nt_status(session_.get()))); std::to_string(smb_session_get_nt_status(session_.get())));
} }
return true; return true;
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
return false;
});
} catch (const std::exception &e) { } catch (const std::exception &e) {
utils::error::handle_exception(function_name, e); utils::error::handle_exception(function_name, e);
} catch (...) { } catch (...) {

View File

@ -28,9 +28,9 @@ auto filetime_to_unix_time(const FILETIME &file_time) -> std::uint64_t {
LARGE_INTEGER date{}; LARGE_INTEGER date{};
date.HighPart = static_cast<LONG>(file_time.dwHighDateTime); date.HighPart = static_cast<LONG>(file_time.dwHighDateTime);
date.LowPart = file_time.dwLowDateTime; date.LowPart = file_time.dwLowDateTime;
date.QuadPart -= 116444736000000000LL; date.QuadPart -= WIN32_TIME_CONVERSION;
return static_cast<std::uint64_t>(date.QuadPart) * 100ULL; return static_cast<std::uint64_t>(date.QuadPart) * WIN32_TIME_NANOS_PER_TICK;
} }
#endif // defined(_WIN32) #endif // defined(_WIN32)
@ -47,11 +47,10 @@ void get_local_time_now(struct tm &local_time) {
} }
auto get_time_now() -> std::uint64_t { auto get_time_now() -> std::uint64_t {
#if defined(_WIN32) return static_cast<std::uint64_t>(
return static_cast<std::uint64_t>(_time64(nullptr)); std::chrono::duration_cast<std::chrono::nanoseconds>(
#else // !defined(_WIN32) std::chrono::system_clock::now().time_since_epoch())
return static_cast<std::uint64_t>(time(nullptr)); .count());
#endif // defined(_WIN32)
} }
#if defined(_WIN32) #if defined(_WIN32)
@ -67,17 +66,22 @@ auto strptime(const char *s, const char *f, struct tm *tm) -> const char * {
return reinterpret_cast<const char *>(s + input.tellg()); return reinterpret_cast<const char *>(s + input.tellg());
} }
auto time64_to_unix_time(const __time64_t &time) -> std::uint64_t {
return static_cast<std::uint64_t>(time * NANOS_PER_SECOND);
}
// https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/ // https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/
auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME { auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME {
auto win_time = (unix_time / 100ULL) + 116444736000000000ULL; auto win_time =
(unix_time / WIN32_TIME_NANOS_PER_TICK) + WIN32_TIME_CONVERSION;
FILETIME file_time{}; FILETIME file_time{};
file_time.dwHighDateTime = static_cast<DWORD>(win_time >> 32U); file_time.dwHighDateTime = static_cast<DWORD>(win_time >> 32U);
file_time.dwLowDateTime = win_time & 0xFFFFFFFF; file_time.dwLowDateTime = win_time & 0xFFFFFFFF;
return file_time; return file_time;
} }
#endif // defined(_WIN32) #endif // defined(_WIN32)
auto unix_time_to_windows_time(std::uint64_t unix_time) -> std::uint64_t {
return (unix_time / WIN32_TIME_NANOS_PER_TICK) + WIN32_TIME_CONVERSION;
}
auto windows_time_to_unix_time(std::uint64_t win_time) -> std::uint64_t {
return (win_time - WIN32_TIME_CONVERSION) * WIN32_TIME_NANOS_PER_TICK;
}
} // namespace repertory::utils::time } // namespace repertory::utils::time