fix relativising symlinks
[id3fs.git] / lib / ID3FS / DB.pm
index 273f6dc..984bec0 100644 (file)
@@ -37,6 +37,7 @@ sub new
     my $init=shift;
     $self->{base}=shift;
     $self->{dbpath}=shift || ($self->{base} . "/" . $dbfile);
+    $self->{dbpath}=Cwd::abs_path($self->{dbpath});
     $self->{absbase}=Cwd::abs_path($self->{base});
 
     my $connectstr="dbi:SQLite:dbname=$self->{dbpath}";
@@ -184,20 +185,21 @@ sub tag_has_values
 
 sub relativise
 {
-    my($self, $path, $name, $mountpoint)=@_;
-    my $id3fs_path=$self->{dbpath};
-    $id3fs_path=~s/(.*)\/.*/$1/;
+    my($self, $path, $name, $mountpoint, $querypath)=@_;
     my $rpath="$self->{absbase}/$path";
-    my $vpath="$mountpoint/$id3fs_path";
+    my $vpath=$mountpoint . $querypath;
     my @path=split(/\//,$rpath);
     my @rel=split(/\//,$vpath);
-    #absolute paths have empty first element due to leading /
+    # drop filename from rel
+    pop @rel;
+    # absolute paths have empty first element due to leading /
     shift(@path) if($path[0] eq "");
     shift(@rel)  if($rel[0]  eq "");
     if($path[0] ne $rel[0])
     {
-       #no path in common, return absolute
-       print "FAIL: NO PATHS IN COMMON\n";
+       # no path in common, return absolute
+       # should never happen
+       # FIXME
        return $name;
     }
     # f: /home/foo/bar/baz.mp3