2 ############################################################################
3 # soepkiptng (c) copyright 2000 Eric Lammerts <eric@lammerts.org>.
5 ############################################################################
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License, version 2, as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # A copy of the GNU General Public License is available on the World Wide Web
16 # at `http://www.gnu.org/copyleft/gpl.html'. You can also obtain it by
17 # writing to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
19 ############################################################################
25 # find program directory
28 my $l = readlink or die "readlink $_: $!\n";
29 if($l =~ m
|^/|) { $_ = $l; } else { s|[^/]*$|/$l|; }
32 my $progdir = abs_path
($1);
34 require "$progdir/soepkiptng.lib";
38 read_configfile
(\
%conf, $opt_c);
40 $ENV{PATH
} = "$progdir/bin:$ENV{PATH}";
44 Usage: soepkiptng_delete [-fqc] [dir]
46 Soepkiptng_delete deletes files from the SoepkipTNG database that do not exist
49 -f : delete entries even if they still exist
51 -x : permanently delete entries that are not present
57 $dbh = DBI
->connect("DBI:$conf{db_type}:$conf{db_name}:$conf{db_host}",
58 $conf{db_user
}, $conf{db_pass
}) or die "can't connect to database";
60 $sth = $dbh->prepare("SELECT filename FROM song WHERE present AND filename like ?");
61 $filename = ($ARGV[0]? abs_path
($ARGV[0]) : "/") . "/%";
62 $filename =~ s/\\/\\\\/g;
63 $sth->execute($filename);
65 while(($filename) = $sth->fetchrow_array) {
66 if(!$opt_f) { -s
$filename and next; }
67 warn "Deleting $filename from database.\n" unless $opt_q;
69 $dbh->do("DELETE FROM song WHERE filename=?", undef, $filename);
71 $dbh->do("UPDATE song SET present=0 WHERE filename=?", undef, $filename);