[PATCH] Don't automatically uncompress files when slurping; otherwise compressed files don't round-trip

Alex Vandiver alexmv at bestpractical.com
Tue Apr 27 04:17:41 UTC 2010


Files compressed with Zlib were being decrypted into a temporary file,
and then slurped in, but the slurping was being too "smart," and
automatically uncompressing compressed files.  Thus files that were
already compressed on disk before being backed up end up being
uncompressed while being restored, and cause checksum mismatches.
Most notably, this affects all git object files.

Since there is no other place where Brackup::Util::slurp is used, the
correct fix is to never attempt to uncompress files as they are
slurped.
---
 lib/Brackup/Decrypt.pm |    2 +-
 lib/Brackup/Util.pm    |    9 +--------
 2 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/lib/Brackup/Decrypt.pm b/lib/Brackup/Decrypt.pm
index e5c9de8..3f45bcf 100644
--- a/lib/Brackup/Decrypt.pm
+++ b/lib/Brackup/Decrypt.pm
@@ -20,7 +20,7 @@ sub decrypt_data {
     my $decrypted_temp = decrypt_file($dataref_temp,%opts);
     unlink($dataref_temp);
 
-    my $data = Brackup::Util::slurp($decrypted_temp);
+    my $data = slurp($decrypted_temp);
     unlink($decrypted_temp);
 
     return \$data;
diff --git a/lib/Brackup/Util.pm b/lib/Brackup/Util.pm
index 3b9b45e..98a86e0 100644
--- a/lib/Brackup/Util.pm
+++ b/lib/Brackup/Util.pm
@@ -51,14 +51,7 @@ sub tempdir {
 
 sub slurp {
     my $file = shift;
-    my $fh;
-    if (eval { require IO::Uncompress::AnyUncompress }) {
-        $fh = IO::Uncompress::AnyUncompress->new($file)
-            or die "Failed to open file $file: $IO::Uncompress::AnyUncompress::AnyUncompressError";
-    }
-    else {
-        sysopen($fh, $file, O_RDONLY) or die "Failed to open $file: $!";
-    }
+    sysopen(my $fh, $file, O_RDONLY) or die "Failed to open $file: $!";
     return do { local $/; <$fh>; }
 }
 
-- 
1.7.0.5



More information about the brackup mailing list