From a77a37a3794cc178915a3c0982c6043e918b96a4 Mon Sep 17 00:00:00 2001 From: Ian Beckwith Date: Tue, 19 Oct 2010 09:08:27 +0100 Subject: [PATCH] fix relativising symlinks --- lib/ID3FS/DB.pm | 16 +++++++++------- lib/ID3FS/Path.pm | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) 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"; -- 2.11.0