diff --git a/lib/Simba/CA.pm b/lib/Simba/CA.pm index d3809b4..57f6778 100644 --- a/lib/Simba/CA.pm +++ b/lib/Simba/CA.pm @@ -80,6 +80,7 @@ sub backup2disk { $self->{last_backup} = $dirs[-1]; $self->{last_backup} = $1 if $self->{last_backup} =~ /(.*)/; # detaint + $self->{last_backup_id} = $self->get_last_session_id(); my $timestamp = $self->{timestamp} || strftime('%Y-%m-%dT%H.%M.%S', localtime); $self->{this_backup} = $self->{basedir} . "/$timestamp/" . $target->{host} . '/' . $target->{dir}; @@ -374,6 +375,14 @@ sub db_record_version { $target->{id}, $f->{name}); } + if ($f->{t} eq 'f' && !defined($f->{checksum})) { + # this must be a link to the previous version + my $db_pv = $self->{dbh}->selectall_arrayref("select * from versions where file=? and session=?", + { Slice => {} }, + $db_f->[0]{id}, + $self->{last_backup_id}); + $f->{checksum} = $db_pv->[0]{checksum}; + } $self->{dbh}->do("insert into versions(file, file_id, file_type, file_size, file_mtime, file_owner, file_group, file_acl, @@ -410,5 +419,14 @@ sub close_session { $self->{dbh}->do("update sessions set end_date=? where id=?", {}, time(), $self->{session_id}); } +sub get_last_session_id { + my ($self) = @_; + my $sessions = $self->{dbh}->selectall_arrayref("select * from sessions where prefix=?", + { Slice => {} }, + $self->{last_backup}); + die "$self->{last_backup} not a unique prefix" unless @$sessions == 1; + return $sessions->[0]{id}; +} + # vim: tw=0 expandtab 1;