bin/imager.restore
changeset 72 2a7ab8422dd6
parent 52 100c97dc02ca
child 74 a8495233e04c
equal deleted inserted replaced
69:c12fa4d32903 72:2a7ab8422dd6
    15 use File::Basename;
    15 use File::Basename;
    16 use autodie qw(:all);
    16 use autodie qw(:all);
    17 use Pod::Usage;
    17 use Pod::Usage;
    18 use Getopt::Long;
    18 use Getopt::Long;
    19 use Hash::Util qw(lock_keys);
    19 use Hash::Util qw(lock_keys);
    20 use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
    20 use Imager;
    21 
    21 
    22 use constant KiB    => 1024;
    22 use constant KiB    => 1024;
    23 use constant MiB    => 1024 * KiB;
    23 use constant MiB    => 1024 * KiB;
    24 use constant GiB    => 1024 * MiB;
    24 use constant GiB    => 1024 * MiB;
    25 use constant ME     => basename $0;
    25 use constant ME     => basename $0;
    65     else               { open($out => ">", $dst) }
    65     else               { open($out => ">", $dst) }
    66 
    66 
    67     while (<$fh>) {
    67     while (<$fh>) {
    68         next if /^#/;
    68         next if /^#/;
    69         my ($blk, $hash, $path) = split;
    69         my ($blk, $hash, $path) = split;
    70         my ($in, $buffer);
    70         my $buffer;
    71 
    71         if (-f "$data/$path") { Imager::get_block("$data/$path" => \$buffer) }
    72         if (-f "$data/$path") {
       
    73             open($in => "$data/$path");
       
    74             binmode($in);
       
    75             local $/ = undef;
       
    76             $buffer = <$in>;
       
    77         }
       
    78         elsif (-f "$data/$path.gz") {
    72         elsif (-f "$data/$path.gz") {
    79             open($in => "$data/$path.gz");
    73             Imager::get_block("$data/$path.gz" => \$buffer);
    80             binmode($in);
       
    81             gunzip($in => \$buffer)
       
    82               or die $GunzipError;
       
    83         }
    74         }
    84         elsif (-f "$data/$path.x") {
    75         elsif (-f "$data/$path.x") {
    85             open($in,
    76             Imager::get_block("$data/$path.x" => \$buffer);
    86                 "openssl @{[CIPHER]} -d -pass $o{pass} -in '$data/$path.x'|");
       
    87             binmode($in);
       
    88             local $/ = undef;
       
    89             $buffer = <$in>;
       
    90         }
    77         }
    91         elsif (-f "$data/$path.gz.x") {
    78         elsif (-f "$data/$path.gz.x") {
    92             open($in,
    79             Imager::get_block("$data/$path.gz.x" => \$buffer);
    93                 "openssl @{[CIPHER]} -d -pass $o{pass} -in $data/$path.gz.x|");
       
    94             binmode($in);
       
    95             gunzip($in => \$buffer)
       
    96               or die $GunzipError;
       
    97         }
    80         }
    98         elsif (-f "$data/$path.x.gz") {
    81         else { die ME . ": Can't open $data/$path: $!\n" }
    99             warn "$data/$path.x.gz: depreciated!\n";
       
   100             open($in,
       
   101 "gzip -d -c $data/$path.x.gz | openssl @{[CIPHER]} -d -pass $o{pass}|"
       
   102             );
       
   103             binmode($in);
       
   104             local $/ = undef;
       
   105             $buffer = <$in>;
       
   106         }
       
   107         else {
       
   108             die ME . ": Can't open $data/$path: $!\n";
       
   109         }
       
   110         print {$out} $buffer;
    82         print {$out} $buffer;
   111         close($in);
       
   112     }
    83     }
   113     close($out);
    84     close($out);
   114     close($fh);
    85     close($fh);
   115 }
    86 }
   116 
    87