From 30512f547165a17d40f64a68de579ff7498d29e6 Mon Sep 17 00:00:00 2001 From: hjp Date: Sun, 4 May 2008 13:42:31 +0000 Subject: [PATCH] fixed some db queries. Identified (but haven't yet fixed) lack of error handling when reading from CA. --- lib/Simba/CA.pm | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/Simba/CA.pm b/lib/Simba/CA.pm index f7570a2..e4f4c0f 100644 --- a/lib/Simba/CA.pm +++ b/lib/Simba/CA.pm @@ -404,39 +404,40 @@ sub db_record_version { where file_type=? and file_size=? and file_mtime=? and file_owner=? and file_group=? and file_acl=? and - file_unix_bits=? and - checksum=? + file_unix_bits=? "; my @args = ( $f->{t}, $f->{s}, $f->{m}, $f->{o}, $f->{g}, $f->{acl}, join(',', map {$f->{$_} ? ($_) : ()} qw(setuid setgid sticky)), - $f->{checksum} ); - if ($f->{t} eq 'b' || $f->{t} eq 'c') { - $query .= " and file_rdev=?"; - push @args, $f->{rdev}; - } - if ($f->{t} eq 'l') { + if ($f->{t} eq 'f') { + $query .= " and checksum=?"; + push @args, $f->{checksum}; + } elsif ($f->{t} eq 'l') { $query .= " and file_linktarget=?"; push @args, $f->{lt}; + } elsif ($f->{t} eq 'b' || $f->{t} eq 'c') { + $query .= " and file_rdev=?"; + push @args, $f->{rdev}; } my $version_id = $self->{dbh}->selectrow_array($query, {}, @args); unless ($version_id) { + # XXX why is $f->{checksum} undef here for ./bin/dash? $self->{dbh}->do("insert into versions2( file_type, file_size, file_mtime, file_owner, file_group, file_acl, file_unix_bits, file_rdev, - checksum, file_linktarget, + checksum, file_linktarget ) values( ?, ?, ?, ?, ?, ?, ?, ?, - ?, ?, + ?, ? )", {}, $f->{t}, $f->{s}, $f->{m}, @@ -512,13 +513,14 @@ and it is more likely that we can link to new copies than to old ones. sub linkdup { my ($self, $f, $backup_filename) = @_; # XXX - my $sth = $self->{dbh}->prepare("select * from versions2, instances, files + my $sth = $self->{dbh}->prepare("select * from versions2, instances, files, sessions where file_type=? and file_size=? and file_mtime=? and file_owner=? and file_group=? and file_acl=? and file_unix_bits=? and checksum=? and online=1 and instances.file=files.id and versions2.id=instances.version + and instances.session=sessions.id order by instances.session desc "); $sth->execute( @@ -628,6 +630,12 @@ sub store_file { } } else { $self->log(5, "unexpected header $header\n"); + # How can we recover here? + # Kill connection so that a new one is created for the next file + # Return failure so that this file is not recorded as done + # + # same problem for other failures in this method. + die "unexpected header $header"; } }