Compare commits
33 Commits
254578f4ab
...
46490f9930
Author | SHA1 | Date | |
---|---|---|---|
46490f9930 | |||
9ede9f5cf5 | |||
00a5f155ad | |||
b6eab4a932 | |||
d5d2b6a889 | |||
51320f9a09 | |||
31e0b4c5d9 | |||
bc0901f6a2 | |||
3b4c590404 | |||
953684f5a6 | |||
989c90bc8d | |||
776862d474 | |||
1ec287f41a | |||
01ed0c65bb | |||
9bed5e961f | |||
f8e7e8f0e3 | |||
9e9d46a9cd | |||
f654d269a7 | |||
c8929fed0b | |||
81fbe7a962 | |||
3bce0e9c70 | |||
d4f0431cd5 | |||
52f2b5b118 | |||
dfc8742fcb | |||
cf516d8663 | |||
e8af147805 | |||
2835809e5e | |||
bc0d299b85 | |||
13c136d01e | |||
218326f812 | |||
6dc10d2a11 | |||
4eff7aae64 | |||
bc85e34310 |
@ -1,4 +1,7 @@
|
||||
_lseeki64
|
||||
_sh_denyno
|
||||
_sh_denyrd
|
||||
_sh_denyrw
|
||||
aarch64
|
||||
advapi32
|
||||
armv8
|
||||
@ -86,6 +89,8 @@ ecdh
|
||||
endforeach
|
||||
endfunction
|
||||
eventlib
|
||||
expect_streq
|
||||
fallocate_impl
|
||||
fext
|
||||
fgetattr
|
||||
flac_version
|
||||
@ -123,14 +128,18 @@ libsfml
|
||||
libsodium_type
|
||||
libuuid
|
||||
libuuid_include_dirs
|
||||
libvlc
|
||||
linkflags
|
||||
mbig
|
||||
msvc
|
||||
msvcr120
|
||||
mtune
|
||||
nana
|
||||
ncrypt
|
||||
nlohmann_json
|
||||
nmakeprg
|
||||
nominmax
|
||||
ntstatus
|
||||
nuspell_version
|
||||
oleaut32
|
||||
openal_version
|
||||
@ -138,13 +147,20 @@ openssldir
|
||||
pkgconfig
|
||||
project_enable_fontconfig
|
||||
project_enable_gtkmm
|
||||
project_enable_libdsm
|
||||
project_enable_nana
|
||||
propgrid
|
||||
psecurity_descriptor
|
||||
pugi
|
||||
pugixml_project
|
||||
puint32
|
||||
pvoid
|
||||
pwstr
|
||||
remote_winfsp
|
||||
richtext
|
||||
rocksdb_library
|
||||
rpcrt4
|
||||
sddl_revision_1
|
||||
secp256k1
|
||||
secur32
|
||||
sfml_project
|
||||
@ -152,13 +168,17 @@ shlwapi
|
||||
source_subdir
|
||||
spdlog
|
||||
spdlog_project
|
||||
st_ctim
|
||||
static-libgcc
|
||||
static-libstdc++
|
||||
stbuf
|
||||
stduuid_project
|
||||
strequal
|
||||
uring
|
||||
userenv
|
||||
utimens_impl
|
||||
vorbis_version
|
||||
waggressive
|
||||
wall
|
||||
wcast-align
|
||||
wconversion
|
||||
@ -166,6 +186,7 @@ wdouble-promotion
|
||||
wduplicated-branches
|
||||
wduplicated-cond
|
||||
wextra
|
||||
wfloat
|
||||
wformat=2
|
||||
winfsp
|
||||
winhttp
|
||||
@ -183,5 +204,6 @@ wserialization
|
||||
wshadow
|
||||
wsign-conversion
|
||||
wunused
|
||||
wuseless
|
||||
wxwidgets_version
|
||||
xattr
|
@ -42,8 +42,8 @@ private:
|
||||
using write_callback = size_t (*)(char *, size_t, size_t, void *);
|
||||
|
||||
struct read_write_info final {
|
||||
repertory::data_buffer data{};
|
||||
repertory::stop_type &stop_requested;
|
||||
data_buffer data{};
|
||||
stop_type &stop_requested;
|
||||
};
|
||||
|
||||
static const write_callback write_data;
|
||||
@ -56,6 +56,11 @@ private:
|
||||
private:
|
||||
bool use_s3_path_style_{false};
|
||||
|
||||
public:
|
||||
[[nodiscard]] static auto create_curl() -> CURL *;
|
||||
|
||||
[[nodiscard]] static auto reset_curl(CURL *curl_handle) -> CURL *;
|
||||
|
||||
public:
|
||||
[[nodiscard]] static auto
|
||||
construct_url(CURL *curl, const std::string &relative_path,
|
||||
@ -139,7 +144,7 @@ public:
|
||||
|
||||
response_code = 0;
|
||||
|
||||
auto *curl = utils::create_curl();
|
||||
auto *curl = create_curl();
|
||||
if (not request.set_method(curl, stop_requested)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -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";
|
||||
|
||||
#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)
|
||||
|
||||
|
@ -64,15 +64,15 @@ private:
|
||||
struct fuse_operations fuse_ops_ {};
|
||||
|
||||
private:
|
||||
[[nodiscard]] auto execute_callback(
|
||||
std::string_view function_name, const char *from, const char *to,
|
||||
const std::function<api_error(const std::string &, const std::string &)>
|
||||
&cb,
|
||||
[[nodiscard]] auto
|
||||
execute_callback(std::string_view function_name, const char *from,
|
||||
const char *to,
|
||||
const std::function<api_error(std::string, std::string)> &cb,
|
||||
bool disable_logging = false) -> int;
|
||||
|
||||
[[nodiscard]] auto
|
||||
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;
|
||||
|
||||
static void execute_void_callback(std::string_view function_name,
|
||||
@ -83,7 +83,7 @@ private:
|
||||
const std::function<void *()> &cb) -> void *;
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
|
@ -42,9 +42,9 @@ private:
|
||||
private:
|
||||
#if defined(_WIN32)
|
||||
#define to_handle(x) (x)
|
||||
#else
|
||||
#else // !defined(_WIN32)
|
||||
static auto to_handle(PVOID file_desc) -> native_handle;
|
||||
#endif
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
public:
|
||||
auto json_create_directory_snapshot(const std::string &path, json &json_data)
|
||||
|
@ -95,6 +95,9 @@ protected:
|
||||
stop_type &stop_requested) -> api_error override;
|
||||
|
||||
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
|
||||
-> std::uint64_t override;
|
||||
|
||||
|
@ -22,14 +22,14 @@
|
||||
#ifndef INCLUDE_TYPES_REMOTE_HPP_
|
||||
#define INCLUDE_TYPES_REMOTE_HPP_
|
||||
|
||||
#define PACKET_SERVICE_FUSE 1U
|
||||
#define PACKET_SERVICE_WINFSP 2U
|
||||
inline constexpr const auto PACKET_SERVICE_FUSE{1U};
|
||||
inline constexpr const auto PACKET_SERVICE_WINFSP{2U};
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define PACKET_SERVICE_FLAGS PACKET_SERVICE_WINFSP
|
||||
#else
|
||||
#define PACKET_SERVICE_FLAGS PACKET_SERVICE_FUSE
|
||||
#endif
|
||||
inline constexpr const auto PACKET_SERVICE_FLAGS{PACKET_SERVICE_WINFSP};
|
||||
#else // !defined(_WIN32)
|
||||
inline constexpr const auto PACKET_SERVICE_FLAGS{PACKET_SERVICE_FUSE};
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
namespace repertory::remote {
|
||||
using block_count = std::uint64_t;
|
||||
@ -65,16 +65,19 @@ enum class open_flags : std::uint32_t {
|
||||
dsync = 131072U,
|
||||
};
|
||||
|
||||
inline auto operator|(const open_flags &flag_1,
|
||||
const open_flags &flag_2) -> open_flags {
|
||||
using t = std::underlying_type_t<open_flags>;
|
||||
return static_cast<open_flags>(static_cast<t>(flag_1) |
|
||||
static_cast<t>(flag_2));
|
||||
#if defined(__GNUG__)
|
||||
__attribute__((unused))
|
||||
#endif // defined(__GNUG__)
|
||||
[[nodiscard]] inline auto
|
||||
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__)
|
||||
__attribute__((unused))
|
||||
#endif
|
||||
#endif // defined(__GNUG__)
|
||||
inline auto
|
||||
operator|=(open_flags &flag_1, const open_flags &flag_2) -> open_flags & {
|
||||
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__)
|
||||
__attribute__((unused))
|
||||
#endif
|
||||
inline auto
|
||||
#endif // defined(__GNUG__)
|
||||
[[nodiscard]] inline auto
|
||||
operator&(const open_flags &flag_1, const open_flags &flag_2) -> open_flags {
|
||||
using t = std::underlying_type_t<open_flags>;
|
||||
return static_cast<open_flags>(static_cast<t>(flag_1) &
|
||||
static_cast<t>(flag_2));
|
||||
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));
|
||||
}
|
||||
|
||||
#pragma pack(1)
|
||||
struct file_info {
|
||||
UINT32 FileAttributes;
|
||||
UINT32 ReparseTag;
|
||||
UINT64 AllocationSize;
|
||||
UINT64 FileSize;
|
||||
UINT64 CreationTime;
|
||||
UINT64 LastAccessTime;
|
||||
UINT64 LastWriteTime;
|
||||
UINT64 ChangeTime;
|
||||
UINT64 IndexNumber;
|
||||
UINT32 HardLinks;
|
||||
UINT32 EaSize;
|
||||
struct file_info final {
|
||||
UINT32 FileAttributes{};
|
||||
UINT32 ReparseTag{};
|
||||
UINT64 AllocationSize{};
|
||||
UINT64 FileSize{};
|
||||
UINT64 CreationTime{};
|
||||
UINT64 LastAccessTime{};
|
||||
UINT64 LastWriteTime{};
|
||||
UINT64 ChangeTime{};
|
||||
UINT64 IndexNumber{};
|
||||
UINT32 HardLinks{};
|
||||
UINT32 EaSize{};
|
||||
};
|
||||
|
||||
struct setattr_x {
|
||||
std::int32_t valid;
|
||||
file_mode mode;
|
||||
user_id uid;
|
||||
group_id gid;
|
||||
file_size size;
|
||||
file_time acctime;
|
||||
file_time modtime;
|
||||
file_time crtime;
|
||||
file_time chgtime;
|
||||
file_time bkuptime;
|
||||
std::uint32_t flags;
|
||||
struct setattr_x final {
|
||||
std::int32_t valid{};
|
||||
file_mode mode{};
|
||||
user_id uid{};
|
||||
group_id gid{};
|
||||
file_size size{};
|
||||
file_time acctime{};
|
||||
file_time modtime{};
|
||||
file_time crtime{};
|
||||
file_time chgtime{};
|
||||
file_time bkuptime{};
|
||||
std::uint32_t flags{};
|
||||
};
|
||||
|
||||
struct stat {
|
||||
file_mode st_mode;
|
||||
file_nlink st_nlink;
|
||||
user_id st_uid;
|
||||
group_id st_gid;
|
||||
file_time st_atimespec;
|
||||
file_time st_mtimespec;
|
||||
file_time st_ctimespec;
|
||||
file_time st_birthtimespec;
|
||||
file_size st_size;
|
||||
block_count st_blocks;
|
||||
block_size st_blksize;
|
||||
std::uint32_t st_flags;
|
||||
struct stat final {
|
||||
file_mode st_mode{};
|
||||
file_nlink st_nlink{};
|
||||
user_id st_uid{};
|
||||
group_id st_gid{};
|
||||
file_time st_atimespec{};
|
||||
file_time st_mtimespec{};
|
||||
file_time st_ctimespec{};
|
||||
file_time st_birthtimespec{};
|
||||
file_size st_size{};
|
||||
block_count st_blocks{};
|
||||
block_size st_blksize{};
|
||||
std::uint32_t st_flags{};
|
||||
};
|
||||
|
||||
struct statfs {
|
||||
std::uint64_t f_bavail;
|
||||
std::uint64_t f_bfree;
|
||||
std::uint64_t f_blocks;
|
||||
std::uint64_t f_favail;
|
||||
std::uint64_t f_ffree;
|
||||
std::uint64_t f_files;
|
||||
std::uint64_t f_bavail{};
|
||||
std::uint64_t f_bfree{};
|
||||
std::uint64_t f_blocks{};
|
||||
std::uint64_t f_favail{};
|
||||
std::uint64_t f_ffree{};
|
||||
std::uint64_t f_files{};
|
||||
};
|
||||
|
||||
struct statfs_x : public statfs {
|
||||
char f_mntfromname[1024];
|
||||
struct statfs_x final : public statfs {
|
||||
std::array<char, 1024U> f_mntfromname{};
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
@ -154,7 +157,7 @@ struct statfs_x : public statfs {
|
||||
|
||||
[[nodiscard]] auto
|
||||
create_os_open_flags(const open_flags &flags) -> std::uint32_t;
|
||||
#endif
|
||||
#endif // !defined(_WIN32)
|
||||
} // namespace repertory::remote
|
||||
|
||||
#endif // INCLUDE_TYPES_REMOTE_HPP_
|
||||
|
@ -23,26 +23,26 @@
|
||||
#define INCLUDE_TYPES_REPERTORY_HPP_
|
||||
|
||||
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";
|
||||
const std::string META_ATTRIBUTES = "attributes";
|
||||
const std::string META_BACKUP = "backup";
|
||||
const std::string META_CHANGED = "changed";
|
||||
const std::string META_CREATION = "creation";
|
||||
const std::string META_DIRECTORY = "directory";
|
||||
const std::string META_GID = "gid";
|
||||
const std::string META_KEY = "key";
|
||||
const std::string META_MODE = "mode";
|
||||
const std::string META_MODIFIED = "modified";
|
||||
const std::string META_OSXFLAGS = "flags";
|
||||
const std::string META_PINNED = "pinned";
|
||||
const std::string META_SIZE = "size";
|
||||
const std::string META_SOURCE = "source";
|
||||
const std::string META_UID = "uid";
|
||||
const std::string META_WRITTEN = "written";
|
||||
inline constexpr const std::string META_ACCESSED{"accessed"};
|
||||
inline constexpr const std::string META_ATTRIBUTES{"attributes"};
|
||||
inline constexpr const std::string META_BACKUP{"backup"};
|
||||
inline constexpr const std::string META_CHANGED{"changed"};
|
||||
inline constexpr const std::string META_CREATION{"creation"};
|
||||
inline constexpr const std::string META_DIRECTORY{"directory"};
|
||||
inline constexpr const std::string META_GID{"gid"};
|
||||
inline constexpr const std::string META_KEY{"key"};
|
||||
inline constexpr const std::string META_MODE{"mode"};
|
||||
inline constexpr const std::string META_MODIFIED{"modified"};
|
||||
inline constexpr const std::string META_OSXFLAGS{"flags"};
|
||||
inline constexpr const std::string META_PINNED{"pinned"};
|
||||
inline constexpr const std::string META_SIZE{"size"};
|
||||
inline constexpr const std::string META_SOURCE{"source"};
|
||||
inline constexpr const std::string META_UID{"uid"};
|
||||
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_CREATION, META_DIRECTORY, META_GID, META_KEY,
|
||||
META_MODE, META_MODIFIED, META_OSXFLAGS, META_PINNED,
|
||||
|
@ -79,8 +79,8 @@ struct head_object_result {
|
||||
#else
|
||||
strptime(date.c_str(), "%a, %d %b %Y %H:%M:%S %Z", &tm1);
|
||||
#endif
|
||||
last_modified =
|
||||
static_cast<std::uint64_t>(mktime(&tm1)) * NANOS_PER_SECOND;
|
||||
last_modified = static_cast<std::uint64_t>(mktime(&tm1)) *
|
||||
utils::time::NANOS_PER_SECOND;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
@ -26,10 +26,6 @@
|
||||
#include "utils/file.hpp"
|
||||
|
||||
namespace repertory::utils::file {
|
||||
// Prototypes
|
||||
[[nodiscard]] auto calculate_used_space(std::string path,
|
||||
bool recursive) -> std::uint64_t;
|
||||
|
||||
void change_to_process_directory();
|
||||
|
||||
[[nodiscard]] auto copy_directory_recursively(std::string from_path,
|
||||
@ -38,11 +34,6 @@ void change_to_process_directory();
|
||||
[[nodiscard]] auto copy_file(std::string from_path,
|
||||
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
|
||||
get_directory_files(std::string path, bool oldest_first,
|
||||
bool recursive = false) -> std::deque<std::string>;
|
||||
@ -53,11 +44,8 @@ get_free_drive_space(const std::string &path) -> std::uint64_t;
|
||||
[[nodiscard]] auto
|
||||
get_total_drive_space(const std::string &path) -> std::uint64_t;
|
||||
|
||||
[[nodiscard]] auto get_modified_time(const std::string &path,
|
||||
std::uint64_t &modified) -> bool;
|
||||
|
||||
[[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;
|
||||
|
||||
[[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>;
|
||||
|
||||
[[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
|
||||
|
||||
#endif // INCLUDE_UTILS_FILE_UTILS_HPP_
|
||||
|
@ -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_time_to_windows_time(const remote::file_time &file_time) -> UINT64;
|
||||
|
||||
void windows_create_to_unix(const UINT32 &create_options,
|
||||
const UINT32 &granted_access, std::uint32_t &flags,
|
||||
remote::file_mode &mode);
|
||||
|
||||
[[nodiscard]] auto
|
||||
windows_time_to_unix_time(std::uint64_t win_time) -> remote::file_time;
|
||||
} // namespace repertory::utils
|
||||
|
||||
#endif // !_WIN32
|
||||
|
@ -29,27 +29,10 @@ void calculate_allocation_size(bool directory, std::uint64_t file_size,
|
||||
UINT64 allocation_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
|
||||
create_volume_label(const provider_type &prov) -> std::string;
|
||||
|
||||
[[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
|
||||
|
||||
#endif // INCLUDE_UTILS_UTILS_HPP_
|
||||
|
@ -92,6 +92,16 @@ auto curl_comm::construct_url(CURL *curl, const std::string &relative_path,
|
||||
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,
|
||||
bool use_s3_path_style) -> host_config {
|
||||
host_config host_cfg{};
|
||||
|
@ -194,7 +194,7 @@ auto packet::decode(remote::statfs &val) -> packet::error_type {
|
||||
auto packet::decode(remote::statfs_x &val) -> packet::error_type {
|
||||
auto ret = decode(*dynamic_cast<remote::statfs *>(&val));
|
||||
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;
|
||||
}
|
||||
@ -372,9 +372,9 @@ void packet::encode(remote::statfs val, bool should_reserve) {
|
||||
|
||||
void packet::encode(remote::statfs_x val) {
|
||||
buffer_.reserve(buffer_.size() + sizeof(remote::statfs) +
|
||||
sizeof(val.f_mntfromname));
|
||||
val.f_mntfromname.size());
|
||||
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) {
|
||||
@ -501,8 +501,8 @@ void packet::encode_top(remote::statfs val, bool should_reserve) {
|
||||
|
||||
void packet::encode_top(remote::statfs_x val) {
|
||||
buffer_.reserve(buffer_.size() + sizeof(remote::statfs) +
|
||||
sizeof(val.f_mntfromname));
|
||||
encode_top(&val.f_mntfromname[0], sizeof(val.f_mntfromname), false);
|
||||
val.f_mntfromname.size());
|
||||
encode_top(val.f_mntfromname.data(), val.f_mntfromname.size(), false);
|
||||
encode_top(*dynamic_cast<remote::statfs *>(&val), false);
|
||||
}
|
||||
|
||||
|
@ -46,30 +46,19 @@ auto eviction::check_minimum_requirements(const std::string &file_path)
|
||||
}
|
||||
|
||||
auto file_size{opt_size.value()};
|
||||
auto ret{false};
|
||||
if (file_size != 0U) {
|
||||
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
|
||||
}
|
||||
if (file_size == 0U) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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> {
|
||||
@ -92,7 +81,7 @@ void eviction::service_function() {
|
||||
|
||||
// Handle maximum cache size eviction
|
||||
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()) {
|
||||
should_evict = (used_bytes > config_.get_max_cache_size_bytes());
|
||||
}
|
||||
|
@ -106,8 +106,8 @@ auto fuse_base::access_(const char *path, int mask) -> int {
|
||||
};
|
||||
|
||||
return instance().instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().access_impl(api_path, mask);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().chflags_impl(api_path, flags);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().chflags_impl(std::move(api_path), flags);
|
||||
});
|
||||
}
|
||||
#endif // __APPLE__
|
||||
@ -132,8 +132,8 @@ auto fuse_base::chmod_(const char *path, mode_t mode,
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().chmod_impl(api_path, mode, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().chmod_impl(std::move(api_path) mode, fi);
|
||||
});
|
||||
}
|
||||
#else
|
||||
@ -143,8 +143,8 @@ auto fuse_base::chmod_(const char *path, mode_t mode) -> int {
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().chmod_impl(api_path, mode);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().chmod_impl(std::move(api_path), mode);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
@ -157,8 +157,8 @@ auto fuse_base::chown_(const char *path, uid_t uid, gid_t gid,
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().chown_impl(api_path, uid, gid, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().chown_impl(std::move(api_path), uid, gid, fi);
|
||||
});
|
||||
}
|
||||
#else
|
||||
@ -168,8 +168,8 @@ auto fuse_base::chown_(const char *path, uid_t uid, gid_t gid) -> int {
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().chown_impl(api_path, uid, gid);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().chown_impl(std::move(api_path), uid, gid);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
@ -181,8 +181,8 @@ auto fuse_base::create_(const char *path, mode_t mode,
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().create_impl(api_path, mode, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().create_impl(std::move(api_path), mode, fi);
|
||||
});
|
||||
}
|
||||
|
||||
@ -237,7 +237,7 @@ auto fuse_base::execute_callback(
|
||||
|
||||
auto fuse_base::execute_callback(
|
||||
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 {
|
||||
const auto api_path = utils::path::create_api_path(path ? 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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().fallocate_impl(api_path, mode, offset, length, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().fgetattr_impl(api_path, st, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().fgetattr_impl(std::move(api_path), st, fi);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
@ -296,8 +297,8 @@ auto fuse_base::fsetattr_x_(const char *path, struct setattr_x *attr,
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().fsetattr_x_impl(api_path, attr, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().fsetattr_x_impl(std::move(api_path), attr, fi);
|
||||
});
|
||||
}
|
||||
#endif // __APPLE__
|
||||
@ -309,8 +310,8 @@ auto fuse_base::fsync_(const char *path, int datasync,
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().fsync_impl(api_path, datasync, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().ftruncate_impl(api_path, size, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().ftruncate_impl(std::move(api_path), size, fi);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
@ -336,8 +337,8 @@ auto fuse_base::getattr_(const char *path, struct stat *st,
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().getattr_impl(api_path, st, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().getattr_impl(std::move(api_path), st, fi);
|
||||
});
|
||||
}
|
||||
#else
|
||||
@ -347,8 +348,8 @@ auto fuse_base::getattr_(const char *path, struct stat *st) -> int {
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().getattr_impl(api_path, st);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().getattr_impl(std::move(api_path), st);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
@ -361,8 +362,8 @@ auto fuse_base::getxtimes_(const char *path, struct timespec *bkuptime,
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().getxtimes_impl(api_path, bkuptime, crtime);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().getxtimes_impl(std::move(api_path), bkuptime, crtime);
|
||||
});
|
||||
}
|
||||
#endif // __APPLE__
|
||||
@ -427,8 +428,8 @@ auto fuse_base::mkdir_(const char *path, mode_t mode) -> int {
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().mkdir_impl(api_path, mode);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().open_impl(api_path, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().opendir_impl(api_path, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
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{};
|
||||
const auto res = instance().execute_callback(
|
||||
function_name, path,
|
||||
[&](const std::string &api_path) -> api_error {
|
||||
return instance().read_impl(api_path, buffer, read_size, read_offset,
|
||||
fi, bytes_read);
|
||||
[&](std::string api_path) -> api_error {
|
||||
return instance().read_impl(std::move(api_path), buffer, read_size,
|
||||
read_offset, fi, bytes_read);
|
||||
},
|
||||
true);
|
||||
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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().readdir_impl(api_path, buf, fuse_fill_dir, offset, fi,
|
||||
flags);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().readdir_impl(std::move(api_path), buf, fuse_fill_dir,
|
||||
offset, fi, flags);
|
||||
});
|
||||
}
|
||||
#else
|
||||
@ -543,9 +544,9 @@ auto fuse_base::readdir_(const char *path, void *buf,
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().readdir_impl(api_path, buf, fuse_fill_dir, offset,
|
||||
fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().readdir_impl(std::move(api_path), buf, fuse_fill_dir,
|
||||
offset, fi);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
@ -556,8 +557,8 @@ auto fuse_base::release_(const char *path, struct fuse_file_info *fi) -> int {
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().release_impl(api_path, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().release_impl(std::move(api_path), fi);
|
||||
});
|
||||
}
|
||||
|
||||
@ -568,8 +569,8 @@ auto fuse_base::releasedir_(const char *path,
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().releasedir_impl(api_path, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().rmdir_impl(api_path);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
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;
|
||||
const auto res = instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().getxattr_impl(api_path, name, value, size, position,
|
||||
attribute_size);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().getxattr_impl(std::move(api_path), name, value, size,
|
||||
position, attribute_size);
|
||||
});
|
||||
|
||||
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;
|
||||
const auto res = instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().getxattr_impl(api_path, name, value, size,
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().getxattr_impl(std::move(api_path), name, value, size,
|
||||
attribute_size);
|
||||
});
|
||||
|
||||
@ -657,9 +658,9 @@ auto fuse_base::listxattr_(const char *path, char *buffer, size_t size) -> int {
|
||||
bool return_size = false;
|
||||
|
||||
const auto res = instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().listxattr_impl(api_path, buffer, size, required_size,
|
||||
return_size);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().listxattr_impl(std::move(api_path), buffer, size,
|
||||
required_size, return_size);
|
||||
});
|
||||
|
||||
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,
|
||||
const std::string &api_path, int ret,
|
||||
std::string_view api_path, int ret,
|
||||
bool disable_logging) {
|
||||
if ((ret >= 0) && disable_logging) {
|
||||
return;
|
||||
@ -766,7 +767,7 @@ void fuse_base::raise_fuse_event(std::string_view function_name,
|
||||
(config_.get_event_level() >= event_level::trace)) {
|
||||
std::string func{function_name};
|
||||
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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().removexattr_impl(api_path, name);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().setxattr_impl(api_path, name, value, size, flags,
|
||||
position);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().setxattr_impl(std::move(api_path), name, value, size,
|
||||
flags, position);
|
||||
});
|
||||
if (res != 0) {
|
||||
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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().setxattr_impl(api_path, name, value, size, flags);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().setxattr_impl(std::move(api_path), name, value, size,
|
||||
flags);
|
||||
});
|
||||
if (res != 0) {
|
||||
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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().setattr_x_impl(api_path, attr);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().setbkuptime_impl(api_path, bkuptime);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().setbkuptime_impl(std::move(api_path), bkuptime);
|
||||
});
|
||||
}
|
||||
|
||||
@ -856,8 +858,8 @@ auto fuse_base::setchgtime_(const char *path,
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().setchgtime_impl(api_path, chgtime);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().setchgtime_impl(std::move(api_path), chgtime);
|
||||
});
|
||||
}
|
||||
|
||||
@ -868,8 +870,8 @@ auto fuse_base::setcrtime_(const char *path,
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().setcrtime_impl(api_path, crtime);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
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(
|
||||
function_name, volname, [&](const std::string &api_path) -> api_error {
|
||||
return instance().setvolname_impl(volname);
|
||||
function_name, volname, [&](std::string api_path) -> api_error {
|
||||
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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().statfs_x_impl(api_path, stbuf);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().statfs_x_impl(std::move(api_path), stbuf);
|
||||
});
|
||||
}
|
||||
#else // __APPLE__
|
||||
@ -901,8 +903,8 @@ auto fuse_base::statfs_(const char *path, struct statvfs *stbuf) -> int {
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().statfs_impl(api_path, stbuf);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().statfs_impl(std::move(api_path), stbuf);
|
||||
});
|
||||
}
|
||||
#endif // __APPLE__
|
||||
@ -915,8 +917,8 @@ auto fuse_base::truncate_(const char *path, off_t size,
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().truncate_impl(api_path, size, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().truncate_impl(std::move(api_path), size, fi);
|
||||
});
|
||||
}
|
||||
#else
|
||||
@ -926,8 +928,8 @@ auto fuse_base::truncate_(const char *path, off_t size) -> int {
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().truncate_impl(api_path, size);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().truncate_impl(std::move(api_path), size);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
@ -938,8 +940,8 @@ auto fuse_base::unlink_(const char *path) -> int {
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().unlink_impl(api_path);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
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(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().utimens_impl(api_path, tv, fi);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().utimens_impl(std::move(api_path), tv, fi);
|
||||
});
|
||||
}
|
||||
#else
|
||||
@ -976,8 +978,8 @@ auto fuse_base::utimens_(const char *path, const struct timespec tv[2]) -> int {
|
||||
};
|
||||
|
||||
return instance().execute_callback(
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().utimens_impl(api_path, tv);
|
||||
function_name, path, [&](std::string api_path) -> api_error {
|
||||
return instance().utimens_impl(std::move(api_path), tv);
|
||||
});
|
||||
}
|
||||
#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(
|
||||
function_name, path,
|
||||
[&](const std::string &api_path) -> api_error {
|
||||
return instance().write_impl(api_path, buffer, write_size, write_offset,
|
||||
fi, bytes_written);
|
||||
[&](std::string api_path) -> api_error {
|
||||
return instance().write_impl(std::move(api_path), buffer, write_size,
|
||||
write_offset, fi, bytes_written);
|
||||
},
|
||||
true);
|
||||
return (res == 0) ? static_cast<int>(bytes_written) : res;
|
||||
|
@ -299,7 +299,7 @@ void fuse_drive_base::populate_stat(const std::string &api_path,
|
||||
std::uint64_t size_or_count,
|
||||
const api_meta_map &meta, bool directory,
|
||||
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>(
|
||||
directory ? 2 + (size_or_count == 0U
|
||||
? provider.get_directory_item_count(api_path)
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/time.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
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.gid = attr->gid;
|
||||
attributes.size = attr->size;
|
||||
attributes.acctime =
|
||||
((attr->acctime.tv_sec * NANOS_PER_SECOND) + attr->acctime.tv_nsec);
|
||||
attributes.modtime =
|
||||
((attr->modtime.tv_sec * NANOS_PER_SECOND) + attr->modtime.tv_nsec);
|
||||
attributes.crtime =
|
||||
((attr->crtime.tv_sec * NANOS_PER_SECOND) + attr->crtime.tv_nsec);
|
||||
attributes.chgtime =
|
||||
((attr->chgtime.tv_sec * NANOS_PER_SECOND) + attr->chgtime.tv_nsec);
|
||||
attributes.acctime = ((attr->acctime.tv_sec * utils::time::NANOS_PER_SECOND) +
|
||||
attr->acctime.tv_nsec);
|
||||
attributes.modtime = ((attr->modtime.tv_sec * utils::time::NANOS_PER_SECOND) +
|
||||
attr->modtime.tv_nsec);
|
||||
attributes.crtime = ((attr->crtime.tv_sec * utils::time::NANOS_PER_SECOND) +
|
||||
attr->crtime.tv_nsec);
|
||||
attributes.chgtime = ((attr->chgtime.tv_sec * utils::time::NANOS_PER_SECOND) +
|
||||
attr->chgtime.tv_nsec);
|
||||
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;
|
||||
return utils::to_api_error(remote_instance_->fuse_fsetattr_x(
|
||||
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);
|
||||
if (res == 0) {
|
||||
bkuptime->tv_nsec =
|
||||
static_cast<long>(repertory_bkuptime % NANOS_PER_SECOND);
|
||||
bkuptime->tv_sec = repertory_bkuptime / NANOS_PER_SECOND;
|
||||
crtime->tv_nsec = static_cast<long>(repertory_crtime % NANOS_PER_SECOND);
|
||||
crtime->tv_sec = repertory_crtime / NANOS_PER_SECOND;
|
||||
static_cast<long>(repertory_bkuptime % utils::time::NANOS_PER_SECOND);
|
||||
bkuptime->tv_sec = repertory_bkuptime / utils::time::NANOS_PER_SECOND;
|
||||
crtime->tv_nsec =
|
||||
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);
|
||||
@ -296,42 +299,51 @@ auto remote_fuse_drive::opendir_impl(
|
||||
|
||||
void remote_fuse_drive::populate_stat(const remote::stat &r_stat,
|
||||
bool directory, struct stat &unix_st) {
|
||||
memset(&unix_st, 0, sizeof(struct stat));
|
||||
std::memset(&unix_st, 0, sizeof(struct stat));
|
||||
|
||||
#if defined(__APPLE__)
|
||||
unix_st.st_blksize = 0;
|
||||
|
||||
unix_st.st_atimespec.tv_nsec = r_stat.st_atimespec % NANOS_PER_SECOND;
|
||||
unix_st.st_atimespec.tv_sec = r_stat.st_atimespec / NANOS_PER_SECOND;
|
||||
unix_st.st_atimespec.tv_nsec =
|
||||
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_sec = r_stat.st_birthtimespec / NANOS_PER_SECOND;
|
||||
unix_st.st_birthtimespec.tv_nsec =
|
||||
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_sec = r_stat.st_ctimespec / NANOS_PER_SECOND;
|
||||
unix_st.st_ctimespec.tv_nsec =
|
||||
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_sec = r_stat.st_mtimespec / NANOS_PER_SECOND;
|
||||
unix_st.st_mtimespec.tv_nsec =
|
||||
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;
|
||||
#else
|
||||
#else // !defined(__APPLE__)
|
||||
unix_st.st_blksize = 4096;
|
||||
|
||||
unix_st.st_atim.tv_nsec =
|
||||
static_cast<suseconds_t>(r_stat.st_atimespec % NANOS_PER_SECOND);
|
||||
unix_st.st_atim.tv_sec =
|
||||
static_cast<suseconds_t>(r_stat.st_atimespec / NANOS_PER_SECOND);
|
||||
unix_st.st_atim.tv_nsec = static_cast<suseconds_t>(
|
||||
r_stat.st_atimespec % utils::time::NANOS_PER_SECOND);
|
||||
unix_st.st_atim.tv_sec = static_cast<suseconds_t>(
|
||||
r_stat.st_atimespec / utils::time::NANOS_PER_SECOND);
|
||||
|
||||
unix_st.st_ctim.tv_nsec =
|
||||
static_cast<suseconds_t>(r_stat.st_ctimespec % NANOS_PER_SECOND);
|
||||
unix_st.st_ctim.tv_sec =
|
||||
static_cast<suseconds_t>(r_stat.st_ctimespec / NANOS_PER_SECOND);
|
||||
unix_st.st_ctim.tv_nsec = static_cast<suseconds_t>(
|
||||
r_stat.st_ctimespec % utils::time::NANOS_PER_SECOND);
|
||||
unix_st.st_ctim.tv_sec = static_cast<suseconds_t>(
|
||||
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) {
|
||||
const auto block_size_stat = static_cast<std::uint64_t>(512U);
|
||||
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.gid = attr->gid;
|
||||
attributes.size = attr->size;
|
||||
attributes.acctime =
|
||||
((attr->acctime.tv_sec * NANOS_PER_SECOND) + attr->acctime.tv_nsec);
|
||||
attributes.modtime =
|
||||
((attr->modtime.tv_sec * NANOS_PER_SECOND) + attr->modtime.tv_nsec);
|
||||
attributes.crtime =
|
||||
((attr->crtime.tv_sec * NANOS_PER_SECOND) + attr->crtime.tv_nsec);
|
||||
attributes.chgtime =
|
||||
((attr->chgtime.tv_sec * NANOS_PER_SECOND) + attr->chgtime.tv_nsec);
|
||||
attributes.acctime = ((attr->acctime.tv_sec * utils::time::NANOS_PER_SECOND) +
|
||||
attr->acctime.tv_nsec);
|
||||
attributes.modtime = ((attr->modtime.tv_sec * utils::time::NANOS_PER_SECOND) +
|
||||
attr->modtime.tv_nsec);
|
||||
attributes.crtime = ((attr->crtime.tv_sec * utils::time::NANOS_PER_SECOND) +
|
||||
attr->crtime.tv_nsec);
|
||||
attributes.chgtime = ((attr->chgtime.tv_sec * utils::time::NANOS_PER_SECOND) +
|
||||
attr->chgtime.tv_nsec);
|
||||
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;
|
||||
return utils::to_api_error(
|
||||
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,
|
||||
const struct timespec *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(
|
||||
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,
|
||||
const struct timespec *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(
|
||||
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,
|
||||
const struct timespec *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(
|
||||
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};
|
||||
if (tv != nullptr) {
|
||||
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>(
|
||||
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(
|
||||
|
@ -125,18 +125,18 @@ void remote_server::populate_file_info(const std::string &api_path,
|
||||
file_info.AllocationSize =
|
||||
utils::divide_with_ceiling(file_size, 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])));
|
||||
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])));
|
||||
file_info.EaSize = 0;
|
||||
file_info.FileAttributes = attributes;
|
||||
file_info.FileSize = file_size;
|
||||
file_info.HardLinks = 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])));
|
||||
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])));
|
||||
if (meta[META_WRITTEN].empty() || (meta[META_WRITTEN] == "0") ||
|
||||
(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,
|
||||
remote::stat &r_stat) {
|
||||
memset(&r_stat, 0, sizeof(r_stat));
|
||||
r_stat = {};
|
||||
|
||||
#if defined(__APPLE__)
|
||||
r_stat.st_flags = unix_st.st_flags;
|
||||
|
||||
r_stat.st_atimespec = unix_st.st_atimespec.tv_nsec +
|
||||
(unix_st.st_atimespec.tv_sec * NANOS_PER_SECOND);
|
||||
r_stat.st_atimespec =
|
||||
unix_st.st_atimespec.tv_nsec +
|
||||
(unix_st.st_atimespec.tv_sec * utils::time::NANOS_PER_SECOND);
|
||||
r_stat.st_birthtimespec =
|
||||
unix_st.st_birthtimespec.tv_nsec +
|
||||
(unix_st.st_birthtimespec.tv_sec * NANOS_PER_SECOND);
|
||||
r_stat.st_ctimespec = unix_st.st_ctimespec.tv_nsec +
|
||||
(unix_st.st_ctimespec.tv_sec * NANOS_PER_SECOND);
|
||||
r_stat.st_mtimespec = unix_st.st_mtimespec.tv_nsec +
|
||||
(unix_st.st_mtimespec.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 +
|
||||
(unix_st.st_ctimespec.tv_sec * utils::time::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__)
|
||||
r_stat.st_flags = 0;
|
||||
|
||||
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>(
|
||||
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>(
|
||||
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>(
|
||||
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__)
|
||||
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);
|
||||
@ -320,8 +328,9 @@ auto remote_server::fuse_fgetattr(
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
r_stat = {};
|
||||
|
||||
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);
|
||||
if (res == 0) {
|
||||
@ -406,16 +415,18 @@ auto remote_server::fuse_fsetattr_x(
|
||||
if (SETATTR_WANTS_MODTIME(&attr)) {
|
||||
struct timeval val[2];
|
||||
if (SETATTR_WANTS_ACCTIME(&attr)) {
|
||||
val[0U].tv_sec = static_cast<time_t>(attr.acctime / NANOS_PER_SECOND);
|
||||
val[0U].tv_usec =
|
||||
static_cast<time_t>((attr.acctime % NANOS_PER_SECOND) / 1000);
|
||||
val[0U].tv_sec =
|
||||
static_cast<time_t>(attr.acctime / utils::time::NANOS_PER_SECOND);
|
||||
val[0U].tv_usec = static_cast<time_t>(
|
||||
(attr.acctime % utils::time::NANOS_PER_SECOND) / 1000);
|
||||
} else {
|
||||
gettimeofday(&val[0U], nullptr);
|
||||
}
|
||||
|
||||
val[1U].tv_sec = static_cast<time_t>(attr.modtime / NANOS_PER_SECOND);
|
||||
val[1U].tv_usec =
|
||||
static_cast<time_t>((attr.modtime % NANOS_PER_SECOND) / 1000);
|
||||
val[1U].tv_sec =
|
||||
static_cast<time_t>(attr.modtime / utils::time::NANOS_PER_SECOND);
|
||||
val[1U].tv_usec = static_cast<time_t>(
|
||||
(attr.modtime % utils::time::NANOS_PER_SECOND) / 1000);
|
||||
|
||||
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 file_path = construct_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();
|
||||
|
||||
@ -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_ffree = r_stat.f_favail =
|
||||
r_stat.f_files - drive_.get_total_item_count();
|
||||
std::memset(&r_stat.f_mntfromname[0U], 0, sizeof(r_stat.f_mntfromname));
|
||||
strncpy(&r_stat.f_mntfromname[0U],
|
||||
std::memset(r_stat.f_mntfromname.data(), 0, r_stat.f_mntfromname.size());
|
||||
strncpy(r_stat.f_mntfromname.data(),
|
||||
(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);
|
||||
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_sec = 0;
|
||||
} else {
|
||||
tv2[0U].tv_nsec = static_cast<time_t>(tv[0U] % NANOS_PER_SECOND);
|
||||
tv2[0U].tv_sec = static_cast<time_t>(tv[0U] / NANOS_PER_SECOND);
|
||||
tv2[0U].tv_nsec =
|
||||
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)) {
|
||||
tv2[1U].tv_nsec = static_cast<time_t>(op1);
|
||||
tv2[1U].tv_sec = 0;
|
||||
} else {
|
||||
tv2[1U].tv_nsec = static_cast<time_t>(tv[1U] % NANOS_PER_SECOND);
|
||||
tv2[1U].tv_sec = static_cast<time_t>(tv[1U] / NANOS_PER_SECOND);
|
||||
tv2[1U].tv_nsec =
|
||||
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 =
|
||||
@ -1543,25 +1559,28 @@ auto remote_server::winfsp_set_basic_info(
|
||||
if ((creation_time != 0U) && (creation_time != max_time)) {
|
||||
drive_.set_item_meta(
|
||||
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)) {
|
||||
drive_.set_item_meta(
|
||||
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)) {
|
||||
drive_.set_item_meta(
|
||||
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)) {
|
||||
drive_.set_item_meta(
|
||||
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);
|
||||
@ -1746,12 +1765,22 @@ auto remote_server::json_release_directory_snapshot(
|
||||
|
||||
auto remote_server::update_to_windows_format(json &item) -> json & {
|
||||
const auto api_path = item["path"].get<std::string>();
|
||||
item["meta"][META_MODIFIED] = std::to_string(utils::unix_time_to_windows_time(
|
||||
utils::string::to_uint64(empty_as_zero(item["meta"][META_MODIFIED]))));
|
||||
item["meta"][META_CREATION] = std::to_string(utils::unix_time_to_windows_time(
|
||||
utils::string::to_uint64(empty_as_zero(item["meta"][META_CREATION]))));
|
||||
item["meta"][META_ACCESSED] = std::to_string(utils::unix_time_to_windows_time(
|
||||
utils::string::to_uint64(empty_as_zero(item["meta"][META_ACCESSED]))));
|
||||
item["meta"][META_ACCESSED] = std::to_string(
|
||||
utils::string::to_uint64(empty_as_zero(item["meta"][META_ACCESSED])));
|
||||
item["meta"][META_CREATION] = std::to_string(
|
||||
utils::string::to_uint64(empty_as_zero(item["meta"][META_CREATION])));
|
||||
item["meta"][META_MODIFIED] = std::to_string(
|
||||
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()) {
|
||||
item["meta"][META_ATTRIBUTES] =
|
||||
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>());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
} // namespace repertory::remote_fuse
|
||||
|
@ -65,7 +65,10 @@ auto remote_client::winfsp_can_delete(PVOID file_desc,
|
||||
request.encode(file_name);
|
||||
|
||||
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,
|
||||
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;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
if (ret == 0) {
|
||||
ret = packet::decode_json(response, json_data);
|
||||
}
|
||||
@ -107,8 +111,9 @@ auto remote_client::json_read_directory_snapshot(
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
if (ret == 0) {
|
||||
ret = packet::decode_json(response, json_data);
|
||||
}
|
||||
@ -129,7 +134,9 @@ auto remote_client::json_release_directory_snapshot(
|
||||
request.encode(handle);
|
||||
|
||||
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);
|
||||
return ret;
|
||||
@ -142,8 +149,14 @@ auto remote_client::winfsp_cleanup(PVOID file_desc, PWSTR file_name,
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
auto handle = to_handle(file_desc);
|
||||
const auto file_path = get_open_file_path(handle);
|
||||
auto handle{
|
||||
to_handle(file_desc),
|
||||
};
|
||||
|
||||
auto file_path{
|
||||
get_open_file_path(handle),
|
||||
};
|
||||
|
||||
was_closed = 0;
|
||||
|
||||
packet request;
|
||||
@ -153,8 +166,9 @@ auto remote_client::winfsp_cleanup(PVOID file_desc, PWSTR file_name,
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
DECODE_OR_IGNORE(&response, was_closed);
|
||||
if (was_closed != 0U) {
|
||||
remove_all(file_path);
|
||||
@ -168,15 +182,21 @@ auto remote_client::winfsp_close(PVOID file_desc) -> packet::error_type {
|
||||
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) {
|
||||
const auto file_path = get_open_file_path(handle);
|
||||
auto file_path{
|
||||
get_open_file_path(handle),
|
||||
};
|
||||
|
||||
packet request;
|
||||
request.encode(file_desc);
|
||||
|
||||
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) ||
|
||||
(ret == static_cast<packet::error_type>(STATUS_INVALID_HANDLE))) {
|
||||
remove_open_info(handle);
|
||||
@ -206,8 +226,9 @@ auto remote_client::winfsp_create(PWSTR file_name, UINT32 create_options,
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
if (ret == STATUS_SUCCESS) {
|
||||
HANDLE 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;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
DECODE_OR_IGNORE(&response, *file_info);
|
||||
|
||||
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
|
||||
@ -274,8 +296,9 @@ auto remote_client::winfsp_get_file_info(
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
DECODE_OR_IGNORE(&response, *file_info);
|
||||
|
||||
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
|
||||
@ -298,8 +321,9 @@ auto remote_client::winfsp_get_security_by_name(
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
|
||||
string_descriptor.clear();
|
||||
DECODE_OR_IGNORE(&response, string_descriptor);
|
||||
@ -326,8 +350,9 @@ auto remote_client::winfsp_get_volume_info(
|
||||
packet request;
|
||||
packet response;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
DECODE_OR_IGNORE(&response, total_size);
|
||||
DECODE_OR_IGNORE(&response, free_size);
|
||||
DECODE_OR_IGNORE(&response, volume_label);
|
||||
@ -346,8 +371,13 @@ auto remote_client::winfsp_mounted(const std::wstring &location)
|
||||
request.encode(location);
|
||||
|
||||
std::uint32_t service_flags{};
|
||||
const auto ret = packet_client_.send(function_name, request, service_flags);
|
||||
const auto mount_location = utils::string::to_utf8(location);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, service_flags),
|
||||
};
|
||||
|
||||
auto mount_location{
|
||||
utils::string::to_utf8(location),
|
||||
};
|
||||
event_system::instance().raise<drive_mounted>(mount_location);
|
||||
|
||||
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, mount_location, ret);
|
||||
@ -369,8 +399,9 @@ auto remote_client::winfsp_open(
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
if (ret == STATUS_SUCCESS) {
|
||||
HANDLE handle{};
|
||||
DECODE_OR_IGNORE(&response, handle);
|
||||
@ -406,8 +437,9 @@ auto remote_client::winfsp_overwrite(
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
DECODE_OR_IGNORE(&response, *file_info);
|
||||
|
||||
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
|
||||
@ -429,8 +461,9 @@ auto remote_client::winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset,
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
DECODE_OR_IGNORE(&response, *bytes_transferred);
|
||||
if (ret == STATUS_SUCCESS) {
|
||||
ret = response.decode(buffer, *bytes_transferred);
|
||||
@ -464,8 +497,9 @@ auto remote_client::winfsp_read_directory(PVOID file_desc, PWSTR pattern,
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
if (ret == STATUS_SUCCESS) {
|
||||
ret = packet::decode_json(response, item_list);
|
||||
}
|
||||
@ -489,7 +523,10 @@ auto remote_client::winfsp_rename(
|
||||
request.encode(replace_if_exists);
|
||||
|
||||
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,
|
||||
utils::path::create_api_path(utils::string::to_utf8(file_name)) + "|" +
|
||||
@ -516,8 +553,9 @@ auto remote_client::winfsp_set_basic_info(
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
DECODE_OR_IGNORE(&response, *file_info);
|
||||
|
||||
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
|
||||
@ -539,8 +577,9 @@ auto remote_client::winfsp_set_file_size(
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
DECODE_OR_IGNORE(&response, *file_info);
|
||||
|
||||
RAISE_REMOTE_WINFSP_CLIENT_EVENT(
|
||||
@ -554,13 +593,17 @@ auto remote_client::winfsp_unmounted(const std::wstring &location)
|
||||
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);
|
||||
packet request;
|
||||
request.encode(location);
|
||||
|
||||
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);
|
||||
|
||||
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, mount_location, ret);
|
||||
@ -587,8 +630,9 @@ auto remote_client::winfsp_write(
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
auto ret{
|
||||
packet_client_.send(function_name, request, response, service_flags),
|
||||
};
|
||||
DECODE_OR_IGNORE(&response, *bytes_transferred);
|
||||
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 {
|
||||
return static_cast<native_handle>(reinterpret_cast<std::uint64_t>(file_desc));
|
||||
}
|
||||
#endif
|
||||
#endif // !defined(_WIN32)
|
||||
} // namespace repertory::remote_winfsp
|
||||
|
@ -92,10 +92,14 @@ void remote_server::populate_stat(const char *path, bool directory,
|
||||
directory ? 2 + drive_.get_directory_item_count(
|
||||
utils::path::create_api_path(path))
|
||||
: 1);
|
||||
r_stat.st_atimespec = utils::time::time64_to_unix_time(unix_st.st_atime);
|
||||
r_stat.st_birthtimespec = utils::time::time64_to_unix_time(unix_st.st_ctime);
|
||||
r_stat.st_ctimespec = utils::time::time64_to_unix_time(unix_st.st_ctime);
|
||||
r_stat.st_mtimespec = utils::time::time64_to_unix_time(unix_st.st_mtime);
|
||||
r_stat.st_atimespec = utils::time::windows_time_to_unix_time(
|
||||
static_cast<std::uint64_t>(unix_st.st_atime));
|
||||
r_stat.st_birthtimespec = utils::time::windows_time_to_unix_time(
|
||||
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_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__),
|
||||
};
|
||||
|
||||
const auto file_path = construct_path(path);
|
||||
const auto windows_mask = utils::unix_access_mask_to_windows(mask);
|
||||
const auto res = _access(file_path.c_str(), windows_mask);
|
||||
const auto ret = ((res < 0) ? -errno : 0);
|
||||
auto file_path{
|
||||
construct_path(path),
|
||||
};
|
||||
|
||||
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);
|
||||
return ret;
|
||||
}
|
||||
@ -181,10 +197,13 @@ auto remote_server::fuse_fgetattr(
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
const auto file_path = construct_path(path);
|
||||
memset(&r_stat, 0, sizeof(remote::stat));
|
||||
r_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) {
|
||||
directory = utils::file::directory(file_path).exists();
|
||||
struct _stat64 unix_st {};
|
||||
@ -221,7 +240,9 @@ auto remote_server::fuse_fsync(
|
||||
|
||||
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) {
|
||||
res = -1;
|
||||
errno = EBADF;
|
||||
@ -250,7 +271,9 @@ auto remote_server::fuse_ftruncate(
|
||||
|
||||
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) {
|
||||
res = -1;
|
||||
errno = EBADF;
|
||||
@ -279,13 +302,16 @@ auto remote_server::fuse_getattr(const char *path, remote::stat &r_st,
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
r_st = {};
|
||||
|
||||
const auto file_path = construct_path(path);
|
||||
memset(&r_st, 0, sizeof(remote::stat));
|
||||
|
||||
directory = utils::file::directory(file_path).exists();
|
||||
|
||||
struct _stat64 st1 {};
|
||||
const auto res = _stat64(file_path.c_str(), &st1);
|
||||
auto res{
|
||||
_stat64(file_path.c_str(), &st1),
|
||||
};
|
||||
if (res == 0) {
|
||||
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 res = _mkdir(file_path.c_str());
|
||||
auto res{
|
||||
_mkdir(file_path.c_str()),
|
||||
};
|
||||
const auto ret = ((res < 0) ? -errno : 0);
|
||||
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, 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 unicode_file_path = utils::string::from_utf8(file_path);
|
||||
auto res = -1;
|
||||
auto res{-1};
|
||||
errno = ENOENT;
|
||||
|
||||
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;
|
||||
} else {
|
||||
int file = -1;
|
||||
const auto res =
|
||||
_sopen_s(&file, file_path.c_str(), open_flags, _SH_DENYNO, perms);
|
||||
auto res{
|
||||
_sopen_s(&file, file_path.c_str(), open_flags, _SH_DENYNO, perms),
|
||||
};
|
||||
if (res == 0) {
|
||||
handle = static_cast<remote::file_handle>(file);
|
||||
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);
|
||||
auto res = -1;
|
||||
auto res{-1};
|
||||
|
||||
if ((flags & remote::open_flags::directory) ==
|
||||
remote::open_flags::directory) {
|
||||
@ -460,13 +489,13 @@ auto remote_server::fuse_read(
|
||||
|
||||
const auto file_path = construct_path(path);
|
||||
auto &data = *reinterpret_cast<data_buffer *>(buffer);
|
||||
auto res = 0;
|
||||
auto res{0};
|
||||
if (read_size > std::numeric_limits<std::size_t>::max()) {
|
||||
res = -1;
|
||||
errno = ERANGE;
|
||||
} else if ((res = has_compat_open_info(handle, EBADF)) == 0) {
|
||||
res = _lseeki64(static_cast<int>(handle), static_cast<__int64>(read_offset),
|
||||
SEEK_SET);
|
||||
res = static_cast<std::decay_t<decltype(res)>>(_lseeki64(
|
||||
static_cast<int>(handle), static_cast<__int64>(read_offset), SEEK_SET));
|
||||
if (res != -1) {
|
||||
data.resize(read_size);
|
||||
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 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);
|
||||
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);
|
||||
std::size_t bytes_written{};
|
||||
auto res = 0;
|
||||
auto res{0};
|
||||
if (write_size > std::numeric_limits<std::size_t>::max()) {
|
||||
res = -1;
|
||||
errno = ERANGE;
|
||||
} else {
|
||||
res = has_compat_open_info(handle, EBADF);
|
||||
if (res == 0) {
|
||||
res = _lseeki64(static_cast<int>(handle),
|
||||
static_cast<__int64>(write_offset), SEEK_SET);
|
||||
res = static_cast<std::decay_t<decltype(res)>>(
|
||||
_lseeki64(static_cast<int>(handle),
|
||||
static_cast<__int64>(write_offset), SEEK_SET));
|
||||
if (res != -1) {
|
||||
res = write(static_cast<int>(handle), buffer,
|
||||
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);
|
||||
auto res = 0;
|
||||
auto res{0};
|
||||
if (offset > std::numeric_limits<std::size_t>::max()) {
|
||||
errno = ERANGE;
|
||||
res = -1;
|
||||
@ -584,7 +616,9 @@ auto remote_server::fuse_release(
|
||||
const auto file_path = construct_path(path);
|
||||
|
||||
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);
|
||||
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 res = _rmdir(file_path.c_str());
|
||||
auto res{
|
||||
_rmdir(file_path.c_str()),
|
||||
};
|
||||
const auto ret = ((res < 0) ? -errno : 0);
|
||||
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, 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_ffree = r_stat.f_favail =
|
||||
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(),
|
||||
sizeof(r_stat.f_mntfromname) - 1U);
|
||||
r_stat.f_mntfromname.size() - 1U);
|
||||
|
||||
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, 0);
|
||||
return 0;
|
||||
@ -757,7 +793,7 @@ auto remote_server::fuse_truncate(
|
||||
|
||||
const auto file_path = construct_path(path);
|
||||
const auto unicode_file_path = utils::string::from_utf8(file_path);
|
||||
auto res = -1;
|
||||
auto res{-1};
|
||||
errno = ENOENT;
|
||||
|
||||
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 res = _unlink(file_path.c_str());
|
||||
auto res{
|
||||
_unlink(file_path.c_str()),
|
||||
};
|
||||
const auto ret = ((res < 0) ? -errno : 0);
|
||||
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, 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 unicode_file_path = utils::string::from_utf8(file_path);
|
||||
|
||||
auto res = -1;
|
||||
auto res{-1};
|
||||
errno = ENOENT;
|
||||
|
||||
const auto flags_and_attributes =
|
||||
@ -870,7 +908,7 @@ auto remote_server::json_create_directory_snapshot(
|
||||
|
||||
const auto file_path = construct_path(path);
|
||||
|
||||
auto res = -1;
|
||||
auto res{-1};
|
||||
errno = ENOENT;
|
||||
|
||||
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
|
||||
|
||||
#endif // _WIN32
|
||||
#endif // defined(_WIN32)
|
||||
|
@ -373,7 +373,7 @@ auto remote_winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
|
||||
::ZeroMemory(directory_info, sizeof(*directory_info));
|
||||
directory_info->Size = static_cast<UINT16>(
|
||||
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)));
|
||||
|
||||
if (not item["meta"].empty() ||
|
||||
|
@ -238,8 +238,10 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
|
||||
|
||||
if ((flags & FspCleanupSetChangeTime) != 0U) {
|
||||
auto res = provider_.set_item_meta(
|
||||
api_path, {{META_CHANGED, std::to_string(now)},
|
||||
{META_MODIFIED, std::to_string(now)}});
|
||||
api_path, {
|
||||
{META_CHANGED, std::to_string(now)},
|
||||
{META_MODIFIED, std::to_string(now)},
|
||||
});
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(
|
||||
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);
|
||||
}
|
||||
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)) {
|
||||
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)) {
|
||||
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)) {
|
||||
meta[META_CHANGED] = std::to_string(change_time);
|
||||
meta[META_MODIFIED] = std::to_string(change_time);
|
||||
meta[META_CHANGED] =
|
||||
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);
|
||||
|
@ -244,7 +244,7 @@ auto file_manager::evict_file(const std::string &api_path) -> bool {
|
||||
|
||||
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) {
|
||||
event_system::instance().raise<filesystem_item_evicted>(api_path,
|
||||
source_path);
|
||||
@ -513,8 +513,8 @@ void file_manager::queue_upload(const std::string &api_path,
|
||||
db::db_insert{*db_.get(), upload_table}
|
||||
.or_replace()
|
||||
.column_value("api_path", api_path)
|
||||
.column_value("date_time", static_cast<std::int64_t>(
|
||||
utils::time::get_time_now()))
|
||||
.column_value("date_time",
|
||||
static_cast<std::int64_t>(utils::time::get_time_now()))
|
||||
.column_value("source_path", source_path)
|
||||
.go();
|
||||
if (result.ok()) {
|
||||
@ -557,7 +557,7 @@ auto file_manager::remove_file(const std::string &api_path) -> api_error {
|
||||
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(
|
||||
function_name, fsi.api_path, fsi.source_path,
|
||||
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);
|
||||
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(
|
||||
function_name, fsi.api_path, fsi.source_path,
|
||||
utils::get_last_error_code(), "failed to delete source path");
|
||||
|
@ -458,7 +458,7 @@ auto file_manager::open_file::close() -> bool {
|
||||
mgr_.store_resume(*this);
|
||||
} else if (get_api_error() != api_error::success) {
|
||||
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(
|
||||
function_name, get_api_path(), fsi_.source_path,
|
||||
utils::get_last_error_code(), "failed to delete file");
|
||||
|
@ -93,7 +93,7 @@ file_manager::ring_buffer_open_file::~ring_buffer_open_file() {
|
||||
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(
|
||||
function_name, fsi_.api_path, fsi_.source_path,
|
||||
utils::get_last_error_code(), "failed to delete file");
|
||||
|
@ -506,7 +506,7 @@ void base_provider::remove_deleted_files() {
|
||||
} else {
|
||||
utils::error::raise_error(
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -90,44 +90,40 @@ auto encrypt_provider::create_api_file(
|
||||
source_path);
|
||||
file.source_path = source_path;
|
||||
#if defined(__APPLE__)
|
||||
file.changed_date =
|
||||
buf.st_ctimespec.tv_nsec + (buf.st_ctimespec.tv_sec * NANOS_PER_SECOND);
|
||||
file.changed_date = buf.st_ctimespec.tv_nsec +
|
||||
(buf.st_ctimespec.tv_sec * utils::time::NANOS_PER_SECOND);
|
||||
file.accessed_date =
|
||||
buf.st_atimespec.tv_nsec + (buf.st_atimespec.tv_sec * NANOS_PER_SECOND);
|
||||
file.creation_date = buf.st_birthtimespec.tv_nsec +
|
||||
(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));
|
||||
buf.st_atimespec.tv_nsec +
|
||||
(buf.st_atimespec.tv_sec * utils::time::NANOS_PER_SECOND);
|
||||
file.creation_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));
|
||||
buf.st_birthtimespec.tv_nsec +
|
||||
(buf.st_birthtimespec.tv_sec * utils::time::NANOS_PER_SECOND);
|
||||
file.modified_date =
|
||||
(static_cast<std::uint64_t>(ft.dwHighDateTime) << 32U) | ft.dwLowDateTime;
|
||||
#else
|
||||
buf.st_mtimespec.tv_nsec +
|
||||
(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>(
|
||||
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>(
|
||||
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>(
|
||||
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>(
|
||||
buf.st_mtim.tv_nsec + (buf.st_mtim.tv_sec * NANOS_PER_SECOND));
|
||||
#endif
|
||||
buf.st_mtim.tv_nsec +
|
||||
(buf.st_mtim.tv_sec * utils::time::NANOS_PER_SECOND));
|
||||
#endif // defined(__APPLE__)
|
||||
|
||||
return file;
|
||||
}
|
||||
|
@ -60,6 +60,24 @@ auto s3_provider::add_if_not_found(
|
||||
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,
|
||||
api_meta_map &meta) -> api_error {
|
||||
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_parent = utils::path::get_parent_api_path(file.api_path);
|
||||
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());
|
||||
file.creation_date = file.changed_date;
|
||||
file.file_size =
|
||||
|
@ -22,12 +22,11 @@
|
||||
#include "rpc/server/full_server.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "drives/directory_iterator.hpp"
|
||||
#include "file_manager/i_file_manager.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/rpc.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
|
||||
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*/,
|
||||
httplib::Response &res) {
|
||||
auto dir_size =
|
||||
utils::file::directory(get_config().get_cache_directory()).size();
|
||||
res.set_content(
|
||||
json({
|
||||
{"cache_space_used",
|
||||
utils::file::calculate_used_space(
|
||||
get_config().get_cache_directory(), false)},
|
||||
{"cache_space_used", dir_size},
|
||||
{"drive_space_total", provider_.get_total_drive_space()},
|
||||
{"drive_space_used", provider_.get_used_drive_space()},
|
||||
{"item_count", provider_.get_total_item_count()},
|
||||
|
@ -23,7 +23,8 @@
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "utils/collection.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
@ -38,7 +39,7 @@ void get_api_authentication_data(std::string &user, std::string &password,
|
||||
{"config.json"});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
|
@ -30,56 +30,6 @@
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
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() {
|
||||
#if defined(_WIN32)
|
||||
std::string file_name;
|
||||
@ -118,7 +68,7 @@ auto copy_directory_recursively(std::string from_path,
|
||||
std::string to_path) -> bool {
|
||||
from_path = utils::path::absolute(from_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 defined(_WIN32)
|
||||
WIN32_FIND_DATA fd{};
|
||||
@ -168,49 +118,6 @@ auto copy_directory_recursively(std::string from_path,
|
||||
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 {
|
||||
#if defined(_WIN32)
|
||||
ULARGE_INTEGER li{};
|
||||
@ -311,12 +218,13 @@ auto get_directory_files(std::string path, bool oldest_first,
|
||||
stat(lookup_path.c_str(), &st);
|
||||
#if defined(__APPLE__)
|
||||
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);
|
||||
#else
|
||||
#else // !defined(__APPLE__)
|
||||
lookup[lookup_path] = static_cast<std::uint64_t>(
|
||||
(st.st_mtim.tv_sec * NANOS_PER_SECOND) + st.st_mtim.tv_nsec);
|
||||
#endif
|
||||
(st.st_mtim.tv_sec * utils::time::NANOS_PER_SECOND) +
|
||||
st.st_mtim.tv_nsec);
|
||||
#endif // defined(__APPLE__)
|
||||
}
|
||||
};
|
||||
|
||||
@ -331,74 +239,13 @@ auto get_directory_files(std::string path, bool oldest_first,
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto get_accessed_time(const std::string &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,
|
||||
auto is_modified_date_older_than(std::string_view path,
|
||||
const std::chrono::hours &hours) -> bool {
|
||||
auto ret = false;
|
||||
std::uint64_t modified{};
|
||||
if (get_modified_time(path, modified)) {
|
||||
const auto seconds =
|
||||
std::chrono::duration_cast<std::chrono::seconds>(hours);
|
||||
#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)) <
|
||||
auto modified = file{path}.get_time(file::time_types::modified);
|
||||
auto seconds = std::chrono::duration_cast<std::chrono::seconds>(hours);
|
||||
return (modified + static_cast<std::uint64_t>(
|
||||
seconds.count() * utils::time::NANOS_PER_SECOND)) <
|
||||
utils::time::get_time_now();
|
||||
#endif
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto move_file(std::string from, std::string to) -> bool {
|
||||
@ -459,24 +306,4 @@ auto reset_modified_time(const std::string &path) -> bool {
|
||||
#endif
|
||||
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
|
||||
|
@ -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,
|
||||
const UINT32 &granted_access, std::uint32_t &flags,
|
||||
remote::file_mode &mode) {
|
||||
@ -221,10 +217,6 @@ void windows_create_to_unix(const UINT32 &create_options,
|
||||
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
|
||||
|
||||
#endif // !_WIN32
|
||||
|
@ -22,15 +22,8 @@
|
||||
#include "utils/utils.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/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/time.hpp"
|
||||
|
||||
namespace repertory::utils {
|
||||
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);
|
||||
}
|
||||
|
||||
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 {
|
||||
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 {
|
||||
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
|
||||
|
@ -23,9 +23,8 @@
|
||||
|
||||
#include "utils/windows/windows_utils.hpp"
|
||||
|
||||
#include "types/startup_exception.hpp"
|
||||
#include "utils/com_init_wrapper.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/time.hpp"
|
||||
|
||||
#if !defined(STATUS_DEVICE_INSUFFICIENT_RESOURCES)
|
||||
#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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
|
@ -21,7 +21,7 @@
|
||||
*/
|
||||
#if defined(PROJECT_ENABLE_BACKWARD_CPP)
|
||||
#include "backward.hpp"
|
||||
#endif
|
||||
#endif // defined(PROJECT_ENABLE_BACKWARD_CPP)
|
||||
|
||||
#include "cli/actions.hpp"
|
||||
#include "initialize.hpp"
|
||||
@ -34,7 +34,7 @@ using namespace repertory;
|
||||
auto main(int argc, char **argv) -> int {
|
||||
#if defined(PROJECT_ENABLE_BACKWARD_CPP)
|
||||
static backward::SignalHandling sh;
|
||||
#endif
|
||||
#endif // defined(PROJECT_ENABLE_BACKWARD_CPP)
|
||||
|
||||
if (not repertory::project_initialize()) {
|
||||
std::cerr << "fatal: failed to initialize repertory" << std::endl;
|
||||
|
@ -132,7 +132,7 @@ public:
|
||||
utils::path::combine(mount_location_, {to_api_path});
|
||||
|
||||
if (overwrite) {
|
||||
if (not utils::file::retry_delete_file(to_file_path)) {
|
||||
if (not utils::file::file(to_file_path).remove()) {
|
||||
return -1;
|
||||
}
|
||||
} else if (utils::file::directory(to_file_path).exists()) ||
|
||||
|
@ -371,8 +371,14 @@ TEST(ring_buffer_open_file, read_full_file) {
|
||||
nf2.close();
|
||||
nf.close();
|
||||
|
||||
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(),
|
||||
utils::file::generate_sha256(dest_path).c_str());
|
||||
auto hash1 = utils::file::file(download_source_path).sha256();
|
||||
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());
|
||||
@ -430,8 +436,14 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
|
||||
nf2.close();
|
||||
nf.close();
|
||||
|
||||
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(),
|
||||
utils::file::generate_sha256(dest_path).c_str());
|
||||
auto hash1 = utils::file::file(download_source_path).sha256();
|
||||
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());
|
||||
@ -490,8 +502,14 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
|
||||
nf2.close();
|
||||
nf.close();
|
||||
|
||||
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(),
|
||||
utils::file::generate_sha256(dest_path).c_str());
|
||||
auto hash1 = utils::file::file(download_source_path).sha256();
|
||||
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());
|
||||
@ -555,8 +573,14 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
|
||||
nf2.close();
|
||||
nf.close();
|
||||
|
||||
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(),
|
||||
utils::file::generate_sha256(dest_path).c_str());
|
||||
auto hash1 = utils::file::file(download_source_path).sha256();
|
||||
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());
|
||||
|
@ -738,7 +738,7 @@ TEST(file_manager, can_evict_file) {
|
||||
fm.close(handle);
|
||||
capture.wait_for_empty();
|
||||
|
||||
EXPECT_TRUE(utils::retryable_action(
|
||||
EXPECT_TRUE(utils::retry_action(
|
||||
[&fm]() -> bool { return not fm.is_processing("/test_evict.txt"); }));
|
||||
|
||||
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);
|
||||
|
||||
EXPECT_TRUE(utils::retryable_action(
|
||||
EXPECT_TRUE(utils::retry_action(
|
||||
[&fm]() -> bool { return fm.is_processing("/test_evict.txt"); }));
|
||||
EXPECT_FALSE(fm.evict_file("/test_evict.txt"));
|
||||
}
|
||||
|
@ -431,8 +431,8 @@ namespace repertory {
|
||||
// // utils::path::combine(mount_location, {"to_rename_file_test"});
|
||||
// // test_rename_file(file_path, to_file_path,
|
||||
// // provider_ptr->is_rename_supported());
|
||||
// // EXPECT_TRUE(utils::file::retry_delete_file(file_path));
|
||||
// // EXPECT_TRUE(utils::file::retry_delete_file(to_file_path));
|
||||
// // EXPECT_TRUE(utils::file::file(file_path).remove());
|
||||
// // EXPECT_TRUE(utils::file::file(to_file_path).remove());
|
||||
// //
|
||||
// // file_path =
|
||||
// // utils::path::combine(mount_location,
|
||||
|
@ -52,7 +52,7 @@ static std::string fuse_remote_dir =
|
||||
static void access_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir, {"access.txt"});
|
||||
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;
|
||||
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_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) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir, {"chflags.txt"});
|
||||
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;
|
||||
const auto ret = client.fuse_create(
|
||||
@ -86,13 +86,13 @@ static void chflags_test(repertory::remote_fuse::remote_client &client) {
|
||||
#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) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir, {"chmod.txt"});
|
||||
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;
|
||||
const auto ret = client.fuse_create(
|
||||
@ -108,13 +108,13 @@ static void chmod_test(repertory::remote_fuse::remote_client &client) {
|
||||
#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) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir, {"chown.txt"});
|
||||
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;
|
||||
const auto ret = client.fuse_create(
|
||||
@ -134,7 +134,7 @@ static void chown_test(repertory::remote_fuse::remote_client &client) {
|
||||
#endif
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
|
||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
||||
}
|
||||
|
||||
static void
|
||||
@ -143,7 +143,7 @@ create_and_release_test(repertory::remote_fuse::remote_client &client,
|
||||
const auto test_file =
|
||||
utils::path::combine(fuse_remote_dir, {"create_and_release.txt"});
|
||||
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;
|
||||
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_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) {
|
||||
@ -167,7 +167,7 @@ static void destroy_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir,
|
||||
{"fallocate.txt"}); const auto api_path =
|
||||
test_file.substr(mount_location_.size());
|
||||
utils::file::retry_delete_file(test_file);
|
||||
utils::file::file(test_file).remove();
|
||||
|
||||
remote::file_handle handle;
|
||||
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);
|
||||
}
|
||||
|
||||
utils::file::retry_delete_file(test_file);
|
||||
utils::file::file(test_file).remove();
|
||||
}*/
|
||||
|
||||
static void fgetattr_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_file =
|
||||
utils::path::combine(fuse_remote_dir, {"fgetattr.txt"});
|
||||
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;
|
||||
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_mode, st.st_mode);
|
||||
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),
|
||||
st.st_mtimespec / NANOS_PER_SECOND);
|
||||
st.st_mtimespec / utils::time::NANOS_PER_SECOND);
|
||||
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),
|
||||
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) {
|
||||
const auto test_file =
|
||||
utils::path::combine(fuse_remote_dir, {"fsetattr_x.txt"});
|
||||
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;
|
||||
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_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) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir, {"fsync.txt"});
|
||||
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;
|
||||
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_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) {
|
||||
const auto test_file =
|
||||
utils::path::combine(fuse_remote_dir, {"ftruncate.txt"});
|
||||
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;
|
||||
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_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) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir, {"getattr.txt"});
|
||||
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;
|
||||
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_mode, st.st_mode);
|
||||
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),
|
||||
st.st_mtimespec / NANOS_PER_SECOND);
|
||||
st.st_mtimespec / utils::time::NANOS_PER_SECOND);
|
||||
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),
|
||||
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) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir,
|
||||
{"getxattr.txt"}); const auto api_path =
|
||||
test_file.substr(mount_location_.size());
|
||||
utils::file::retry_delete_file(test_file);
|
||||
utils::file::file(test_file).remove();
|
||||
|
||||
remote::file_handle handle;
|
||||
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
|
||||
}
|
||||
|
||||
utils::file::retry_delete_file(test_file);
|
||||
utils::file::file(test_file).remove();
|
||||
}
|
||||
|
||||
static void getxattr_osx_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir,
|
||||
{"getxattr_osx.txt"}); const auto api_path =
|
||||
test_file.substr(mount_location_.size());
|
||||
utils::file::retry_delete_file(test_file);
|
||||
utils::file::file(test_file).remove();
|
||||
|
||||
remote::file_handle handle;
|
||||
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));
|
||||
}
|
||||
|
||||
utils::file::retry_delete_file(test_file);
|
||||
utils::file::file(test_file).remove();
|
||||
}*/
|
||||
|
||||
static void getxtimes_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_file =
|
||||
utils::path::combine(fuse_remote_dir, {"getxtimes.txt"});
|
||||
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;
|
||||
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_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) {
|
||||
@ -414,7 +414,7 @@ static void init_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir,
|
||||
{"listxattr.txt"}); const auto api_path =
|
||||
test_file.substr(mount_location_.size());
|
||||
utils::file::retry_delete_file(test_file);
|
||||
utils::file::file(test_file).remove();
|
||||
|
||||
remote::file_handle handle;
|
||||
const auto ret = client.fuse_create(
|
||||
@ -427,7 +427,7 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
|
||||
#endif
|
||||
}
|
||||
|
||||
utils::file::retry_delete_file(test_file);
|
||||
utils::file::file(test_file).remove();
|
||||
}*/
|
||||
|
||||
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) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir, {"open.txt"});
|
||||
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;
|
||||
#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_TRUE(utils::file::retry_delete_file(test_file));
|
||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
||||
}
|
||||
|
||||
static void
|
||||
@ -499,7 +499,7 @@ static void read_and_write_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_file =
|
||||
utils::path::combine(fuse_remote_dir, {"read_and_write.txt"});
|
||||
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;
|
||||
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_TRUE(utils::file::retry_delete_file(test_file));
|
||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
||||
}
|
||||
|
||||
static void
|
||||
@ -525,7 +525,7 @@ read_and_write_base64_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_file =
|
||||
utils::path::combine(fuse_remote_dir, {"read_and_write_base64.txt"});
|
||||
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;
|
||||
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_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) {
|
||||
@ -579,7 +579,7 @@ static void readdir_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir,
|
||||
{"removexattr.txt"}); const auto api_path =
|
||||
test_file.substr(mount_location_.size());
|
||||
utils::file::retry_delete_file(test_file);
|
||||
utils::file::file(test_file).remove();
|
||||
|
||||
remote::file_handle handle;
|
||||
const auto ret = client.fuse_create(
|
||||
@ -592,7 +592,7 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
|
||||
"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) {
|
||||
@ -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 renamed_api_path =
|
||||
renamed_test_file.substr(mount_location_.size());
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(renamed_test_file));
|
||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
||||
EXPECT_TRUE(utils::file::file(renamed_test_file).remove());
|
||||
|
||||
remote::file_handle handle;
|
||||
#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::retry_delete_file(test_file));
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(renamed_test_file));
|
||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
||||
EXPECT_TRUE(utils::file::file(renamed_test_file).remove());
|
||||
}
|
||||
|
||||
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 =
|
||||
utils::path::combine(fuse_remote_dir, {"setattr_x.txt"});
|
||||
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;
|
||||
const auto ret = client.fuse_create(
|
||||
@ -670,14 +670,14 @@ static void setattr_x_test(repertory::remote_fuse::remote_client &client) {
|
||||
#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) {
|
||||
const auto test_file =
|
||||
utils::path::combine(fuse_remote_dir, {"setbkuptime.txt"});
|
||||
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;
|
||||
const auto ret = client.fuse_create(
|
||||
@ -695,14 +695,14 @@ static void setbkuptime_test(repertory::remote_fuse::remote_client &client) {
|
||||
#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) {
|
||||
const auto test_file =
|
||||
utils::path::combine(fuse_remote_dir, {"setchgtime.txt"});
|
||||
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;
|
||||
const auto ret = client.fuse_create(
|
||||
@ -720,14 +720,14 @@ static void setchgtime_test(repertory::remote_fuse::remote_client &client) {
|
||||
#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) {
|
||||
const auto test_file =
|
||||
utils::path::combine(fuse_remote_dir, {"setcrtime.txt"});
|
||||
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;
|
||||
const auto ret = client.fuse_create(
|
||||
@ -745,7 +745,7 @@ static void setcrtime_test(repertory::remote_fuse::remote_client &client) {
|
||||
#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) {
|
||||
@ -756,7 +756,7 @@ static void setvolname_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir,
|
||||
{"setxattr.txt"}); const auto api_path =
|
||||
test_file.substr(mount_location_.size());
|
||||
utils::file::retry_delete_file(test_file);
|
||||
utils::file::file(test_file).remove();
|
||||
|
||||
remote::file_handle handle;
|
||||
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
|
||||
}
|
||||
|
||||
utils::file::retry_delete_file(test_file);
|
||||
utils::file::file(test_file).remove();
|
||||
}
|
||||
|
||||
static void setxattr_osx_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir,
|
||||
{"setxattr_osx.txt"}); const auto api_path =
|
||||
test_file.substr(mount_location_.size());
|
||||
utils::file::retry_delete_file(test_file);
|
||||
utils::file::file(test_file).remove();
|
||||
|
||||
remote::file_handle handle;
|
||||
const auto ret = client.fuse_create(
|
||||
@ -791,7 +791,7 @@ remote::open_flags::ReadWrite, handle); EXPECT_EQ(0, ret); if (ret == 0) {
|
||||
0));
|
||||
}
|
||||
|
||||
utils::file::retry_delete_file(test_file);
|
||||
utils::file::file(test_file).remove();
|
||||
}*/
|
||||
|
||||
#if defined(_WIN32)
|
||||
@ -832,7 +832,7 @@ static void statfs_x_test(repertory::remote_fuse::remote_client &client,
|
||||
|
||||
remote::statfs_x 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());
|
||||
|
||||
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 =
|
||||
utils::path::combine(fuse_remote_dir, {"truncate.txt"});
|
||||
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;
|
||||
#if defined(_WIN32)
|
||||
@ -876,13 +876,13 @@ static void truncate_test(repertory::remote_fuse::remote_client &client) {
|
||||
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) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir, {"unlink.txt"});
|
||||
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;
|
||||
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_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) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir, {"utimens.txt"});
|
||||
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;
|
||||
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_TRUE(utils::file::retry_delete_file(test_file));
|
||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
||||
}
|
||||
|
||||
TEST(remote_fuse, all_tests) {
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "platform/platform.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/time.hpp"
|
||||
|
||||
using namespace repertory;
|
||||
using namespace repertory::remote_winfsp;
|
||||
@ -45,7 +46,7 @@ static std::string win_remote_dir =
|
||||
static void can_delete_test(remote_client &client) {
|
||||
const auto test_file =
|
||||
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 =
|
||||
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()));
|
||||
|
||||
nf.close();
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
|
||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename t>
|
||||
static void create_and_close_test(remote_client &client, t &server) {
|
||||
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 =
|
||||
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, 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) {
|
||||
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 =
|
||||
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_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) {
|
||||
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 =
|
||||
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_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) {
|
||||
const auto test_file =
|
||||
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 =
|
||||
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_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) {
|
||||
const auto test_file =
|
||||
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 =
|
||||
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_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) {
|
||||
@ -202,7 +203,7 @@ static void mounted_test(remote_client &client) {
|
||||
|
||||
static void open_test(remote_client &client) {
|
||||
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 =
|
||||
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_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) {
|
||||
const auto test_file =
|
||||
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 =
|
||||
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_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) {
|
||||
@ -329,7 +330,7 @@ static void open_and_read_directory_test(remote_client &client) {
|
||||
static void read_and_write_test(remote_client &client) {
|
||||
const auto test_file =
|
||||
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 =
|
||||
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_TRUE(utils::file::retry_delete_file(test_file));
|
||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
||||
}
|
||||
|
||||
static void rename_test(remote_client &client) {
|
||||
const auto test_file = utils::path::combine(win_remote_dir, {"rename.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::retry_delete_file(test_file2));
|
||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
||||
EXPECT_TRUE(utils::file::file(test_file2).remove());
|
||||
auto api_path =
|
||||
utils::string::from_utf8(test_file).substr(mount_location_.size());
|
||||
auto api_path2 =
|
||||
@ -394,15 +395,15 @@ static void rename_test(remote_client &client) {
|
||||
|
||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
||||
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(test_file2));
|
||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
||||
EXPECT_TRUE(utils::file::file(test_file2).remove());
|
||||
}
|
||||
|
||||
static void set_basic_info_test(remote_client &client) {
|
||||
const auto test_file =
|
||||
utils::path::combine(win_remote_dir, {"set_basic_info.txt"});
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
|
||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
||||
auto api_path =
|
||||
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;
|
||||
#else
|
||||
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_write_time = creation_time + 2;
|
||||
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_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) {
|
||||
const auto test_file =
|
||||
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 =
|
||||
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_TRUE(utils::file::retry_delete_file(test_file));
|
||||
EXPECT_TRUE(utils::file::file(test_file).remove());
|
||||
}
|
||||
|
||||
static void unmounted_test(remote_client &client) {
|
||||
|
@ -50,8 +50,8 @@ TEST(utils, convert_api_date) {
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(utils, generate_sha256) {
|
||||
const auto res = utils::file::generate_sha256(__FILE__);
|
||||
std::cout << res << std::endl;
|
||||
}
|
||||
// TEST(utils, generate_sha256) {
|
||||
// const auto res = utils::file::generate_sha256(__FILE__);
|
||||
// std::cout << res << std::endl;
|
||||
// }
|
||||
} // namespace repertory
|
||||
|
@ -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) {
|
||||
TEST_HEADER(__FUNCTION__);
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,8 @@ struct result final {
|
||||
[[nodiscard]] operator bool() const { return ok; }
|
||||
};
|
||||
|
||||
using retryable_action_t = std::function<bool()>;
|
||||
|
||||
[[nodiscard]] inline constexpr auto
|
||||
calculate_read_size(std::uint64_t total_size, std::size_t read_size,
|
||||
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;
|
||||
#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>
|
||||
inline constexpr auto divide_with_ceiling(result_t numerator,
|
||||
data_t denominator) -> result_t {
|
||||
|
@ -283,6 +283,10 @@ public:
|
||||
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 truncate(std::size_t size) -> bool override;
|
||||
|
@ -25,7 +25,9 @@
|
||||
#include "utils/config.hpp"
|
||||
|
||||
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)
|
||||
[[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)
|
||||
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;
|
||||
#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
|
||||
|
||||
#endif // REPERTORY_INCLUDE_UTILS_TIME_HPP_
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
#include "utils/common.hpp"
|
||||
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
namespace repertory::utils {
|
||||
@ -153,4 +154,27 @@ auto get_next_available_port(std::uint16_t first_port,
|
||||
return not error_code;
|
||||
}
|
||||
#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
|
||||
|
@ -206,8 +206,7 @@ encrypting_reader::encrypting_reader(
|
||||
throw std::runtime_error("failed to get file size|" +
|
||||
source_file_->get_path());
|
||||
}
|
||||
|
||||
auto file_size{opt_size.value()};
|
||||
auto file_size = opt_size.value();
|
||||
|
||||
const auto total_chunks = utils::divide_with_ceiling(
|
||||
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|" +
|
||||
source_file_->get_path());
|
||||
}
|
||||
|
||||
auto file_size{opt_size.value()};
|
||||
auto file_size = opt_size.value();
|
||||
|
||||
const auto total_chunks = utils::divide_with_ceiling(
|
||||
file_size, static_cast<std::uint64_t>(data_chunk_size_));
|
||||
@ -289,7 +287,6 @@ encrypting_reader::encrypting_reader(
|
||||
source_file_->get_path() + '|' +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
auto file_size{opt_size.value()};
|
||||
|
||||
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::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
auto file_size{opt_size.value()};
|
||||
|
||||
const auto total_chunks = utils::divide_with_ceiling(
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/time.hpp"
|
||||
|
||||
namespace repertory::utils::file {
|
||||
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) {
|
||||
case time_types::access:
|
||||
#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)
|
||||
return static_cast<std::uint64_t>(st.st_atim.tv_nsec +
|
||||
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:
|
||||
#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)
|
||||
return static_cast<std::uint64_t>(st.st_ctim.tv_nsec +
|
||||
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:
|
||||
#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)
|
||||
return static_cast<std::uint64_t>(st.st_mtim.tv_nsec +
|
||||
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:
|
||||
#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)
|
||||
return static_cast<std::uint64_t>(st.st_mtim.tv_nsec +
|
||||
st.st_mtim.tv_sec *
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
#include "utils/file.hpp"
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/unix.hpp"
|
||||
#include "utils/windows.hpp"
|
||||
@ -329,6 +330,7 @@ auto directory::remove() -> bool {
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
return utils::retry_action([this]() -> bool {
|
||||
try {
|
||||
#if defined(_WIN32)
|
||||
return (not exists() || ::RemoveDirectoryA(path_.c_str()));
|
||||
@ -342,6 +344,7 @@ auto directory::remove() -> bool {
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
auto directory::remove_recursively() -> bool {
|
||||
|
@ -21,11 +21,14 @@
|
||||
*/
|
||||
#include "utils/file.hpp"
|
||||
|
||||
#include "utils/collection.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/encryption.hpp"
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/time.hpp"
|
||||
#include <optional>
|
||||
|
||||
namespace {
|
||||
[[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");
|
||||
}
|
||||
|
||||
auto res = fseeko(file_.get(), static_cast<std::int64_t>(offset), SEEK_SET);
|
||||
if (res == -1) {
|
||||
if (fseeko(file_.get(), static_cast<std::int64_t>(offset), SEEK_SET) ==
|
||||
-1) {
|
||||
throw std::runtime_error("failed to seek before read");
|
||||
}
|
||||
|
||||
std::size_t bytes_read{0U};
|
||||
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())) {
|
||||
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;
|
||||
}
|
||||
|
||||
#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 {
|
||||
#if defined(_WIN32)
|
||||
recur_mutex_lock lock{*mtx_};
|
||||
@ -339,12 +410,14 @@ auto file::remove() -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
return utils::retry_action([this]() -> bool {
|
||||
#if defined(_WIN32)
|
||||
return !!::DeleteFileA(path_.c_str());
|
||||
#else // !defined(_WIN32)
|
||||
std::error_code ec{};
|
||||
return std::filesystem::remove(path_, ec);
|
||||
#endif // defined(_WIN32)
|
||||
});
|
||||
}
|
||||
|
||||
auto file::truncate(std::size_t size) -> bool {
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
#include "utils/file.hpp"
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/error.hpp"
|
||||
|
||||
#if defined(PROJECT_ENABLE_LIBDSM)
|
||||
@ -490,6 +491,8 @@ auto smb_directory::remove() -> bool {
|
||||
throw std::runtime_error("session not found|" + path_);
|
||||
}
|
||||
|
||||
return utils::retry_action([this]() -> bool {
|
||||
try {
|
||||
auto res = smb_directory_rm(session_.get(), tid_,
|
||||
smb_create_relative_path(path_).c_str());
|
||||
if (res != DSM_SUCCESS) {
|
||||
@ -504,6 +507,14 @@ auto smb_directory::remove() -> bool {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
#include "utils/file.hpp"
|
||||
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
@ -273,6 +274,8 @@ auto smb_file::remove() -> bool {
|
||||
try {
|
||||
close();
|
||||
|
||||
return utils::retry_action([this]() -> bool {
|
||||
try {
|
||||
auto res = smb_tree_connect(session_.get(), share_name_.c_str(), &tid_);
|
||||
if (res != DSM_SUCCESS) {
|
||||
throw std::runtime_error("failed to connect to share|" + share_name_ +
|
||||
@ -295,6 +298,14 @@ auto smb_file::remove() -> bool {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -28,9 +28,9 @@ auto filetime_to_unix_time(const FILETIME &file_time) -> std::uint64_t {
|
||||
LARGE_INTEGER date{};
|
||||
date.HighPart = static_cast<LONG>(file_time.dwHighDateTime);
|
||||
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)
|
||||
|
||||
@ -47,11 +47,10 @@ void get_local_time_now(struct tm &local_time) {
|
||||
}
|
||||
|
||||
auto get_time_now() -> std::uint64_t {
|
||||
#if defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(_time64(nullptr));
|
||||
#else // !defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(time(nullptr));
|
||||
#endif // defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
.count());
|
||||
}
|
||||
|
||||
#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());
|
||||
}
|
||||
|
||||
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/
|
||||
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{};
|
||||
file_time.dwHighDateTime = static_cast<DWORD>(win_time >> 32U);
|
||||
file_time.dwLowDateTime = win_time & 0xFFFFFFFF;
|
||||
return file_time;
|
||||
}
|
||||
#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
|
||||
|
Reference in New Issue
Block a user