From fa93c2669d4b4f2bb7113bec7bd3a5538526d401 Mon Sep 17 00:00:00 2001 From: Les De Ridder Date: Sun, 16 Oct 2016 02:49:56 +0200 Subject: [PATCH] Add file system implementation stub --- source/app.d | 3 ++- source/filesystem.d | 52 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/source/app.d b/source/app.d index 73503ab..4ca6546 100644 --- a/source/app.d +++ b/source/app.d @@ -8,6 +8,7 @@ import dfuse.fuse; import dtagfs.filesystem; import dtagfs.tagprovider; +import dtagfs.dublincore; void main(string[] args) { @@ -22,7 +23,7 @@ void main(string[] args) auto source = args[1]; auto mountPoint = args[2]; - TagProvider[] tagProviders; + TagProvider[] tagProviders = [new DublinCoreTagProvider()]; string[] mountOptions; bool fork; diff --git a/source/filesystem.d b/source/filesystem.d index 3b4a97a..5ae448d 100644 --- a/source/filesystem.d +++ b/source/filesystem.d @@ -1,13 +1,65 @@ module dtagfs.filesystem; +import std.algorithm; +import std.range; +import std.file; +import std.conv; + import dfuse.fuse; import dtagfs.tagprovider; class FileSystem : Operations { + private string _source; + private TagProvider[] _tagProviders; + + private string[][string] _tagCache; + this(string source, TagProvider[] tagProviders) { + _source = source; + _tagProviders = tagProviders; + cacheTags(); + } + + @property + TagProvider primaryTagProvider() + { + return _tagProviders[0]; + } + + void cacheTags() + { + foreach(tagProvider; _tagProviders.filter!(a => a.cacheReads)) + { + foreach(file; dirEntries(_source, SpanMode.breadth).filter!(a => a.isFile)) + { + _tagCache[file] ~= tagProvider.getTags(file); + } + } + } + + override void getattr(const(char)[] path, ref stat_t stat) + { + if(path == "/") + { + stat.st_mode = S_IFDIR | octal!755; + stat.st_size = 0; + return; + } + + throw new FuseException(errno.ENOENT); + } + + override string[] readdir(const(char)[] path) + { + return _tagCache.byValue() + .joiner + .array + .sort() + .uniq + .array; } }