bin/imager.check
changeset 72 2a7ab8422dd6
parent 68 25d318915ae9
child 81 f8fc94c18ebd
equal deleted inserted replaced
69:c12fa4d32903 72:2a7ab8422dd6
     9 use File::Temp;
     9 use File::Temp;
    10 use Digest::MD5 qw(md5_hex);
    10 use Digest::MD5 qw(md5_hex);
    11 use File::Basename;
    11 use File::Basename;
    12 use autodie qw(:all);
    12 use autodie qw(:all);
    13 use Cwd qw(abs_path);
    13 use Cwd qw(abs_path);
    14 use IO::Compress::Gzip qw(&gzip $GzipError Z_BEST_SPEED);
    14 use Imager;
    15 use IO::Uncompress::Gunzip qw(&gunzip $GunzipError);
       
    16 
    15 
    17 use Getopt::Long;
    16 use Getopt::Long;
    18 use constant CIPHER => "aes-128-cbc";
    17 use constant CIPHER => "aes-128-cbc";
    19 sub get_block_list;
    18 sub get_block_list;
    20 sub purge_unused;
    19 sub purge_unused;
    21 sub check_images;
    20 sub check_images;
    22 
    21 
    23 my %o = (
    22 our %o = (
    24     yes      => undef,
    23     yes      => undef,
    25     verbose  => 1,
    24     verbose  => 1,
    26     checksum => undef,
    25     checksum => undef,
    27     pass     => undef,
    26     pass     => undef,
    28 );
    27 );
   224         }
   223         }
   225 
   224 
   226         next if not $o{checksum};
   225         next if not $o{checksum};
   227 
   226 
   228         # checking the checksum
   227         # checking the checksum
   229         my $buffer;
   228 	Imager::get_block($file => \my $buffer);
   230         given ($file) {
       
   231             when (/\.gz\.x$/) {
       
   232                 open(
       
   233                     my $fh =>
       
   234                       "openssl @{[CIPHER]} -d -pass $o{pass} -in $file|");
       
   235                 local $/ = undef;
       
   236                 gunzip($fh => \$buffer) or die $GunzipError;
       
   237             }
       
   238             when (/\.gz$/) { gunzip($file => \$buffer) or die $GunzipError }
       
   239             when (/\.x$/) {
       
   240                 open(
       
   241                     my $fh =>
       
   242                       "openssl @{[CIPHER]} -d -pass $o{pass} -in $file|");
       
   243                 local $/ = undef;
       
   244                 $buffer = <$fh>;
       
   245             }
       
   246             default { open(my $fh => $file); local $/ = undef; $buffer = <$fh> }
       
   247         }
       
   248 
       
   249         next if md5_hex($buffer) eq basename($file, qw(.gz .x .gz.x));
   229         next if md5_hex($buffer) eq basename($file, qw(.gz .x .gz.x));
   250         say "wrong checksum for $file\n";
   230         say "wrong checksum for $file\n";
   251         @invalid{@$i} = ();
   231         @invalid{@$i} = ();
   252 
   232 
   253     }
   233     }