--- trunk/bin/BackupPC_updatedb 2005/08/20 14:08:02 47 +++ trunk/bin/BackupPC_updatedb 2005/08/20 14:13:58 48 @@ -1,8 +1,9 @@ #!/usr/local/bin/perl -w use strict; -use DBI; use lib "__INSTALLDIR__/lib"; + +use DBI; use BackupPC::Lib; use BackupPC::View; use Data::Dumper; @@ -10,6 +11,7 @@ use Time::HiRes qw/time/; use File::Pid; use POSIX qw/strftime/; + use constant BPC_FTYPE_DIR => 5; my $debug = 0; @@ -280,10 +282,15 @@ sub found_in_db { - my ($shareID,undef,$name,$path,undef,$date,undef,$size) = @_; + my @data = @_; + shift @data; + + my ($key, $shareID,undef,$name,$path,undef,$date,undef,$size) = @_; + + return $beenThere->{$key} if (defined($beenThere->{$key})); $sth->{file_in_db} ||= $dbh->prepare(qq{ - SELECT count(*) FROM files + SELECT 1 FROM files WHERE shareID = ? and path = ? and name = ? and @@ -293,8 +300,12 @@ my @param = ($shareID,$path,$name,$date,$size); $sth->{file_in_db}->execute(@param); - my ($rows) = $sth->{file_in_db}->fetchrow_array(); + my $rows = $sth->{file_in_db}->rows; print STDERR "## found_in_db ",( $rows ? '+' : '-' ), join(" ",@param), "\n" if ($debug >= 3); + + $beenThere->{$key}++; + + $sth->{'insert_files'}->execute(@data) unless ($rows); return $rows; } @@ -339,9 +350,9 @@ )); - if (! $beenThere->{$key} && ! found_in_db(@data)) { + if (! defined($beenThere->{$key}) && ! found_in_db($key, @data)) { print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2); - $sth->{'insert_files'}->execute(@data); + if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) { $new_dirs++; print STDERR " dir\n" if ($debug >= 2); @@ -350,7 +361,6 @@ print STDERR " file\n" if ($debug >= 2); } } - $beenThere->{$key}++; if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) { $nr_dirs++;