diff -r f1fea4381014 -r 9362fac2a7c8 bin/imager.save --- a/bin/imager.save Sun Jul 31 23:22:59 2011 +0200 +++ b/bin/imager.save Sun Jul 31 23:47:09 2011 +0200 @@ -35,6 +35,7 @@ blocksize => BS, pass => undef, comment => undef, + threads => undef, ); lock_keys(%o); @@ -50,6 +51,7 @@ -noperldoc => system("perldoc -V >/dev/null 2>&1") ); }, + "t|threads:i" => sub { $o{threads} = $_[1] ? $_[1] : 2 }, "c|comment=s" => \$o{comment}, "z|compress:i" => sub { $o{compress} = $_[1] ? $_[1] : Z_BEST_SPEED }, "p|pass=s" => \$o{pass}, @@ -101,20 +103,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 +151,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 +183,27 @@ 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 +211,6 @@ . sprintf "%3d%%" => 100 * ($stats{skipped} / ($stats{written} + $stats{skipped})); - rename $index->filename => "$idx/" . DATETIME; - close $index; - } sub get_devsize {