Add file listing
This commit is contained in:
parent
fa93c2669d
commit
347107fc0e
@ -4,6 +4,8 @@ import std.algorithm;
|
||||
import std.range;
|
||||
import std.file;
|
||||
import std.conv;
|
||||
import std.path;
|
||||
import std.array;
|
||||
|
||||
import dfuse.fuse;
|
||||
|
||||
@ -43,23 +45,80 @@ class FileSystem : Operations
|
||||
|
||||
override void getattr(const(char)[] path, ref stat_t stat)
|
||||
{
|
||||
if(path == "/")
|
||||
if(path == "/" || isTag(path.baseName))
|
||||
{
|
||||
stat.st_mode = S_IFDIR | octal!755;
|
||||
stat.st_mode = S_IFDIR | octal!700;
|
||||
stat.st_size = 0;
|
||||
return;
|
||||
}
|
||||
else if(isFile(path.baseName))
|
||||
{
|
||||
stat.st_mode = S_IFREG | octal!700;
|
||||
stat.st_size = 42;
|
||||
return;
|
||||
}
|
||||
|
||||
throw new FuseException(errno.ENOENT);
|
||||
}
|
||||
|
||||
bool isTag(const(char)[] name)
|
||||
{
|
||||
return _tagCache.values.any!(a => a.canFind(name));
|
||||
}
|
||||
|
||||
bool isFile(const(char)[] name)
|
||||
{
|
||||
return _tagCache.keys.any!(a => a.baseName == name);
|
||||
}
|
||||
|
||||
string[] getTags(const(char)[] path)
|
||||
{
|
||||
if(path == "/")
|
||||
{
|
||||
return _tagCache.byValue()
|
||||
.joiner
|
||||
.array
|
||||
.sort()
|
||||
.uniq
|
||||
.array;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto tags = pathSplitter(path).array[1..$];
|
||||
|
||||
return _tagCache.byKeyValue()
|
||||
.filter!(a => tags.all!(b => a.value.canFind(b)))
|
||||
.filter!(a => !tags.canFind(a.value))
|
||||
.map!(a => a.value)
|
||||
.joiner
|
||||
.array
|
||||
.sort()
|
||||
.uniq
|
||||
.array;
|
||||
}
|
||||
}
|
||||
|
||||
string[] getFiles(const(char)[] path)
|
||||
{
|
||||
if(path == "/")
|
||||
{
|
||||
return _tagCache.keys.map!(a => a.baseName).array;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto tags = pathSplitter(path).array[1..$];
|
||||
|
||||
return _tagCache.byKeyValue()
|
||||
.filter!(a => tags.all!(b => a.value.canFind(b)))
|
||||
.map!(a => a.key.baseName)
|
||||
.array;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override string[] readdir(const(char)[] path)
|
||||
{
|
||||
return _tagCache.byValue()
|
||||
.joiner
|
||||
.array
|
||||
.sort()
|
||||
.uniq
|
||||
.array;
|
||||
//TODO: Don't return tags if only one file (or files with exactly the same set of tags) files?
|
||||
return getTags(path) ~ getFiles(path);
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,6 @@ class DublinCoreTagProvider : TagProvider
|
||||
|
||||
string[] tags;
|
||||
|
||||
std.stdio.writeln(path);
|
||||
|
||||
tags ~= map!(a => a)(getElementData!"Subject"(path)).array;
|
||||
tags ~= map!(a => "copyright:" ~ a)(getElementData!"Rights"(path)).array;
|
||||
tags ~= map!(a => "relation:" ~ a)(getElementData!"Relation"(path)).array;
|
||||
|
Loading…
x
Reference in New Issue
Block a user