Compare commits

...

7 Commits

5 changed files with 85 additions and 17 deletions

38
PKGBUILD Normal file
View File

@ -0,0 +1,38 @@
# Maintainer: Les De Ridder <aur@lesderid.net>
_pkgname=dtagfs
pkgname=dtagfs-git
pkgver=0.1.0.r0.ga141d74
pkgrel=1
pkgdesc="Tag-based FUSE virtual file system"
arch=('i386' 'x86_64')
url="https://git.fuwafuwa.moe/lesderid/dtagfs"
license=('custom:NCSA')
depends=('fuse' 'exempi')
makedepends=('git' 'dub' 'd-compiler')
provides=($_pkgname)
conflicts=($_pkgname)
source=('git+https://git.fuwafuwa.moe/lesderid/dtagfs')
md5sums=('SKIP')
build() {
cd "$srcdir/$_pkgname"
dub build -b=release
}
package() {
cd "$srcdir/$_pkgname"
mkdir -p $pkgdir/usr/bin/
cp dtagfs $pkgdir/usr/bin/dtagfs
ln -s /usr/bin/dtagfs $pkgdir/usr/bin/mount.fuse.dtagfs
mkdir -p $pkgdir/usr/share/licenses/$_pkgname/
cp LICENSE $pkgdir/usr/share/licenses/$_pkgname/LICENSE
}
pkgver() {
cd "$srcdir/$_pkgname"
git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^v//'
}

View File

@ -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).

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

@ -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

@ -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();
@ -52,7 +59,8 @@ class FileSystem : Operations
{
foreach(file; dirEntries(_source, SpanMode.breadth).filter!(a => a.isFile))
{
_tagCache[file] ~= tagProvider.getTags(file);
auto tags = tagProvider.getTags(file);
_tagCache[file] ~= tags.map!(tag => tag.replace("/", "")).array; //replace '/' (directory separator) with full-width solidus
_fileLinkCache[file.baseName] = file;
}
@ -71,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;
}
@ -106,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 == "/")
@ -114,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
@ -136,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;
}
@ -172,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);