From 96226f1036a7c15539fe93b355361f878ff5c2dd Mon Sep 17 00:00:00 2001 From: Ian Beckwith Date: Tue, 9 Nov 2010 02:48:46 +0000 Subject: [PATCH] fix pruning tags + only prune files/dirs under @ARGV --- bin/id3fs-index | 4 ++-- lib/ID3FS/DB.pm | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bin/id3fs-index b/bin/id3fs-index index f27c7f6..4ee56e5 100755 --- a/bin/id3fs-index +++ b/bin/id3fs-index @@ -75,7 +75,7 @@ else $db->last_update(time()); my $base=$db->base_dir(); my $abs_base=Cwd::abs_path($base); - while(my $path=shift) + for my $path (@ARGV) { if(Cwd::abs_path($path) !~ /^$abs_base/) { @@ -83,7 +83,7 @@ else } File::Find::find( {wanted => \&wanted, follow => 1, no_chdir => 1}, $path); } - my $directories_pruned=$db->prune_directories(); + my $directories_pruned=$db->prune_directories(@ARGV); if($files_pruned || $directories_pruned) { print "$me: pruning removed files from db\n" if $verbose; diff --git a/lib/ID3FS/DB.pm b/lib/ID3FS/DB.pm index 5821b53..9972864 100644 --- a/lib/ID3FS/DB.pm +++ b/lib/ID3FS/DB.pm @@ -71,7 +71,8 @@ sub find_db my $base=undef; for my $dir (@dirs) { - my $path=Cwd::abs_path($dir); +# my $path=Cwd::abs_path($dir); + my $path=$dir; do { $base=$path; @@ -254,6 +255,8 @@ sub add { "artists_id" => $artist_id, "albums_id" => $albums_id, "paths_id" => $path_id }); + + $self->remove_tag_refs($file_id); if(@tags) { for my $tag (@tags) @@ -376,6 +379,14 @@ sub add_relation $self->cmd($sql, map { $fields->{$_}; } sort keys(%$fields)); } +# remove existing files_x_tags relations before reindexing +sub remove_tag_refs +{ + my ($self, $id)=@_; + my $sql="DELETE FROM files_x_tags WHERE files_id=?\n"; + return($self->cmd($sql, $id)); +} + sub files_in { my ($self, $dir)=@_; @@ -398,13 +409,15 @@ sub unindex sub prune_directories { - my($self)=@_; + my($self,@includepaths)=@_; my $sql=("SELECT name, id FROM paths\n"); my $pathsref=$self->cmd_rows($sql); my @ids=(); for my $pathpair (@$pathsref) { my($path, $id)=@$pathpair; + my $relpath = $self->{base} . "/" . $path; + next unless(grep { $relpath =~ /^$_/; } @includepaths); my $fullpath="$self->{absbase}/$path"; unless(-d $fullpath) { -- 2.11.0