Update with latest fixes
[catagits/BackPAN-Web.git] / lib / BackPAN / Index.pm
index 15cbbf9..6b7d0e8 100644 (file)
@@ -96,8 +96,6 @@ sub _update_database {
         $should_update_db = 1 if $db_mtime < $archive_mtime;
     }
 
-    unlink $db_file if -e $db_file and $should_update_db;
-
     $self->schema( BackPAN::Index::Schema->connect("dbi:SQLite:dbname=$db_file") );
     return unless $should_update_db;
 
@@ -108,10 +106,6 @@ sub _update_database {
 
     $self->_setup_database;
 
-    $should_update_db = 1 if $self->_database_is_empty;
-
-    return unless $should_update_db;
-
     my $dbh = $self->_dbh;
 
     $self->_log("Populating database...");
@@ -273,10 +267,16 @@ CREATE TABLE IF NOT EXISTS dists (
 )
 SQL
 );
+    my %delete_for = (
+        files => 'DELETE FROM files',
+        releases => 'DELETE FROM releases',
+        dists => 'DELETE FROM dists',
+    );
 
     my $dbh = $self->_dbh;
-    for my $sql (values %create_for) {
-        $dbh->do($sql);
+    for my $table_name (keys %create_for) {
+        $dbh->do($create_for{$table_name});
+        $dbh->do($delete_for{$table_name});
     }
 
     $self->schema->rescan;
@@ -367,7 +367,7 @@ sub _backpan_index_has_changed {
     $self->_backpan_index_file->touch;
 
     my(undef, undef, $remote_mod_time) = head($self->backpan_index_url);
-    return $remote_mod_time > $local_mod_time;
+    return defined $remote_mod_time && $remote_mod_time > $local_mod_time;
 }