From 7b102f78390ff56c4e94c4019d3912c213c9d4fa Mon Sep 17 00:00:00 2001 From: Les De Ridder Date: Tue, 29 Nov 2016 19:00:57 +0100 Subject: [PATCH] Add negative tag matching with an exclusion prefix --- source/filesystem.d | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/source/filesystem.d b/source/filesystem.d index 257c21d..f21db08 100644 --- a/source/filesystem.d +++ b/source/filesystem.d @@ -8,6 +8,7 @@ import std.path; import std.array; import std.string; import std.stdio; +import std.typecons; import core.sys.posix.unistd; import core.stdc.string; @@ -32,6 +33,8 @@ class FileSystem : Operations private bool _noCommon; + enum exclusionChar = '!'; + this(string source, TagProvider[] tagProviders, bool noCommon) { _source = source; @@ -76,7 +79,8 @@ class FileSystem : Operations stat.st_uid = _sourceStat.st_uid; stat.st_gid = _sourceStat.st_gid; - if(path == "/" || isTag(path.baseName)) + //excluded tags are also valid directories + if(path == "/" || isTag(path.baseName.stripLeft(exclusionChar))) { stat.st_mode = _sourceStat.st_mode; } @@ -141,10 +145,14 @@ class FileSystem : Operations } else { - auto tags = pathSplitter(path).array[1..$]; + //map the path to a range of tuples with an exclude (bool) and a name (string) field for each tag in the path + auto tags = pathSplitter(path) + .array[1..$] + .map!(tag => tuple!("exclude", "name")(tag[0] == exclusionChar, tag.stripLeft(exclusionChar))); + //filter files with tags that (should not be excluded && can be found) || (should be excluded && can't be found) return _tagCache.byKeyValue() - .filter!(a => tags.all!(b => a.value.canFind(b))) + .filter!(a => tags.all!(b => !b.exclude == a.value.canFind(b.name))) .map!(a => a.key.baseName) .array; }