From 6cae320556413e6d180d82749fc4bcd4ff6292e0 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 28 Aug 2024 17:43:13 -0500 Subject: [PATCH 1/2] fix --- .../src/drives/winfsp/winfsp_drive.cpp | 9 +--- .../providers/encrypt/encrypt_provider.cpp | 49 ++++++------------- repertory/repertory_test/src/winfsp_test.cpp | 2 +- 3 files changed, 18 insertions(+), 42 deletions(-) diff --git a/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp b/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp index 4abf8033..a1b77ca4 100644 --- a/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp +++ b/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp @@ -510,14 +510,10 @@ auto winfsp_drive::GetSecurityByName(PWSTR file_name, PUINT32 attributes, std::uint64_t sds = descriptor_size == nullptr ? 0U : *descriptor_size; auto ret = get_security_by_name(file_name, attributes, descriptor, sds > 0U ? &sds : nullptr); - if (attributes != nullptr) { - event_system::instance().raise( - std::string{function_name}, api_path, - std::to_string(*attributes & FILE_ATTRIBUTE_DIRECTORY)); - } if (sds != 0U) { *descriptor_size = static_cast(sds); } + RAISE_WINFSP_EVENT(function_name, api_path, ret); return ret; } @@ -713,8 +709,6 @@ auto winfsp_drive::Open(PWSTR file_name, UINT32 create_options, std::uint64_t handle{}; std::shared_ptr file; error = fm_->open(api_path, directory, ofd, handle, file); - event_system::instance().raise( - std::string{function_name}, api_path, std::to_string(handle)); if (error == api_error::success) { api_meta_map meta; error = provider_.get_item_meta(api_path, meta); @@ -905,7 +899,6 @@ auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc, static constexpr const std::string_view function_name{ static_cast(__FUNCTION__), }; - event_system::instance().raise(std::string{function_name}, "", ""); std::string api_path; auto error = api_error::invalid_handle; diff --git a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp index 106f4cec..cefc6d01 100644 --- a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp +++ b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp @@ -78,10 +78,7 @@ auto encrypt_provider::create_api_file( #if defined(_WIN32) struct _stat64 buf {}; - auto res = _stat64(source_path.c_str(), &buf); - event_system::instance().raise( - std::string{function_name}, source_path, - std::to_string(res) + ':' + std::to_string(directory)); + _stat64(source_path.c_str(), &buf); #else struct stat buf {}; stat(source_path.c_str(), &buf); @@ -137,15 +134,9 @@ auto encrypt_provider::create_api_file( void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory, const api_file &file) { - static constexpr const std::string_view function_name{ - static_cast(__FUNCTION__), - }; - #if defined(_WIN32) struct _stat64 buf {}; - auto res = _stat64(file.source_path.c_str(), &buf); - event_system::instance().raise( - std::string{function_name}, file.source_path, std::to_string(res)); + _stat64(file.source_path.c_str(), &buf); #else struct stat buf {}; stat(file.source_path.c_str(), &buf); @@ -153,12 +144,21 @@ void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory, meta[META_ACCESSED] = std::to_string(file.accessed_date); #if defined(_WIN32) - meta[META_ATTRIBUTES] = - std::to_string(::GetFileAttributesA(file.source_path.c_str())); -#endif + meta[META_ATTRIBUTES] = std::to_string( + ::GetFileAttributesA(file.source_path.c_str()) & + ~(FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_COMPRESSED | + FILE_ATTRIBUTE_DEVICE | FILE_ATTRIBUTE_TEMPORARY | + FILE_ATTRIBUTE_SPARSE_FILE | FILE_ATTRIBUTE_OFFLINE | + FILE_ATTRIBUTE_NOT_CONTENT_INDEXED | FILE_ATTRIBUTE_ENCRYPTED | + FILE_ATTRIBUTE_INTEGRITY_STREAM | FILE_ATTRIBUTE_VIRTUAL | + FILE_ATTRIBUTE_NO_SCRUB_DATA | FILE_ATTRIBUTE_EA | + FILE_ATTRIBUTE_PINNED | FILE_ATTRIBUTE_UNPINNED | + FILE_ATTRIBUTE_RECALL_ON_OPEN | FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS)); +#endif // defined(_WIN32) + #if defined(__APPLE__) meta[META_BACKUP]; -#endif +#endif // defined(__APPLE__) meta[META_CHANGED] = std::to_string(file.changed_date); meta[META_CREATION] = std::to_string(file.creation_date); meta[META_DIRECTORY] = utils::string::from_bool(directory); @@ -167,7 +167,7 @@ void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory, meta[META_MODIFIED] = std::to_string(file.modified_date); #if defined(__APPLE__) meta[META_OSXFLAGS]; -#endif +#endif // defined(__APPLE__) meta[META_SIZE] = std::to_string(file.file_size); meta[META_SOURCE] = file.source_path; meta[META_UID] = std::to_string(buf.st_uid); @@ -448,13 +448,9 @@ auto encrypt_provider::get_file_list(api_file_list &list) const -> api_error { }; const auto cfg = config_.get_encrypt_config(); - event_system::instance().raise(std::string{function_name}, - cfg.path, ""); try { for (auto &&dir_entry : utils::file::directory{cfg.path}.get_items()) { - event_system::instance().raise( - std::string{function_name}, cfg.path, dir_entry->get_path()); std::string api_path{}; if (process_directory_entry(*dir_entry.get(), cfg, api_path)) { list.emplace_back(create_api_file( @@ -503,10 +499,6 @@ auto encrypt_provider::get_file_size( auto encrypt_provider::get_filesystem_item( const std::string &api_path, bool directory, filesystem_item &fsi) const -> api_error { - static constexpr const std::string_view function_name{ - static_cast(__FUNCTION__), - }; - auto result = db::db_select{*db_, source_table} .column("source_path") .where("api_path") @@ -519,9 +511,6 @@ auto encrypt_provider::get_filesystem_item( auto source_path = row->get_column("source_path").get_value(); - event_system::instance().raise( - std::string{function_name}, source_path, std::to_string(directory)); - if (directory) { result = db::db_select{*db_, directory_table} .column("api_path") @@ -612,10 +601,6 @@ auto encrypt_provider::get_pinned_files() const -> std::vector { auto encrypt_provider::get_item_meta(const std::string &api_path, api_meta_map &meta) const -> api_error { - static constexpr const std::string_view function_name{ - static_cast(__FUNCTION__), - }; - auto result = db::db_select{*db_, source_table} .column("source_path") .where("api_path") @@ -635,8 +620,6 @@ auto encrypt_provider::get_item_meta(const std::string &api_path, } auto file = create_api_file(api_path, exists, source_path); - event_system::instance().raise( - std::string{function_name}, api_path, exists ? "true" : "false"); create_item_meta(meta, exists, file); return api_error::success; } diff --git a/repertory/repertory_test/src/winfsp_test.cpp b/repertory/repertory_test/src/winfsp_test.cpp index 5d5a91c1..b6482c45 100644 --- a/repertory/repertory_test/src/winfsp_test.cpp +++ b/repertory/repertory_test/src/winfsp_test.cpp @@ -81,7 +81,7 @@ static void root_creation_test(const std::string &mount_point) { TEST_HEADER(__FUNCTION__); WIN32_FILE_ATTRIBUTE_DATA ad{}; EXPECT_TRUE( - ::GetFileAttributesEx(&mount_point[0], GetFileExInfoStandard, &ad)); + ::GetFileAttributesEx(mount_point.c_str(), GetFileExInfoStandard, &ad)); EXPECT_EQ(FILE_ATTRIBUTE_DIRECTORY, ad.dwFileAttributes); EXPECT_EQ(0, ad.nFileSizeHigh); EXPECT_EQ(0, ad.nFileSizeLow); From 4bb34781feb4b91c34bb18abcad7c7395dcf805b Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 28 Aug 2024 18:00:25 -0500 Subject: [PATCH 2/2] cleanup --- .../librepertory/src/providers/encrypt/encrypt_provider.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp index cefc6d01..47297743 100644 --- a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp +++ b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp @@ -72,10 +72,6 @@ encrypt_provider::encrypt_provider(app_config &config) : config_(config) {} auto encrypt_provider::create_api_file( const std::string &api_path, bool directory, const std::string &source_path) -> api_file { - static constexpr const std::string_view function_name{ - static_cast(__FUNCTION__), - }; - #if defined(_WIN32) struct _stat64 buf {}; _stat64(source_path.c_str(), &buf); @@ -114,7 +110,7 @@ auto encrypt_provider::create_api_file( static_cast(buf.st_ctime)); file.modified_date = utils::time::windows_time_to_unix_time( static_cast(buf.st_mtime)); -#else // !defined(_WIN32) +#else // !defined(_WIN32) && !defined(__APPLE__) file.changed_date = static_cast( buf.st_mtim.tv_nsec + (buf.st_mtim.tv_sec * utils::time::NANOS_PER_SECOND));