Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
Les De Ridder | b0c0a8924e | |
Les De Ridder | dc59816373 | |
Les De Ridder | 7b102f7839 | |
Les De Ridder | 0adc5ba0de | |
Les De Ridder | 407a83e1cd |
11
README.md
11
README.md
|
@ -1,5 +1,5 @@
|
|||
# dtagfs
|
||||
dtagfs is a FUSE file system that mounts a directory with tagged files as a file system tree.
|
||||
dtagfs is a FUSE file system that mounts a directory with tagged files as a file tree.
|
||||
|
||||
This allows for easy filtering of tagged files (e.g. '/mountpoint/tag1/tag2/' contains all files with tags 'tag1' and 'tag2').
|
||||
|
||||
|
@ -7,12 +7,15 @@ 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: don't fork to background
|
||||
-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)
|
||||
|
||||
## License
|
||||
dtags is released under the [University of Illinois/NCSA license](LICENSE).
|
||||
dtagfs is released under the [University of Illinois/NCSA license](LICENSE).
|
||||
|
|
|
@ -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) */
|
||||
|
|
10
source/app.d
10
source/app.d
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -30,11 +31,17 @@ class FileSystem : Operations
|
|||
private string[] _tagList;
|
||||
private string[string] _fileLinkCache;
|
||||
|
||||
this(string source, TagProvider[] tagProviders)
|
||||
private bool _noCommon;
|
||||
|
||||
enum exclusionChar = '!';
|
||||
|
||||
this(string source, TagProvider[] tagProviders, bool noCommon)
|
||||
{
|
||||
_source = source;
|
||||
_tagProviders = tagProviders;
|
||||
|
||||
_noCommon = noCommon;
|
||||
|
||||
lstat(toStringz(source), &_sourceStat);
|
||||
|
||||
cacheTags();
|
||||
|
@ -72,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;
|
||||
}
|
||||
|
@ -107,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 == "/")
|
||||
|
@ -115,13 +132,14 @@ class FileSystem : Operations
|
|||
}
|
||||
else
|
||||
{
|
||||
auto tags = pathSplitter(path).array[1..$];
|
||||
auto tags = pathToTagTuples(path);
|
||||
|
||||
return _tagCache.byKeyValue()
|
||||
.filter!(a => tags.all!(b => a.value.canFind(b)))
|
||||
.map!(a => a.value)
|
||||
//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()
|
||||
.uniq
|
||||
|
@ -137,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;
|
||||
}
|
||||
|
@ -173,7 +192,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);
|
||||
|
|
Loading…
Reference in New Issue