From 5e3fa8e42469f58ad622698964c7e0a6818514ce Mon Sep 17 00:00:00 2001 From: Manuel Schneider Date: Tue, 26 Sep 2023 12:25:52 +0200 Subject: [PATCH] [files] Fix "rel. dirpaths of depth 1 have dot prepended" issue --- files/CMakeLists.txt | 2 +- files/src/fsindexnodes.cpp | 3 ++- files/src/fsindexnodes.h | 1 + files/src/fsindexpath.cpp | 3 +++ files/src/plugin.cpp | 2 +- files/test/test.cpp | 18 ++++++++++-------- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/files/CMakeLists.txt b/files/CMakeLists.txt index f9e68582..20681594 100644 --- a/files/CMakeLists.txt +++ b/files/CMakeLists.txt @@ -1,4 +1,4 @@ -project(files VERSION 1.6) +project(files VERSION 1.7) albert_plugin( NAME Files DESCRIPTION "Open and browse files" diff --git a/files/src/fsindexnodes.cpp b/files/src/fsindexnodes.cpp index 2fd10503..971d005b 100644 --- a/files/src/fsindexnodes.cpp +++ b/files/src/fsindexnodes.cpp @@ -134,9 +134,10 @@ void DirNode::update(const std::shared_ptr& shared_this, // Match against name filters auto exclude = false; + auto relative_path = fi.filePath().mid(settings.root_path.length()+1); for (const auto &filter: settings.name_filters) if (((exclude && filter.type == PatternType::Include) || (!exclude && filter.type == PatternType::Exclude)) - && filter.regex.match(QDir(relativeFilePath()).filePath(fi.fileName())).hasMatch()) + && filter.regex.match(relative_path).hasMatch()) exclude = !exclude; // Index structure diff --git a/files/src/fsindexnodes.h b/files/src/fsindexnodes.h index d6d8f6c1..e2903c63 100644 --- a/files/src/fsindexnodes.h +++ b/files/src/fsindexnodes.h @@ -25,6 +25,7 @@ struct NameFilter { struct IndexSettings { + QString root_path; std::vector name_filters; std::vector mime_filters; uint8_t max_depth; diff --git a/files/src/fsindexpath.cpp b/files/src/fsindexpath.cpp index 88ce7e65..e725ed5b 100644 --- a/files/src/fsindexpath.cpp +++ b/files/src/fsindexpath.cpp @@ -37,6 +37,9 @@ QString FsIndexPath::path() const { return root_->filePath(); } void FsIndexPath::update(const bool &abort, std::function status) { IndexSettings s; + + s.root_path = this->path(); + for (const auto &pattern : name_filters) s.name_filters.emplace_back(pattern); for (const auto &pattern : mime_filters) diff --git a/files/src/plugin.cpp b/files/src/plugin.cpp index 772ddbb5..28fa2cc9 100644 --- a/files/src/plugin.cpp +++ b/files/src/plugin.cpp @@ -19,7 +19,7 @@ const char* CFG_MIME_FILTERS = "mimeFilters"; const QStringList DEF_MIME_FILTERS = { "inode/directory" }; const char* CFG_NAME_FILTERS = "nameFilters"; #if defined Q_OS_MACOS -const QStringList DEF_NAME_FILTERS = { ".DS_Store" }; +const QStringList DEF_NAME_FILTERS = { "\\.DS_Store" }; #else const QStringList DEF_NAME_FILTERS = {}; #endif diff --git a/files/test/test.cpp b/files/test/test.cpp index cffeadad..8b8fce60 100644 --- a/files/test/test.cpp +++ b/files/test/test.cpp @@ -10,6 +10,7 @@ #include #include #include +#include "src/fileitems.h" #include "src/fsindexpath.h" using namespace std; ALBERT_LOGGING_CATEGORY("files_test") @@ -38,9 +39,12 @@ TEST_CASE("FsIndexPath") CHECK(QFile::link(root.filePath("a"), root.filePath("b/c"))); - - // -- -- -- // - + // ─┬─── / + // ├─┬─ a/ + // │ ├─ a/.foo.txt + // │ └─ a/.foo.txt + // └─┬─ b/ + // └─ b/c/ vector> items; FsIndexPath *p; @@ -88,18 +92,16 @@ TEST_CASE("FsIndexPath") p->setFollowSymlinks(true); update(); CHECK(items.size() == 6); + p->setFollowSymlinks(false); // namefilters p->setNameFilters({"b"}); update(); CHECK(items.size() == 4); - - // namefilters - p->setNameFilters({"b"}); + p->setNameFilters({"^a"}); update(); - CHECK(items.size() == 4); - + CHECK(items.size() == 3); p = new FsIndexPath(dir.filePath("b")); update();