revert
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
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
|
||||
@@ -204,7 +204,9 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
void fuse_drive::destroy_impl(void * /* ptr */) {
|
||||
void fuse_drive::destroy_impl(void *ptr) {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
event_system::instance().raise<drive_unmount_pending>(get_mount_location());
|
||||
|
||||
remote_server_.reset();
|
||||
@@ -240,8 +242,10 @@ void fuse_drive::destroy_impl(void * /* ptr */) {
|
||||
config_.save();
|
||||
|
||||
if (not lock_data_.set_mount_state(false, "", -1)) {
|
||||
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
|
||||
utils::error::raise_error(function_name, "failed to set mount state");
|
||||
}
|
||||
|
||||
fuse_base::destroy_impl(ptr);
|
||||
}
|
||||
|
||||
auto fuse_drive::fallocate_impl(std::string /*api_path*/, int mode,
|
||||
@@ -387,10 +391,12 @@ auto fuse_drive::get_directory_item_count(const std::string &api_path) const
|
||||
|
||||
auto fuse_drive::get_directory_items(const std::string &api_path) const
|
||||
-> directory_item_list {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
directory_item_list list{};
|
||||
auto res = provider_.get_directory_items(api_path, list);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
|
||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||
"failed to get directory items");
|
||||
}
|
||||
|
||||
@@ -399,10 +405,12 @@ auto fuse_drive::get_directory_items(const std::string &api_path) const
|
||||
|
||||
auto fuse_drive::get_file_size(const std::string &api_path) const
|
||||
-> std::uint64_t {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
std::uint64_t file_size{};
|
||||
auto res = provider_.get_file_size(api_path, file_size);
|
||||
if (res == api_error::success) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
|
||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||
"failed to get file size from provider");
|
||||
}
|
||||
|
||||
@@ -519,7 +527,13 @@ auto fuse_drive::init_impl(struct fuse_conn_info *conn, struct fuse_config *cfg)
|
||||
#else
|
||||
void *fuse_drive::init_impl(struct fuse_conn_info *conn) {
|
||||
#endif
|
||||
utils::file::change_to_process_directory();
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto *ret = fuse_drive_base::init_impl(conn, cfg);
|
||||
#else
|
||||
auto *ret = fuse_drive_base::init_impl(conn);
|
||||
#endif
|
||||
|
||||
if (console_enabled_) {
|
||||
console_consumer_ = std::make_unique<console_consumer>();
|
||||
@@ -562,22 +576,18 @@ void *fuse_drive::init_impl(struct fuse_conn_info *conn) {
|
||||
}
|
||||
|
||||
if (not lock_data_.set_mount_state(true, get_mount_location(), getpid())) {
|
||||
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
|
||||
utils::error::raise_error(function_name, "failed to set mount state");
|
||||
}
|
||||
event_system::instance().raise<drive_mounted>(get_mount_location());
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::raise_error(__FUNCTION__, e, "exception during fuse init");
|
||||
utils::error::raise_error(function_name, e, "exception during fuse init");
|
||||
|
||||
destroy_impl(this);
|
||||
|
||||
fuse_exit(fuse_get_context()->fuse);
|
||||
}
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
return fuse_drive_base::init_impl(conn, cfg);
|
||||
#else
|
||||
return fuse_drive_base::init_impl(conn);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto fuse_drive::is_processing(const std::string &api_path) const -> bool {
|
||||
@@ -585,6 +595,8 @@ auto fuse_drive::is_processing(const std::string &api_path) const -> bool {
|
||||
}
|
||||
|
||||
auto fuse_drive::mkdir_impl(std::string api_path, mode_t mode) -> api_error {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
auto res = check_parent_access(api_path, W_OK | X_OK);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
@@ -594,17 +606,18 @@ auto fuse_drive::mkdir_impl(std::string api_path, mode_t mode) -> api_error {
|
||||
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_DIRECTORY, now, now,
|
||||
true, get_effective_gid(), "", mode, now,
|
||||
0U, 0U, 0U, "", get_effective_uid(), now);
|
||||
if ((res = provider_.create_directory(api_path, meta)) !=
|
||||
api_error::success) {
|
||||
res = provider_.create_directory(api_path, meta);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if (api_path != "/") {
|
||||
if ((res = provider_.set_item_meta(
|
||||
utils::path::get_parent_api_path(api_path), META_MODIFIED,
|
||||
std::to_string(now))) != api_error::success) {
|
||||
res = provider_.set_item_meta(utils::path::get_parent_api_path(api_path),
|
||||
META_MODIFIED, std::to_string(now));
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(
|
||||
__FUNCTION__, api_path, res, "failed to set directory modified time");
|
||||
function_name, api_path, res,
|
||||
"failed to set directory modified time");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,13 +674,6 @@ auto fuse_drive::opendir_impl(std::string api_path,
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
void fuse_drive::populate_stat(const directory_item &dir_item,
|
||||
struct stat &st) const {
|
||||
fuse_drive_base::populate_stat(dir_item.api_path, dir_item.size,
|
||||
dir_item.meta, dir_item.directory, provider_,
|
||||
&st);
|
||||
}
|
||||
|
||||
auto fuse_drive::read_impl(std::string api_path, char *buffer, size_t read_size,
|
||||
off_t read_offset, struct fuse_file_info *file_info,
|
||||
std::size_t &bytes_read) -> api_error {
|
||||
@@ -910,8 +916,8 @@ auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size,
|
||||
#endif
|
||||
const auto attribute_name_size = strlen(attribute_name.c_str()) + 1U;
|
||||
if (size >= attribute_name_size) {
|
||||
strncpy(&buffer[required_size], attribute_name.c_str(),
|
||||
attribute_name_size);
|
||||
std::memcpy(&buffer[required_size], attribute_name.data(),
|
||||
attribute_name_size);
|
||||
size -= attribute_name_size;
|
||||
} else {
|
||||
res = api_error::xattr_buffer_small;
|
||||
@@ -1024,9 +1030,11 @@ auto fuse_drive::setxattr_impl(std::string api_path, const char *name,
|
||||
void fuse_drive::set_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
const std::string &value) {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
auto res = provider_.set_item_meta(api_path, key, value);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
|
||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||
"key|" + key + "|value|" + value);
|
||||
}
|
||||
}
|
||||
@@ -1187,10 +1195,11 @@ auto fuse_drive::statfs_x_impl(std::string /*api_path*/, struct statfs *stbuf)
|
||||
stbuf->f_files = 4294967295;
|
||||
stbuf->f_ffree = stbuf->f_files - provider_.get_total_item_count();
|
||||
stbuf->f_owner = getuid();
|
||||
strncpy(&stbuf->f_mntonname[0], get_mount_location().c_str(), MNAMELEN);
|
||||
strncpy(&stbuf->f_mntfromname[0],
|
||||
strncpy(&stbuf->f_mntonname[0U], get_mount_location().c_str(),
|
||||
get_mount_location().size());
|
||||
strncpy(&stbuf->f_mntfromname[0U],
|
||||
(utils::create_volume_label(config_.get_provider_type())).c_str(),
|
||||
MNAMELEN);
|
||||
sizeof(stbuf->f_mntfromname) - 1U);
|
||||
|
||||
return api_error::success;
|
||||
}
|
||||
@@ -1203,11 +1212,10 @@ auto fuse_drive::statfs_impl(std::string /*api_path*/, struct statvfs *stbuf)
|
||||
|
||||
const auto total_bytes = provider_.get_total_drive_space();
|
||||
const auto total_used = provider_.get_used_drive_space();
|
||||
const auto used_blocks = utils::divide_with_ceiling(
|
||||
total_used, static_cast<std::uint64_t>(stbuf->f_frsize));
|
||||
const auto used_blocks =
|
||||
utils::divide_with_ceiling(total_used, stbuf->f_frsize);
|
||||
stbuf->f_files = 4294967295;
|
||||
stbuf->f_blocks = utils::divide_with_ceiling(
|
||||
total_bytes, static_cast<std::uint64_t>(stbuf->f_frsize));
|
||||
stbuf->f_blocks = utils::divide_with_ceiling(total_bytes, stbuf->f_frsize);
|
||||
stbuf->f_bavail = stbuf->f_bfree =
|
||||
stbuf->f_blocks == 0U ? 0 : (stbuf->f_blocks - used_blocks);
|
||||
stbuf->f_ffree = stbuf->f_favail =
|
||||
@@ -1345,11 +1353,13 @@ auto fuse_drive::write_impl(std::string /*api_path*/
|
||||
}
|
||||
|
||||
void fuse_drive::update_accessed_time(const std::string &api_path) {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
if (atime_enabled_) {
|
||||
auto res = provider_.set_item_meta(
|
||||
api_path, META_ACCESSED, std::to_string(utils::get_file_time_now()));
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
|
||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||
"failed to set accessed time");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user