refactor
This commit is contained in:
@ -343,7 +343,7 @@ auto sqlite_meta_db::set_item_meta(const std::string &api_path,
|
||||
// TODO handle error
|
||||
}
|
||||
|
||||
for (auto &&item : meta) {
|
||||
for (const auto &item : meta) {
|
||||
existing_meta[item.first] = item.second;
|
||||
}
|
||||
|
||||
|
@ -38,14 +38,15 @@ void directory_cache::execute_action(const std::string &api_path,
|
||||
auto directory_cache::get_directory(std::uint64_t handle)
|
||||
-> std::shared_ptr<directory_iterator> {
|
||||
recur_mutex_lock directory_lock(directory_mutex_);
|
||||
auto it = std::find_if(directory_lookup_.begin(), directory_lookup_.end(),
|
||||
[handle](auto &&kv) -> bool {
|
||||
auto &&handles = kv.second.handles;
|
||||
return std::find(handles.begin(), handles.end(),
|
||||
handle) != kv.second.handles.end();
|
||||
});
|
||||
if (it != directory_lookup_.end()) {
|
||||
return it->second.iterator;
|
||||
auto iter =
|
||||
std::find_if(directory_lookup_.begin(), directory_lookup_.end(),
|
||||
[handle](auto &&item) -> bool {
|
||||
auto &&handles = item.second.handles;
|
||||
return std::find(handles.begin(), handles.end(), handle) !=
|
||||
item.second.handles.end();
|
||||
});
|
||||
if (iter != directory_lookup_.end()) {
|
||||
return iter->second.iterator;
|
||||
}
|
||||
|
||||
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) {
|
||||
recur_mutex_lock directory_lock(directory_mutex_);
|
||||
auto it = std::find_if(directory_lookup_.begin(), directory_lookup_.end(),
|
||||
[handle](auto &&kv) -> bool {
|
||||
auto &&handles = kv.second.handles;
|
||||
return std::find(handles.begin(), handles.end(),
|
||||
handle) != kv.second.handles.end();
|
||||
});
|
||||
if (it != directory_lookup_.end()) {
|
||||
utils::collection::remove_element(it->second.handles, handle);
|
||||
if (it->second.handles.empty()) {
|
||||
directory_lookup_.erase(it);
|
||||
}
|
||||
auto iter =
|
||||
std::find_if(directory_lookup_.begin(), directory_lookup_.end(),
|
||||
[handle](auto &&item) -> bool {
|
||||
auto &&handles = item.second.handles;
|
||||
return std::find(handles.begin(), handles.end(), handle) !=
|
||||
item.second.handles.end();
|
||||
});
|
||||
if (iter == directory_lookup_.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
utils::collection::remove_element(iter->second.handles, handle);
|
||||
if (iter->second.handles.empty()) {
|
||||
directory_lookup_.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,21 +89,26 @@ void directory_cache::service_function() {
|
||||
auto lookup = directory_lookup_;
|
||||
directory_lock.unlock();
|
||||
|
||||
for (auto &&kv : lookup) {
|
||||
for (const auto &item : lookup) {
|
||||
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_lookup_.erase(kv.first);
|
||||
directory_lookup_.erase(item.first);
|
||||
directory_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
if (not get_stop_requested()) {
|
||||
unique_mutex_lock shutdown_lock(get_mutex());
|
||||
if (not get_stop_requested()) {
|
||||
get_notify().wait_for(shutdown_lock, 15s);
|
||||
}
|
||||
if (get_stop_requested()) {
|
||||
return;
|
||||
}
|
||||
|
||||
unique_mutex_lock shutdown_lock(get_mutex());
|
||||
if (get_stop_requested()) {
|
||||
return;
|
||||
}
|
||||
|
||||
get_notify().wait_for(shutdown_lock, 15s);
|
||||
}
|
||||
|
||||
void directory_cache::set_directory(
|
||||
|
@ -632,7 +632,7 @@ auto fuse_base::parse_args(std::vector<std::string> &args) -> int {
|
||||
}
|
||||
|
||||
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) {
|
||||
const auto parts = utils::string::split(option, '=', true);
|
||||
if (parts.size() == 2u) {
|
||||
|
@ -958,7 +958,7 @@ auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size,
|
||||
api_meta_map meta;
|
||||
res = provider_.get_item_meta(api_path, meta);
|
||||
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)) {
|
||||
auto attribute_name = meta_item.first;
|
||||
#if defined(__APPLE__)
|
||||
|
@ -65,7 +65,7 @@ void remote_open_file_table::close_all(const std::string &client_id) {
|
||||
});
|
||||
lock.unlock();
|
||||
|
||||
for (auto &&handle : compat_handles) {
|
||||
for (const auto &handle : compat_handles) {
|
||||
#if defined(_WIN32)
|
||||
_close(static_cast<int>(handle));
|
||||
#else
|
||||
@ -74,7 +74,7 @@ void remote_open_file_table::close_all(const std::string &client_id) {
|
||||
remove_compat_open_info(handle);
|
||||
}
|
||||
|
||||
for (auto &&handle : handles) {
|
||||
for (const auto &handle : handles) {
|
||||
#if defined(_WIN32)
|
||||
::CloseHandle(handle);
|
||||
#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;
|
||||
lock.lock();
|
||||
for (auto &&kv : directory_lookup_) {
|
||||
for (const auto &kv : directory_lookup_) {
|
||||
if (kv.first == client_id) {
|
||||
dirs.insert(dirs.end(), kv.second.begin(), kv.second.end());
|
||||
}
|
||||
}
|
||||
lock.unlock();
|
||||
|
||||
for (auto &&dir : dirs) {
|
||||
for (const auto &dir : dirs) {
|
||||
remove_directory(client_id, dir);
|
||||
}
|
||||
}
|
||||
@ -185,11 +185,11 @@ void remote_open_file_table::remove_all(const std::string &file_path) {
|
||||
});
|
||||
lock.unlock();
|
||||
|
||||
for (auto &&handle : compat_open_list) {
|
||||
for (const auto &handle : compat_open_list) {
|
||||
remove_compat_open_info(handle);
|
||||
}
|
||||
|
||||
for (auto &&handle : open_list) {
|
||||
for (const auto &handle : open_list) {
|
||||
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));
|
||||
lock.unlock();
|
||||
|
||||
for (auto &&open_handle : op_info.handles) {
|
||||
for (const auto &open_handle : op_info.handles) {
|
||||
#if defined(_WIN32)
|
||||
::CloseHandle(open_handle);
|
||||
#else // !defined(_WIN32)
|
||||
|
@ -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 enable_console = false;
|
||||
for (auto &&arg : drive_args) {
|
||||
for (const auto &arg : drive_args) {
|
||||
if (arg == "-f") {
|
||||
if (not force_no_console) {
|
||||
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),
|
||||
&ret)) {
|
||||
auto item_found = false;
|
||||
for (auto &&item : item_list) {
|
||||
for (const auto &item : item_list) {
|
||||
auto item_path = item["path"].get<std::string>();
|
||||
auto display_name = utils::string::from_utf8(
|
||||
utils::path::strip_to_file_name(item_path));
|
||||
|
@ -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 enable_console = false;
|
||||
for (auto &&arg : drive_args) {
|
||||
for (const auto &arg : drive_args) {
|
||||
if (arg == "-f") {
|
||||
if (not force_no_console) {
|
||||
enable_console = true;
|
||||
|
@ -146,7 +146,7 @@ void polling::stop() {
|
||||
notify_.notify_all();
|
||||
thread_lock.unlock();
|
||||
|
||||
for (auto &&thread : frequency_threads_) {
|
||||
for (auto &thread : frequency_threads_) {
|
||||
thread->join();
|
||||
thread.reset();
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ TYPED_TEST(fuse_test, access_directory_permutations_test) {
|
||||
std::string dir_name{"access_test"};
|
||||
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);
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ TYPED_TEST(fuse_test, access_file_permutations_test) {
|
||||
std::string file_name{"access_test"};
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ TYPED_TEST(fuse_test, create_can_create_directory_with_specific_perms) {
|
||||
std::string dir_name{"create_test"};
|
||||
auto dir_path = this->create_directory_and_test(dir_name, S_IRUSR);
|
||||
|
||||
struct stat64 unix_st {};
|
||||
struct stat64 unix_st{};
|
||||
EXPECT_EQ(0, stat64(dir_path.c_str(), &unix_st));
|
||||
EXPECT_EQ(S_IRUSR, unix_st.st_mode & ACCESSPERMS);
|
||||
|
||||
@ -52,7 +52,7 @@ TYPED_TEST(fuse_test, create_can_create_file_with_specific_perms) {
|
||||
std::string file_name{"create_test"};
|
||||
auto file_path = this->create_file_and_test(file_name, S_IRUSR);
|
||||
|
||||
struct stat64 unix_st {};
|
||||
struct stat64 unix_st{};
|
||||
EXPECT_EQ(0, stat64(file_path.c_str(), &unix_st));
|
||||
EXPECT_EQ(S_IRUSR, unix_st.st_mode & ACCESSPERMS);
|
||||
|
||||
@ -376,7 +376,7 @@ TYPED_TEST(fuse_test, create_fails_with_excl_if_path_is_directory) {
|
||||
std::string dir_name{"create_test"};
|
||||
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);
|
||||
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"};
|
||||
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);
|
||||
EXPECT_EQ(-1, handle);
|
||||
|
||||
@ -420,7 +420,7 @@ TYPED_TEST(fuse_test, create_fails_if_path_is_directory) {
|
||||
std::string dir_name{"create_test"};
|
||||
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);
|
||||
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"};
|
||||
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);
|
||||
EXPECT_EQ(-1, handle);
|
||||
|
||||
@ -463,7 +463,7 @@ TYPED_TEST(fuse_test, create_fails_if_invalid) {
|
||||
std::string file_name{"create_test"};
|
||||
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);
|
||||
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"};
|
||||
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);
|
||||
EXPECT_EQ(-1, handle);
|
||||
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"};
|
||||
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);
|
||||
EXPECT_EQ(-1, handle);
|
||||
EXPECT_EQ(ENOENT, errno);
|
||||
|
@ -97,7 +97,7 @@ TYPED_TEST(winfsp_test, cr8_file_can_delete_file_after_close) {
|
||||
|
||||
TYPED_TEST(winfsp_test,
|
||||
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(
|
||||
|
Reference in New Issue
Block a user