#!/usr/local/bin/perl -w
use strict;
-use DBI;
use lib "__INSTALLDIR__/lib";
+
+use DBI;
use BackupPC::Lib;
use BackupPC::View;
use Data::Dumper;
use Time::HiRes qw/time/;
use File::Pid;
use POSIX qw/strftime/;
+
use constant BPC_FTYPE_DIR => 5;
my $debug = 0;
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
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;
}
));
- 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);
print STDERR " file\n" if ($debug >= 2);
}
}
- $beenThere->{$key}++;
if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
$nr_dirs++;