This commit is contained in:
2025-01-21 08:01:15 -06:00
parent b5ae3e4ed1
commit be678e8f9c
11 changed files with 62 additions and 53 deletions

View File

@ -343,7 +343,7 @@ auto sqlite_meta_db::set_item_meta(const std::string &api_path,
// TODO handle error // TODO handle error
} }
for (auto &&item : meta) { for (const auto &item : meta) {
existing_meta[item.first] = item.second; existing_meta[item.first] = item.second;
} }

View File

@ -38,14 +38,15 @@ void directory_cache::execute_action(const std::string &api_path,
auto directory_cache::get_directory(std::uint64_t handle) auto directory_cache::get_directory(std::uint64_t handle)
-> std::shared_ptr<directory_iterator> { -> std::shared_ptr<directory_iterator> {
recur_mutex_lock directory_lock(directory_mutex_); recur_mutex_lock directory_lock(directory_mutex_);
auto it = std::find_if(directory_lookup_.begin(), directory_lookup_.end(), auto iter =
[handle](auto &&kv) -> bool { std::find_if(directory_lookup_.begin(), directory_lookup_.end(),
auto &&handles = kv.second.handles; [handle](auto &&item) -> bool {
return std::find(handles.begin(), handles.end(), auto &&handles = item.second.handles;
handle) != kv.second.handles.end(); return std::find(handles.begin(), handles.end(), handle) !=
item.second.handles.end();
}); });
if (it != directory_lookup_.end()) { if (iter != directory_lookup_.end()) {
return it->second.iterator; return iter->second.iterator;
} }
return nullptr; return nullptr;
@ -66,17 +67,20 @@ auto directory_cache::remove_directory(const std::string &api_path)
void directory_cache::remove_directory(std::uint64_t handle) { void directory_cache::remove_directory(std::uint64_t handle) {
recur_mutex_lock directory_lock(directory_mutex_); recur_mutex_lock directory_lock(directory_mutex_);
auto it = std::find_if(directory_lookup_.begin(), directory_lookup_.end(), auto iter =
[handle](auto &&kv) -> bool { std::find_if(directory_lookup_.begin(), directory_lookup_.end(),
auto &&handles = kv.second.handles; [handle](auto &&item) -> bool {
return std::find(handles.begin(), handles.end(), auto &&handles = item.second.handles;
handle) != kv.second.handles.end(); return std::find(handles.begin(), handles.end(), handle) !=
item.second.handles.end();
}); });
if (it != directory_lookup_.end()) { if (iter == directory_lookup_.end()) {
utils::collection::remove_element(it->second.handles, handle); return;
if (it->second.handles.empty()) {
directory_lookup_.erase(it);
} }
utils::collection::remove_element(iter->second.handles, handle);
if (iter->second.handles.empty()) {
directory_lookup_.erase(iter);
} }
} }
@ -85,22 +89,27 @@ void directory_cache::service_function() {
auto lookup = directory_lookup_; auto lookup = directory_lookup_;
directory_lock.unlock(); directory_lock.unlock();
for (auto &&kv : lookup) { for (const auto &item : lookup) {
if (std::chrono::duration_cast<std::chrono::seconds>( if (std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now() - kv.second.last_update) >= 120s) { std::chrono::system_clock::now() - item.second.last_update) >=
120s) {
directory_lock.lock(); directory_lock.lock();
directory_lookup_.erase(kv.first); directory_lookup_.erase(item.first);
directory_lock.unlock(); directory_lock.unlock();
} }
} }
if (not get_stop_requested()) { if (get_stop_requested()) {
return;
}
unique_mutex_lock shutdown_lock(get_mutex()); unique_mutex_lock shutdown_lock(get_mutex());
if (not get_stop_requested()) { if (get_stop_requested()) {
return;
}
get_notify().wait_for(shutdown_lock, 15s); get_notify().wait_for(shutdown_lock, 15s);
} }
}
}
void directory_cache::set_directory( void directory_cache::set_directory(
const std::string &api_path, std::uint64_t handle, const std::string &api_path, std::uint64_t handle,

View File

@ -632,7 +632,7 @@ auto fuse_base::parse_args(std::vector<std::string> &args) -> int {
} }
const auto option_parts = utils::string::split(options, ',', true); const auto option_parts = utils::string::split(options, ',', true);
for (auto &&option : option_parts) { for (const auto &option : option_parts) {
if (option.find("gid") == 0) { if (option.find("gid") == 0) {
const auto parts = utils::string::split(option, '=', true); const auto parts = utils::string::split(option, '=', true);
if (parts.size() == 2u) { if (parts.size() == 2u) {

View File

@ -958,7 +958,7 @@ auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size,
api_meta_map meta; api_meta_map meta;
res = provider_.get_item_meta(api_path, meta); res = provider_.get_item_meta(api_path, meta);
if (res == api_error::success) { if (res == api_error::success) {
for (auto &&meta_item : meta) { for (const auto &meta_item : meta) {
if (utils::collection::excludes(META_USED_NAMES, meta_item.first)) { if (utils::collection::excludes(META_USED_NAMES, meta_item.first)) {
auto attribute_name = meta_item.first; auto attribute_name = meta_item.first;
#if defined(__APPLE__) #if defined(__APPLE__)

View File

@ -65,7 +65,7 @@ void remote_open_file_table::close_all(const std::string &client_id) {
}); });
lock.unlock(); lock.unlock();
for (auto &&handle : compat_handles) { for (const auto &handle : compat_handles) {
#if defined(_WIN32) #if defined(_WIN32)
_close(static_cast<int>(handle)); _close(static_cast<int>(handle));
#else #else
@ -74,7 +74,7 @@ void remote_open_file_table::close_all(const std::string &client_id) {
remove_compat_open_info(handle); remove_compat_open_info(handle);
} }
for (auto &&handle : handles) { for (const auto &handle : handles) {
#if defined(_WIN32) #if defined(_WIN32)
::CloseHandle(handle); ::CloseHandle(handle);
#else // !defined(_WIN32) #else // !defined(_WIN32)
@ -85,14 +85,14 @@ void remote_open_file_table::close_all(const std::string &client_id) {
std::vector<std::uint64_t> dirs; std::vector<std::uint64_t> dirs;
lock.lock(); lock.lock();
for (auto &&kv : directory_lookup_) { for (const auto &kv : directory_lookup_) {
if (kv.first == client_id) { if (kv.first == client_id) {
dirs.insert(dirs.end(), kv.second.begin(), kv.second.end()); dirs.insert(dirs.end(), kv.second.begin(), kv.second.end());
} }
} }
lock.unlock(); lock.unlock();
for (auto &&dir : dirs) { for (const auto &dir : dirs) {
remove_directory(client_id, dir); remove_directory(client_id, dir);
} }
} }
@ -185,11 +185,11 @@ void remote_open_file_table::remove_all(const std::string &file_path) {
}); });
lock.unlock(); lock.unlock();
for (auto &&handle : compat_open_list) { for (const auto &handle : compat_open_list) {
remove_compat_open_info(handle); remove_compat_open_info(handle);
} }
for (auto &&handle : open_list) { for (const auto &handle : open_list) {
remove_open_info(handle); remove_open_info(handle);
} }
} }
@ -262,7 +262,7 @@ void remote_open_file_table::remove_and_close_all(const native_handle &handle) {
auto op_info = *file_lookup_.at(handle_lookup_.at(handle)); auto op_info = *file_lookup_.at(handle_lookup_.at(handle));
lock.unlock(); lock.unlock();
for (auto &&open_handle : op_info.handles) { for (const auto &open_handle : op_info.handles) {
#if defined(_WIN32) #if defined(_WIN32)
::CloseHandle(open_handle); ::CloseHandle(open_handle);
#else // !defined(_WIN32) #else // !defined(_WIN32)

View File

@ -238,7 +238,7 @@ auto remote_winfsp_drive::mount(const std::vector<std::string> &drive_args)
auto force_no_console = utils::collection::includes(drive_args, "-nc"); auto force_no_console = utils::collection::includes(drive_args, "-nc");
auto enable_console = false; auto enable_console = false;
for (auto &&arg : drive_args) { for (const auto &arg : drive_args) {
if (arg == "-f") { if (arg == "-f") {
if (not force_no_console) { if (not force_no_console) {
enable_console = true; enable_console = true;
@ -352,7 +352,7 @@ auto remote_winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
directory_buffer, static_cast<BOOLEAN>(nullptr == marker), directory_buffer, static_cast<BOOLEAN>(nullptr == marker),
&ret)) { &ret)) {
auto item_found = false; auto item_found = false;
for (auto &&item : item_list) { for (const auto &item : item_list) {
auto item_path = item["path"].get<std::string>(); auto item_path = item["path"].get<std::string>();
auto display_name = utils::string::from_utf8( auto display_name = utils::string::from_utf8(
utils::path::strip_to_file_name(item_path)); utils::path::strip_to_file_name(item_path));

View File

@ -583,7 +583,7 @@ auto winfsp_drive::mount(const std::vector<std::string> &drive_args) -> int {
auto force_no_console = utils::collection::includes(drive_args, "-nc"); auto force_no_console = utils::collection::includes(drive_args, "-nc");
auto enable_console = false; auto enable_console = false;
for (auto &&arg : drive_args) { for (const auto &arg : drive_args) {
if (arg == "-f") { if (arg == "-f") {
if (not force_no_console) { if (not force_no_console) {
enable_console = true; enable_console = true;

View File

@ -146,7 +146,7 @@ void polling::stop() {
notify_.notify_all(); notify_.notify_all();
thread_lock.unlock(); thread_lock.unlock();
for (auto &&thread : frequency_threads_) { for (auto &thread : frequency_threads_) {
thread->join(); thread->join();
thread.reset(); thread.reset();
} }

View File

@ -103,7 +103,7 @@ TYPED_TEST(fuse_test, access_directory_permutations_test) {
std::string dir_name{"access_test"}; std::string dir_name{"access_test"};
auto dir_path = this->create_directory_and_test(dir_name); auto dir_path = this->create_directory_and_test(dir_name);
for (auto &&permutation : access_permutations) { for (const auto &permutation : access_permutations) {
perform_access_test(permutation, dir_path); perform_access_test(permutation, dir_path);
} }
@ -114,7 +114,7 @@ TYPED_TEST(fuse_test, access_file_permutations_test) {
std::string file_name{"access_test"}; std::string file_name{"access_test"};
auto file_path = this->create_file_and_test(file_name); auto file_path = this->create_file_and_test(file_name);
for (auto &&permutation : access_permutations) { for (const auto &permutation : access_permutations) {
perform_access_test(permutation, file_path); perform_access_test(permutation, file_path);
} }

View File

@ -376,7 +376,7 @@ TYPED_TEST(fuse_test, create_fails_with_excl_if_path_is_directory) {
std::string dir_name{"create_test"}; std::string dir_name{"create_test"};
auto dir_path = this->create_directory_and_test(dir_name); auto dir_path = this->create_directory_and_test(dir_name);
for (auto &&flags : ops) { for (const auto &flags : ops) {
auto handle = open(dir_path.c_str(), flags, ACCESSPERMS); auto handle = open(dir_path.c_str(), flags, ACCESSPERMS);
EXPECT_EQ(-1, handle); EXPECT_EQ(-1, handle);
@ -396,7 +396,7 @@ TYPED_TEST(fuse_test, create_fails_with_excl_if_file_exists) {
std::string file_name{"create_test"}; std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name); auto file_path = this->create_file_and_test(file_name);
for (auto &&flags : ops) { for (const auto &flags : ops) {
auto handle = open(file_path.c_str(), flags, ACCESSPERMS); auto handle = open(file_path.c_str(), flags, ACCESSPERMS);
EXPECT_EQ(-1, handle); EXPECT_EQ(-1, handle);
@ -420,7 +420,7 @@ TYPED_TEST(fuse_test, create_fails_if_path_is_directory) {
std::string dir_name{"create_test"}; std::string dir_name{"create_test"};
auto dir_path = this->create_directory_and_test(dir_name); auto dir_path = this->create_directory_and_test(dir_name);
for (auto &&flags : ops) { for (const auto &flags : ops) {
auto handle = open(dir_path.c_str(), flags, ACCESSPERMS); auto handle = open(dir_path.c_str(), flags, ACCESSPERMS);
EXPECT_EQ(-1, handle); EXPECT_EQ(-1, handle);
@ -447,7 +447,7 @@ TYPED_TEST(fuse_test, create_fails_if_parent_path_does_not_exist) {
std::string file_name{"no_dir/create_test"}; std::string file_name{"no_dir/create_test"};
auto file_path = this->create_file_path(file_name); auto file_path = this->create_file_path(file_name);
for (auto &&flags : ops) { for (const auto &flags : ops) {
auto handle = open(file_path.c_str(), flags, ACCESSPERMS); auto handle = open(file_path.c_str(), flags, ACCESSPERMS);
EXPECT_EQ(-1, handle); EXPECT_EQ(-1, handle);
@ -463,7 +463,7 @@ TYPED_TEST(fuse_test, create_fails_if_invalid) {
std::string file_name{"create_test"}; std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name); auto file_path = this->create_file_path(file_name);
for (auto &&flags : ops) { for (const auto &flags : ops) {
auto handle = open(file_path.c_str(), flags, ACCESSPERMS); auto handle = open(file_path.c_str(), flags, ACCESSPERMS);
EXPECT_EQ(-1, handle); EXPECT_EQ(-1, handle);
@ -481,7 +481,7 @@ TYPED_TEST(fuse_test, create_open_fails_if_path_is_directory) {
std::string dir_name{"create_test"}; std::string dir_name{"create_test"};
auto dir_path = this->create_directory_and_test(dir_name); auto dir_path = this->create_directory_and_test(dir_name);
for (auto &&flags : ops) { for (const auto &flags : ops) {
auto handle = open(dir_path.c_str(), flags); auto handle = open(dir_path.c_str(), flags);
EXPECT_EQ(-1, handle); EXPECT_EQ(-1, handle);
if (handle != -1) { if (handle != -1) {
@ -510,7 +510,7 @@ TYPED_TEST(fuse_test, create_open_fails_if_path_does_not_exist) {
std::string file_name{"create_test"}; std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name); auto file_path = this->create_file_path(file_name);
for (auto &&flags : ops) { for (const auto &flags : ops) {
auto handle = open(file_path.c_str(), flags); auto handle = open(file_path.c_str(), flags);
EXPECT_EQ(-1, handle); EXPECT_EQ(-1, handle);
EXPECT_EQ(ENOENT, errno); EXPECT_EQ(ENOENT, errno);

View File

@ -97,7 +97,7 @@ TYPED_TEST(winfsp_test, cr8_file_can_delete_file_after_close) {
TYPED_TEST(winfsp_test, TYPED_TEST(winfsp_test,
cr8_file_cannot_create_files_with_invalid_characters_in_path) { cr8_file_cannot_create_files_with_invalid_characters_in_path) {
for (auto &&invalid_char : std::array<std::string, 7U>{ for (const auto &invalid_char : std::array<std::string, 7U>{
{"*", ":", "<", ">", "?", "|", "\""}, {"*", ":", "<", ">", "?", "|", "\""},
}) { }) {
auto handle = ::CreateFileA( auto handle = ::CreateFileA(