10 Commits

Author SHA1 Message Date
b508d98dd7 windows fixes
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
2024-10-25 17:42:32 -05:00
4b68e5e4b7 fixes 2024-10-25 13:19:02 -05:00
3f6121839a fix 2024-10-25 12:03:45 -05:00
5e1745ebfb fix 2024-10-25 11:59:29 -05:00
b20bc6c28a refactor 2024-10-25 11:50:19 -05:00
9a1483377c refactor 2024-10-25 11:45:10 -05:00
4c97f6b098 remove logging 2024-10-25 11:37:52 -05:00
f9af43309d fixes 2024-10-25 11:24:47 -05:00
a77fd75687 refactor 2024-10-25 10:18:29 -05:00
f5b4928818 fix windows upload 2024-10-25 10:15:35 -05:00
21 changed files with 549 additions and 463 deletions

View File

@ -39,8 +39,8 @@ struct http_put_file final : http_request_base {
std::shared_ptr<utils::encryption::encrypting_reader> reader;
std::string source_path;
[[nodiscard]] auto
set_method(CURL *curl, stop_type &stop_requested) const -> bool override;
[[nodiscard]] auto set_method(CURL *curl, stop_type &stop_requested) const
-> bool override;
private:
mutable std::shared_ptr<read_file_info> read_info{};

View File

@ -26,9 +26,7 @@
#include "utils/file.hpp"
namespace repertory::curl::requests {
using read_callback = size_t (*)(char *, size_t, size_t, void *);
using response_callback =
using curl_response_callback =
std::function<void(const data_buffer &data, long response_code)>;
struct read_file_info final {
@ -37,19 +35,8 @@ struct read_file_info final {
std::uint64_t offset{};
};
inline const auto read_file_data = static_cast<read_callback>(
[](char *buffer, size_t size, size_t nitems, void *instream) -> size_t {
auto *read_info = reinterpret_cast<read_file_info *>(instream);
std::size_t bytes_read{};
auto ret =
read_info->file->read(reinterpret_cast<unsigned char *>(buffer),
size * nitems, read_info->offset, &bytes_read);
if (ret) {
read_info->offset += bytes_read;
}
return ret && not read_info->stop_requested ? bytes_read
: CURL_READFUNC_ABORT;
});
[[nodiscard]] auto curl_file_reader(char *buffer, size_t size, size_t nitems,
void *instream) -> size_t;
struct http_request_base {
http_request_base() = default;
@ -68,14 +55,15 @@ struct http_request_base {
std::string path{};
http_query_parameters query{};
std::optional<http_range> range{};
std::optional<response_callback> response_handler;
std::optional<curl_response_callback> response_handler;
std::optional<http_headers> response_headers;
std::optional<std::uint64_t> total_size{};
[[nodiscard]] virtual auto get_path() const -> std::string { return path; }
[[nodiscard]] virtual auto
set_method(CURL *curl, stop_type &stop_requested) const -> bool = 0;
[[nodiscard]] virtual auto set_method(CURL *curl,
stop_type &stop_requested) const
-> bool = 0;
};
} // namespace repertory::curl::requests

View File

@ -21,21 +21,23 @@
*/
#include "comm/curl/requests/http_put_file.hpp"
#include "utils/error_utils.hpp"
#include "utils/string.hpp"
namespace repertory::curl::requests {
auto http_put_file::set_method(CURL *curl, stop_type &stop_requested) const
-> bool {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
REPERTORY_USES_FUNCTION_NAME();
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_INFILE, nullptr);
if (source_path.empty()) {
curl_easy_setopt(curl, CURLOPT_INFILE, nullptr);
curl_easy_setopt(curl, CURLOPT_INFILESIZE, 0L);
return true;
}
if (reader) {
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_READDATA, reader.get());
curl_easy_setopt(
curl, CURLOPT_READFUNCTION,
@ -51,19 +53,27 @@ auto http_put_file::set_method(CURL *curl, stop_type &stop_requested) const
});
if (not*read_info->file) {
utils::error::raise_url_error(function_name, get_path(), source_path,
std::runtime_error("failed to open file"));
return false;
}
auto file_size = read_info->file->size();
auto opt_size = read_info->file->size();
if (not opt_size.has_value()) {
utils::error::raise_url_error(
function_name, get_path(), source_path,
std::runtime_error("failed to get file size"));
return false;
}
auto file_size = opt_size.value();
if (file_size == 0U) {
curl_easy_setopt(curl, CURLOPT_INFILE, nullptr);
curl_easy_setopt(curl, CURLOPT_INFILESIZE, 0L);
return true;
}
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_READDATA, read_info.get());
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_file_data);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, curl_file_reader);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_size);
return true;

View File

@ -0,0 +1,43 @@
/*
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 "comm/curl/requests/http_request_base.hpp"
#include "utils/file.hpp"
#include "utils/string.hpp"
namespace repertory::curl::requests {
auto curl_file_reader(char *buffer, size_t size, size_t nitems, void *instream)
-> size_t {
auto *read_info = reinterpret_cast<read_file_info *>(instream);
std::size_t bytes_read{};
auto ret =
read_info->file->read(reinterpret_cast<unsigned char *>(buffer),
size * nitems, read_info->offset, &bytes_read);
if (ret) {
read_info->offset += bytes_read;
}
return ret && not read_info->stop_requested ? bytes_read
: CURL_READFUNC_ABORT;
}
} // namespace repertory::curl::requests

View File

@ -36,7 +36,9 @@ auto eviction::check_minimum_requirements(const std::string &file_path)
-> bool {
REPERTORY_USES_FUNCTION_NAME();
auto opt_size = utils::file::file{file_path}.size();
auto check_file = utils::file::file{file_path};
auto opt_size = check_file.size();
if (not opt_size.has_value()) {
utils::error::raise_error(function_name, utils::get_last_error_code(),
file_path, "failed to get file size");
@ -48,17 +50,20 @@ auto eviction::check_minimum_requirements(const std::string &file_path)
return false;
}
auto reference_time = utils::file::file{file_path}.get_time(
config_.get_eviction_uses_accessed_time()
? utils::file::time_type::accessed
: utils::file::time_type::modified);
auto reference_time =
check_file.get_time(config_.get_eviction_uses_accessed_time()
? utils::file::time_type::accessed
: utils::file::time_type::modified);
if (not reference_time.has_value()) {
utils::error::raise_error(function_name, utils::get_last_error_code(),
file_path, "failed to get file time");
return false;
}
auto delay = (config_.get_eviction_delay_mins() * 60UL) *
utils::time::NANOS_PER_SECOND;
return ((reference_time.value() + static_cast<std::uint64_t>(delay)) <=
utils::time::get_time_now());
}

View File

@ -81,8 +81,8 @@ auto fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid,
struct fuse_file_info * /*file_info*/)
-> api_error {
#else
auto fuse_drive::chown_impl(std::string api_path, uid_t uid,
gid_t gid) -> api_error {
auto fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid)
-> api_error {
#endif
return check_and_perform(
api_path, X_OK, [&](api_meta_map &meta) -> api_error {
@ -185,9 +185,8 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
#endif // defined(__APPLE__)
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now, now,
is_directory_op, get_effective_gid(), "", mode, now, 0U, osx_flags,
0U,
now, FILE_ATTRIBUTE_ARCHIVE, now, now, is_directory_op,
get_effective_gid(), "", mode, now, 0U, osx_flags, 0U,
utils::path::combine(config_.get_cache_directory(),
{utils::create_uuid_string()}),
get_effective_uid(), now);
@ -454,8 +453,8 @@ auto fuse_drive::getattr_impl(std::string api_path, struct stat *st,
struct fuse_file_info * /*file_info*/)
-> api_error {
#else
auto fuse_drive::getattr_impl(std::string api_path,
struct stat *st) -> api_error {
auto fuse_drive::getattr_impl(std::string api_path, struct stat *st)
-> api_error {
#endif
const auto parent = utils::path::get_parent_api_path(api_path);
@ -537,8 +536,8 @@ auto fuse_drive::getxtimes_impl(std::string api_path, struct timespec *bkuptime,
#endif // __APPLE__
#if FUSE_USE_VERSION >= 30
auto fuse_drive::init_impl(struct fuse_conn_info *conn,
struct fuse_config *cfg) -> void * {
auto fuse_drive::init_impl(struct fuse_conn_info *conn, struct fuse_config *cfg)
-> void * {
#else
void *fuse_drive::init_impl(struct fuse_conn_info *conn) {
#endif
@ -763,8 +762,9 @@ auto fuse_drive::release_impl(std::string /*api_path*/,
return api_error::success;
}
auto fuse_drive::releasedir_impl(
std::string /*api_path*/, struct fuse_file_info *file_info) -> api_error {
auto fuse_drive::releasedir_impl(std::string /*api_path*/,
struct fuse_file_info *file_info)
-> api_error {
auto iter = directory_cache_->get_directory(file_info->fh);
if (iter == nullptr) {
return api_error::invalid_handle;
@ -782,8 +782,8 @@ auto fuse_drive::rename_directory(const std::string &from_api_path,
}
auto fuse_drive::rename_file(const std::string &from_api_path,
const std::string &to_api_path,
bool overwrite) -> int {
const std::string &to_api_path, bool overwrite)
-> int {
const auto res = fm_->rename_file(from_api_path, to_api_path, overwrite);
errno = std::abs(utils::from_api_error(res));
return (res == api_error::success) ? 0 : -1;
@ -793,8 +793,8 @@ auto fuse_drive::rename_file(const std::string &from_api_path,
auto fuse_drive::rename_impl(std::string from_api_path, std::string to_api_path,
unsigned int /*flags*/) -> api_error {
#else
auto fuse_drive::rename_impl(std::string from_api_path,
std::string to_api_path) -> api_error {
auto fuse_drive::rename_impl(std::string from_api_path, std::string to_api_path)
-> api_error {
#endif
auto res = check_parent_access(to_api_path, W_OK | X_OK);
if (res != api_error::success) {
@ -901,15 +901,15 @@ auto fuse_drive::getxattr_impl(std::string api_path, const char *name,
}
#else // __APPLE__
auto fuse_drive::getxattr_impl(std::string api_path, const char *name,
char *value, size_t size,
int &attribute_size) -> api_error {
char *value, size_t size, int &attribute_size)
-> api_error {
return getxattr_common(api_path, name, value, size, attribute_size, nullptr);
}
#endif // __APPLE__
auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size,
int &required_size,
bool &return_size) -> api_error {
int &required_size, bool &return_size)
-> api_error {
const auto check_size = (size == 0);
auto res = check_parent_access(api_path, X_OK);
@ -948,8 +948,8 @@ auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size,
return res;
}
auto fuse_drive::removexattr_impl(std::string api_path,
const char *name) -> api_error {
auto fuse_drive::removexattr_impl(std::string api_path, const char *name)
-> api_error {
std::string attribute_name;
#if defined(__APPLE__)
auto res = parse_xattr_parameters(name, 0, attribute_name, api_path);
@ -977,8 +977,8 @@ auto fuse_drive::setxattr_impl(std::string api_path, const char *name,
uint32_t position) -> api_error {
#else // __APPLE__
auto fuse_drive::setxattr_impl(std::string api_path, const char *name,
const char *value, size_t size,
int flags) -> api_error {
const char *value, size_t size, int flags)
-> api_error {
#endif
std::string attribute_name;
#if defined(__APPLE__)
@ -1053,8 +1053,8 @@ void fuse_drive::set_item_meta(const std::string &api_path,
}
#if defined(__APPLE__)
auto fuse_drive::setattr_x_impl(std::string api_path,
struct setattr_x *attr) -> api_error {
auto fuse_drive::setattr_x_impl(std::string api_path, struct setattr_x *attr)
-> api_error {
bool exists{};
auto res = provider_.is_file(api_path, exists);
if (res != api_error::success) {
@ -1108,7 +1108,7 @@ auto fuse_drive::setattr_x_impl(std::string api_path,
ts[0].tv_sec = attr->acctime.tv_sec;
ts[0].tv_nsec = attr->acctime.tv_nsec;
} else {
struct timeval tv {};
struct timeval tv{};
gettimeofday(&tv, NULL);
ts[0].tv_sec = tv.tv_sec;
ts[0].tv_nsec = tv.tv_usec * 1000;
@ -1153,8 +1153,9 @@ auto fuse_drive::setattr_x_impl(std::string api_path,
return api_error::success;
}
auto fuse_drive::setbkuptime_impl(
std::string api_path, const struct timespec *bkuptime) -> api_error {
auto fuse_drive::setbkuptime_impl(std::string api_path,
const struct timespec *bkuptime)
-> api_error {
return check_and_perform(
api_path, X_OK, [&](api_meta_map &meta) -> api_error {
const auto nanos = bkuptime->tv_nsec +
@ -1190,8 +1191,8 @@ auto fuse_drive::setvolname_impl(const char * /*volname*/) -> api_error {
return api_error::success;
}
auto fuse_drive::statfs_x_impl(std::string /*api_path*/,
struct statfs *stbuf) -> api_error {
auto fuse_drive::statfs_x_impl(std::string /*api_path*/, struct statfs *stbuf)
-> api_error {
if (statfs(&config_.get_cache_directory()[0], stbuf) != 0) {
return api_error::os_error;
}
@ -1216,8 +1217,8 @@ auto fuse_drive::statfs_x_impl(std::string /*api_path*/,
return api_error::success;
}
#else // __APPLE__
auto fuse_drive::statfs_impl(std::string /*api_path*/,
struct statvfs *stbuf) -> api_error {
auto fuse_drive::statfs_impl(std::string /*api_path*/, struct statvfs *stbuf)
-> api_error {
if (statvfs(config_.get_cache_directory().data(), stbuf) != 0) {
return api_error::os_error;
}
@ -1298,8 +1299,8 @@ auto fuse_drive::utimens_impl(std::string api_path, const struct timespec tv[2],
struct fuse_file_info * /*file_info*/)
-> api_error {
#else
auto fuse_drive::utimens_impl(std::string api_path,
const struct timespec tv[2]) -> api_error {
auto fuse_drive::utimens_impl(std::string api_path, const struct timespec tv[2])
-> api_error {
#endif
api_meta_map meta;
auto res = provider_.get_item_meta(api_path, meta);

View File

@ -96,7 +96,7 @@ auto remote_server::populate_file_info(const std::string &api_path,
meta_attributes =
utils::file::directory(construct_path(api_path)).exists()
? std::to_string(FILE_ATTRIBUTE_DIRECTORY)
: std::to_string(FILE_ATTRIBUTE_NORMAL);
: std::to_string(FILE_ATTRIBUTE_ARCHIVE);
drive_.set_item_meta(api_path, META_ATTRIBUTES, meta_attributes);
}
const auto attributes = utils::string::to_uint32(meta_attributes);
@ -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,
const remote::file_offset &read_offset,
const remote::file_handle &handle) -> packet::error_type {
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 {
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,
const remote::file_offset &write_offset,
const remote::file_handle &handle) -> packet::error_type {
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 {
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);
@ -1030,8 +1042,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 +1120,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);
@ -1120,14 +1132,11 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
attributes |= FILE_ATTRIBUTE_DIRECTORY;
} else {
attributes &= static_cast<UINT32>(~FILE_ATTRIBUTE_DIRECTORY);
attributes |= FILE_ATTRIBUTE_ARCHIVE;
}
if (not attributes) {
attributes = FILE_ATTRIBUTE_NORMAL;
}
remote::file_mode mode = 0;
std::uint32_t flags = 0;
remote::file_mode mode{0U};
std::uint32_t flags{0U};
utils::windows_create_to_unix(create_options, granted_access, flags, mode);
int res = 0;
@ -1179,8 +1188,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);
@ -1223,9 +1233,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);
@ -1242,10 +1253,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);
@ -1281,10 +1293,11 @@ auto remote_server::winfsp_open(
return ret;
}
auto remote_server::winfsp_overwrite(
PVOID file_desc, UINT32 attributes, BOOLEAN replace_attributes,
UINT64 /*allocation_size*/,
remote::file_info *file_info) -> packet::error_type {
auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
BOOLEAN replace_attributes,
UINT64 /*allocation_size*/,
remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME();
const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
@ -1315,10 +1328,9 @@ auto remote_server::winfsp_overwrite(
}
if (set_attributes) {
attributes &= static_cast<UINT32>(
~(FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_NORMAL));
attributes &= static_cast<UINT32>(~FILE_ATTRIBUTE_NORMAL);
if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL;
attributes = FILE_ATTRIBUTE_ARCHIVE;
}
drive_.set_item_meta(api_path, META_ATTRIBUTES,
std::to_string(attributes));
@ -1401,9 +1413,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);
@ -1447,15 +1460,15 @@ auto remote_server::winfsp_set_basic_info(
} else if (attributes == 0) {
attributes = utils::file::directory(file_path).exists()
? FILE_ATTRIBUTE_DIRECTORY
: FILE_ATTRIBUTE_NORMAL;
: FILE_ATTRIBUTE_ARCHIVE;
}
const auto api_path = construct_api_path(file_path);
api_meta_map meta;
if (attributes != 0U) {
if (((attributes & FILE_ATTRIBUTE_NORMAL) != 0U) &&
(attributes != FILE_ATTRIBUTE_NORMAL)) {
attributes &= static_cast<UINT32>(~(FILE_ATTRIBUTE_NORMAL));
attributes &= static_cast<UINT32>(~FILE_ATTRIBUTE_NORMAL);
if (attributes == = 0U) {
attributes |= static_cast<UINT32>(FILE_ATTRIBUTE_ARCHIVE);
}
drive_.set_item_meta(api_path, META_ATTRIBUTES,
std::to_string(attributes));
@ -1497,9 +1510,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);
@ -1535,10 +1549,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;
@ -1586,8 +1602,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);
@ -1646,8 +1663,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);
@ -1677,7 +1694,7 @@ auto remote_server::update_to_windows_format(json &item) -> json & {
if (item["meta"][META_ATTRIBUTES].empty()) {
item["meta"][META_ATTRIBUTES] =
item["directory"].get<bool>() ? std::to_string(FILE_ATTRIBUTE_DIRECTORY)
: std::to_string(FILE_ATTRIBUTE_NORMAL);
: std::to_string(FILE_ATTRIBUTE_ARCHIVE);
drive_.set_item_meta(api_path, META_ATTRIBUTES,
item["meta"][META_ATTRIBUTES].get<std::string>());
}

View File

@ -991,11 +991,9 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
create_flags |= FILE_FLAG_POSIX_SEMANTICS;
attributes |= FILE_ATTRIBUTE_DIRECTORY;
} else {
attributes &= static_cast<UINT32>(~FILE_ATTRIBUTE_DIRECTORY);
}
if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL;
attributes &= static_cast<UINT32>(
~(FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_NORMAL));
attributes |= FILE_ATTRIBUTE_ARCHIVE;
}
auto *handle = ::CreateFileW(
@ -1165,8 +1163,9 @@ auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
if (ret == STATUS_SUCCESS) {
if (replace_attributes != 0U) {
if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL;
attributes = FILE_ATTRIBUTE_ARCHIVE;
}
FILE_BASIC_INFO basic_info{};
basic_info.FileAttributes = attributes;
if (::SetFileInformationByHandle(handle, FileBasicInfo, &basic_info,

View File

@ -177,10 +177,16 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
}
if (directory) {
auto res = provider_.remove_directory(api_path);
if (res != api_error::success) {
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to remove directory");
if (provider_.get_directory_item_count(api_path) == 0) {
auto res = provider_.remove_directory(api_path);
if (res != api_error::success) {
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to remove directory");
}
} else {
utils::error::raise_api_path_error(
function_name, api_path, api_error::directory_not_empty,
"failed to remove non-empty directory");
}
} else {
auto res = fm_->remove_file(api_path);
@ -286,6 +292,7 @@ auto winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
UINT64 /*allocation_size*/, PVOID * /*file_node*/,
PVOID *file_desc, OpenFileInfo *ofi) -> NTSTATUS {
REPERTORY_USES_FUNCTION_NAME();
*file_desc = reinterpret_cast<PVOID>(INVALID_HANDLE_VALUE);
// TODO Need to revisit this
// (ConvertSecurityDescriptorToStringSecurityDescriptor/ConvertStringSecurityDescriptorToSecurityDescriptor)
@ -294,11 +301,9 @@ auto winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
if ((create_options & FILE_DIRECTORY_FILE) != 0U) {
attributes |= FILE_ATTRIBUTE_DIRECTORY;
} else {
attributes &= static_cast<UINT32>(~FILE_ATTRIBUTE_DIRECTORY);
}
if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL;
attributes &= static_cast<UINT32>(
~(FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_NORMAL));
attributes |= FILE_ATTRIBUTE_ARCHIVE;
}
const auto now = utils::time::get_time_now();
@ -331,7 +336,11 @@ auto winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
*file_desc = reinterpret_cast<PVOID>(handle);
}
auto ret = utils::from_api_error(error);
auto ret =
error == api_error::item_exists || error == api_error::directory_exists
? STATUS_OBJECT_NAME_COLLISION
: utils::from_api_error(error);
RAISE_WINFSP_EVENT(function_name, api_path, ret);
return ret;
}
@ -556,6 +565,7 @@ auto winfsp_drive::Init(PVOID host) -> NTSTATUS {
file_system_host->SetCasePreservedNames(TRUE);
file_system_host->SetNamedStreams(FALSE);
file_system_host->SetUnicodeOnDisk(TRUE);
file_system_host->SetMaxComponentLength(4096U);
file_system_host->SetPersistentAcls(FALSE);
file_system_host->SetPostCleanupWhenModifiedOnly(TRUE);
file_system_host->SetPassQueryDirectoryPattern(FALSE);
@ -663,6 +673,7 @@ auto winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, PVOID * /*file_node*/,
PVOID *file_desc, OpenFileInfo *ofi) -> NTSTATUS {
REPERTORY_USES_FUNCTION_NAME();
*file_desc = reinterpret_cast<PVOID>(INVALID_HANDLE_VALUE);
const auto api_path =
utils::path::create_api_path(utils::string::to_utf8(file_name));
@ -733,7 +744,7 @@ auto winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc,
// Handle replace attributes
if (replace_attributes != 0U) {
if (attributes == 0U) {
attributes = FILE_ATTRIBUTE_NORMAL;
attributes = FILE_ATTRIBUTE_ARCHIVE;
}
meta[META_ATTRIBUTES] = std::to_string(attributes);
error = provider_.set_item_meta(api_path, meta);
@ -801,9 +812,7 @@ void winfsp_drive::populate_file_info(std::uint64_t file_size,
FSP_FSCTL_FILE_INFO &file_info) {
file_info.FileSize = file_size;
file_info.AllocationSize =
utils::divide_with_ceiling(file_size == 0U ? WINFSP_ALLOCATION_UNIT
: file_size,
WINFSP_ALLOCATION_UNIT) *
utils::divide_with_ceiling(file_size, WINFSP_ALLOCATION_UNIT) *
WINFSP_ALLOCATION_UNIT;
file_info.ChangeTime = utils::get_changed_time_from_meta(meta);
file_info.CreationTime = utils::get_creation_time_from_meta(meta);
@ -1013,19 +1022,20 @@ auto winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
if (fm_->get_open_file(handle, false, file)) {
api_path = file->get_api_path();
if (attributes == INVALID_FILE_ATTRIBUTES) {
attributes = 0;
} else if (attributes == 0) {
attributes = 0U;
} else if (attributes == 0U) {
attributes = file->is_directory() ? FILE_ATTRIBUTE_DIRECTORY
: FILE_ATTRIBUTE_NORMAL;
: FILE_ATTRIBUTE_ARCHIVE;
}
api_meta_map meta;
if (attributes != 0U) {
if (((attributes & FILE_ATTRIBUTE_NORMAL) != 0U) &&
(attributes != FILE_ATTRIBUTE_NORMAL)) {
attributes &= static_cast<UINT32>(~FILE_ATTRIBUTE_NORMAL);
auto next_attributes =
attributes & static_cast<UINT32>(~FILE_ATTRIBUTE_NORMAL);
if (next_attributes == 0U) {
next_attributes = attributes;
}
meta[META_ATTRIBUTES] = std::to_string(attributes);
meta[META_ATTRIBUTES] = std::to_string(next_attributes);
}
if ((creation_time != 0U) && (creation_time != max_time)) {
meta[META_CREATION] = std::to_string(

View File

@ -180,8 +180,14 @@ auto file_manager::create(const std::string &api_path, api_meta_map &meta,
std::shared_ptr<i_open_file> &file) -> api_error {
recur_mutex_lock file_lock(open_file_mtx_);
auto res = provider_.create_file(api_path, meta);
if (res != api_error::success && res != api_error::item_exists) {
return res;
if (res != api_error::success) {
#if !defined(_WIN32)
if (res != api_error::item_exists) {
#endif //! defined (_WIN32)
return res;
#if !defined(_WIN32)
}
#endif //! defined (_WIN32)
}
return open(api_path, false, ofd, handle, file);
@ -206,8 +212,8 @@ auto file_manager::evict_file(const std::string &api_path) -> bool {
std::string pinned;
auto res = provider_.get_item_meta(api_path, META_PINNED, pinned);
if (res != api_error::success && res != api_error::item_not_found) {
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to get pinned status");
utils::error::raise_api_path_error(std::string{function_name}, api_path,
res, "failed to get pinned status");
return false;
}
@ -218,8 +224,8 @@ auto file_manager::evict_file(const std::string &api_path) -> bool {
std::string source_path{};
res = provider_.get_item_meta(api_path, META_SOURCE, source_path);
if (res != api_error::success) {
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to get source path");
utils::error::raise_api_path_error(std::string{function_name}, api_path,
res, "failed to get source path");
return false;
}
if (source_path.empty()) {

View File

@ -225,8 +225,7 @@ auto provider_meta_handler(i_provider &provider, bool directory,
const api_file &file) -> api_error {
const auto meta = create_meta_attributes(
file.accessed_date,
directory ? FILE_ATTRIBUTE_DIRECTORY
: FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE,
directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_ARCHIVE,
file.changed_date, file.creation_date, directory, getgid(), file.key,
directory ? S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR
: S_IFREG | S_IRUSR | S_IWUSR,

View File

@ -196,8 +196,7 @@ auto provider_meta_handler(i_provider &provider, bool directory,
const api_file &file) -> api_error {
const auto meta = create_meta_attributes(
file.accessed_date,
directory ? FILE_ATTRIBUTE_DIRECTORY
: FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE,
directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_ARCHIVE,
file.changed_date, file.creation_date, directory, 0u, file.key,
directory ? S_IFDIR : S_IFREG, file.modified_date, 0u, 0u, file.file_size,
file.source_path, 0u, file.modified_date);

View File

@ -409,8 +409,6 @@ auto encrypt_provider::get_file_list(api_file_list &list) const -> api_error {
REPERTORY_USES_FUNCTION_NAME();
const auto cfg = config_.get_encrypt_config();
event_system::instance().raise<debug_log>(std::string{function_name},
cfg.path, "");
try {
for (auto &&dir_entry : utils::file::directory{cfg.path}.get_items()) {

View File

@ -38,26 +38,30 @@ auto get_directory_files(std::string_view path, bool oldest_first,
#if defined(_WIN32)
WIN32_FIND_DATA fd{};
auto search = utils::path::combine(abs_path, {"*.*"});
auto find = ::FindFirstFile(search.c_str(), &fd);
auto find = ::FindFirstFileA(search.c_str(), &fd);
if (find != INVALID_HANDLE_VALUE) {
try {
do {
auto full_path = utils::path::combine(abs_path, {fd.cFileName});
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ==
FILE_ATTRIBUTE_DIRECTORY) {
if (recursive) {
auto sub_files =
get_directory_files(full_path, oldest_first, recursive);
ret.insert(ret.end(), sub_files.begin(), sub_files.end());
} else {
ULARGE_INTEGER li{};
li.HighPart = fd.ftLastWriteTime.dwHighDateTime;
li.LowPart = fd.ftLastWriteTime.dwLowDateTime;
lookup[full_path] = li.QuadPart;
ret.emplace_back(full_path);
std::string name{fd.cFileName};
if (name == "." || name == ".." || not recursive) {
continue;
}
auto sub_files =
get_directory_files(full_path, oldest_first, recursive);
ret.insert(ret.end(), sub_files.begin(), sub_files.end());
continue;
}
} while (::FindNextFile(find, &fd) != 0);
ULARGE_INTEGER li{};
li.HighPart = fd.ftLastWriteTime.dwHighDateTime;
li.LowPart = fd.ftLastWriteTime.dwLowDateTime;
lookup[full_path] = li.QuadPart;
ret.emplace_back(full_path);
} while (::FindNextFileA(find, &fd) != 0);
} catch (const std::exception &e) {
utils::error::raise_error(function_name, e,
"failed to get directory files");
@ -75,15 +79,18 @@ auto get_directory_files(std::string_view path, bool oldest_first,
struct dirent *de{};
while ((de = readdir(root)) != nullptr) {
if (de->d_type == DT_DIR) {
if (recursive) {
auto sub_files = get_directory_files(
utils::path::combine(abs_path, {de->d_name}), oldest_first,
recursive);
ret.insert(ret.end(), sub_files.begin(), sub_files.end());
std::string name{de->d_name};
if (name == "." || name == ".." || not recursive) {
continue;
}
} else {
ret.emplace_back(utils::path::combine(abs_path, {de->d_name}));
auto sub_files = get_directory_files(
utils::path::combine(abs_path, {name}), oldest_first, recursive);
ret.insert(ret.end(), sub_files.begin(), sub_files.end());
continue;
}
ret.emplace_back(utils::path::combine(abs_path, {name}));
}
} catch (const std::exception &e) {
utils::error::raise_error(function_name, e,

View File

@ -37,8 +37,7 @@ void calculate_allocation_size(bool directory, std::uint64_t file_size,
if (file_size > allocation_size) {
allocation_size = file_size;
}
allocation_size =
((allocation_size == 0U) ? WINFSP_ALLOCATION_UNIT : allocation_size);
allocation_size =
utils::divide_with_ceiling(allocation_size, WINFSP_ALLOCATION_UNIT) *
WINFSP_ALLOCATION_UNIT;

View File

@ -140,8 +140,8 @@ protected:
}
public:
[[nodiscard]] static auto
create_directory_and_test(std::string &dir_name) -> std::string {
[[nodiscard]] static auto create_directory_and_test(std::string &dir_name)
-> std::string {
dir_name += std::to_string(++idx);
auto api_path = utils::path::create_api_path(dir_name);
auto dir_path = utils::path::combine(mount_location, {dir_name});
@ -152,8 +152,8 @@ public:
return dir_path;
}
[[nodiscard]] static auto
create_file_and_test(std::string &file_name) -> std::string {
[[nodiscard]] static auto create_file_and_test(std::string &file_name)
-> std::string {
file_name += std::to_string(++idx);
auto api_path = utils::path::create_api_path(file_name);
auto file_path = utils::path::combine(mount_location, {file_name});
@ -173,7 +173,7 @@ public:
std::string attr;
EXPECT_EQ(api_error::success,
provider->get_item_meta(api_path, META_ATTRIBUTES, attr));
EXPECT_EQ(FILE_ATTRIBUTE_NORMAL, utils::string::to_uint32(attr));
EXPECT_EQ(FILE_ATTRIBUTE_ARCHIVE, utils::string::to_uint32(attr));
return file_path;
}

View File

@ -141,7 +141,7 @@ public:
auto directory = utils::file::directory(file_path).exists();
auto attributes =
FILE_FLAG_BACKUP_SEMANTICS |
(directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL);
(directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_ARCHIVE);
auto share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
auto handle = ::CreateFileA(
file_path.c_str(), GENERIC_READ, static_cast<DWORD>(share_mode),

View File

@ -130,9 +130,9 @@ TEST_F(file_manager_test, can_create_and_close_file) {
std::shared_ptr<i_open_file> f;
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10, now + 4u);
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));
@ -235,9 +235,9 @@ TEST_F(file_manager_test, can_open_and_close_file) {
{
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10, now + 4u);
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).Times(0u);
@ -330,9 +330,9 @@ TEST_F(file_manager_test, can_open_and_close_multiple_handles_for_same_file) {
cfg->get_cache_directory(), {utils::create_uuid_string()});
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10, now + 4u);
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).Times(0u);
@ -404,8 +404,8 @@ TEST_F(file_manager_test,
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u,
now, FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u, false, 1, "key", 2,
now + 3u, 3u, 4u,
utils::encryption::encrypting_reader::get_data_chunk_size() * 4u,
source_path, 10, now + 4u);
auto &nf =
@ -558,8 +558,8 @@ TEST_F(file_manager_test, upload_occurs_after_write_if_fully_downloaded) {
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u,
now, FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u, false, 1, "key", 2,
now + 3u, 3u, 4u,
utils::encryption::encrypting_reader::get_data_chunk_size() * 4u,
source_path, 10, now + 4u);
auto &nf =
@ -657,9 +657,9 @@ TEST_F(file_manager_test, can_evict_file) {
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10, now + 4u);
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);
std::uint64_t handle{};
{
std::shared_ptr<i_open_file> f;
@ -859,9 +859,9 @@ TEST_F(file_manager_test, evict_file_fails_if_file_is_uploading) {
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "", 2, now + 3u, 3u, 4u, 0u, source_path, 10, now + 4u);
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "", 2, now + 3u, 3u,
4u, 0u, source_path, 10, now + 4u);
std::uint64_t handle{};
{
std::shared_ptr<i_open_file> f;
@ -1040,9 +1040,9 @@ TEST_F(file_manager_test, file_is_not_opened_if_provider_create_file_fails) {
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "", 2, now + 3u, 3u, 4u, 0u, "/test_create.src", 10, now + 4u);
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "", 2, now + 3u, 3u,
4u, 0u, "/test_create.src", 10, now + 4u);
file_manager fm(*cfg, mp);
EXPECT_CALL(mp, create_file("/test_create.txt", meta))
@ -1431,8 +1431,8 @@ TEST_F(file_manager_test, file_is_closed_after_download_timeout) {
const auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u,
now, FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u, false, 1, "key", 2,
now + 3u, 3u, 4u,
utils::encryption::encrypting_reader::get_data_chunk_size() * 4u,
source_path, 10, now + 4u);

View File

@ -179,7 +179,7 @@ static void get_security_by_name_test(remote_client &client) {
ret = client.winfsp_get_security_by_name(
&api_path[0], &attributes, &security_descriptor_size, str_descriptor);
EXPECT_EQ(STATUS_SUCCESS, ret);
EXPECT_EQ(static_cast<UINT32>(FILE_ATTRIBUTE_NORMAL), attributes);
EXPECT_EQ(static_cast<UINT32>(FILE_ATTRIBUTE_ARCHIVE), attributes);
EXPECT_FALSE(str_descriptor.empty());
EXPECT_TRUE(utils::file::file(test_file).remove());

View File

@ -26,198 +26,202 @@
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, 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, run_winfsp_tests) {
if (this->provider->is_read_only()) {

View File

@ -111,8 +111,8 @@ auto get_free_drive_space(std::string_view path)
try {
#if defined(_WIN32)
ULARGE_INTEGER li{};
if (not ::GetDiskFreeSpaceEx(std::string{path}.c_str(), &li, nullptr,
nullptr)) {
if (not::GetDiskFreeSpaceEx(std::string{path}.c_str(), &li, nullptr,
nullptr)) {
throw utils::error::create_exception(
function_name, {
"failed to get free disk space",
@ -125,7 +125,7 @@ auto get_free_drive_space(std::string_view path)
#endif // defined(_WIN32)
#if defined(__linux__)
struct statfs64 st {};
struct statfs64 st{};
if (statfs64(std::string{path}.c_str(), &st) != 0) {
throw utils::error::create_exception(
function_name, {
@ -139,7 +139,7 @@ auto get_free_drive_space(std::string_view path)
#endif // defined(__linux__)
#if defined(__APPLE__)
struct statvfs st {};
struct statvfs st{};
if (statvfs(path.c_str(), &st) != 0) {
throw utils::error::create_exception(
function_name, {
@ -165,8 +165,8 @@ auto get_free_drive_space(std::wstring_view path)
return get_free_drive_space(utils::string::to_utf8(path));
}
auto get_time(std::string_view path,
time_type type) -> std::optional<std::uint64_t> {
auto get_time(std::string_view path, time_type type)
-> std::optional<std::uint64_t> {
auto times = get_times(path);
if (times.has_value()) {
return times->get(type);
@ -175,8 +175,8 @@ auto get_time(std::string_view path,
return std::nullopt;
}
auto get_time(std::wstring_view path,
time_type type) -> std::optional<std::uint64_t> {
auto get_time(std::wstring_view path, time_type type)
-> std::optional<std::uint64_t> {
return get_time(utils::string::to_utf8(path), type);
}
@ -207,7 +207,7 @@ auto get_times(std::string_view path) -> std::optional<file_times> {
}
}
struct _stat64 st {};
struct _stat64 st{};
if (_stat64(std::string{path}.c_str(), &st) != 0) {
throw utils::error::create_exception(
function_name, {
@ -222,7 +222,7 @@ auto get_times(std::string_view path) -> std::optional<file_times> {
ret.modified = utils::time::windows_time_t_to_unix_time(st.st_mtime);
ret.written = utils::time::windows_time_t_to_unix_time(st.st_mtime);
#else // !defined(_WIN32)
struct stat64 st {};
struct stat64 st{};
if (stat64(std::string{path}.c_str(), &st) != 0) {
throw utils::error::create_exception(
function_name, {
@ -268,8 +268,8 @@ auto get_total_drive_space(std::string_view path)
try {
#if defined(_WIN32)
ULARGE_INTEGER li{};
if (not ::GetDiskFreeSpaceEx(std::string{path}.c_str(), nullptr, &li,
nullptr)) {
if (not::GetDiskFreeSpaceEx(std::string{path}.c_str(), nullptr, &li,
nullptr)) {
throw utils::error::create_exception(
function_name, {
"failed to get total disk space",
@ -282,7 +282,7 @@ auto get_total_drive_space(std::string_view path)
#endif // defined(_WIN32)
#if defined(__linux__)
struct statfs64 st {};
struct statfs64 st{};
if (statfs64(std::string{path}.c_str(), &st) != 0) {
throw utils::error::create_exception(
function_name, {
@ -296,7 +296,7 @@ auto get_total_drive_space(std::string_view path)
#endif // defined(__linux__)
#if defined(__APPLE__)
struct statvfs st {};
struct statvfs st{};
if (statvfs(path.c_str(), &st) != 0) {
throw utils::error::create_exception(
function_name, {
@ -368,7 +368,7 @@ auto read_json_file(std::string_view path, nlohmann::json &data) -> bool {
try {
auto abs_path = utils::path::absolute(path);
auto file = file::open_file(abs_path);
if (not *file) {
if (not*file) {
return false;
}
@ -416,8 +416,8 @@ auto read_json_file(std::string_view path, nlohmann::json &data) -> bool {
auto write_json_file(std::string_view path, const nlohmann::json &data,
std::optional<std::string_view> password) -> bool {
#else // !defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
auto write_json_file(std::string_view path,
const nlohmann::json &data) -> bool {
auto write_json_file(std::string_view path, const nlohmann::json &data)
-> bool {
#endif // defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
REPERTORY_USES_FUNCTION_NAME();
@ -482,8 +482,8 @@ auto read_json_file(std::wstring_view path, nlohmann::json &data) -> bool {
return read_json_file(utils::string::to_utf8(path), data);
}
auto write_json_file(std::wstring_view path,
const nlohmann::json &data) -> bool {
auto write_json_file(std::wstring_view path, const nlohmann::json &data)
-> bool {
return write_json_file(utils::string::to_utf8(path), data);
}
#endif // defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
@ -498,8 +498,8 @@ static constexpr const auto validate_smb_path =
std::count(path.begin(), path.end(), '/') >= 3U);
};
auto smb_create_smb_path(std::string_view smb_path,
std::string_view rel_path) -> std::string {
auto smb_create_smb_path(std::string_view smb_path, std::string_view rel_path)
-> std::string {
REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) {
@ -532,8 +532,9 @@ auto smb_create_smb_path(std::string_view smb_path,
return path;
}
auto smb_create_and_validate_relative_path(
std::string_view smb_path, std::string_view path) -> std::string {
auto smb_create_and_validate_relative_path(std::string_view smb_path,
std::string_view path)
-> std::string {
REPERTORY_USES_FUNCTION_NAME();
if (not validate_smb_path(smb_path)) {
@ -689,8 +690,8 @@ auto smb_get_uri_path(std::string_view smb_path, std::string_view user,
std::string{smb_path.substr(2U)};
}
auto smb_parent_is_same(std::string_view smb_path1,
std::string_view smb_path2) -> bool {
auto smb_parent_is_same(std::string_view smb_path1, std::string_view smb_path2)
-> bool {
if (not(validate_smb_path(smb_path1) && validate_smb_path(smb_path2))) {
return false;
}