1#!/usr/local/bin/perl 2use strict; 3 4if (@ARGV and $ARGV[0] eq "--help") { 5 print 6q(This script will test magicrescue on existing files on your hard disk to see 7if your recipe is good enough. It can be very useful when creating or modifying 8a recipe. 9 10Usage: 11./magicrescue -Mio OPTIONS FILES|tools/checkrecipe [OPTIONS] 12 13Options: 14 -s VALUE Size tolerance, in percent. Specifies when checkrecipe should 15 complain about the output file size being different from the input. 16 17Usage examples: 18 19find / -name \*.png -print0 \ 20|xargs -0 ./magicrescue -Mio -r png -d /tmp/test-output 2>/dev/null \ 21|tools/checkrecipe 22 23 or 24 25slocate \*.png|sed "s/['\"\\\\[:blank:]]/\\\\\\\\&/g" \ 26|xargs ./magicrescue -Mio -r png -d /tmp/test-output 2>/dev/null \ 27|tools/checkrecipe 28); 29 exit; 30} 31 32my $size_tolerance = 0; 33 34while (defined(my $arg = shift(@ARGV))) { 35 if ($arg eq "-s") { 36 $size_tolerance = shift(@ARGV)/100; 37 } else { 38 die "$0: Unknown option $arg. Use --help for usage info.\n"; 39 } 40} 41 42my ($curfile, $cur_ok); 43while (<STDIN>) { 44 if (/^i (.*)$/) { 45 if ($curfile and !$cur_ok and -s $curfile) { 46 print "$curfile: not extracted\n"; 47 } 48 $curfile = $1; 49 $cur_ok = 0; 50 } elsif (/^o (.*)$/) { 51 my $outfile = $1; 52 if ($curfile and $cur_ok) { 53 print "$curfile: extracted again\n"; 54 55 } else { 56 my ($insize, $outsize) = (-s $curfile, -s $outfile); 57 if ($size_tolerance >= 0 and $insize and -f $outfile 58 and abs($outsize - $insize)/$insize > $size_tolerance) { 59 print "$curfile: is $insize bytes, extracted $outsize bytes\n"; 60 } 61 } 62 63 $cur_ok = 1; 64 unlink $outfile or warn "unlinking $outfile: $!"; 65 } 66} 67 68