Add file system implementation stub
This commit is contained in:
parent
5187be0e01
commit
fa93c2669d
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user