Add file system implementation stub

This commit is contained in:
Les De Ridder 2016-10-16 02:49:56 +02:00
parent 5187be0e01
commit fa93c2669d
No known key found for this signature in database
GPG Key ID: 5EC132DFA85DB372
2 changed files with 54 additions and 1 deletions

View File

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

View File

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