Compare commits

...

3 Commits

2 changed files with 22 additions and 7 deletions

View File

@ -193,7 +193,7 @@ extern(System)
threads from the runtime because after fuse_main finishes the pthreads
are joined. We circumvent that problem by just exiting while our
threads still run. */
import std.c.process;
import core.stdc.stdlib : exit;
exit(0);
}
} /* extern(C) */

View File

@ -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;
}
@ -111,6 +115,15 @@ class FileSystem : Operations
return _fileLinkCache[name];
}
Tuple!(bool, "exclude", string, "name")[] pathToTagTuples(const(char)[] path)
{
//map the path to a range of tuples with an exclude (bool) and a name (string) field for each tag in the path
return pathSplitter(path)
.array[1..$]
.map!(tag => tuple!("exclude", "name")(tag[0] == exclusionChar, cast(immutable)tag.stripLeft(exclusionChar)))
.array;
}
string[] getTags(const(char)[] path)
{
if(path == "/")
@ -119,12 +132,13 @@ class FileSystem : Operations
}
else
{
auto tags = pathSplitter(path).array[1..$];
auto tags = pathToTagTuples(path);
auto filePairs = _tagCache.byKeyValue().filter!(a => tags.all!(b => a.value.canFind(b)));
//filter pairs with tags that (should not be excluded && can be found) || (should be excluded && can't be found)
auto filePairs = _tagCache.byKeyValue().filter!(a => tags.all!(b => !b.exclude == a.value.canFind(b.name)));
return filePairs.map!(a => a.value)
.joiner
.filter!(a => !tags.canFind(a))
.filter!(a => !tags.map!(tag => tag.name).canFind(a)) //don't match tags that are already in the path
.filter!(a => !_noCommon || !filePairs.all!(f => f.value.canFind(a)))
.array
.sort()
@ -141,10 +155,11 @@ class FileSystem : Operations
}
else
{
auto tags = pathSplitter(path).array[1..$];
auto tags = pathToTagTuples(path);
//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;
}