sub _log {
my $self = shift;
return unless $self->debug;
- print STDERR @_, "\n";
+ print STDOUT @_, "\n";
}
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;
$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...");
)
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;
$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;
}