Skip to content

Commit

Permalink
[files] Fix "rel. dirpaths of depth 1 have dot prepended" issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelSchneid3r committed Sep 26, 2023
1 parent 703474f commit 5e3fa8e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion files/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project(files VERSION 1.6)
project(files VERSION 1.7)
albert_plugin(
NAME Files
DESCRIPTION "Open and browse files"
Expand Down
3 changes: 2 additions & 1 deletion files/src/fsindexnodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ void DirNode::update(const std::shared_ptr<DirNode>& 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
Expand Down
1 change: 1 addition & 0 deletions files/src/fsindexnodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct NameFilter {

struct IndexSettings
{
QString root_path;
std::vector<NameFilter> name_filters;
std::vector<QRegularExpression> mime_filters;
uint8_t max_depth;
Expand Down
3 changes: 3 additions & 0 deletions files/src/fsindexpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ QString FsIndexPath::path() const { return root_->filePath(); }
void FsIndexPath::update(const bool &abort, std::function<void(const QString &)> 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)
Expand Down
2 changes: 1 addition & 1 deletion files/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions files/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QDebug>
#include <QFile>
#include <QTemporaryDir>
#include "src/fileitems.h"
#include "src/fsindexpath.h"
using namespace std;
ALBERT_LOGGING_CATEGORY("files_test")
Expand Down Expand Up @@ -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<shared_ptr<AbstractFileItem>> items;
FsIndexPath *p;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 5e3fa8e

Please sign in to comment.