incomplete support for filtering directories by whether they actually have contents
authorIan Beckwith <ianb@erislabs.net>
Sat, 16 Oct 2010 10:24:01 +0000 (11:24 +0100)
committerIan Beckwith <ianb@erislabs.net>
Sat, 16 Oct 2010 10:24:01 +0000 (11:24 +0100)
lib/ID3FS/Fuse.pm
lib/ID3FS/Path.pm

index ebe6243..f24f680 100644 (file)
@@ -94,11 +94,28 @@ sub getdir
 #    print "**GETDIR: $filename\n";
     my $path=ID3FS::Path->new($self->{db}, $filename);
     return(-ENOENT()) unless($path->isvalid());
-    if($path->isdir())
-    {
-       return(".", "..", $path->dirents(), 0);
-    }
-    return -ENOTDIR();
+    return(-ENOTDIR()) unless($path->isdir());
+    my @dents=(".", "..");
+    my($dirs, $files)=$path->dirents();
+    push(@dents, grep { $self->hascontents($filename, $_); } @$dirs);
+    push(@dents, @$files);
+    return(@dents, 0);
+}
+
+sub hascontents
+{
+    return 1;
+    # FIXME
+    my($self, $base, $dir)=@_;
+    print "hascontents: $base / $dir\n";
+    my $path=ID3FS::Path->new($self->{db}, "$base/$dir");
+    print "VALID: ", $path->isvalid(), "\n";
+    return 1 unless($path->isvalid());
+    my($subdirs,$subfiles)=$path->dirents();
+    print "SUBDIRS: ", join(", ", @$subdirs), "\n";
+    print "SUBFILES: ", join(", ", @$subfiles), "\n";
+    return 1 if(@$subdirs || @$subfiles);
+    return 0;
 }
 
 # unused stubs
index 4898aeb..5555bb2 100644 (file)
@@ -69,6 +69,7 @@ sub dirents
 {
     my($self)=@_;
     my @dents=();
+    my @fents=();
     my $state=$self->state();
 #    print "DIRENTS: STATE: $state\n";
 #    print "DIRENTS: FILE: $self->{path}\n";
@@ -112,13 +113,13 @@ sub dirents
     }
     elsif($state==$STATE_TRACKLIST)
     {
-       @dents=$self->tracks();
+       @fents=$self->tracks();
     }
     else
     {
        print "DIRENTS: UNHANDLED STATE: $state\n";
     }
-    return(@dents);
+    return(\@dents, \@fents);
 }
 
 sub parse
@@ -335,7 +336,6 @@ sub parse
        }
     }
 
-    print "ROOT_NOT: $root_not TAGS_SEEN: $tags_seen\n";
     if($root_not && ($tags_seen < 2))
     {
        $self->{bare_not}=1;
@@ -485,7 +485,7 @@ sub tail_parent
 sub tags
 {
     my($self)=@_;
-    if(!$self->{tagtree}) # / or /NOT
+    if(!$self->{tagtree}) # / or /NOT  # FIXME: /ALL too?
     {
        my $sql="SELECT DISTINCT name FROM tags WHERE parents_id='';";
        return($self->{db}->cmd_firstcol($sql));
@@ -754,6 +754,7 @@ sub filename
 sub tags_subselect
 {
     my($self)=@_;
+    my $hasvals=$self->tag_has_values();
     # we need to specially handle a bare /NOT/tag with no other clauses,
     # using a simple WHERE id !='tagid' instead of a LEFT JOIN
     if($self->{bare_not})
@@ -765,7 +766,6 @@ sub tags_subselect
        return "\tSELECT id FROM files AS files_id\n";
     }
     my $tree=$self->{tagtree};
-    my $hasvals=$self->tag_has_values();
     my $parent=$self->trailing_tag_parent();
 
 #    print "ELEMENTS: ", join('/', map { $_->{name}; } @{$self->{elements}}), "\n";