specify max tag depth (default: 15)
authorIan Beckwith <ianb@erislabs.net>
Mon, 18 Oct 2010 00:17:05 +0000 (01:17 +0100)
committerIan Beckwith <ianb@erislabs.net>
Mon, 18 Oct 2010 00:17:05 +0000 (01:17 +0100)
lib/ID3FS/Fuse.pm
lib/ID3FS/Path.pm
sbin/id3fsd

index 14304f7..3345bc2 100644 (file)
@@ -6,8 +6,9 @@ use ID3FS::Path;
 use Fuse;
 use Cwd;
 use POSIX qw(EINVAL EROFS ENOENT EOPNOTSUPP S_IRUSR S_IRGRP S_IROTH S_IXUSR S_IXGRP S_IXOTH);
-our ($TYPE_DIR, $TYPE_SYMLINK)=(0040, 0120);
 
+our ($TYPE_DIR, $TYPE_SYMLINK)=(0040, 0120);
+our $DEFAULT_MAXTAGDEPTH = 15;
 sub new
 {
     my $proto=shift;
@@ -19,6 +20,8 @@ sub new
     $self->{source}=shift;
     $self->{mountpoint}=Cwd::abs_path(shift);
     $self->{verbose}=shift;
+    $self->{tagdepth}=shift;
+    $self->{tagdepth}=$DEFAULT_MAXTAGDEPTH unless($self->{tagdepth});
     $self->{perms} = S_IRUSR() | S_IXUSR() | S_IRGRP() | S_IXGRP() | S_IROTH() | S_IXOTH();
 
     return $self;
@@ -65,7 +68,7 @@ sub getattr
 {
     my($self, $filename)=@_;
 #    print "**GETATTR: $filename\n";
-    my $path=ID3FS::Path->new($self->{db}, $filename, $self->{verbose});
+    my $path=ID3FS::Path->new($self->{db}, $filename, $self->{verbose}, $self->{tagdepth});
     my $last_update=$self->{db}->last_update();
     return(-ENOENT()) unless($path->isvalid());
     my($dev,$ino,$nlink)=(0,0,1);
@@ -83,7 +86,7 @@ sub readlink
 {
     my($self,$filename)=@_;
 #    print "**READLINK: $filename\n";
-    my $path=ID3FS::Path->new($self->{db}, $filename, $self->{verbose});
+    my $path=ID3FS::Path->new($self->{db}, $filename, $self->{verbose}, $self->{tagdepth});
     return(-EINVAL()) unless($path->isfile());
     return $path->dest($self->{mountpoint});
 }
@@ -92,7 +95,7 @@ sub getdir
 {
     my($self, $filename)=@_;
 #    print "**GETDIR: $filename\n";
-    my $path=ID3FS::Path->new($self->{db}, $filename, $self->{verbose});
+    my $path=ID3FS::Path->new($self->{db}, $filename, $self->{verbose}, $self->{tagdepth});
     return(-ENOENT()) unless($path->isvalid());
     return(-ENOTDIR()) unless($path->isdir());
     my @dents=();
index 0455375..cd8b5ac 100644 (file)
@@ -31,6 +31,8 @@ sub new
     $self->{db}=shift;
     $self->{path}=shift;
     $self->{verbose}=shift;
+    $self->{maxtagdepth}=shift;
+    $self->{curtagdepth}=0;
     $self->{path} =~ s/\/\//\//g; # drop doubled slashes
 
     $self->parse();
@@ -95,7 +97,11 @@ sub dirents
        }
        else
        {
-           @dents=(qw(AND OR), $PATH_ALLTRACKS, $PATH_NOARTIST, $self->artists());
+           if($self->{maxtagdepth} && ($self->{curtagdepth} < $self->{maxtagdepth}))
+           {
+               @dents=qw(AND OR);
+           }
+           push(@dents, $PATH_ALLTRACKS, $PATH_NOARTIST, $self->artists());
        }
     }
     elsif($state==$STATE_BOOLEAN)
@@ -372,7 +378,11 @@ sub parse
 sub state
 {
     my($self, $newstate)=@_;
-    $self->{state}=$newstate if(defined($newstate));
+    if(defined($newstate))
+    {
+       $self->{state}=$newstate;
+       $self->{curtagdepth}++ if($newstate == $STATE_TAG);
+    }
     return $self->{state};
 }
 
@@ -863,7 +873,7 @@ sub empty
     my($self, $dir, $maxdepth)=@_;
     return 0 unless($maxdepth);
 #    print "testing($maxdepth): $dir\n";
-    my $path=ID3FS::Path->new($self->{db}, $dir, $self->{verbose});
+    my $path=ID3FS::Path->new($self->{db}, $dir, $self->{verbose}, $self->{tagdepth});
 #    print "PATH INVALID\n" unless($path->isvalid());
     return 1 unless($path->isvalid());
     my($subdirs,$subfiles)=$path->dirents();
index 8331e13..b46706a 100755 (executable)
@@ -14,12 +14,14 @@ our $VERSION="1.00";
 my $verbose=0;
 my $help=0;
 my $dbpath=undef;
+my $tagdepth=undef;
 
 Configure(qw(bundling no_ignore_case));
 my $optret=GetOptions(
     "verbose|v"    => sub { $verbose++; },
     "help|h"       => \$help,
     "database|f=s" => \$dbpath,
+    "t|tagdepth=s" => \$tagdepth,
     );
 
 usage() if(scalar(@ARGV) != 2 || !$optret || $help);
@@ -30,7 +32,7 @@ my $mountpoint=shift;
 my $db=ID3FS::DB->new($me, $verbose, 0, $dbpath, $source);
 exit unless($db);
 
-my $fuse=ID3FS::Fuse->new($db, $source, $mountpoint, $verbose);
+my $fuse=ID3FS::Fuse->new($db, $source, $mountpoint, $verbose, $tagdepth);
 $fuse->run();
 
 sub usage