added stub ID3FS::Path
authorIan Beckwith <ianb@erislabs.net>
Mon, 20 Sep 2010 20:05:24 +0000 (21:05 +0100)
committerIan Beckwith <ianb@erislabs.net>
Mon, 20 Sep 2010 20:05:24 +0000 (21:05 +0100)
lib/ID3FS/Fuse.pm
lib/ID3FS/Path.pm [new file with mode: 0644]

index 44fdc6e..68a1b52 100644 (file)
@@ -2,6 +2,7 @@ package ID3FS::Fuse;
 
 use strict;
 use warnings;
+use ID3FS::Path;
 use Fuse;
 use POSIX qw(EINVAL EROFS EOPNOTSUPP S_IRUSR S_IRGRP S_IROTH S_IXUSR S_IXGRP S_IXOTH);
 use vars qw($TYPE_DIR $TYPE_SYMLINK);
@@ -69,15 +70,9 @@ sub getattr
     my($rdev,$size)=(0,1);
     my($atime,$mtime,$ctime)=(0,0,0);
     my($blksize,$blocks)=(512,1);
-    my $mode;
-    if($filename eq "/")
-    {
-       $mode=$self->mode($TYPE_DIR);
-    }
-    else
-    {
-       $mode=$self->mode($TYPE_SYMLINK);
-    }
+
+    my $path=ID3FS::Path->new($self->{db}, $filename);
+    my $mode=$self->mode( $path->isdir() ? $TYPE_DIR : $TYPE_SYMLINK );
     return($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
           $atime,$mtime,$ctime,$blksize,$blocks);
 }
@@ -86,18 +81,21 @@ sub readlink
 {
     my($self,$filename)=@_;
     print "READLINK: $filename\n";
-    return "FIXME";
+    my $path=ID3FS::Path->new($self->{db}, $filename);
+    return(-EINVAL()) if($path->isdir());
+    return $path->dest();
 }
 
 sub getdir
 {
     my($self, $filename)=@_;
-    print "GETDIR(", ref($self), ": $filename\n";
-    if($filename eq "/")
+    print "GETDIR: $filename\n";
+    my $path=ID3FS::Path->new($self->{db}, $filename);
+    if($path->isdir())
     {
-       return(".", "..", $self->{db}->tags(), 0);
+       return(".", "..", $path->dirents(), 0);
     }
-    return('.',0);
+    return -ENOTDIR();
 }
 
 # unused stubs
diff --git a/lib/ID3FS/Path.pm b/lib/ID3FS/Path.pm
new file mode 100644 (file)
index 0000000..b2202c2
--- /dev/null
@@ -0,0 +1,39 @@
+package ID3FS::Path;
+
+use strict;
+use warnings;
+
+sub new
+{
+    my $proto=shift;
+    my $class=ref($proto) || $proto;
+    my $self={};
+    bless($self,$class);
+
+    $self->{db}=shift;
+    $self->{path}=shift;
+
+    return $self;
+}
+
+sub isdir
+{
+    my($self)=@_;
+    return 1 if($self->{path} eq "/");
+    return 0;
+}
+
+sub dest
+{
+    my($self)=@_;
+    return "FIXME";
+}
+
+sub dirents
+{
+    my($self)=@_;
+    return $self->{db}->tags();
+}
+
+
+1;