From: Ian Beckwith Date: Tue, 19 Oct 2010 08:08:27 +0000 (+0100) Subject: fix relativising symlinks X-Git-Tag: debian/1.0-1~41 X-Git-Url: http://erislabs.net/gitweb/?p=id3fs.git;a=commitdiff_plain;h=a77a37a3794cc178915a3c0982c6043e918b96a4 fix relativising symlinks --- diff --git a/lib/ID3FS/DB.pm b/lib/ID3FS/DB.pm index 273f6dc..984bec0 100644 --- a/lib/ID3FS/DB.pm +++ b/lib/ID3FS/DB.pm @@ -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 diff --git a/lib/ID3FS/Path.pm b/lib/ID3FS/Path.pm index 5d13188..0326af6 100644 --- a/lib/ID3FS/Path.pm +++ b/lib/ID3FS/Path.pm @@ -688,7 +688,7 @@ sub filename print "FILENAME SQL: $sql\n" if($self->{verbose}); my ($path, $name)=$self->{db}->cmd_onerow($sql, $id); my $id3fs_path=join('/', map { $_->{name}; } @{$self->{elements}}); - return($self->{db}->relativise($path, $name, $mountpoint)); + return($self->{db}->relativise($path, $name, $mountpoint, $self->{path})); } # should never happen return "ERROR";