summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSandro Cazzaniga <kharec@mageia.org>2012-09-25 09:53:36 +0000
committerSandro Cazzaniga <kharec@mageia.org>2012-09-25 09:53:36 +0000
commite4ef2cb4fff5ee825b00deaafcdfc39447d6adfe (patch)
treed4fb39c17cfcf4f0de6431e2191091e553ca8f4a
parent20d94b5d72327914d1da0f9c2c9d1f724db1f086 (diff)
downloadmgatools-e4ef2cb4fff5ee825b00deaafcdfc39447d6adfe.tar
mgatools-e4ef2cb4fff5ee825b00deaafcdfc39447d6adfe.tar.gz
mgatools-e4ef2cb4fff5ee825b00deaafcdfc39447d6adfe.tar.bz2
mgatools-e4ef2cb4fff5ee825b00deaafcdfc39447d6adfe.tar.xz
mgatools-e4ef2cb4fff5ee825b00deaafcdfc39447d6adfe.zip
tidying the code
-rw-r--r--pm/MGATools/iso.pm87
1 files changed, 51 insertions, 36 deletions
diff --git a/pm/MGATools/iso.pm b/pm/MGATools/iso.pm
index 8fe13e5..24d91b4 100644
--- a/pm/MGATools/iso.pm
+++ b/pm/MGATools/iso.pm
@@ -5,12 +5,12 @@ use Digest::MD5;
require Exporter;
use URPM;
-our @ISA = qw(Exporter);;
+our @ISA = qw(Exporter);
our @EXPORT = qw(include_md5);
-our ($INFO_OFFSET, $SIZE_OFFSET, $SKIP);
+our ( $INFO_OFFSET, $SIZE_OFFSET, $SKIP );
$INFO_OFFSET = 883;
$SIZE_OFFSET = 84;
-$SKIP = 15;
+$SKIP = 15;
=head1 NAME
@@ -52,37 +52,51 @@ md5 code highly inspired from Redhat anaconda md5 in ISO code
=cut
-
# function copied from Mkcd::Tools
# TODO must add some check of maximum authorized size
sub include_md5 {
- my ($iso, $write, $verbose) = @_;
- my $ISO;
+ my ( $iso, $write, $verbose ) = @_;
+ my $ISO;
if ($write) {
- open $ISO, "+<$iso" or return "ERROR include_md5: unable to open $iso ($!)\n";
- } else {
- open $ISO, $iso or return "ERROR include_md5: unable to open $iso ($!)\n";
+ open $ISO, "+<$iso"
+ or return "ERROR include_md5: unable to open $iso ($!)\n";
+ }
+ else {
+ open $ISO, $iso
+ or return "ERROR include_md5: unable to open $iso ($!)\n";
}
binmode $ISO;
- my $offset = 16*2048;
+ my $offset = 16 * 2048;
+
# blank header
seek $ISO, $offset, 0;
- my ($buf, $msg);
+ my ( $buf, $msg );
while (1) {
- read $ISO,$buf,2048;
- my $c = ord $buf;
- last if $c == 1;
- return "ERROR include_md5: could not find primary volume descriptor\n" if $c == 255;
- $offset += 2048
+ read $ISO, $buf, 2048;
+ my $c = ord $buf;
+ last if $c == 1;
+ return "ERROR include_md5: could not find primary volume descriptor\n"
+ if $c == 255;
+ $offset += 2048;
}
- my $size = ((ord substr $buf, $SIZE_OFFSET, 1) * 0x1000000 +
- (ord substr $buf, $SIZE_OFFSET + 1, 1) * 0x10000 +
- (ord substr $buf, $SIZE_OFFSET + 2, 1) * 0x100 +
- (ord substr $buf, $SIZE_OFFSET + 3, 1)) * 2048;
- my ($system, $volume, $publisher, $prep, $app) = map { $a = $_ ; $a =~ s/^\s*//; $a =~ s/\s*$//; $a } (substr($buf, 8, 22), substr($buf, 30, 40), substr($buf, 318, 128), substr($buf, 446, 32), substr($buf, 574, 128));
- print "include_md5:\nSystem: \t$system\nVolume: \t$volume\nPublisher: \t$publisher\nData preparer: \t$prep\nApplication: \t$app\nISO size: \t$size\n" if $verbose;
+ my $size =
+ ( ( ord substr $buf, $SIZE_OFFSET, 1 ) * 0x1000000 +
+ ( ord substr $buf, $SIZE_OFFSET + 1, 1 ) * 0x10000 +
+ ( ord substr $buf, $SIZE_OFFSET + 2, 1 ) * 0x100 +
+ ( ord substr $buf, $SIZE_OFFSET + 3, 1 ) ) * 2048;
+ my ( $system, $volume, $publisher, $prep, $app ) =
+ map { $a = $_; $a =~ s/^\s*//; $a =~ s/\s*$//; $a } (
+ substr( $buf, 8, 22 ),
+ substr( $buf, 30, 40 ),
+ substr( $buf, 318, 128 ),
+ substr( $buf, 446, 32 ),
+ substr( $buf, 574, 128 )
+ );
+ print
+"include_md5:\nSystem: \t$system\nVolume: \t$volume\nPublisher: \t$publisher\nData preparer: \t$prep\nApplication: \t$app\nISO size: \t$size\n"
+ if $verbose;
seek $ISO, $offset + $INFO_OFFSET, 0;
- read $ISO, $buf,512;
+ read $ISO, $buf, 512;
my ($md5sum) = $buf =~ /.md5 = (\S+)/;
$msg .= "include_md5: previous data $buf\n";
seek $ISO, 0, 0;
@@ -91,33 +105,34 @@ sub include_md5 {
$md5->add($buf);
seek $ISO, 512, 1;
$read += 512;
- $|=1;
- my $val = int $size/2048/100;
+ $| = 1;
+ my $val = int $size / 2048 / 100;
$verbose and print "\rReading: 0 %";
- my ($i, $j);
- # skip last $SKIP bytes that sometimes are not correctly burned by some drives
+ my ( $i, $j );
+
+ # skip last $SKIP bytes that sometimes are not correctly burned by some drives
my $n = 1;
- while ($n && $read < $size - $SKIP * 2048) {
- $n = read $ISO, $buf,2048;
- print "\rReading: ", $j++, " %" if ($verbose && !($i++ % $val));
- $md5->add($buf);
- $read += $n;
+ while ( $n && $read < $size - $SKIP * 2048 ) {
+ $n = read $ISO, $buf, 2048;
+ print "\rReading: ", $j++, " %" if ( $verbose && !( $i++ % $val ) );
+ $md5->add($buf);
+ $read += $n;
}
print "\n";
my $digest = $md5->hexdigest;
$msg .= "include_md5: computed md5 $digest\n";
my $res = $md5sum eq $digest;
if ($md5sum) {
- $msg .= "include_md5: previous md5 $md5sum\ninclude_md5: md5sum check ";
- $msg .= $res ? "OK\n" : "FAILED\n"
+ $msg .= "include_md5: previous md5 $md5sum\ninclude_md5: md5sum check ";
+ $msg .= $res ? "OK\n" : "FAILED\n";
}
print $msg if $verbose;
$write or return $res;
seek $ISO, $offset + $INFO_OFFSET, 0;
my $str = substr "$volume.md5 = $digest", 0, 512;
my $l = length $str;
- print $ISO ($l > 512 ? substr $str, -1, 512 : $str . ' ' x (512 - $l));
- close $ISO
+ print $ISO ( $l > 512 ? substr $str, -1, 512 : $str . ' ' x ( 512 - $l ) );
+ close $ISO;
}
1