--- 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 {