[Bps-public-commit] brackup branch, master, updated. fc647da300dffad6409aa1999ec4be150f6286fe

Alex Vandiver alexmv at bestpractical.com
Fri Sep 3 15:59:35 EDT 2010


The branch, master has been updated
       via  fc647da300dffad6409aa1999ec4be150f6286fe (commit)
       via  e62467adfa80bf6b7b54d360730d0b36b1b3deda (commit)
       via  746be803dbc4a622837f9d0a63f55b6d83f9b8a8 (commit)
      from  5445cb3c0d21c9555b579fd929eef3043e3c1418 (commit)

Summary of changes:
 lib/Brackup/Restore.pm       |   40 +++++++++++++++++++++++-----------------
 lib/Brackup/Target/Amazon.pm |    2 ++
 2 files changed, 25 insertions(+), 17 deletions(-)

- Log -----------------------------------------------------------------
commit 746be803dbc4a622837f9d0a63f55b6d83f9b8a8
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Sep 3 16:00:10 2010 -0400

    Look at the same ENV variables as Net::Amazon::S3

diff --git a/lib/Brackup/Target/Amazon.pm b/lib/Brackup/Target/Amazon.pm
index d55e394..ed5a7e9 100644
--- a/lib/Brackup/Target/Amazon.pm
+++ b/lib/Brackup/Target/Amazon.pm
@@ -81,11 +81,13 @@ sub new_from_backup_header {
     my ($class, $header, $confsec) = @_;
 
     my $accesskey     = ($ENV{'AWS_KEY'} || 
+                         $ENV{'AWS_ACCESS_KEY_ID'} || 
                          $header->{AWSAccessKeyID} || 
                          $confsec->value('aws_access_key_id') || 
                          _prompt("Your Amazon AWS access key? "))
         or die "Need your Amazon access key.\n";
     my $sec_accesskey = ($ENV{'AWS_SEC_KEY'} || 
+                         $ENV{'AWS_ACCESS_KEY_SECRET'} || 
                          $confsec->value('aws_secret_access_key') || 
                          _prompt("Your Amazon AWS secret access key? "))
         or die "Need your Amazon secret access key.\n";

commit e62467adfa80bf6b7b54d360730d0b36b1b3deda
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Sep 3 16:00:56 2010 -0400

    Refactor out the SHA-checking after downloading the chunk

diff --git a/lib/Brackup/Restore.pm b/lib/Brackup/Restore.pm
index 3b8ab48..ff4cadd 100644
--- a/lib/Brackup/Restore.pm
+++ b/lib/Brackup/Restore.pm
@@ -8,6 +8,7 @@ use Fcntl qw(O_RDONLY O_CREAT O_WRONLY O_TRUNC);
 use String::Escape qw(unprintable);
 use Brackup::DecryptedFile;
 use Brackup::Decrypt;
+use Brackup::Util qw(io_sha1);
 
 sub new {
     my ($class, %opts) = @_;
@@ -278,6 +279,19 @@ sub _restore_fifo {
     $self->_update_statinfo($full, $it);
 }
 
+sub _digest_matches {
+    my ($self, $it, $path) = @_;
+    my $good_dig = $it->{Digest};
+    return undef unless $good_dig and $good_dig =~ /^sha1:(.+)/;
+    $good_dig = $1;
+    sysopen(my $readfh, $path, O_RDONLY) or die "Failed to open '$path' for verification: $!";
+    binmode($readfh);
+    my $sha1 = Digest::SHA1->new;
+    $sha1->addfile($readfh);
+    my $actual_dig = $sha1->hexdigest;
+    return $actual_dig eq $good_dig;
+}
+
 sub _restore_file {
     my ($self, $full, $it) = @_;
 
@@ -333,22 +347,9 @@ sub _restore_file {
     }
     close($fh) or die "Close failed";
 
-    if (my $good_dig = $it->{Digest}) {
-        die "not capable of verifying digests of from anything but sha1"
-            unless $good_dig =~ /^sha1:(.+)/;
-        $good_dig = $1;
-
-        sysopen(my $readfh, $full, O_RDONLY) or die "Failed to reopen '$full' for verification: $!";
-        binmode($readfh);
-        my $sha1 = Digest::SHA1->new;
-        $sha1->addfile($readfh);
-        my $actual_dig = $sha1->hexdigest;
-
-        # TODO: support --onerror={continue,prompt}, etc, but for now we just die
-        unless ($actual_dig eq $good_dig || $full =~ m!\.brackup-digest\.db\b!) {
-            die "Digest of restored file ($full) doesn't match";
-        }
-    }
+    my $digest_ok = $self->_digest_matches($it, $full);
+    die "Digest of restored file ($full) doesn't match"
+        if defined $digest_ok and not $digest_ok and $full !~ m!\.brackup-digest\.db\b!;
 
     $self->_update_statinfo($full, $it);
 }

commit fc647da300dffad6409aa1999ec4be150f6286fe
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Sep 3 16:01:20 2010 -0400

    If the file exists on disk already, but the hashes match, keep calm and carry on

diff --git a/lib/Brackup/Restore.pm b/lib/Brackup/Restore.pm
index ff4cadd..baacb29 100644
--- a/lib/Brackup/Restore.pm
+++ b/lib/Brackup/Restore.pm
@@ -296,8 +296,13 @@ sub _restore_file {
     my ($self, $full, $it) = @_;
 
     if (-e $full && -s $full) {
+        if ($self->_digest_matches($it, $full)) {
+            warn "   ** file already exists on disk\n" if $self->{verbose};
+            $self->_update_statinfo($full, $it);
+            return;
+        }
         # TODO: add --conflict={skip,overwrite} option, defaulting to nothing: which dies
-        die "File $full ($it->{Path}) already exists.  Aborting.";
+        die "File $full ($it->{Path}) already exists, and contents differ.  Aborting.";
     }
 
     sysopen(my $fh, $full, O_CREAT|O_WRONLY|O_TRUNC) or die "Failed to open '$full' for writing: $!";

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list