summaryrefslogtreecommitdiffstats
path: root/pm
diff options
context:
space:
mode:
authorSandro Cazzaniga <kharec@mageia.org>2012-09-25 12:18:24 +0000
committerSandro Cazzaniga <kharec@mageia.org>2012-09-25 12:18:24 +0000
commit9adc6bd9fe71b99e9e5c0de820d1a76b858d8873 (patch)
tree78f642cc793e529235133340346da6c6d4e2474d /pm
parente4ef2cb4fff5ee825b00deaafcdfc39447d6adfe (diff)
downloadmgatools-9adc6bd9fe71b99e9e5c0de820d1a76b858d8873.tar
mgatools-9adc6bd9fe71b99e9e5c0de820d1a76b858d8873.tar.gz
mgatools-9adc6bd9fe71b99e9e5c0de820d1a76b858d8873.tar.bz2
mgatools-9adc6bd9fe71b99e9e5c0de820d1a76b858d8873.tar.xz
mgatools-9adc6bd9fe71b99e9e5c0de820d1a76b858d8873.zip
revert previous commit
Diffstat (limited to 'pm')
-rw-r--r--pm/MGATools/iso.pm87
1 files changed, 36 insertions, 51 deletions
diff --git a/pm/MGATools/iso.pm b/pm/MGATools/iso.pm
index 24d91b4..8fe13e5 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,51 +52,37 @@ 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;
@@ -105,34 +91,33 @@ 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