# HG changeset patch # User Heiko Schlittermann (JUMPER) # Date 1312149752 -7200 # Node ID 9a717ec183a23580f221f5b3fb47177729d3cbcd # Parent f1fea438101490792ab23154f44f8cb30d6f221e# Parent 8b655cc9bd2794bd0cd8c3fa8265a09e87692436 joined from testing (no tmp file for index) diff -r f1fea4381014 -r 9a717ec183a2 bin/imager.save --- a/bin/imager.save Sun Jul 31 23:22:59 2011 +0200 +++ b/bin/imager.save Mon Aug 01 00:02:32 2011 +0200 @@ -50,8 +50,8 @@ -noperldoc => system("perldoc -V >/dev/null 2>&1") ); }, - "c|comment=s" => \$o{comment}, - "z|compress:i" => sub { $o{compress} = $_[1] ? $_[1] : Z_BEST_SPEED }, + "c|comment=s" => \$o{comment}, + "z|compress:i" => sub { $o{compress} = $_[1] ? $_[1] : Z_BEST_SPEED }, "p|pass=s" => \$o{pass}, "b|blocksize=s" => sub { given ($_[1]) { @@ -101,20 +101,18 @@ -d $dst or die "$0: $dst: $!\n"; mkpath([$data, $idx, $info]); - my $index = File::Temp->new(DIR => $idx); - print {$index} <<__EOT; -# imager -format: 1 -host: @{[hostname]} -filesystem: $src -blocksize: $o{blocksize} -devsize: $size -timestamp: @{[NOW]} -datetime: @{[DATETIME]} -comment: @{[$o{comment}//"none"]} -encryption: @{[$o{pass} ? CIPHER : "none"]} - -__EOT + my %index; + $index{META} = { + format => 1, + host => hostname, + filesystem => $src, + blocksize => $o{blocksize}, + devsize => $size, + timestamp => NOW, + datetime => DATETIME, + (defined $o{comment} ? (comment => $o{comment}) : ()), + encryption => $o{pass} ? CIPHER : "none", + }; open(my $in => $src); binmode($in); @@ -151,7 +149,8 @@ $ext .= $o{pass} ? ".x" : ""; # the extension we do not put into the index - my $log = sprintf "%12d %s %s" => ($. - 1), $cs, $file; + push @{ $index{BLOCKS} }, sprintf "%12d %s %s" => ($. - 1), + $cs, $file; if ( not( -e "$data/$file" @@ -182,20 +181,26 @@ else { print {$out} $buffer } close($out); rename($out => "$data/$file$ext"); - $log .= " *"; + $index{BLOCKS}[$. - 1] .= " *"; $stats{written}++; } else { - $log .= " "; $stats{skipped}++; } - - say {$index} $log; } $SIG{ALRM}->(); alarm 0; - say {$index} "# DONE (runtime " . (time() - $^T) . "s)"; + $index{META}{blocks} = @{ $index{BLOCKS} }; + $index{META}{runtime} = time() - $^T . "s"; + + my $index = File::Temp->new(DIR => $idx); + say $index join "\n" => "# imager", + (map { "$_: $index{META}{$_}" } sort(keys %{ $index{META} })), + "", + @{ $index{BLOCKS} }; + close($index); + rename $index->filename => "$idx/" . DATETIME; say "# $src DONE (runtime " . (time() - $^T) . "s)"; say "# $src WRITTEN $stats{written}, SKIPPED $stats{skipped} blocks"; @@ -203,9 +208,6 @@ . sprintf "%3d%%" => 100 * ($stats{skipped} / ($stats{written} + $stats{skipped})); - rename $index->filename => "$idx/" . DATETIME; - close $index; - } sub get_devsize {