diff --git a/repertory/librepertory/src/drives/fuse/fuse_drive.cpp b/repertory/librepertory/src/drives/fuse/fuse_drive.cpp index b9e555f3..878988f0 100644 --- a/repertory/librepertory/src/drives/fuse/fuse_drive.cpp +++ b/repertory/librepertory/src/drives/fuse/fuse_drive.cpp @@ -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); diff --git a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp index 34c0d52c..399a5308 100644 --- a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp +++ b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp @@ -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(handle), EBADF); if (res == 0) { directory = utils::file::directory(file_path).exists(); - struct stat64 unix_st {}; + struct stat64 unix_st{}; res = fstat64(static_cast(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(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(~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(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(file_desc); @@ -1315,10 +1328,9 @@ auto remote_server::winfsp_overwrite( } if (set_attributes) { - attributes &= static_cast( - ~(FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_NORMAL)); + attributes &= static_cast(~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(~(FILE_ATTRIBUTE_NORMAL)); + attributes &= static_cast(~FILE_ATTRIBUTE_NORMAL); + if (attributes == = 0U) { + attributes |= static_cast(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(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() ? 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()); } diff --git a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp index 46152371..5a4ef6bb 100644 --- a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp +++ b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp @@ -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(~FILE_ATTRIBUTE_DIRECTORY); - } - - if (attributes == 0U) { - attributes = FILE_ATTRIBUTE_NORMAL; + attributes &= static_cast( + ~(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, diff --git a/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp b/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp index e6e5316c..0fb044b9 100644 --- a/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp +++ b/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp @@ -301,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(~FILE_ATTRIBUTE_DIRECTORY); - } - - if (attributes == 0U) { - attributes = FILE_ATTRIBUTE_NORMAL; + attributes &= static_cast( + ~(FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_NORMAL)); + attributes |= FILE_ATTRIBUTE_ARCHIVE; } const auto now = utils::time::get_time_now(); @@ -567,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); @@ -745,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); @@ -813,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); @@ -1025,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(~FILE_ATTRIBUTE_NORMAL); + auto next_attributes = + attributes & static_cast(~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( diff --git a/repertory/librepertory/src/platform/unix_platform.cpp b/repertory/librepertory/src/platform/unix_platform.cpp index 3803a573..14cd0c41 100644 --- a/repertory/librepertory/src/platform/unix_platform.cpp +++ b/repertory/librepertory/src/platform/unix_platform.cpp @@ -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, diff --git a/repertory/librepertory/src/platform/win32_platform.cpp b/repertory/librepertory/src/platform/win32_platform.cpp index de108672..13630adf 100644 --- a/repertory/librepertory/src/platform/win32_platform.cpp +++ b/repertory/librepertory/src/platform/win32_platform.cpp @@ -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); diff --git a/repertory/librepertory/src/utils/utils.cpp b/repertory/librepertory/src/utils/utils.cpp index 72a1b855..86183424 100644 --- a/repertory/librepertory/src/utils/utils.cpp +++ b/repertory/librepertory/src/utils/utils.cpp @@ -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; diff --git a/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp b/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp index 62c11160..cd21ea54 100644 --- a/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp +++ b/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp @@ -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; } diff --git a/repertory/repertory_test/include/mocks/mock_winfsp_drive.hpp b/repertory/repertory_test/include/mocks/mock_winfsp_drive.hpp index e30c3c1f..3ed202d7 100644 --- a/repertory/repertory_test/include/mocks/mock_winfsp_drive.hpp +++ b/repertory/repertory_test/include/mocks/mock_winfsp_drive.hpp @@ -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(share_mode), diff --git a/repertory/repertory_test/src/file_manager_test.cpp b/repertory/repertory_test/src/file_manager_test.cpp index 091a479a..19d0f313 100644 --- a/repertory/repertory_test/src/file_manager_test.cpp +++ b/repertory/repertory_test/src/file_manager_test.cpp @@ -130,9 +130,9 @@ TEST_F(file_manager_test, can_create_and_close_file) { std::shared_ptr 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 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 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); diff --git a/repertory/repertory_test/src/remote_winfsp_test.cpp b/repertory/repertory_test/src/remote_winfsp_test.cpp index 2b62746c..f756daee 100644 --- a/repertory/repertory_test/src/remote_winfsp_test.cpp +++ b/repertory/repertory_test/src/remote_winfsp_test.cpp @@ -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(FILE_ATTRIBUTE_NORMAL), attributes); + EXPECT_EQ(static_cast(FILE_ATTRIBUTE_ARCHIVE), attributes); EXPECT_FALSE(str_descriptor.empty()); EXPECT_TRUE(utils::file::file(test_file).remove());