pass path to db methods, not just elements
authorIan Beckwith <ianb@erislabs.net>
Sat, 9 Oct 2010 14:37:49 +0000 (15:37 +0100)
committerIan Beckwith <ianb@erislabs.net>
Sat, 9 Oct 2010 14:37:49 +0000 (15:37 +0100)
lib/ID3FS/DB.pm
lib/ID3FS/Fuse.pm
lib/ID3FS/Path.pm
lib/ID3FS/Path/Node.pm

index 9369fbf..50d9043 100644 (file)
@@ -180,7 +180,8 @@ sub cmd_sth
 
 sub tags
 {
-    my($self, @constraints)=@_;
+    my($self, $path)=@_;
+    my @constraints=@{$path->{elements}};
     if(!@constraints) # /
     {
        # FIXME: add ALL?
@@ -245,7 +246,8 @@ sub tag_values
 
 sub artists
 {
-    my($self, @constraints)=@_;
+    my($self, $path)=@_;
+    my @constraints=@{$path->{elements}};
     if(!@constraints) # /ALL
     {
        my $sql="SELECT DISTINCT name FROM artists;";
@@ -268,12 +270,13 @@ sub artists
 
 sub albums
 {
-    my($self, @constraints)=@_;
+    my($self, $path)=@_;
+    my @constraints=@{$path->{elements}};
     my @ids=();
     # FIXME: rework PathElements
     if(ref($constraints[$#constraints]) eq "ID3FS::PathElement::Artist")
     {
-       return $self->artist_albums($constraints[$#constraints]->{id}, @constraints);
+       return $self->artist_albums($constraints[$#constraints]->{id}, $path);
     }
     my $sql=("SELECT albums.name\n" .
             "\tFROM (\n" .
@@ -291,7 +294,8 @@ sub albums
 
 sub artist_albums
 {
-    my($self, $artist_id, @constraints)=@_;
+    my($self, $artist_id, $path)=@_;
+    my @constraints=@{$path->{elements}};
     my $sql=("SELECT albums.name FROM (\n" .
             $self->tags_subselect(@constraints) .
             "\t) AS subselect\n" .
@@ -309,7 +313,8 @@ sub artist_albums
 
 sub artist_tracks
 {
-    my($self, $artist_id, @constraints)=@_;
+    my($self, $artist_id, $path)=@_;
+    my @constraints=@{$path->{elements}};
     my $sql=("SELECT files.name FROM (\n" .
             $self->tags_subselect(@constraints) .
             "\t) AS subselect\n" .
@@ -342,7 +347,8 @@ sub album_tracks
 
 sub tracks
 {
-    my($self, @constraints)=@_;
+    my($self, $path)=@_;
+    my @constraints=@{$path->{elements}};
     # FIXME: rework PathElements
     if(ref($constraints[$#constraints]) eq "ID3FS::PathElement::Artist")
     {
@@ -375,7 +381,8 @@ sub tracks
 
 sub filename
 {
-    my($self, $mountpoint, @constraints)=@_;
+    my($self, $mountpoint, $path)=@_;
+    my @constraints=@{$path->{elements}};
     if(ref($constraints[$#constraints]) eq "ID3FS::PathElement::File")
     {
        my $id=$constraints[$#constraints]->{id};
index bbf6f34..ebe6243 100644 (file)
@@ -35,6 +35,7 @@ sub run
        getattr     => sub { $self->getattr(@_); },
        readlink    => sub { $self->readlink(@_); },
        getdir      => sub { $self->getdir(@_); },
+
        # Not used
 #      mknod       => sub { $self->mknod(@_);       },
 #      mkdir       => sub { $self->mkdir(@_);       },
index a27cd7e..33d3ccd 100644 (file)
@@ -59,7 +59,7 @@ sub dest
     my($self, $mountpoint)=@_;
     if($self->state() == $STATE_FILE)
     {
-       return $self->{db}->filename($mountpoint, @{$self->{elements}});
+       return $self->{db}->filename($mountpoint, $self);
     }
     return "ERROR"; #should never happen?
 }
@@ -79,12 +79,12 @@ sub dirents
           ref($tag) eq "ID3FS::PathElement::Tag" &&
           $self->{db}->tag_has_values($tag->{id}))
        {
-           @dents=$self->{db}->tags(@{$self->{elements}});
+           @dents=$self->{db}->tags($self);
        }
        else
        {
            @dents=(qw(AND OR TRACKS NOARTIST),
-                   $self->{db}->artists(@{$self->{elements}}));
+                   $self->{db}->artists($self));
        }
     }
     elsif($state==$STATE_BOOLEAN)
@@ -96,19 +96,19 @@ sub dirents
        {
            push(@dents, "NOT");
        }
-       push(@dents, $self->{db}->tags(@{$self->{elements}}));
+       push(@dents, $self->{db}->tags($self));
     }
     elsif($state==$STATE_ROOT)
     {
-       @dents=(qw(ALL NOT), $self->{db}->tags(@{$self->{elements}}));
+       @dents=(qw(ALL NOT), $self->{db}->tags($self));
     }
     elsif($state==$STATE_ALBUMS)
     {
-       @dents=(qw(TRACKS NOALBUM),$self->{db}->albums(@{$self->{elements}}));
+       @dents=(qw(TRACKS NOALBUM),$self->{db}->albums($self));
     }
     elsif($state==$STATE_TRACKLIST)
     {
-       @dents=$self->{db}->tracks(@{$self->{elements}});
+       @dents=$self->{db}->tracks($self);
     }
     else
     {
@@ -307,6 +307,8 @@ sub parse
         $self->{andsneeded}) = $self->{tagtree}->to_sql();
        print("SQL CONDITION(", $self->{andsneeded}, "): ",
              $self->{sqlconditions}, "\n");
+#      use Data::Dumper;
+#      print Dumper $self->{tagtree};
     }
 }
 
index 4fe4f48..771a15a 100644 (file)
@@ -58,8 +58,9 @@ sub print_node
 
 sub to_sql
 {
-    my($self, $andlevel)=@_;
+    my($self, $andlevel, $parent_is_tag)=@_;
     $andlevel=1 unless(defined($andlevel));
+    $parent_is_tag=0 unless(defined($parent_is_tag));
     my ($leftandlevel, $rightandlevel);
     my ($leftstr, $rightstr);
     my $op=$self->op();