Add an option to hide common tags

This commit is contained in:
Les De Ridder 2016-11-14 05:23:58 +01:00
parent 407a83e1cd
commit 0adc5ba0de
No known key found for this signature in database
GPG Key ID: 5EC132DFA85DB372
3 changed files with 21 additions and 7 deletions

View File

@ -7,9 +7,12 @@ This allows for easy filtering of tagged files (e.g. '/mountpoint/tag1/tag2/' co
See [example.md](example.md).
## Usage
`usage: dtagfs <source> <mount point> [-f] [-o option[,options...]]`
```text
usage: dtagfs <source> <mount point> [-f] [-o option[,options...]]`
-f: foreground (don't fork to background)
-o nocomm: don't show tags that all files in a directory have in common
```
## Supported tag sources
* Dublin Core (XMP), via [exempi-d](https://github.com/lesderid/exempi-d)

View File

@ -3,6 +3,7 @@ module dtagfs.app;
import std.stdio;
import std.getopt;
import std.array;
import std.algorithm;
import dfuse.fuse;
@ -40,7 +41,14 @@ void main(string[] args)
FileSystem mount(string source, string mountPoint, TagProvider[] tagProviders, string[] options, bool foreground)
{
auto filesystem = new FileSystem(source, tagProviders);
auto noCommon = false;
if(options.canFind("nocomm"))
{
options = options.remove!(a => a == "nocomm");
noCommon = true;
}
auto filesystem = new FileSystem(source, tagProviders, noCommon);
auto fuse = new Fuse("dtagfs", foreground, false);
fuse.mount(filesystem, mountPoint, options);

View File

@ -30,11 +30,15 @@ class FileSystem : Operations
private string[] _tagList;
private string[string] _fileLinkCache;
this(string source, TagProvider[] tagProviders)
private bool _noCommon;
this(string source, TagProvider[] tagProviders, bool noCommon)
{
_source = source;
_tagProviders = tagProviders;
_noCommon = noCommon;
lstat(toStringz(source), &_sourceStat);
cacheTags();
@ -117,11 +121,11 @@ class FileSystem : Operations
{
auto tags = pathSplitter(path).array[1..$];
return _tagCache.byKeyValue()
.filter!(a => tags.all!(b => a.value.canFind(b)))
.map!(a => a.value)
auto filePairs = _tagCache.byKeyValue().filter!(a => tags.all!(b => a.value.canFind(b)));
return filePairs.map!(a => a.value)
.joiner
.filter!(a => !tags.canFind(a))
.filter!(a => !_noCommon || !filePairs.all!(f => f.value.canFind(a)))
.array
.sort()
.uniq
@ -173,7 +177,6 @@ class FileSystem : Operations
return _dirCache[path];
}
//TODO: Don't return tags if only one file (or files with exactly the same set of tags)?
if (path == "/")
{
return _dirCache[path] = getTags(path) ~ getFiles(path);