Index: trunk/Changes
===================================================================
--- trunk/Changes	(revision 12)
+++ trunk/Changes	(revision 13)
@@ -3,4 +3,5 @@
 0.03
     - added "exclude_path" option to filesystem backend
+    - added "sync_db" method to the DB backend
 
 0.02  1 Feb 2006
Index: trunk/Makefile.PL
===================================================================
--- trunk/Makefile.PL	(revision 12)
+++ trunk/Makefile.PL	(revision 13)
@@ -12,4 +12,5 @@
     EXE_FILES => [qw(
         bin/mp3find
+        bin/mp3db
     )],    
     ($] >= 5.005 ?     ## Add these new keywords supported since 5.005
Index: trunk/lib/MP3/Find.pm
===================================================================
--- trunk/lib/MP3/Find.pm	(revision 12)
+++ trunk/lib/MP3/Find.pm	(revision 13)
@@ -9,5 +9,5 @@
 use Carp;
 
-$VERSION = '0.02';
+$VERSION = '0.03';
 
 @EXPORT = qw(find_mp3s);
Index: trunk/lib/MP3/Find/DB.pm
===================================================================
--- trunk/lib/MP3/Find/DB.pm	(revision 12)
+++ trunk/lib/MP3/Find/DB.pm	(revision 13)
@@ -147,4 +147,27 @@
 }
 
+sub sync_db {
+    my $self = shift;
+    my $db_file = shift or croak "Need the name of the databse to sync";
+    
+    my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file", '', '', {RaiseError => 1});
+    my $select_sth = $dbh->prepare('SELECT FILENAME FROM mp3');
+    my $delete_sth = $dbh->prepare('DELETE FROM mp3 WHERE FILENAME = ?');
+    
+    # the number of records removed
+    my $count = 0;
+    
+    $select_sth->execute;
+    while (my ($filename) = $select_sth->fetchrow_array) {
+        unless (-e $filename) {
+            $delete_sth->execute($filename);
+            print STDERR "D $filename\n";
+            $count++;
+        }
+    }
+    
+    return $count;    
+}
+
 sub destroy_db {
     my $self = shift;
@@ -259,4 +282,12 @@
 sinc ethe last time C<update_db> was run.
 
+=head2 sync_db
+
+    my $count = $finder->sync_db($db_filename);
+
+Removes entries from the database that refer to files that no longer
+exist in the filesystem. Returns the count of how many records were
+removed.
+
 =head2 destroy_db
 
@@ -270,5 +301,6 @@
 
 Allow the passing of a DSN or an already created C<$dbh> instead
-of a SQLite database filename.
+of a SQLite database filename; or write driver classes to handle
+database dependent tasks (create_db/destroy_db).
 
 =head1 SEE ALSO
