29 Commits

Author SHA1 Message Date
38f5374e49 winfsp unit tests and fixes
Some checks reported errors
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit
2024-10-31 14:46:42 -05:00
db1320dd3a updated build system 2024-10-31 14:12:32 -05:00
2f8f38b6a2 winfsp unit tests and fixes 2024-10-31 12:14:09 -05:00
0303dcf16a updated build system 2024-10-31 10:55:31 -05:00
4c4db56a82 winfsp unit tests and fixes 2024-10-31 10:43:41 -05:00
11c58c4afb winfsp unit tests and fixes 2024-10-30 15:28:33 -05:00
07d0eb0616 winfsp unit tests and fixes 2024-10-30 14:56:50 -05:00
7d74d192f9 winfsp unit tests and fixes 2024-10-30 12:37:26 -05:00
da60c39216 winfsp unit tests and fixes 2024-10-30 11:25:08 -05:00
5ca67b28cf winfsp unit tests and fixes 2024-10-30 11:01:45 -05:00
8247669d3b winfsp unit tests and fixes 2024-10-30 09:49:28 -05:00
55762f9c92 winfsp unit tests and fixes 2024-10-30 09:26:45 -05:00
2a1a48bc68 show logging 2024-10-30 07:49:01 -05:00
d5b47a803c winfsp unit tests and fixes 2024-10-29 14:53:30 -05:00
695a7b0195 winfsp unit tests and fixes 2024-10-29 14:45:19 -05:00
ff13142093 winfsp unit tests and fixes 2024-10-29 14:45:05 -05:00
d6aace8c51 winfsp unit tests and fixes 2024-10-29 14:29:10 -05:00
ec2b8e1854 winfsp unit tests and fixes 2024-10-29 14:21:15 -05:00
884d2d6890 winfsp unit tests 2024-10-29 14:15:04 -05:00
72899173a0 fix 2024-10-28 15:15:10 -05:00
79c72d1aef added test 2024-10-28 14:36:38 -05:00
ab0b1b645b fix 2024-10-28 14:20:02 -05:00
7eb12d09f9 fixes 2024-10-28 14:18:24 -05:00
ed8ec257cc fix 2024-10-28 14:09:52 -05:00
c7a28ae526 refactor 2024-10-28 13:57:06 -05:00
c22c68ef28 refactor 2024-10-28 13:51:24 -05:00
d07e1f9cce refactor 2024-10-28 12:50:53 -05:00
158cd55b1a fixes 2024-10-28 12:50:20 -05:00
5fcc59434b refactor 2024-10-28 12:35:46 -05:00
39 changed files with 1507 additions and 1774 deletions

View File

@ -23,6 +23,7 @@ cppflags
cpphttplib
cpptrace
cppvsdbg
create_notraverse
crypto_aead_xchacha20poly1305_ietf_npubbytes
cstdint
cxxflags

View File

@ -1,15 +1,15 @@
set(BINUTILS_VERSION 2.41)
set(BOOST2_MAJOR_VERSION 1)
set(BOOST2_MINOR_VERSION 76)
set(BOOST2_PATCH_VERSION 0)
set(BOOST_MAJOR_VERSION 1)
set(BOOST_MINOR_VERSION 85)
set(BOOST_PATCH_VERSION 0)
set(BOOST2_MAJOR_VERSION 1)
set(BOOST2_MINOR_VERSION 76)
set(BOOST2_PATCH_VERSION 0)
set(CPP_HTTPLIB_VERSION 0.16.3)
set(CURL2_VERSION 8_9_1)
set(CURL_VERSION 8.9.1)
set(EXPAT2_VERSION 2_6_2)
set(CURL2_VERSION 8_9_1)
set(EXPAT_VERSION 2.6.2)
set(EXPAT2_VERSION 2_6_2)
set(GCC_VERSION 14.2.0)
set(GTEST_VERSION 1.15.2)
set(ICU_VERSION 75-1)
@ -21,7 +21,7 @@ set(OPENSSL_VERSION 3.3.1)
set(PKG_CONFIG_VERSION 0.29.2)
set(PUGIXML_VERSION 1.14)
set(SPDLOG_VERSION 1.14.1)
set(SQLITE2_VERSION 3.46.1)
set(SQLITE_VERSION 3460100)
set(SQLITE2_VERSION 3.46.1)
set(STDUUID_VERSION 1.2.3)
set(ZLIB_VERSION 1.3.1)

View File

@ -31,22 +31,25 @@ class i_winfsp_drive {
INTERFACE_SETUP(i_winfsp_drive);
public:
[[nodiscard]] virtual auto get_directory_item_count(
const std::string &api_path) const -> std::uint64_t = 0;
[[nodiscard]] virtual auto get_directory_items(
const std::string &api_path) const -> directory_item_list = 0;
[[nodiscard]] virtual auto
get_directory_item_count(const std::string &api_path) const
-> std::uint64_t = 0;
[[nodiscard]] virtual auto
get_file_size(const std::string &api_path) const -> std::uint64_t = 0;
get_directory_items(const std::string &api_path) const
-> directory_item_list = 0;
[[nodiscard]] virtual auto
get_item_meta(const std::string &api_path, const std::string &name,
std::string &value) const -> api_error = 0;
[[nodiscard]] virtual auto get_file_size(const std::string &api_path) const
-> std::uint64_t = 0;
[[nodiscard]] virtual auto
get_item_meta(const std::string &api_path,
api_meta_map &meta) const -> api_error = 0;
[[nodiscard]] virtual auto get_item_meta(const std::string &api_path,
const std::string &name,
std::string &value) const
-> api_error = 0;
[[nodiscard]] virtual auto get_item_meta(const std::string &api_path,
api_meta_map &meta) const
-> api_error = 0;
[[nodiscard]] virtual auto
get_security_by_name(PWSTR file_name, PUINT32 attributes,
@ -62,9 +65,9 @@ public:
virtual void get_volume_info(UINT64 &total_size, UINT64 &free_size,
std::string &volume_label) const = 0;
[[nodiscard]] virtual auto
populate_file_info(const std::string &api_path,
remote::file_info &fi) -> api_error = 0;
[[nodiscard]] virtual auto populate_file_info(const std::string &api_path,
remote::file_info &fi) const
-> api_error = 0;
};
} // namespace repertory

View File

@ -75,22 +75,28 @@ private:
std::unique_ptr<remote_winfsp::remote_server> remote_server_;
private:
static auto
parse_mount_location(const std::wstring &mount_location) -> std::string;
[[nodiscard]] auto handle_error(std::string_view function_name,
const std::string &api_path, api_error error,
FileInfo *file_info, std::uint64_t file_size,
bool raise_on_failure_only = false) const
-> NTSTATUS;
static auto parse_mount_location(const std::wstring &mount_location)
-> std::string;
void populate_file_info(const std::string &api_path, std::uint64_t file_size,
const api_meta_map &meta,
FSP_FSCTL_OPEN_FILE_INFO &ofi);
FSP_FSCTL_OPEN_FILE_INFO &ofi) const;
void populate_file_info(std::uint64_t file_size, api_meta_map meta,
FSP_FSCTL_FILE_INFO &fi);
FSP_FSCTL_FILE_INFO &fi) const;
static void set_file_info(remote::file_info &dest,
const FSP_FSCTL_FILE_INFO &src);
public:
auto CanDelete(PVOID file_node, PVOID file_desc,
PWSTR file_name) -> NTSTATUS override;
auto CanDelete(PVOID file_node, PVOID file_desc, PWSTR file_name)
-> NTSTATUS override;
VOID Cleanup(PVOID file_node, PVOID file_desc, PWSTR file_name,
ULONG flags) override;
@ -102,8 +108,8 @@ public:
UINT64 allocation_size, PVOID *file_node, PVOID *file_desc,
OpenFileInfo *ofi) -> NTSTATUS override;
auto Flush(PVOID file_node, PVOID file_desc,
FileInfo *file_info) -> NTSTATUS override;
auto Flush(PVOID file_node, PVOID file_desc, FileInfo *file_info)
-> NTSTATUS override;
[[nodiscard]] auto get_directory_item_count(const std::string &api_path) const
-> std::uint64_t override;
@ -111,24 +117,25 @@ public:
[[nodiscard]] auto get_directory_items(const std::string &api_path) const
-> directory_item_list override;
auto GetFileInfo(PVOID file_node, PVOID file_desc,
FileInfo *file_info) -> NTSTATUS override;
auto GetFileInfo(PVOID file_node, PVOID file_desc, FileInfo *file_info)
-> NTSTATUS override;
[[nodiscard]] auto
get_file_size(const std::string &api_path) const -> std::uint64_t override;
[[nodiscard]] auto get_file_size(const std::string &api_path) const
-> std::uint64_t override;
[[nodiscard]] auto
get_item_meta(const std::string &api_path,
api_meta_map &meta) const -> api_error override;
[[nodiscard]] auto get_item_meta(const std::string &api_path,
api_meta_map &meta) const
-> api_error override;
[[nodiscard]] auto
get_item_meta(const std::string &api_path, const std::string &name,
std::string &value) const -> api_error override;
[[nodiscard]] auto get_item_meta(const std::string &api_path,
const std::string &name,
std::string &value) const
-> api_error override;
[[nodiscard]] auto
get_security_by_name(PWSTR file_name, PUINT32 attributes,
[[nodiscard]] auto get_security_by_name(PWSTR file_name, PUINT32 attributes,
PSECURITY_DESCRIPTOR descriptor,
std::uint64_t *descriptor_size) -> NTSTATUS override;
std::uint64_t *descriptor_size)
-> NTSTATUS override;
auto GetSecurityByName(PWSTR file_name, PUINT32 attributes,
PSECURITY_DESCRIPTOR descriptor,
@ -152,16 +159,16 @@ public:
auto Mounted(PVOID host) -> NTSTATUS override;
auto Open(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
PVOID *file_node, PVOID *file_desc,
OpenFileInfo *ofi) -> NTSTATUS override;
PVOID *file_node, PVOID *file_desc, OpenFileInfo *ofi)
-> NTSTATUS override;
auto Overwrite(PVOID file_node, PVOID file_desc, UINT32 attributes,
BOOLEAN replace_attributes, UINT64 allocation_size,
FileInfo *file_info) -> NTSTATUS override;
[[nodiscard]] auto
populate_file_info(const std::string &api_path,
remote::file_info &file_info) -> api_error override;
[[nodiscard]] auto populate_file_info(const std::string &api_path,
remote::file_info &file_info) const
-> api_error override;
auto Read(PVOID file_node, PVOID file_desc, PVOID buffer, UINT64 offset,
ULONG length, PULONG bytes_transferred) -> NTSTATUS override;
@ -171,8 +178,8 @@ public:
PULONG bytes_transferred) -> NTSTATUS override;
auto Rename(PVOID file_node, PVOID file_desc, PWSTR file_name,
PWSTR new_file_name,
BOOLEAN replace_if_exists) -> NTSTATUS override;
PWSTR new_file_name, BOOLEAN replace_if_exists)
-> NTSTATUS override;
auto SetBasicInfo(PVOID file_node, PVOID file_desc, UINT32 attributes,
UINT64 creation_time, UINT64 last_access_time,
@ -180,15 +187,15 @@ public:
FileInfo *file_info) -> NTSTATUS override;
auto SetFileSize(PVOID file_node, PVOID file_desc, UINT64 new_size,
BOOLEAN set_allocation_size,
FileInfo *file_info) -> NTSTATUS override;
BOOLEAN set_allocation_size, FileInfo *file_info)
-> NTSTATUS override;
VOID Unmounted(PVOID host) override;
auto Write(PVOID file_node, PVOID file_desc, PVOID buffer, UINT64 offset,
ULONG length, BOOLEAN write_to_end, BOOLEAN constrained_io,
PULONG bytes_transferred,
FileInfo *file_info) -> NTSTATUS override;
PULONG bytes_transferred, FileInfo *file_info)
-> NTSTATUS override;
void shutdown();

View File

@ -68,7 +68,7 @@ private:
private:
bool notified_ = false;
std::size_t read_chunk_index_{};
std::size_t read_chunk_{};
boost::dynamic_bitset<> read_state_;
std::unique_ptr<std::thread> reader_thread_;
std::unique_ptr<std::thread> download_thread_;
@ -77,8 +77,8 @@ private:
private:
void download_chunk(std::size_t chunk, bool skip_active, bool should_reset);
void download_range(std::size_t start_chunk_index,
std::size_t end_chunk_index, bool should_reset);
void download_range(std::size_t start_chunk, std::size_t end_chunk,
bool should_reset);
void set_modified();

View File

@ -208,8 +208,8 @@ auto remote_server::fuse_access(const char *path, const std::int32_t &mask)
return ret;
}
auto remote_server::fuse_chflags(const char *path,
std::uint32_t flags) -> packet::error_type {
auto remote_server::fuse_chflags(const char *path, std::uint32_t flags)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path);
@ -316,9 +316,10 @@ length); ret = ((res < 0) ? -errno : 0); #endif
return ret;
}*/
auto remote_server::fuse_fgetattr(
const char *path, remote::stat &r_stat, bool &directory,
const remote::file_handle &handle) -> packet::error_type {
auto remote_server::fuse_fgetattr(const char *path, remote::stat &r_stat,
bool &directory,
const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
r_stat = {};
@ -328,7 +329,7 @@ auto remote_server::fuse_fgetattr(
auto res = has_open_info(static_cast<native_handle>(handle), EBADF);
if (res == 0) {
directory = utils::file::directory(file_path).exists();
struct stat64 unix_st {};
struct stat64 unix_st{};
res = fstat64(static_cast<native_handle>(handle), &unix_st);
if (res == 0) {
populate_stat(unix_st, r_stat);
@ -340,9 +341,10 @@ auto remote_server::fuse_fgetattr(
return ret;
}
auto remote_server::fuse_fsetattr_x(
const char *path, const remote::setattr_x &attr,
const remote::file_handle &handle) -> packet::error_type {
auto remote_server::fuse_fsetattr_x(const char *path,
const remote::setattr_x &attr,
const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path);
@ -458,9 +460,10 @@ auto remote_server::fuse_fsync(const char *path, const std::int32_t &datasync,
return ret;
}
auto remote_server::fuse_ftruncate(
const char *path, const remote::file_offset &size,
const remote::file_handle &handle) -> packet::error_type {
auto remote_server::fuse_ftruncate(const char *path,
const remote::file_offset &size,
const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path);
@ -488,7 +491,7 @@ auto remote_server::fuse_getattr(const char *path, remote::stat &r_stat,
directory = utils::file::directory(file_path).exists();
struct stat64 unix_st {};
struct stat64 unix_st{};
auto res = stat64(file_path.c_str(), &unix_st);
if (res == 0) {
populate_stat(unix_st, r_stat);
@ -553,9 +556,10 @@ STATUS_NOT_IMPLEMENTED; #endif RAISE_REMOTE_FUSE_SERVER_EVENT(function_name,
file_path, ret); return ret;
}*/
auto remote_server::fuse_getxtimes(
const char *path, remote::file_time &bkuptime,
remote::file_time &crtime) -> packet::error_type {
auto remote_server::fuse_getxtimes(const char *path,
remote::file_time &bkuptime,
remote::file_time &crtime)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path);
@ -655,10 +659,11 @@ auto remote_server::fuse_opendir(const char *path, remote::file_handle &handle)
return ret;
}
auto remote_server::fuse_read(
const char *path, char *buffer, const remote::file_size &read_size,
auto remote_server::fuse_read(const char *path, char *buffer,
const remote::file_size &read_size,
const remote::file_offset &read_offset,
const remote::file_handle &handle) -> packet::error_type {
const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path);
@ -679,8 +684,8 @@ auto remote_server::fuse_read(
return static_cast<packet::error_type>(ret);
}
auto remote_server::fuse_rename(const char *from,
const char *to) -> packet::error_type {
auto remote_server::fuse_rename(const char *from, const char *to)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto from_path = utils::path::combine(mount_location_, {from});
@ -718,8 +723,9 @@ auto remote_server::fuse_readdir(const char *path,
return ret;
}
auto remote_server::fuse_release(
const char *path, const remote::file_handle &handle) -> packet::error_type {
auto remote_server::fuse_release(const char *path,
const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
packet::error_type ret = 0;
@ -736,8 +742,9 @@ auto remote_server::fuse_release(
return ret;
}
auto remote_server::fuse_releasedir(
const char *path, const remote::file_handle &handle) -> packet::error_type {
auto remote_server::fuse_releasedir(const char *path,
const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path);
@ -788,8 +795,9 @@ auto remote_server::fuse_setattr_x(const char *path, remote::setattr_x &attr)
return ret;
}
auto remote_server::fuse_setbkuptime(
const char *path, const remote::file_time &bkuptime) -> packet::error_type {
auto remote_server::fuse_setbkuptime(const char *path,
const remote::file_time &bkuptime)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path);
@ -808,8 +816,9 @@ auto remote_server::fuse_setbkuptime(
return ret;
}
auto remote_server::fuse_setchgtime(
const char *path, const remote::file_time &chgtime) -> packet::error_type {
auto remote_server::fuse_setchgtime(const char *path,
const remote::file_time &chgtime)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path);
@ -828,8 +837,9 @@ auto remote_server::fuse_setchgtime(
return ret;
}
auto remote_server::fuse_setcrtime(
const char *path, const remote::file_time &crtime) -> packet::error_type {
auto remote_server::fuse_setcrtime(const char *path,
const remote::file_time &crtime)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path);
@ -920,8 +930,9 @@ auto remote_server::fuse_statfs_x(const char *path, std::uint64_t bsize,
return 0;
}
auto remote_server::fuse_truncate(
const char *path, const remote::file_offset &size) -> packet::error_type {
auto remote_server::fuse_truncate(const char *path,
const remote::file_offset &size)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path);
@ -942,8 +953,8 @@ auto remote_server::fuse_unlink(const char *path) -> packet::error_type {
}
auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
std::uint64_t op0,
std::uint64_t op1) -> packet::error_type {
std::uint64_t op0, std::uint64_t op1)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path);
@ -970,10 +981,11 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
return ret;
}
auto remote_server::fuse_write(
const char *path, const char *buffer, const remote::file_size &write_size,
auto remote_server::fuse_write(const char *path, const char *buffer,
const remote::file_size &write_size,
const remote::file_offset &write_offset,
const remote::file_handle &handle) -> packet::error_type {
const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path);
@ -1003,8 +1015,8 @@ auto remote_server::fuse_write_base64(
}
// WinFSP Layer
auto remote_server::winfsp_can_delete(PVOID file_desc,
PWSTR file_name) -> packet::error_type {
auto remote_server::winfsp_can_delete(PVOID file_desc, PWSTR file_name)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_name);
@ -1020,8 +1032,7 @@ auto remote_server::winfsp_can_delete(PVOID file_desc,
utils::path::create_api_path(relative_path))
? STATUS_DIRECTORY_NOT_EMPTY
: STATUS_SUCCESS
: drive_.is_processing(utils::path::create_api_path(relative_path))
? STATUS_DEVICE_BUSY
: STATUS_SUCCESS);
}
@ -1030,8 +1041,8 @@ auto remote_server::winfsp_can_delete(PVOID file_desc,
}
auto remote_server::winfsp_cleanup(PVOID /*file_desc*/, PWSTR file_name,
UINT32 flags,
BOOLEAN &was_closed) -> packet::error_type {
UINT32 flags, BOOLEAN &was_closed)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_name);
@ -1108,8 +1119,8 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, UINT32 attributes,
UINT64 /*allocation_size*/, PVOID *file_desc,
remote::file_info *file_info,
std::string &normalized_name,
BOOLEAN &exists) -> packet::error_type {
std::string &normalized_name, BOOLEAN &exists)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_name);
@ -1176,8 +1187,9 @@ auto remote_server::winfsp_flush(PVOID file_desc, remote::file_info *file_info)
return ret;
}
auto remote_server::winfsp_get_file_info(
PVOID file_desc, remote::file_info *file_info) -> packet::error_type {
auto remote_server::winfsp_get_file_info(PVOID file_desc,
remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
@ -1220,9 +1232,10 @@ auto remote_server::winfsp_get_security_by_name(
return ret;
}
auto remote_server::winfsp_get_volume_info(
UINT64 &total_size, UINT64 &free_size,
std::string &volume_label) -> packet::error_type {
auto remote_server::winfsp_get_volume_info(UINT64 &total_size,
UINT64 &free_size,
std::string &volume_label)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
drive_.get_volume_info(total_size, free_size, volume_label);
@ -1239,10 +1252,11 @@ auto remote_server::winfsp_mounted(const std::wstring &location)
return STATUS_SUCCESS;
}
auto remote_server::winfsp_open(
PWSTR file_name, UINT32 create_options, UINT32 granted_access,
PVOID *file_desc, remote::file_info *file_info,
std::string &normalized_name) -> packet::error_type {
auto remote_server::winfsp_open(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, PVOID *file_desc,
remote::file_info *file_info,
std::string &normalized_name)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_name);
@ -1278,10 +1292,11 @@ auto remote_server::winfsp_open(
return ret;
}
auto remote_server::winfsp_overwrite(
PVOID file_desc, UINT32 attributes, BOOLEAN replace_attributes,
auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
BOOLEAN replace_attributes,
UINT64 /*allocation_size*/,
remote::file_info *file_info) -> packet::error_type {
remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
@ -1397,9 +1412,10 @@ auto remote_server::winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/,
return ret;
}
auto remote_server::winfsp_rename(
PVOID /*file_desc*/, PWSTR file_name, PWSTR new_file_name,
BOOLEAN replace_if_exists) -> packet::error_type {
auto remote_server::winfsp_rename(PVOID /*file_desc*/, PWSTR file_name,
PWSTR new_file_name,
BOOLEAN replace_if_exists)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_name);
@ -1493,9 +1509,10 @@ auto remote_server::winfsp_set_basic_info(
return ret;
}
auto remote_server::winfsp_set_file_size(
PVOID file_desc, UINT64 new_size, BOOLEAN set_allocation_size,
remote::file_info *file_info) -> packet::error_type {
auto remote_server::winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
BOOLEAN set_allocation_size,
remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
@ -1531,10 +1548,12 @@ auto remote_server::winfsp_unmounted(const std::wstring &location)
return STATUS_SUCCESS;
}
auto remote_server::winfsp_write(
PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
BOOLEAN write_to_end, BOOLEAN constrained_io, PUINT32 bytes_transferred,
remote::file_info *file_info) -> packet::error_type {
auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
UINT32 length, BOOLEAN write_to_end,
BOOLEAN constrained_io,
PUINT32 bytes_transferred,
remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
*bytes_transferred = 0;
@ -1582,8 +1601,9 @@ auto remote_server::winfsp_write(
return ret;
}
auto remote_server::json_create_directory_snapshot(
const std::string &path, json &json_data) -> packet::error_type {
auto remote_server::json_create_directory_snapshot(const std::string &path,
json &json_data)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path);
@ -1642,8 +1662,8 @@ auto remote_server::json_read_directory_snapshot(
}
auto remote_server::json_release_directory_snapshot(
const std::string &path,
const remote::file_handle &handle) -> packet::error_type {
const std::string &path, const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path);

View File

@ -361,7 +361,7 @@ auto remote_winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
// if (not utils::path::is_ads_file_path(item_path)) {
union {
UINT8 B[FIELD_OFFSET(FSP_FSCTL_DIR_INFO, FileNameBuf) +
((MAX_PATH + 1) * sizeof(WCHAR))];
((repertory::max_path_length + 1U) * sizeof(WCHAR))];
FSP_FSCTL_DIR_INFO D;
} directory_info_buffer;
@ -369,7 +369,8 @@ 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(static_cast<size_t>(MAX_PATH), display_name.size()) *
(std::min(static_cast<size_t>(repertory::max_path_length),
display_name.size()) *
sizeof(WCHAR)));
if (not item["meta"].empty() ||
@ -377,8 +378,8 @@ auto remote_winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
populate_file_info(item, directory_info->FileInfo);
}
if (ret == STATUS_SUCCESS) {
::wcscpy_s(&directory_info->FileNameBuf[0], MAX_PATH,
&display_name[0]);
::wcscpy_s(&directory_info->FileNameBuf[0],
repertory::max_path_length, &display_name[0]);
FspFileSystemFillDirectoryBuffer(directory_buffer, directory_info,
&ret);

File diff suppressed because it is too large Load Diff

View File

@ -207,11 +207,10 @@ void open_file::download_chunk(std::size_t chunk, bool skip_active,
}
}
void open_file::download_range(std::size_t start_chunk_index,
std::size_t end_chunk_index, bool should_reset) {
for (std::size_t chunk_index = start_chunk_index;
chunk_index <= end_chunk_index; ++chunk_index) {
download_chunk(chunk_index, false, should_reset);
void open_file::download_range(std::size_t start_chunk, std::size_t end_chunk,
bool should_reset) {
for (std::size_t chunk = start_chunk; chunk <= end_chunk; ++chunk) {
download_chunk(chunk, false, should_reset);
if (get_api_error() != api_error::success) {
return;
}
@ -305,9 +304,8 @@ auto open_file::native_operation(
read_state_.resize(is_empty_file ? 0U : last_chunk + 1U);
if (not is_empty_file) {
for (std::size_t chunk_index = old_size; chunk_index <= last_chunk;
++chunk_index) {
read_state_.set(chunk_index);
for (std::size_t chunk = old_size; chunk <= last_chunk; ++chunk) {
read_state_.set(chunk);
}
}
@ -374,14 +372,13 @@ auto open_file::read(std::size_t read_size, std::uint64_t read_offset,
}
file_lock.unlock();
const auto start_chunk_index =
static_cast<std::size_t>(read_offset / chunk_size_);
const auto end_chunk_index =
const auto start_chunk = static_cast<std::size_t>(read_offset / chunk_size_);
const auto end_chunk =
static_cast<std::size_t>((read_size + read_offset) / chunk_size_);
update_background_reader(start_chunk_index);
update_background_reader(start_chunk);
download_range(start_chunk_index, end_chunk_index, true);
download_range(start_chunk, end_chunk, true);
if (get_api_error() != api_error::success) {
return get_api_error();
}
@ -495,7 +492,7 @@ void open_file::set_modified() {
void open_file::update_background_reader(std::size_t read_chunk) {
recur_mutex_lock reader_lock(file_mtx_);
read_chunk_index_ = read_chunk;
read_chunk_ = read_chunk;
if (not reader_thread_ && not stop_requested_) {
reader_thread_ = std::make_unique<std::thread>([this]() {
@ -513,10 +510,9 @@ void open_file::update_background_reader(std::size_t read_chunk) {
io_lock.unlock();
} else {
do {
next_chunk = read_chunk_index_ =
((read_chunk_index_ + 1U) >= read_state_.size())
? 0U
: read_chunk_index_ + 1U;
next_chunk = read_chunk_ =
((read_chunk_ + 1U) >= read_state_.size()) ? 0U
: read_chunk_ + 1U;
} while ((next_chunk != 0U) && (active_downloads_.find(next_chunk) !=
active_downloads_.end()));
@ -548,15 +544,14 @@ auto open_file::write(std::uint64_t write_offset, const data_buffer &data,
}
write_lock.unlock();
const auto start_chunk_index =
static_cast<std::size_t>(write_offset / chunk_size_);
const auto end_chunk_index =
const auto start_chunk = static_cast<std::size_t>(write_offset / chunk_size_);
const auto end_chunk =
static_cast<std::size_t>((write_offset + data.size()) / chunk_size_);
update_background_reader(start_chunk_index);
update_background_reader(start_chunk);
download_range(start_chunk_index,
std::min(read_state_.size() - 1U, end_chunk_index), true);
download_range(start_chunk, std::min(read_state_.size() - 1U, end_chunk),
true);
if (get_api_error() != api_error::success) {
return get_api_error();
}

View File

@ -36,6 +36,7 @@
#include "utils/polling.hpp"
#include "utils/string.hpp"
#include "utils/time.hpp"
#include <utils/config.hpp>
namespace repertory {
s3_provider::s3_provider(app_config &config, i_http_comm &comm)
@ -283,6 +284,8 @@ auto s3_provider::get_directory_item_count(const std::string &api_path) const
auto s3_provider::get_directory_items_impl(const std::string &api_path,
directory_item_list &list) const
-> api_error {
REPERTORY_USES_FUNCTION_NAME();
const auto cfg = get_config().get_s3_config();
const auto is_encrypted = not cfg.encryption_token.empty();
@ -313,6 +316,8 @@ auto s3_provider::get_directory_items_impl(const std::string &api_path,
}
if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error(function_name, api_path, response_code,
"failed to get directory items");
return api_error::comm_error;
}
@ -430,6 +435,8 @@ auto s3_provider::get_file(const std::string &api_path, api_file &file) const
}
auto s3_provider::get_file_list(api_file_list &list) const -> api_error {
REPERTORY_USES_FUNCTION_NAME();
std::string response_data;
long response_code{};
if (not get_object_list(response_data, response_code)) {
@ -437,12 +444,16 @@ auto s3_provider::get_file_list(api_file_list &list) const -> api_error {
}
if (response_code != http_error_codes::ok) {
utils::error::raise_error(function_name, response_code,
"failed to get file list");
return api_error::comm_error;
}
pugi::xml_document doc;
auto res = doc.load_string(response_data.c_str());
if (res.status != pugi::xml_parse_status::status_ok) {
utils::error::raise_error(function_name, res.status,
"failed to parse xml document");
return api_error::comm_error;
}
@ -538,6 +549,8 @@ auto s3_provider::get_object_info(bool directory, const std::string &api_path,
}
if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error(function_name, api_path, response_code,
"failed to get object info");
return api_error::comm_error;
}
@ -885,6 +898,8 @@ void s3_provider::stop() {
auto s3_provider::upload_file_impl(const std::string &api_path,
const std::string &source_path,
stop_type &stop_requested) -> api_error {
REPERTORY_USES_FUNCTION_NAME();
std::uint64_t file_size{};
if (utils::file::file{source_path}.exists()) {
auto opt_size = utils::file::file{source_path}.size();
@ -926,6 +941,8 @@ auto s3_provider::upload_file_impl(const std::string &api_path,
}
if (response_code != http_error_codes::ok) {
utils::error::raise_api_path_error(function_name, api_path, response_code,
"failed to get upload file");
return api_error::comm_error;
}

View File

@ -54,6 +54,7 @@ public:
static std::string cfg_directory;
static std::unique_ptr<app_config> config;
static std::filesystem::path current_directory;
static provider_type current_provider;
static std::unique_ptr<fuse_drive> drive;
static std::vector<std::string> drive_args;
static std::unique_ptr<meta_db> meta;
@ -68,20 +69,18 @@ protected:
test::get_test_output_dir(),
{
"fuse_test",
std::to_string(static_cast<std::uint8_t>(provider_t::type)),
app_config::get_provider_name(current_provider),
});
ASSERT_TRUE(utils::file::directory(test_directory).remove_recursively());
mount_location = utils::path::combine(test_directory, {"mount"});
ASSERT_TRUE(utils::file::directory(mount_location).create_directory());
cfg_directory = utils::path::combine(test_directory, {"cfg"});
ASSERT_TRUE(utils::file::directory(cfg_directory).create_directory());
config = std::make_unique<app_config>(provider_t::type, cfg_directory);
config = std::make_unique<app_config>(current_provider, cfg_directory);
switch (provider_t::type) {
switch (current_provider) {
case provider_type::s3: {
{
app_config src_cfg{
@ -145,9 +144,6 @@ protected:
static void TearDownTestCase() {
execute_unmount();
std::filesystem::current_path(current_directory);
[[maybe_unused]] auto ret =
utils::file::directory(test_directory).remove_recursively();
}
public:
@ -237,6 +233,9 @@ std::unique_ptr<app_config> fuse_test<provider_t>::config{};
template <typename provider_t>
std::filesystem::path fuse_test<provider_t>::current_directory{};
template <typename provider_t>
provider_type winfsp_test<provider_t>::current_provider{provider_t::type};
template <typename provider_t>
std::unique_ptr<fuse_drive> fuse_test<provider_t>::drive{};

View File

@ -49,9 +49,11 @@ public:
static std::unique_ptr<app_config> config;
static std::filesystem::path current_directory;
static std::unique_ptr<winfsp_drive> drive;
static std::vector<std::string> drive_args;
static std::string mount_location;
static std::unique_ptr<i_provider> provider;
static std::string test_directory;
static provider_type current_provider;
protected:
static void SetUpTestCase() {
@ -61,18 +63,17 @@ protected:
test::get_test_output_dir(),
{
"winfsp_test",
std::to_string(static_cast<std::uint8_t>(provider_t::type)),
app_config::get_provider_name(current_provider),
});
mount_location = "U:";
cfg_directory = utils::path::combine(test_directory, {"cfg"});
ASSERT_TRUE(utils::file::directory(cfg_directory).create_directory());
config = std::make_unique<app_config>(provider_t::type, cfg_directory);
config = std::make_unique<app_config>(current_provider, cfg_directory);
std::vector<std::string> drive_args{};
switch (provider_t::type) {
switch (current_provider) {
case provider_type::s3: {
{
app_config src_cfg{
@ -84,7 +85,6 @@ protected:
config->set_s3_config(src_cfg.get_s3_config());
}
comm = std::make_unique<curl_comm>(config->get_s3_config());
drive_args = std::vector<std::string>({
"-s3",
"-na",
@ -99,11 +99,15 @@ protected:
utils::path::combine(test::get_test_config_dir(), {"sia"}),
};
config->set_enable_drive_events(true);
config->set_event_level(event_level::debug);
config->set_event_level(event_level::trace);
config->set_host_config(src_cfg.get_host_config());
config->set_sia_config(src_cfg.get_sia_config());
}
comm = std::make_unique<curl_comm>(config->get_host_config());
drive_args = std::vector<std::string>({
"-na",
"sia",
});
} break;
// case 0U: {
// config =
@ -117,10 +121,6 @@ protected:
// config->set_event_level(event_level::trace);
// config->set_s3_config(src_cfg.get_s3_config());
// }
//
// comm = std::make_unique<curl_comm>(config->get_s3_config());
// provider = std::make_unique<s3_provider>(*config, *comm);
// drive_args = std::vector<std::string>({"-en"});
// } break;
default:
@ -128,15 +128,13 @@ protected:
return;
}
provider = std::make_unique<provider_t>(*config, *comm);
drive_args.push_back(mount_location);
execute_mount();
}
static void TearDownTestCase() {
execute_unmount();
std::filesystem::current_path(current_directory);
[[maybe_unused]] auto ret =
utils::file::directory(test_directory).remove_recursively();
}
public:
@ -159,8 +157,9 @@ public:
auto file_path = utils::path::combine(mount_location, {file_name});
auto handle =
::CreateFileA(file_path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr,
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
EXPECT_TRUE(::CloseHandle(handle));
@ -191,9 +190,10 @@ public:
EXPECT_FALSE(utils::file::file(file_path).exists());
}
static void execute_mount(auto &&drive_args) {
auto mount_cmd = ".\\repertory.exe -dd \"" + config->get_data_directory() +
"\"" + " " + utils::string::join(drive_args, ' ');
static void execute_mount() {
auto mount_cmd = "start .\\repertory.exe -f -dd \"" +
config->get_data_directory() + "\"" + " " +
utils::string::join(drive_args, ' ');
std::cout << "mount command: " << mount_cmd << std::endl;
ASSERT_EQ(0, system(mount_cmd.c_str()));
std::this_thread::sleep_for(5s);
@ -204,10 +204,11 @@ public:
auto unmounted{false};
auto unmount_cmd = ".\\repertory.exe -dd \"" +
config->get_data_directory() + "\" -unmount";
config->get_data_directory() + "\"" + " " +
utils::string::join(drive_args, ' ') + " -unmount";
for (int i = 0; not unmounted && (i < 50); i++) {
std::cout << "unmount command: " << unmount_cmd << std::endl;
ASSERT_EQ(0, system(unmount_cmd.c_str()));
system(unmount_cmd.c_str());
unmounted = not utils::file::directory{mount_location}.exists();
if (not unmounted) {
std::this_thread::sleep_for(5s);
@ -221,6 +222,9 @@ public:
template <typename provider_t>
std::string winfsp_test<provider_t>::cfg_directory;
template <typename provider_t>
std::unique_ptr<curl_comm> winfsp_test<provider_t>::comm;
template <typename provider_t>
std::unique_ptr<app_config> winfsp_test<provider_t>::config;
@ -228,7 +232,13 @@ template <typename provider_t>
std::filesystem::path winfsp_test<provider_t>::current_directory;
template <typename provider_t>
std::unique_ptr<curl_comm> winfsp_test<provider_t>::comm;
provider_type winfsp_test<provider_t>::current_provider{provider_t::type};
template <typename provider_t>
std::unique_ptr<winfsp_drive> winfsp_test<provider_t>::drive;
template <typename provider_t>
std::vector<std::string> winfsp_test<provider_t>::drive_args;
template <typename provider_t>
std::string winfsp_test<provider_t>::mount_location;
@ -239,10 +249,8 @@ std::unique_ptr<i_provider> winfsp_test<provider_t>::provider;
template <typename provider_t>
std::string winfsp_test<provider_t>::test_directory;
template <typename provider_t>
std::unique_ptr<winfsp_drive> winfsp_test<provider_t>::drive;
using winfsp_provider_types = ::testing::Types<s3_provider, sia_provider>;
using winfsp_provider_types = ::testing::Types<s3_provider>;
// using winfsp_provider_types = ::testing::Types<s3_provider, sia_provider>;
} // namespace repertory
#endif // defined(_WIN32)

View File

@ -136,7 +136,8 @@ public:
}
auto populate_file_info(const std::string &api_path,
remote::file_info &file_info) -> api_error override {
remote::file_info &file_info) const
-> api_error override {
auto file_path = utils::path::combine(mount_location_, {api_path});
auto directory = utils::file::directory(file_path).exists();
auto attributes =

View File

@ -28,6 +28,8 @@
using namespace repertory;
int PROJECT_TEST_RESULT{0};
auto main(int argc, char **argv) -> int {
#if defined(PROJECT_ENABLE_BACKWARD_CPP)
static backward::SignalHandling sh;
@ -39,9 +41,9 @@ auto main(int argc, char **argv) -> int {
}
::testing::InitGoogleTest(&argc, argv);
auto ret = RUN_ALL_TESTS();
PROJECT_TEST_RESULT = RUN_ALL_TESTS();
repertory::project_cleanup();
return ret;
return PROJECT_TEST_RESULT;
}

View File

@ -67,10 +67,7 @@ protected:
cfg->set_enable_chunk_downloader_timeout(false);
}
void TearDown() override {
// EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
event_system::instance().stop();
}
void TearDown() override { event_system::instance().stop(); }
};
std::atomic<std::size_t> file_manager_test::inst{0U};
@ -1535,4 +1532,74 @@ TEST_F(file_manager_test, remove_file_fails_if_provider_remove_file_fails) {
EXPECT_EQ(api_error::item_not_found, fm.remove_file("/test_remove.txt"));
}
TEST_F(file_manager_test,
resize_greater_than_chunk_size_sets_new_chunks_to_read) {
cfg->set_enable_chunk_downloader_timeout(true);
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
polling::instance().start(cfg.get());
file_manager fm(*cfg, mp);
fm.start();
event_capture capture({
"item_timeout",
"filesystem_item_opened",
"filesystem_item_handle_opened",
"filesystem_item_handle_closed",
"filesystem_item_closed",
});
std::uint64_t handle{};
{
const auto source_path = utils::path::combine(
cfg->get_cache_directory(), {utils::create_uuid_string()});
std::shared_ptr<i_open_file> f;
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "key", 2, now + 3u,
3u, 4u, 0u, source_path, 10, now + 4u);
EXPECT_CALL(mp, create_file("/test_create.txt", meta))
.WillOnce(Return(api_error::success));
EXPECT_CALL(mp, get_filesystem_item)
.WillOnce([&meta](const std::string &api_path, bool directory,
filesystem_item &fsi) -> api_error {
EXPECT_STREQ("/test_create.txt", api_path.c_str());
EXPECT_FALSE(directory);
fsi.api_path = api_path;
fsi.api_parent = utils::path::get_parent_api_path(api_path);
fsi.directory = directory;
fsi.size = utils::string::to_uint64(meta[META_SIZE]);
fsi.source_path = meta[META_SOURCE];
return api_error::success;
});
#if defined(_WIN32)
EXPECT_EQ(api_error::success,
fm.create("/test_create.txt", meta, {}, handle, f));
#else
EXPECT_EQ(api_error::success,
fm.create("/test_create.txt", meta, O_RDWR, handle, f));
#endif
f->resize(utils::encryption::encrypting_reader::get_data_chunk_size() *
4UL);
auto read_state = f->get_read_state();
EXPECT_TRUE(read_state.all());
}
fm.close(handle);
capture.wait_for_empty();
fm.stop();
polling::instance().stop();
}
} // namespace repertory

View File

@ -631,7 +631,6 @@ static void run_tests(const app_config &cfg, i_provider &provider) {
TEST(providers, encrypt_provider) {
const auto config_path =
utils::path::combine(test::get_test_output_dir(), {"encrypt_provider"});
ASSERT_TRUE(utils::file::directory(config_path).remove_recursively());
console_consumer consumer{};
event_system::instance().start();
@ -674,7 +673,6 @@ TEST(providers, encrypt_provider) {
TEST(providers, s3_provider) {
const auto config_path =
utils::path::combine(test::get_test_output_dir(), {"s3_provider"});
ASSERT_TRUE(utils::file::directory(config_path).remove_recursively());
console_consumer consumer{};
event_system::instance().start();
@ -713,7 +711,6 @@ TEST(providers, s3_provider) {
TEST(providers, sia_provider) {
const auto config_path =
utils::path::combine(test::get_test_output_dir(), {"sia_provider"});
ASSERT_TRUE(utils::file::directory(config_path).remove_recursively());
console_consumer consumer{};
event_system::instance().start();

View File

@ -206,10 +206,10 @@ static void fgetattr_test(repertory::remote_fuse::remote_client &client) {
EXPECT_FALSE(directory);
#if defined(_WIN32)
struct _stat64 st1 {};
struct _stat64 st1{};
_stat64(&test_file[0], &st1);
#else
struct stat st1 {};
struct stat st1{};
stat(&test_file[0], &st1);
#endif
@ -318,10 +318,10 @@ static void getattr_test(repertory::remote_fuse::remote_client &client) {
EXPECT_EQ(0, client.fuse_getattr(api_path.c_str(), st, directory));
EXPECT_FALSE(directory);
#if defined(_WIN32)
struct _stat64 st1 {};
struct _stat64 st1{};
_stat64(&test_file[0], &st1);
#else
struct stat st1 {};
struct stat st1{};
stat(&test_file[0], &st1);
#endif
EXPECT_EQ(11u, st.st_gid);
@ -990,6 +990,5 @@ TEST(remote_fuse, all_tests) {
}
event_system::instance().stop();
EXPECT_TRUE(utils::file::directory(fuse_remote_dir).remove_recursively());
}
} // namespace fuse_test

View File

@ -538,6 +538,5 @@ TEST(remote_winfsp, all_tests) {
}
event_system::instance().stop();
EXPECT_TRUE(utils::file::directory(win_remote_dir).remove_recursively());
}
} // namespace winfsp_test

View File

@ -0,0 +1,216 @@
/*
Copyright <2018-2024> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <fileapi.h>
#if defined(_WIN32)
//
// Implemented test cases based on WinFsp tests:
// https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests
//
#include "fixtures/winfsp_fixture.hpp"
namespace repertory {
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
TYPED_TEST(winfsp_test, cr8_attr_can_create_new_file_with_normal_attribute) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_1"}),
};
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
::CloseHandle(handle);
auto attr = ::GetFileAttributesA(file_path.c_str());
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE, attr);
EXPECT_TRUE(::DeleteFileA(file_path.c_str()));
}
TYPED_TEST(winfsp_test, cr8_attr_can_create_new_file_with_read_only_attribute) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_1"}),
};
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
FILE_ATTRIBUTE_READONLY, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
::CloseHandle(handle);
auto attr = ::GetFileAttributesA(file_path.c_str());
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY, attr);
EXPECT_TRUE(::SetFileAttributesA(file_path.c_str(), FILE_ATTRIBUTE_NORMAL));
EXPECT_TRUE(::DeleteFileA(file_path.c_str()));
}
// TYPED_TEST(winfsp_test, cr8_attr_can_create_new_file_with_system_attribute) {
// auto file_path{
// utils::path::combine(this->mount_location, {"test_file_1"}),
// };
//
// auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ |
// GENERIC_WRITE,
// FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
// CREATE_NEW, FILE_ATTRIBUTE_SYSTEM, 0);
// ASSERT_NE(INVALID_HANDLE_VALUE, handle);
// ::CloseHandle(handle);
//
// auto attr = ::GetFileAttributesA(file_path.c_str());
// EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM, attr);
//
// EXPECT_TRUE(::SetFileAttributesA(file_path.c_str(),
// FILE_ATTRIBUTE_NORMAL));
//
// EXPECT_TRUE(::DeleteFileA(file_path.c_str()));
// }
TYPED_TEST(winfsp_test, cr8_attr_can_create_new_file_with_hidden_attribute) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_1"}),
};
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
FILE_ATTRIBUTE_HIDDEN, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
::CloseHandle(handle);
auto attr = ::GetFileAttributesA(file_path.c_str());
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN, attr);
EXPECT_TRUE(::SetFileAttributesA(file_path.c_str(), FILE_ATTRIBUTE_NORMAL));
EXPECT_TRUE(::DeleteFileA(file_path.c_str()));
}
TYPED_TEST(winfsp_test, cr8_attr_can_create_always_file_with_normal_attribute) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_1"}),
};
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
::CloseHandle(handle);
auto attr = ::GetFileAttributesA(file_path.c_str());
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE, attr);
}
TYPED_TEST(winfsp_test, cr8_attr_can_create_file_with_read_only_attribute) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_1"}),
};
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
CREATE_ALWAYS, FILE_ATTRIBUTE_READONLY, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
::CloseHandle(handle);
auto attr = ::GetFileAttributesA(file_path.c_str());
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_READONLY, attr);
EXPECT_TRUE(::SetFileAttributesA(file_path.c_str(), FILE_ATTRIBUTE_NORMAL));
}
// TYPED_TEST(winfsp_test,
// cr8_attr_can_create_always_file_with_system_attribute) {
// auto file_path{
// utils::path::combine(this->mount_location, {"test_file_1"}),
// };
//
// auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ |
// GENERIC_WRITE,
// FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
// CREATE_ALWAYS, FILE_ATTRIBUTE_SYSTEM, 0);
// ASSERT_NE(INVALID_HANDLE_VALUE, handle);
// ::CloseHandle(handle);
//
// auto attr = ::GetFileAttributesA(file_path.c_str());
// EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_SYSTEM, attr);
//
// EXPECT_TRUE(::SetFileAttributesA(file_path.c_str(),
// FILE_ATTRIBUTE_NORMAL));
// }
TYPED_TEST(winfsp_test, cr8_attr_can_create_always_file_with_hidden_attribute) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_1"}),
};
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
::CloseHandle(handle);
auto attr = ::GetFileAttributesA(file_path.c_str());
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN, attr);
EXPECT_TRUE(::SetFileAttributesA(file_path.c_str(), FILE_ATTRIBUTE_NORMAL));
EXPECT_TRUE(::DeleteFileA(file_path.c_str()));
}
TYPED_TEST(winfsp_test, cr8_attr_can_handle_read_only_directory) {
auto dir_path{
utils::path::combine(this->mount_location, {"test_dir_1"}),
};
auto file_path{
utils::path::combine(dir_path, {"test_file_1"}),
};
EXPECT_TRUE(::CreateDirectoryA(dir_path.c_str(), nullptr));
EXPECT_TRUE(::SetFileAttributesA(
dir_path.c_str(), FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_READONLY));
auto attr = ::GetFileAttributesA(dir_path.c_str());
EXPECT_EQ((FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_READONLY), attr);
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
::CloseHandle(handle);
EXPECT_TRUE(::DeleteFileA(file_path.c_str()));
EXPECT_FALSE(::RemoveDirectoryA(dir_path.c_str()));
EXPECT_EQ(ERROR_ACCESS_DENIED, ::GetLastError());
EXPECT_TRUE(::SetFileAttributesA(dir_path.c_str(), FILE_ATTRIBUTE_DIRECTORY));
attr = ::GetFileAttributesA(dir_path.c_str());
EXPECT_EQ(FILE_ATTRIBUTE_DIRECTORY, attr);
EXPECT_TRUE(::RemoveDirectoryA(dir_path.c_str()));
}
} // namespace repertory
#endif // defined(_WIN32)

View File

@ -0,0 +1,79 @@
/*
Copyright <2018-2024> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#if defined(_WIN32)
//
// Implemented test cases based on WinFsp tests:
// https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests
//
#include "fixtures/winfsp_fixture.hpp"
namespace repertory {
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
TYPED_TEST(winfsp_test, cr8_nl_can_create_file_of_max_component_length) {
if (this->current_provider != provider_type::s3) {
DWORD max_length{};
EXPECT_TRUE(::GetVolumeInformationA(this->mount_location.c_str(), nullptr,
0, nullptr, &max_length, nullptr,
nullptr, 0));
EXPECT_EQ(255U, max_length);
auto file_path = utils::path::combine(this->mount_location,
{
std::string(max_length, 'a'),
});
auto handle =
::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
EXPECT_TRUE(::CloseHandle(handle));
}
}
TYPED_TEST(winfsp_test,
cr8_nl_can_not_create_file_greater_than_max_component_length) {
if (this->current_provider != provider_type::s3) {
DWORD max_length{};
EXPECT_TRUE(::GetVolumeInformationA(this->mount_location.c_str(), nullptr,
0, nullptr, &max_length, nullptr,
nullptr, 0));
EXPECT_EQ(255U, max_length);
auto file_path = utils::path::combine(this->mount_location,
{
std::string(max_length + 1U, 'a'),
});
auto handle =
::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0);
ASSERT_EQ(INVALID_HANDLE_VALUE, handle);
EXPECT_EQ(ERROR_INVALID_NAME, ::GetLastError());
}
}
} // namespace repertory
#endif // defined(_WIN32)

View File

@ -0,0 +1,190 @@
/*
Copyright <2018-2024> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#if defined(_WIN32)
//
// Implemented test cases based on WinFsp tests:
// https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests
//
#include "fixtures/winfsp_fixture.hpp"
namespace repertory {
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
TYPED_TEST(winfsp_test, cr8_file_can_create_file) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_0"}),
};
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
::CloseHandle(handle);
}
TYPED_TEST(winfsp_test, cr8_file_create_new_fails_when_file_exists) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_0"}),
};
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL, 0);
ASSERT_EQ(INVALID_HANDLE_VALUE, handle);
EXPECT_EQ(ERROR_FILE_EXISTS, ::GetLastError());
}
TYPED_TEST(winfsp_test, cr8_file_can_open_existing_file) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_0"}),
};
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
::CloseHandle(handle);
}
TYPED_TEST(winfsp_test, cr8_file_create_always_succeeds_when_file_exists) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_0"}),
};
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
// EXPECT file_size is 0
::CloseHandle(handle);
}
TYPED_TEST(winfsp_test, cr8_file_can_delete_file_after_close) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_0"}),
};
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
::CloseHandle(handle);
handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING,
FILE_FLAG_DELETE_ON_CLOSE, 0);
ASSERT_EQ(INVALID_HANDLE_VALUE, handle);
EXPECT_EQ(ERROR_FILE_NOT_FOUND, ::GetLastError());
// EXPECT file not found
}
TYPED_TEST(winfsp_test,
cr8_file_cannot_create_files_with_invalid_characters_in_path) {
for (auto &&invalid_char : std::array<std::string, 7U>{
{"*", ":", "<", ">", "?", "|", "\""},
}) {
auto handle = ::CreateFileA(
(this->mount_location + "\\" + invalid_char + "\\test_file_0").c_str(),
GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
ASSERT_EQ(INVALID_HANDLE_VALUE, handle);
if (handle != INVALID_HANDLE_VALUE) {
std::cout << "char: " << invalid_char << std::endl;
}
EXPECT_EQ(ERROR_INVALID_NAME, ::GetLastError());
}
}
TYPED_TEST(winfsp_test,
cr8_file_cannot_create_stream_files_with_extra_component_in_path) {
auto file_path{
utils::path::combine(this->mount_location,
{
"test_file_0:test",
"moose",
}),
};
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL, 0);
ASSERT_EQ(INVALID_HANDLE_VALUE, handle);
EXPECT_EQ(ERROR_INVALID_NAME, ::GetLastError());
}
TYPED_TEST(winfsp_test, cr8_file_can_create_directory) {
auto dir_path{
utils::path::combine(this->mount_location,
{
"test_dir_0",
}),
};
EXPECT_TRUE(::CreateDirectoryA(dir_path.c_str(), nullptr));
EXPECT_FALSE(::CreateDirectoryA(dir_path.c_str(), nullptr));
}
TYPED_TEST(winfsp_test, cr8_file_directory_delete_fails_if_not_empty) {
auto dir_path{
utils::path::combine(this->mount_location,
{
"test_dir_0",
}),
};
auto file_path{
utils::path::combine(dir_path,
{
"test_file_0",
}),
};
auto handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
::CloseHandle(handle);
handle =
::CreateFileA(dir_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_DELETE_ON_CLOSE, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
::CloseHandle(handle);
handle = ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING,
FILE_FLAG_DELETE_ON_CLOSE, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
::CloseHandle(handle);
handle =
::CreateFileA(dir_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_DELETE_ON_CLOSE, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
::CloseHandle(handle);
handle =
::CreateFileA(dir_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_DELETE_ON_CLOSE, 0);
ASSERT_EQ(INVALID_HANDLE_VALUE, handle);
EXPECT_EQ(ERROR_FILE_NOT_FOUND, ::GetLastError());
}
} // namespace repertory
#endif // defined(_WIN32)

View File

@ -0,0 +1,86 @@
/*
Copyright <2018-2024> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#if defined(_WIN32)
//
// Implemented test cases based on WinFsp tests:
// https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests
//
#include "fixtures/winfsp_fixture.hpp"
namespace repertory {
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
TYPED_TEST(winfsp_test, info_can_get_tag_info) {
auto file_path{
utils::path::combine(this->mount_location, {"test_file_2"}),
};
auto handle =
::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
FILE_ATTRIBUTE_TAG_INFO tag_info{};
EXPECT_TRUE(::GetFileInformationByHandleEx(handle, FileAttributeTagInfo,
&tag_info, sizeof tag_info));
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE, tag_info.FileAttributes);
EXPECT_EQ(0, tag_info.ReparseTag);
::CloseHandle(handle);
}
TYPED_TEST(winfsp_test, info_can_get_basic_info) {
FILETIME file_time{};
::GetSystemTimeAsFileTime(&file_time);
auto time_low = ((PLARGE_INTEGER)&file_time)->QuadPart;
auto time_high = time_low + 10000 * 10000 /* 10 seconds */;
auto file_path{
utils::path::combine(this->mount_location, {"test_file_2"}),
};
auto handle =
::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0);
ASSERT_NE(INVALID_HANDLE_VALUE, handle);
FILE_BASIC_INFO basic_info{};
EXPECT_TRUE(::GetFileInformationByHandleEx(handle, FileBasicInfo, &basic_info,
sizeof basic_info));
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE, basic_info.FileAttributes);
EXPECT_LE(time_low, basic_info.CreationTime.QuadPart);
EXPECT_GT(time_high, basic_info.CreationTime.QuadPart);
EXPECT_LE(time_low, basic_info.LastAccessTime.QuadPart);
EXPECT_GT(time_high, basic_info.LastAccessTime.QuadPart);
EXPECT_LE(time_low, basic_info.LastWriteTime.QuadPart);
EXPECT_GT(time_high, basic_info.LastWriteTime.QuadPart);
EXPECT_LE(time_low, basic_info.ChangeTime.QuadPart);
EXPECT_GT(time_high, basic_info.ChangeTime.QuadPart);
::CloseHandle(handle);
}
} // namespace repertory
#endif // defined(_WIN32)

View File

@ -21,231 +21,28 @@
*/
#if defined(_WIN32)
// TODO revisit create_related
// TODO revisit create_allocation
// TODO revisit create_sd
// TODO revisit create_notraverse
// TODO revisit create_backup
// TODO revisit create_restore
// TODO revisit create_share
// TODO revisit getfileattr_test
//
// Implemented test cases based on WinFsp tests:
// https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests
//
#include "fixtures/winfsp_fixture.hpp"
namespace repertory {
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
// TYPED_TEST(winfsp_test, root_is_created) {
// WIN32_FILE_ATTRIBUTE_DATA ad{};
// ASSERT_TRUE(::GetFileAttributesEx(this->mount_location.c_str(),
// GetFileExInfoStandard, &ad));
// EXPECT_EQ(FILE_ATTRIBUTE_DIRECTORY, ad.dwFileAttributes);
// EXPECT_EQ(0, ad.nFileSizeHigh);
// EXPECT_EQ(0, ad.nFileSizeLow);
// }
//
// TYPED_TEST(winfsp_test, can_create_and_delete_directory) {
// std::string dir_name{"test_create_and_delete_dir"};
// auto dir_path = this->create_directory_and_test(dir_name);
// this->delete_directory_and_test(dir_path);
// }
//
// TYPED_TEST(winfsp_test, can_create_and_delete_file) {
// std::string file_name{"test_create_and_delete_file"};
// auto file_path = this->create_file_and_test(file_name);
// this->delete_file_and_test(file_path);
// }
//
// TYPED_TEST(winfsp_test, can_write_to_and_read_from_file) {
// std::string file_name{"test_write_file"};
// auto file_path = this->create_file_and_test(file_name);
//
// auto handle =
// ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
// FILE_SHARE_READ | FILE_SHARE_DELETE | FILE_SHARE_WRITE,
// nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
// EXPECT_NE(INVALID_HANDLE_VALUE, handle);
// if (handle == INVALID_HANDLE_VALUE) {
// return;
// }
//
// std::string write_buffer{"0123456789"};
// {
// DWORD bytes_written{0};
// EXPECT_TRUE(::WriteFile(handle, write_buffer.c_str(),
// static_cast<DWORD>(write_buffer.size()),
// &bytes_written, nullptr));
// EXPECT_EQ(static_cast<DWORD>(write_buffer.size()), bytes_written);
//
// auto opt_size = utils::file::file(file_path).size();
// EXPECT_TRUE(opt_size.has_value());
// EXPECT_EQ(write_buffer.size(), opt_size.value());
// }
//
// {
// data_buffer read_buffer;
// read_buffer.resize(write_buffer.size());
//
// DWORD bytes_read{0};
// EXPECT_EQ(0, ::SetFilePointer(handle, 0, nullptr, FILE_BEGIN));
// EXPECT_TRUE(::ReadFile(handle, read_buffer.data(),
// static_cast<DWORD>(read_buffer.size()),
// &bytes_read, nullptr));
// EXPECT_EQ(static_cast<DWORD>(write_buffer.size()), bytes_read);
// EXPECT_EQ(0,
// std::memcmp(write_buffer.data(), read_buffer.data(),
// std::min(read_buffer.size(),
// write_buffer.size())));
// }
//
// EXPECT_TRUE(::CloseHandle(handle));
//
// this->delete_file_and_test(file_path);
// }
//
// TYPED_TEST(winfsp_test, can_rename_file) {
// std::string file_name{"rename_file"};
// auto file_path = this->create_file_and_test(file_name);
// auto api_path = utils::path::create_api_path(file_name);
//
// api_meta_map meta1{};
// EXPECT_EQ(api_error::success, this->provider->get_item_meta(api_path,
// meta1));
//
// auto file_path2 =
// utils::path::combine(this->mount_location, {file_name + "_2"});
// auto api_path2 = api_path + "_2";
// EXPECT_TRUE(::MoveFile(file_path.c_str(), file_path2.c_str()));
//
// EXPECT_TRUE(utils::file::file(file_path2).exists());
// EXPECT_FALSE(utils::file::file(file_path).exists());
//
// api_meta_map meta2{};
// EXPECT_EQ(api_error::success,
// this->provider->get_item_meta(api_path2, meta2));
// EXPECT_STREQ(meta1[META_SOURCE].c_str(), meta2[META_SOURCE].c_str());
//
// filesystem_item fsi{};
// EXPECT_EQ(api_error::success,
// this->provider->get_filesystem_item(api_path2, false, fsi));
// EXPECT_STREQ(meta1[META_SOURCE].c_str(), fsi.source_path.c_str());
//
// filesystem_item fsi2{};
// EXPECT_EQ(api_error::success,
// this->provider->get_filesystem_item_from_source_path(
// fsi.source_path, fsi2));
// EXPECT_STREQ(api_path2.c_str(), fsi2.api_path.c_str());
//
// EXPECT_EQ(api_error::item_not_found,
// this->provider->get_item_meta(api_path, meta2));
//
// this->delete_file_and_test(file_path2);
// }
//
// TYPED_TEST(winfsp_test, can_rename_directory) {
// std::string dir_name{"rename_dir"};
// auto dir_path = this->create_directory_and_test(dir_name);
//
// auto dir_path2{dir_path + "_2"};
//
// EXPECT_TRUE(::MoveFileA(dir_path.c_str(), dir_path2.c_str()));
// EXPECT_FALSE(::PathIsDirectoryA(dir_path.c_str()));
// EXPECT_TRUE(::PathIsDirectoryA(dir_path2.c_str()));
//
// this->delete_directory_and_test(dir_path2);
// }
//
// TYPED_TEST(winfsp_test, can_overwrite_file) {
// std::string file_name{"overwrite_file"};
// auto file_path = this->create_file_and_test(file_name);
//
// auto file_path2{file_path + "_2"};
// EXPECT_TRUE(::CopyFile(file_path.c_str(), file_path2.c_str(), TRUE));
// EXPECT_TRUE(::CopyFile(file_path.c_str(), file_path2.c_str(), FALSE));
// EXPECT_FALSE(::CopyFile(file_path.c_str(), file_path2.c_str(), TRUE));
//
// this->delete_file_and_test(file_path);
// this->delete_file_and_test(file_path2);
// }
//
// TYPED_TEST(winfsp_test, can_get_and_set_basic_info_test) {
// std::string file_name{"overwrite_file"};
// auto file_path = this->create_file_and_test(file_name);
//
// auto handle =
// ::CreateFileA(file_path.c_str(), GENERIC_READ | GENERIC_WRITE,
// FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
// nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
// EXPECT_NE(INVALID_HANDLE_VALUE, handle);
// if (handle == INVALID_HANDLE_VALUE) {
// return;
// }
//
// SYSTEMTIME st{};
// ::GetSystemTime(&st);
// st.wMinute = 0;
//
// FILETIME test_ch_time{};
// st.wMinute++;
// ::SystemTimeToFileTime(&st, &test_ch_time);
//
// FILETIME test_cr_time{};
// st.wMinute++;
// ::SystemTimeToFileTime(&st, &test_cr_time);
//
// FILETIME test_la_time{};
// st.wMinute++;
// ::SystemTimeToFileTime(&st, &test_la_time);
//
// FILETIME test_lw_time{};
// st.wMinute++;
// ::SystemTimeToFileTime(&st, &test_lw_time);
//
// FILE_BASIC_INFO fbi{};
// fbi.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
// fbi.ChangeTime.HighPart = static_cast<LONG>(test_ch_time.dwHighDateTime);
// fbi.ChangeTime.LowPart = test_ch_time.dwLowDateTime;
// fbi.CreationTime = *reinterpret_cast<LARGE_INTEGER *>(&test_cr_time);
// fbi.LastAccessTime = *reinterpret_cast<LARGE_INTEGER *>(&test_la_time);
// fbi.LastWriteTime = *reinterpret_cast<LARGE_INTEGER *>(&test_lw_time);
//
// EXPECT_TRUE(::SetFileInformationByHandle(handle, FileBasicInfo, &fbi,
// sizeof(FILE_BASIC_INFO)));
//
// FILE_BASIC_INFO fbi2{};
// EXPECT_TRUE(::GetFileInformationByHandleEx(handle, FileBasicInfo, &fbi2,
// sizeof(FILE_BASIC_INFO)));
//
// EXPECT_EQ(0, memcmp(&fbi, &fbi2, sizeof(FILE_BASIC_INFO)));
//
// std::cout << fbi.FileAttributes << " " << fbi.ChangeTime.QuadPart << " "
// << fbi.CreationTime.QuadPart << " " <<
// fbi.LastAccessTime.QuadPart
// << " " << fbi.LastWriteTime.QuadPart << std::endl;
// std::cout << fbi2.FileAttributes << " " << fbi2.ChangeTime.QuadPart << " "
// << fbi2.CreationTime.QuadPart << " " <<
// fbi2.LastAccessTime.QuadPart
// << " " << fbi2.LastWriteTime.QuadPart << std::endl;
//
// EXPECT_TRUE(::CloseHandle(handle));
//
// this->delete_file_and_test(file_path);
// }
TYPED_TEST(winfsp_test, can_set_current_directory_to_mount_location) {
EXPECT_TRUE(::SetCurrentDirectoryA(this->mount_location.c_str()));
TYPED_TEST(winfsp_test, run_winfsp_tests) {
if (this->provider->is_read_only()) {
return;
}
auto cur = std::filesystem::current_path();
std::filesystem::current_path(this->mount_location);
std::vector<std::string> test_options{
"--external",
"--resilient",
};
auto test_exec = utils::path::combine(test::get_test_input_dir(),
{
"bin",
"winfsp-tests-x64.exe",
}) +
' ' + utils::string::join(test_options, ' ');
EXPECT_EQ(0, system(test_exec.c_str()));
std::filesystem::current_path(cur);
EXPECT_TRUE(::SetCurrentDirectoryA(this->current_directory.string().c_str()));
}
} // namespace repertory

View File

@ -1,708 +0,0 @@
The WinFsp project is Copyright (C) Bill Zissimopoulos. It is licensed
under the terms of the GPLv3.
As a special exception to GPLv3, Bill Zissimopoulos grants additional
permissions to Free/Libre and Open Source Software ("FLOSS") without requiring
that such software is covered by the GPLv3.
1. Permission to link with a platform specific version of the WinFsp DLL
(one of: winfsp-a64.dll, winfsp-x64.dll, winfsp-x86.dll, winfsp-msil.dll).
2. Permission to distribute unmodified binary releases of the WinFsp
installer (as released by the WinFsp project).
These permissions (and no other) are granted provided that the software:
1. Is distributed under a license that satisfies the Free Software
Definition Version 1.141 (https://www.gnu.org/philosophy/free-sw.en.html)
or the Open Source Definition Version 1.9 (https://opensource.org/osd).
2. Includes the copyright notice "WinFsp - Windows File System Proxy,
Copyright (C) Bill Zissimopoulos" and a link to the WinFsp repository in
its user-interface and any user-facing documentation.
3. Is not linked or distributed with proprietary (non-FLOSS) software.
[You cannot mix FLOSS and proprietary software while using WinFsp under
this special exception.]
Commercial licensing options are also available: Please contact
Bill Zissimopoulos <billziss at navimatics.com>.
The full text of the GPLv3 license follows below.
-----------------------------------------------------------------------
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@ -1,64 +0,0 @@
## WINFSP-TESTS
Winfsp-tests is a file system test suite that is used to test WinFsp and the file systems that ship with it. It is not intended for use by end users. If you have downloaded winfsp-tests, you likely wanted to download the WinFsp installer instead (i.e. the file that is named `winfsp-VERSION.msi`).
**WINFSP-TESTS IS UNSUPPORTED SOFTWARE. IT MAY CRASH OR LOCK UP YOUR COMPUTER, CREATE ZOMBIE/UNKILLABLE PROCESSES OR CORRUPT YOUR DATA. DO NOT USE UNLESS YOU KNOW WHAT YOU ARE DOING. DO NOT POST BUGS/ISSUES/QUESTIONS AGAINST WINFSP-TESTS UNLESS YOU ALSO POST THE FIX. YOU HAVE BEEN WARNED!**
## USAGE
Winfsp-tests has two different test modes: a default internal mode in which it runs its tests against an embedded copy of MEMFS and an external mode in which it runs its tests against the file system in the current directory.
Unless you are doing WinFsp development there should never be a need to run winfsp-tests in the default internal mode. However the external mode can be useful to test third party file systems that do not ship with WinFsp.
To run winfsp-tests in external mode, you must use the `--external` command line option. I also recommend using the `--resilient` command line option, to have winfsp-tests improve test flakiness by retrying failed operations.
```
> winfsp-tests-x64 --external --resilient
create_test............................ OK 0.00s
create_fileattr_test................... OK 0.00s
...
--- COMPLETE ---
```
Specific tests to be run may be specified. For example, to run all tests that start with `rename`:
```
> winfsp-tests-x64 --external --resilient rename*
rename_test............................ OK 0.01s
rename_open_test....................... OK 0.00s
...
--- COMPLETE ---
```
To exclude a test or tests use the `-` prefix. For example, to run all `create` tests, except the `create_fileattr_test`:
```
> winfsp-tests-x64 --external --resilient create* -create_fileattr_test
create_test............................ OK 0.05s
create_readonlydir_test................ OK 0.01s
...
--- COMPLETE ---
```
By default only regular tests are run. To include optional or long running tests use the `+` prefix. For example, to run all tests use `+*`; to run oplock tests use `+oplock*`:
```
> winfsp-tests-x64 --external --resilient +oplock*
oplock_level1_test..................... OK 1.26s
oplock_level2_test..................... OK 2.46s
...
--- COMPLETE ---
```
To list tests without running them use the `--list` option:
```
> winfsp-tests-x64 --external --resilient --list +oplock*
oplock_level1_test
oplock_level2_test
...
```
If a test fails the test suite stops immediately with an assertion failure. There is no additional explanation of the problem and you have to study the winfsp-tests source code to understand the failure and determine a fix for your file system. Additionally there may be garbage files remaining in the file system as winfsp-tests does not cleanup after itself.
**NOTE**: Some tests require Administrator privileges in order to run.

View File

@ -29,22 +29,22 @@
namespace repertory::utils::collection {
template <typename col_t>
[[nodiscard]] inline auto
excludes(const col_t &collection,
const typename col_t::value_type &val) -> bool;
[[nodiscard]] inline auto excludes(const col_t &collection,
const typename col_t::value_type &val)
-> bool;
template <typename col_t>
[[nodiscard]] inline auto
includes(const col_t &collection,
const typename col_t::value_type &val) -> bool;
[[nodiscard]] inline auto includes(const col_t &collection,
const typename col_t::value_type &val)
-> bool;
template <typename val_t>
[[nodiscard]] inline auto from_hex_string(std::string_view str,
val_t &val) -> bool;
[[nodiscard]] inline auto from_hex_string(std::string_view str, val_t &val)
-> bool;
template <typename val_t>
[[nodiscard]] inline auto from_hex_string(std::wstring_view str,
val_t &val) -> bool;
[[nodiscard]] inline auto from_hex_string(std::wstring_view str, val_t &val)
-> bool;
template <typename col_t>
inline auto remove_element(col_t &collection,
const typename col_t::value_type &value) -> col_t &;
@ -53,8 +53,8 @@ template <typename col_t>
[[nodiscard]] inline auto to_hex_string(const col_t &collection) -> std::string;
template <typename col_t>
[[nodiscard]] inline auto
to_hex_wstring(const col_t &collection) -> std::wstring;
[[nodiscard]] inline auto to_hex_wstring(const col_t &collection)
-> std::wstring;
template <typename col_t>
inline auto excludes(const col_t &collection,
@ -71,8 +71,8 @@ inline auto includes(const col_t &collection,
}
template <typename val_t>
[[nodiscard]] inline auto from_hex_string_t(std::string_view str,
val_t &val) -> bool {
[[nodiscard]] inline auto from_hex_string_t(std::string_view str, val_t &val)
-> bool {
REPERTORY_USES_FUNCTION_NAME();
static constexpr const auto base16{16};

View File

@ -44,13 +44,13 @@ calculate_read_size(std::uint64_t total_size, std::size_t read_size,
: read_size);
}
[[nodiscard]] auto
compare_version_strings(std::string version1,
std::string version2) -> std::int32_t;
[[nodiscard]] auto compare_version_strings(std::string version1,
std::string version2)
-> std::int32_t;
[[nodiscard]] auto
compare_version_strings(std::wstring_view version1,
std::wstring_view version2) -> std::int32_t;
[[nodiscard]] auto compare_version_strings(std::wstring_view version1,
std::wstring_view version2)
-> std::int32_t;
#if defined(PROJECT_ENABLE_STDUUID)
[[nodiscard]] auto create_uuid_string() -> std::string;
@ -59,12 +59,13 @@ compare_version_strings(std::wstring_view version1,
#endif // defined(PROJECT_ENABLE_STDUUID)
template <typename result_t, typename data_t>
[[nodiscard]] inline constexpr auto
divide_with_ceiling(result_t numerator, data_t denominator) -> result_t;
[[nodiscard]] inline constexpr auto divide_with_ceiling(result_t numerator,
data_t denominator)
-> result_t;
template <typename data_t>
[[nodiscard]] inline auto generate_random_between(data_t begin,
data_t end) -> data_t;
[[nodiscard]] inline auto generate_random_between(data_t begin, data_t end)
-> data_t;
[[nodiscard]] auto generate_random_string(std::size_t length) -> std::string;
@ -78,22 +79,22 @@ template <typename data_t>
[[nodiscard]] inline auto generate_secure_random(std::size_t size) -> data_t;
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
[[nodiscard]] auto
get_environment_variable(std::string_view variable) -> std::string;
[[nodiscard]] auto get_environment_variable(std::string_view variable)
-> std::string;
[[nodiscard]] auto
get_environment_variable(std::wstring_view variable) -> std::wstring;
[[nodiscard]] auto get_environment_variable(std::wstring_view variable)
-> std::wstring;
#if defined(PROJECT_ENABLE_BOOST)
[[nodiscard]] auto
get_next_available_port(std::uint16_t first_port,
std::uint16_t &available_port) -> bool;
[[nodiscard]] auto 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;
[[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,

View File

@ -53,50 +53,50 @@ inline constexpr const std::wstring_view not_directory_seperator_w{backslash_w};
#endif // defined(_WIN32)
template <typename char_t>
[[nodiscard]] inline constexpr auto
get_backslash() -> std::basic_string_view<char_t>;
[[nodiscard]] inline constexpr auto get_backslash()
-> std::basic_string_view<char_t>;
template <>
[[nodiscard]] inline constexpr auto
get_backslash<char>() -> std::basic_string_view<char> {
[[nodiscard]] inline constexpr auto get_backslash<char>()
-> std::basic_string_view<char> {
return backslash;
}
template <>
[[nodiscard]] inline constexpr auto
get_backslash<wchar_t>() -> std::basic_string_view<wchar_t> {
[[nodiscard]] inline constexpr auto get_backslash<wchar_t>()
-> std::basic_string_view<wchar_t> {
return backslash_w;
}
template <typename char_t>
[[nodiscard]] inline constexpr auto
get_directory_seperator() -> std::basic_string_view<char_t>;
[[nodiscard]] inline constexpr auto get_directory_seperator()
-> std::basic_string_view<char_t>;
template <>
[[nodiscard]] inline constexpr auto
get_directory_seperator<char>() -> std::basic_string_view<char> {
[[nodiscard]] inline constexpr auto get_directory_seperator<char>()
-> std::basic_string_view<char> {
return directory_seperator;
}
template <>
[[nodiscard]] inline constexpr auto
get_directory_seperator<wchar_t>() -> std::basic_string_view<wchar_t> {
[[nodiscard]] inline constexpr auto get_directory_seperator<wchar_t>()
-> std::basic_string_view<wchar_t> {
return directory_seperator_w;
}
template <typename char_t>
[[nodiscard]] inline constexpr auto
get_not_directory_seperator() -> std::basic_string_view<char_t>;
[[nodiscard]] inline constexpr auto get_not_directory_seperator()
-> std::basic_string_view<char_t>;
template <>
[[nodiscard]] inline constexpr auto
get_not_directory_seperator<char>() -> std::basic_string_view<char> {
[[nodiscard]] inline constexpr auto get_not_directory_seperator<char>()
-> std::basic_string_view<char> {
return not_directory_seperator;
}
template <>
[[nodiscard]] inline constexpr auto
get_not_directory_seperator<wchar_t>() -> std::basic_string_view<wchar_t> {
[[nodiscard]] inline constexpr auto get_not_directory_seperator<wchar_t>()
-> std::basic_string_view<wchar_t> {
return not_directory_seperator_w;
}
@ -104,95 +104,95 @@ template <typename char_t>
[[nodiscard]] inline constexpr auto get_dot() -> std::basic_string_view<char_t>;
template <>
[[nodiscard]] inline constexpr auto
get_dot<char>() -> std::basic_string_view<char> {
[[nodiscard]] inline constexpr auto get_dot<char>()
-> std::basic_string_view<char> {
return dot;
}
template <>
[[nodiscard]] inline constexpr auto
get_dot<wchar_t>() -> std::basic_string_view<wchar_t> {
[[nodiscard]] inline constexpr auto get_dot<wchar_t>()
-> std::basic_string_view<wchar_t> {
return dot_w;
}
template <typename char_t>
[[nodiscard]] inline constexpr auto
get_dot_backslash() -> std::basic_string_view<char_t>;
[[nodiscard]] inline constexpr auto get_dot_backslash()
-> std::basic_string_view<char_t>;
template <>
[[nodiscard]] inline constexpr auto
get_dot_backslash<char>() -> std::basic_string_view<char> {
[[nodiscard]] inline constexpr auto get_dot_backslash<char>()
-> std::basic_string_view<char> {
return dot_backslash;
}
template <>
[[nodiscard]] inline constexpr auto
get_dot_backslash<wchar_t>() -> std::basic_string_view<wchar_t> {
[[nodiscard]] inline constexpr auto get_dot_backslash<wchar_t>()
-> std::basic_string_view<wchar_t> {
return dot_backslash_w;
}
template <typename char_t>
[[nodiscard]] inline constexpr auto
get_dot_slash() -> std::basic_string_view<char_t>;
[[nodiscard]] inline constexpr auto get_dot_slash()
-> std::basic_string_view<char_t>;
template <>
[[nodiscard]] inline constexpr auto
get_dot_slash<char>() -> std::basic_string_view<char> {
[[nodiscard]] inline constexpr auto get_dot_slash<char>()
-> std::basic_string_view<char> {
return dot_slash;
}
template <>
[[nodiscard]] inline constexpr auto
get_dot_slash<wchar_t>() -> std::basic_string_view<wchar_t> {
[[nodiscard]] inline constexpr auto get_dot_slash<wchar_t>()
-> std::basic_string_view<wchar_t> {
return dot_slash_w;
}
template <typename char_t>
[[nodiscard]] inline constexpr auto
get_long_notation() -> std::basic_string_view<char_t>;
[[nodiscard]] inline constexpr auto get_long_notation()
-> std::basic_string_view<char_t>;
template <>
[[nodiscard]] inline constexpr auto
get_long_notation<char>() -> std::basic_string_view<char> {
[[nodiscard]] inline constexpr auto get_long_notation<char>()
-> std::basic_string_view<char> {
return long_notation;
}
template <>
[[nodiscard]] inline constexpr auto
get_long_notation<wchar_t>() -> std::basic_string_view<wchar_t> {
[[nodiscard]] inline constexpr auto get_long_notation<wchar_t>()
-> std::basic_string_view<wchar_t> {
return long_notation_w;
}
template <typename char_t>
[[nodiscard]] inline constexpr auto
get_slash() -> std::basic_string_view<char_t>;
[[nodiscard]] inline constexpr auto get_slash()
-> std::basic_string_view<char_t>;
template <>
[[nodiscard]] inline constexpr auto
get_slash<char>() -> std::basic_string_view<char> {
[[nodiscard]] inline constexpr auto get_slash<char>()
-> std::basic_string_view<char> {
return slash;
}
template <>
[[nodiscard]] inline constexpr auto
get_slash<wchar_t>() -> std::basic_string_view<wchar_t> {
[[nodiscard]] inline constexpr auto get_slash<wchar_t>()
-> std::basic_string_view<wchar_t> {
return slash_w;
}
#if defined(_WIN32)
template <typename char_t>
[[nodiscard]] inline constexpr auto
get_unc_notation() -> std::basic_string_view<char_t>;
[[nodiscard]] inline constexpr auto get_unc_notation()
-> std::basic_string_view<char_t>;
template <>
[[nodiscard]] inline constexpr auto
get_unc_notation<char>() -> std::basic_string_view<char> {
[[nodiscard]] inline constexpr auto get_unc_notation<char>()
-> std::basic_string_view<char> {
return unc_notation;
}
template <>
[[nodiscard]] inline constexpr auto
get_unc_notation<wchar_t>() -> std::basic_string_view<wchar_t> {
[[nodiscard]] inline constexpr auto get_unc_notation<wchar_t>()
-> std::basic_string_view<wchar_t> {
return unc_notation_w;
}
#endif // defined(_WIN32)
@ -204,13 +204,13 @@ template <typename string_t>
[[nodiscard]] auto absolute(std::wstring_view path) -> std::wstring;
[[nodiscard]] inline auto
combine(std::string_view path,
const std::vector<std::string_view> &paths) -> std::string;
[[nodiscard]] inline auto combine(std::string_view path,
const std::vector<std::string_view> &paths)
-> std::string;
[[nodiscard]] inline auto
combine(std::wstring_view path,
const std::vector<std::wstring_view> &paths) -> std::wstring;
[[nodiscard]] inline auto combine(std::wstring_view path,
const std::vector<std::wstring_view> &paths)
-> std::wstring;
[[nodiscard]] auto contains_trash_directory(std::string_view path) -> bool;
@ -242,28 +242,28 @@ format_path(string_t &path,
std::basic_string_view<typename string_t::value_type> not_sep)
-> string_t &;
[[nodiscard]] inline auto
get_parent_api_path(std::string_view path) -> std::string;
[[nodiscard]] inline auto get_parent_api_path(std::string_view path)
-> std::string;
[[nodiscard]] inline auto
get_parent_api_path(std::wstring_view path) -> std::wstring;
[[nodiscard]] inline auto get_parent_api_path(std::wstring_view path)
-> std::wstring;
[[nodiscard]] auto get_parent_path(std::string_view path) -> std::string;
[[nodiscard]] auto get_parent_path(std::wstring_view path) -> std::wstring;
[[nodiscard]] inline auto
get_parts(std::string_view path) -> std::vector<std::string>;
[[nodiscard]] inline auto get_parts(std::string_view path)
-> std::vector<std::string>;
[[nodiscard]] inline auto
get_parts_w(std::wstring_view path) -> std::vector<std::wstring>;
[[nodiscard]] inline auto get_parts_w(std::wstring_view path)
-> std::vector<std::wstring>;
[[nodiscard]] auto get_relative_path(std::string_view path,
std::string_view root_path) -> std::string;
[[nodiscard]] auto
get_relative_path(std::wstring_view path,
std::wstring_view root_path) -> std::wstring;
[[nodiscard]] auto get_relative_path(std::wstring_view path,
std::wstring_view root_path)
-> std::wstring;
[[nodiscard]] auto make_file_uri(std::string_view path) -> std::string;
@ -301,15 +301,16 @@ inline auto combine(std::string_view path,
return combine_t<std::string>(path, paths);
}
inline auto
combine(std::wstring_view path,
const std::vector<std::wstring_view> &paths) -> std::wstring {
inline auto combine(std::wstring_view path,
const std::vector<std::wstring_view> &paths)
-> std::wstring {
return combine_t<std::wstring>(path, paths);
}
template <typename string_t>
[[nodiscard]] inline auto create_api_path_t(
std::basic_string_view<typename string_t::value_type> path) -> string_t {
[[nodiscard]] inline auto
create_api_path_t(std::basic_string_view<typename string_t::value_type> path)
-> string_t {
auto backslash_t = get_backslash<typename string_t::value_type>();
auto dot_backslash_t = get_dot_backslash<typename string_t::value_type>();
auto dot_slash_t = get_dot_slash<typename string_t::value_type>();
@ -357,8 +358,9 @@ inline auto create_api_path(std::wstring_view path) -> std::wstring {
}
template <typename string_t>
[[nodiscard]] inline auto finalize_t(
std::basic_string_view<typename string_t::value_type> path) -> string_t {
[[nodiscard]] inline auto
finalize_t(std::basic_string_view<typename string_t::value_type> path)
-> string_t {
string_t dir_sep_t{get_directory_seperator<typename string_t::value_type>()};
string_t fmt_path{path};
if (fmt_path.empty()) {
@ -463,7 +465,7 @@ template <>
[[nodiscard]] inline auto get_current_path<std::string>() -> std::string {
#if defined(_WIN32)
std::string path;
path.resize(repertory::max_path_length + 1);
path.resize(repertory::max_path_length + 1U);
::GetCurrentDirectoryA(static_cast<DWORD>(path.size()), path.data());
path = path.c_str();
return finalize(path);
@ -482,25 +484,25 @@ template <typename string_t>
std::basic_string_view<typename string_t::value_type> path) -> string_t {
auto slash_t = get_slash<typename string_t::value_type>();
string_t ret;
if (path == slash_t) {
return ret;
return string_t{path};
}
ret = path.substr(0, path.rfind(slash_t) + 1);
if (ret == slash_t) {
return ret;
auto sub_path = path.substr(0, path.rfind(slash_t) + 1);
if (sub_path == slash_t) {
return string_t{sub_path};
}
string_t ret{sub_path};
return utils::string::right_trim(ret, slash_t.at(0U));
}
inline auto get_parent_api_path(std::string_view path) -> std::string {
return get_parent_api_path_t<std::string>(path);
return create_api_path(get_parent_api_path_t<std::string>(path));
}
inline auto get_parent_api_path(std::wstring_view path) -> std::wstring {
return get_parent_api_path_t<std::wstring>(path);
return create_api_path(get_parent_api_path_t<std::wstring>(path));
}
template <typename string_t>

View File

@ -31,8 +31,8 @@ using passwd_callback_t = std::function<void(struct passwd *pass)>;
#if defined(__APPLE__)
template <typename thread_t>
[[nodiscard]] auto
convert_to_uint64(const thread_t *thread_ptr) -> std::uint64_t;
[[nodiscard]] auto convert_to_uint64(const thread_t *thread_ptr)
-> std::uint64_t;
#else // !defined(__APPLE__)
[[nodiscard]] auto convert_to_uint64(const pthread_t &thread) -> std::uint64_t;
#endif // defined(__APPLE__)
@ -45,14 +45,14 @@ convert_to_uint64(const thread_t *thread_ptr) -> std::uint64_t;
void set_last_error_code(int error_code);
[[nodiscard]] auto use_getpwuid(uid_t uid,
passwd_callback_t callback) -> utils::result;
[[nodiscard]] auto use_getpwuid(uid_t uid, passwd_callback_t callback)
-> utils::result;
// template implementations
#if defined(__APPLE__)
template <typename t>
[[nodiscard]] auto
convert_to_uint64(const thread_t *thread_ptr) -> std::uint64_t {
[[nodiscard]] auto convert_to_uint64(const thread_t *thread_ptr)
-> std::uint64_t {
return static_cast<std::uint64_t>(
reinterpret_cast<std::uintptr_t>(thread_ptr));
}

View File

@ -37,7 +37,7 @@ auto change_to_process_directory() -> bool {
try {
#if defined(_WIN32)
std::string file_name;
file_name.resize(MAX_PATH + 1U);
file_name.resize(repertory::max_path_length + 1U);
::GetModuleFileNameA(nullptr, file_name.data(),
static_cast<DWORD>(file_name.size() - 1U));

View File

@ -33,7 +33,7 @@ namespace {
file_size = 0U;
#if defined(_WIN32)
struct _stat64 st {};
struct _stat64 st{};
auto res = _stat64(std::string{path}.c_str(), &st);
if (res != 0) {
return false;
@ -55,7 +55,7 @@ namespace {
return ((::PathFileExistsA(abs_path.c_str()) != 0) &&
(::PathIsDirectoryA(abs_path.c_str()) == 0));
#else // !defined(_WIN32)
struct stat64 st {};
struct stat64 st{};
return (stat64(abs_path.c_str(), &st) == 0 && not S_ISDIR(st.st_mode));
#endif // defined(_WIN32)
}
@ -70,12 +70,12 @@ namespace repertory::utils::file {
// std::string path;
//
// #if defined(_WIN32)
// path.resize(repertory::max_path_length + 1);
// path.resize(repertory::max_path_length + 1U);
// ::GetFinalPathNameByHandleA(handle, path.data(),
// static_cast<DWORD>(path.size()),
// FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
// #else // !defined(_WIN32)
// path.resize(repertory::max_path_length + 1);
// path.resize(repertory::max_path_length + 1U);
//
// #if defined(__APPLE__)
// fcntl(handle, F_GETPATH, source_path.data());
@ -155,8 +155,8 @@ auto file::open_file(std::string_view path, bool read_only) -> fs_file_t {
return new_file;
}
auto file::open_or_create_file(std::string_view path,
bool read_only) -> fs_file_t {
auto file::open_or_create_file(std::string_view path, bool read_only)
-> fs_file_t {
auto abs_path = utils::path::absolute(path);
if (not is_file(abs_path)) {
#if defined(_WIN32)

View File

@ -94,7 +94,7 @@ auto absolute(std::string_view path) -> std::string {
}
std::string temp;
temp.resize(repertory::max_path_length + 1);
temp.resize(repertory::max_path_length + 1U);
::GetFullPathNameA(abs_path.c_str(), static_cast<DWORD>(temp.size()),
temp.data(), nullptr);
#else // !defined(_WIN32)
@ -206,8 +206,8 @@ auto get_parent_path(std::wstring_view path) -> std::wstring {
get_parent_path(utils::string::to_utf8(path)));
}
auto get_relative_path(std::string_view path,
std::string_view root_path) -> std::string {
auto get_relative_path(std::string_view path, std::string_view root_path)
-> std::string {
auto abs_path = absolute(path);
auto abs_root_path =
absolute(root_path) + std::string{get_directory_seperator<char>()};
@ -223,8 +223,8 @@ auto get_relative_path(std::string_view path,
return abs_path;
}
auto get_relative_path(std::wstring_view path,
std::wstring_view root_path) -> std::wstring {
auto get_relative_path(std::wstring_view path, std::wstring_view root_path)
-> std::wstring {
return utils::string::from_utf8(get_relative_path(
utils::string::to_utf8(path), utils::string::to_utf8(root_path)));
}
@ -257,6 +257,10 @@ auto make_file_uri(std::wstring_view path) -> std::wstring {
}
auto strip_to_file_name(std::string path) -> std::string {
if (path == "." || path == "..") {
return path;
}
#if defined(_WIN32)
return ::PathFindFileNameA(path.c_str());
#else // !defined(_WIN32)

View File

@ -116,7 +116,8 @@ auto run_process_elevated(std::vector<const char *> args) -> int {
std::string full_path;
full_path.resize(repertory::max_path_length + 1);
if (::GetModuleFileNameA(nullptr, full_path.data(), MAX_PATH)) {
if (::GetModuleFileNameA(nullptr, full_path.data(),
repertory::max_path_length)) {
SHELLEXECUTEINFOA sei{};
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
sei.cbSize = sizeof(sei);

View File

@ -37,8 +37,8 @@ using namespace ::testing;
#include "utils/all.hpp"
namespace repertory::test {
[[nodiscard]] auto
create_random_file(std::size_t size) -> utils::file::i_file &;
[[nodiscard]] auto create_random_file(std::size_t size)
-> utils::file::i_file &;
[[nodiscard]] auto
generate_test_file_name(std::string_view file_name_no_extension) -> std::string;

View File

@ -21,6 +21,8 @@
*/
#include "test.hpp"
extern int PROJECT_TEST_RESULT;
namespace {
static std::recursive_mutex file_mtx{};
@ -28,6 +30,7 @@ static std::vector<std::unique_ptr<repertory::utils::file::i_fs_item>>
generated_files{};
static void delete_generated_files() {
if (PROJECT_TEST_RESULT == 0) {
repertory::recur_mutex_lock lock{file_mtx};
std::map<std::string, bool> parent_paths;
for (auto &&path : generated_files) {
@ -41,9 +44,10 @@ static void delete_generated_files() {
repertory::utils::file::directory(entry.first).remove_recursively());
}
EXPECT_TRUE(
repertory::utils::file::directory(repertory::test::get_test_output_dir())
EXPECT_TRUE(repertory::utils::file::directory(
repertory::test::get_test_output_dir())
.remove_recursively());
}
}
struct file_deleter final {