refactor
This commit is contained in:
parent
1eec19c583
commit
fe0fef2f21
@ -96,6 +96,7 @@ expect_streq
|
||||
fallocate_impl
|
||||
fext
|
||||
fgetattr
|
||||
fgetattr_impl
|
||||
filebase
|
||||
flac_version
|
||||
flag_nopath
|
||||
|
@ -205,19 +205,24 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
|
||||
if ((res != api_error::item_exists) && (res != api_error::success)) {
|
||||
return res;
|
||||
}
|
||||
} else if (((res = fm_->open(api_path, is_directory_op, file_info->flags,
|
||||
handle, open_file)) != api_error::success)) {
|
||||
} else {
|
||||
res = fm_->open(api_path, is_directory_op, file_info->flags, handle,
|
||||
open_file);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file_info->fh = handle;
|
||||
if (is_truncate_op) {
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
if ((res = truncate_impl(api_path, 0, file_info)) != api_error::success) {
|
||||
#else
|
||||
if ((res = ftruncate_impl(api_path, 0, file_info)) != api_error::success) {
|
||||
#endif
|
||||
res = truncate_impl(api_path, 0, file_info);
|
||||
if (res != api_error::success) {
|
||||
#else // FUSE_USE_VERSION < 30
|
||||
res = ftruncate_impl(api_path, 0, file_info);
|
||||
if (res != api_error::success) {
|
||||
#endif // FUSE_USE_VERSION >= 30
|
||||
fm_->close(handle);
|
||||
file_info->fh = 0U;
|
||||
errno = std::abs(utils::from_api_error(res));
|
||||
@ -286,9 +291,9 @@ auto fuse_drive::fallocate_impl(std::string /*api_path*/, int mode,
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((res = check_open_flags(
|
||||
open_file->get_open_data(file_info->fh), O_WRONLY | O_APPEND,
|
||||
api_error::invalid_handle)) != api_error::success) {
|
||||
res = check_open_flags(open_file->get_open_data(file_info->fh),
|
||||
O_WRONLY | O_APPEND, api_error::invalid_handle);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -476,8 +481,8 @@ auto fuse_drive::getattr_impl(std::string api_path,
|
||||
auto found = false;
|
||||
directory_cache_->execute_action(parent, [&](directory_iterator &iter) {
|
||||
directory_item dir_item{};
|
||||
if ((found = (iter.get_directory_item(api_path, dir_item) ==
|
||||
api_error::success))) {
|
||||
found = (iter.get_directory_item(api_path, dir_item) == api_error::success);
|
||||
if (found) {
|
||||
fuse_drive_base::populate_stat(api_path, dir_item.size, dir_item.meta,
|
||||
dir_item.directory, provider_, st);
|
||||
}
|
||||
@ -485,7 +490,8 @@ auto fuse_drive::getattr_impl(std::string api_path,
|
||||
|
||||
if (not found) {
|
||||
api_meta_map meta{};
|
||||
if ((res = provider_.get_item_meta(api_path, meta)) != api_error::success) {
|
||||
res = provider_.get_item_meta(api_path, meta);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -672,7 +678,8 @@ auto fuse_drive::opendir_impl(std::string api_path,
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((res = check_parent_access(api_path, mask)) != api_error::success) {
|
||||
res = check_parent_access(api_path, mask);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -686,8 +693,8 @@ auto fuse_drive::opendir_impl(std::string api_path,
|
||||
}
|
||||
|
||||
directory_item_list list{};
|
||||
if ((res = provider_.get_directory_items(api_path, list)) !=
|
||||
api_error::success) {
|
||||
res = provider_.get_directory_items(api_path, list);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -715,7 +722,8 @@ auto fuse_drive::read_impl(std::string api_path, char *buffer, size_t read_size,
|
||||
data_buffer data;
|
||||
res =
|
||||
open_file->read(read_size, static_cast<std::uint64_t>(read_offset), data);
|
||||
if ((bytes_read = data.size()) != 0U) {
|
||||
bytes_read = data.size();
|
||||
if (bytes_read != 0U) {
|
||||
std::memcpy(buffer, data.data(), data.size());
|
||||
data.clear();
|
||||
update_accessed_time(api_path);
|
||||
@ -809,8 +817,8 @@ auto fuse_drive::rename_impl(std::string from_api_path,
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((res = check_parent_access(from_api_path, W_OK | X_OK)) !=
|
||||
api_error::success) {
|
||||
res = check_parent_access(from_api_path, W_OK | X_OK);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -837,7 +845,8 @@ auto fuse_drive::rmdir_impl(std::string api_path) -> api_error {
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((res = provider_.remove_directory(api_path)) != api_error::success) {
|
||||
res = provider_.remove_directory(api_path);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -862,42 +871,48 @@ auto fuse_drive::getxattr_common(std::string api_path, const char *name,
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((res = check_parent_access(api_path, X_OK)) != api_error::success) {
|
||||
res = check_parent_access(api_path, X_OK);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
api_meta_map meta;
|
||||
auto found = false;
|
||||
auto found{false};
|
||||
directory_cache_->execute_action(
|
||||
utils::path::get_parent_api_path(api_path),
|
||||
[&](directory_iterator &iterator) {
|
||||
directory_item dir_item{};
|
||||
if ((found = (iterator.get_directory_item(api_path, dir_item) ==
|
||||
api_error::success))) {
|
||||
found = (iterator.get_directory_item(api_path, dir_item) ==
|
||||
api_error::success);
|
||||
if (found) {
|
||||
meta = dir_item.meta;
|
||||
}
|
||||
});
|
||||
|
||||
if (found ||
|
||||
((res = provider_.get_item_meta(api_path, meta)) == api_error::success)) {
|
||||
res = api_error::xattr_not_found;
|
||||
if (meta.find(attribute_name) != meta.end()) {
|
||||
auto data = macaron::Base64::Decode(meta[attribute_name]);
|
||||
if ((position == nullptr) || (*position < data.size())) {
|
||||
res = api_error::success;
|
||||
attribute_size = static_cast<int>(data.size());
|
||||
if (size != 0U) {
|
||||
res = api_error::xattr_buffer_small;
|
||||
if (size >= data.size()) {
|
||||
memcpy(value, data.data(), data.size());
|
||||
return api_error::success;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
res = found ? api_error::success : provider_.get_item_meta(api_path, meta);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
return res;
|
||||
if (meta.find(attribute_name) == meta.end()) {
|
||||
return api_error::xattr_not_found;
|
||||
}
|
||||
|
||||
auto data = macaron::Base64::Decode(meta.at(attribute_name));
|
||||
if ((position == nullptr) || (*position < data.size())) {
|
||||
attribute_size = static_cast<int>(data.size());
|
||||
if (size == 0U) {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
if (size < data.size()) {
|
||||
return api_error::xattr_buffer_small;
|
||||
}
|
||||
|
||||
std::memcpy(value, data.data(), data.size());
|
||||
}
|
||||
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
#if defined(__APPLE__)
|
||||
@ -926,7 +941,8 @@ auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size,
|
||||
}
|
||||
|
||||
api_meta_map meta;
|
||||
if ((res = provider_.get_item_meta(api_path, meta)) == api_error::success) {
|
||||
res = provider_.get_item_meta(api_path, meta);
|
||||
if (res == api_error::success) {
|
||||
for (auto &&meta_item : meta) {
|
||||
if (utils::collection::excludes(META_USED_NAMES, meta_item.first)) {
|
||||
auto attribute_name = meta_item.first;
|
||||
@ -1019,15 +1035,18 @@ auto fuse_drive::setxattr_impl(std::string api_path, const char *name,
|
||||
}
|
||||
|
||||
api_meta_map meta;
|
||||
if ((res = provider_.get_item_meta(api_path, meta)) != api_error::success) {
|
||||
res = provider_.get_item_meta(api_path, meta);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((res = check_parent_access(api_path, X_OK)) != api_error::success) {
|
||||
res = check_parent_access(api_path, X_OK);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((res = check_owner(meta)) != api_error::success) {
|
||||
res = check_owner(meta);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -1257,12 +1276,12 @@ auto fuse_drive::truncate_impl(std::string api_path, off_t size) -> api_error {
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((res = check_parent_access(api_path, X_OK)) != api_error::success) {
|
||||
res = check_parent_access(api_path, X_OK);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((res = check_access(api_path, W_OK)) != api_error::success) {
|
||||
res = check_access(api_path, W_OK);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -1270,8 +1289,8 @@ auto fuse_drive::truncate_impl(std::string api_path, off_t size) -> api_error {
|
||||
{
|
||||
open_file_data ofd{O_RDWR};
|
||||
std::shared_ptr<i_open_file> open_file;
|
||||
if ((res = fm_->open(api_path, false, ofd, handle, open_file)) !=
|
||||
api_error::success) {
|
||||
res = fm_->open(api_path, false, ofd, handle, open_file);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -1314,7 +1333,8 @@ auto fuse_drive::utimens_impl(std::string api_path,
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((res = check_owner(meta)) != api_error::success) {
|
||||
res = check_owner(meta);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user