equal
deleted
inserted
replaced
49 -verbose => 2, |
49 -verbose => 2, |
50 exit => 0, |
50 exit => 0, |
51 -noperldoc => system("perldoc -V >/dev/null 2>&1") |
51 -noperldoc => system("perldoc -V >/dev/null 2>&1") |
52 ); |
52 ); |
53 }, |
53 }, |
54 "t|threads:i" => sub { $o{threads} = $_[1] ? $_[1] : 2 }, |
54 "t|threads:i" => sub { $o{threads} = $_[1] ? $_[1] : 2 }, |
55 "c|comment=s" => \$o{comment}, |
55 "c|comment=s" => \$o{comment}, |
56 "z|compress:i" => sub { $o{compress} = $_[1] ? $_[1] : Z_BEST_SPEED }, |
56 "z|compress:i" => sub { $o{compress} = $_[1] ? $_[1] : Z_BEST_SPEED }, |
57 "p|pass=s" => \$o{pass}, |
57 "p|pass=s" => \$o{pass}, |
58 "b|blocksize=s" => sub { |
58 "b|blocksize=s" => sub { |
59 given ($_[1]) { |
59 given ($_[1]) { |
60 when (/(\d+)G/i) { $o{blocksize} = $1 * GiB }; |
60 when (/(\d+)G/i) { $o{blocksize} = $1 * GiB }; |
61 when (/(\d+)M/i) { $o{blocksize} = $1 * MiB }; |
61 when (/(\d+)M/i) { $o{blocksize} = $1 * MiB }; |
103 -d $dst or die "$0: $dst: $!\n"; |
103 -d $dst or die "$0: $dst: $!\n"; |
104 mkpath([$data, $idx, $info]); |
104 mkpath([$data, $idx, $info]); |
105 |
105 |
106 my %index; |
106 my %index; |
107 $index{META} = { |
107 $index{META} = { |
108 format => 1, |
108 format => 1, |
109 host => hostname, |
109 host => hostname, |
110 filesystem => $src, |
110 filesystem => $src, |
111 blocksize => $o{blocksize}, |
111 blocksize => $o{blocksize}, |
112 devsize => $size, |
112 devsize => $size, |
113 timestamp => NOW, |
113 timestamp => NOW, |
114 datetime => DATETIME, |
114 datetime => DATETIME, |
115 (defined $o{comment} ? (comment => $o{comment}) : ()), |
115 (defined $o{comment} ? (comment => $o{comment}) : ()), |
116 encryption => $o{pass} ? CIPHER : "none", |
116 encryption => $o{pass} ? CIPHER : "none", |
117 }; |
117 }; |
118 |
118 |
119 open(my $in => $src); |
119 open(my $in => $src); |
120 binmode($in); |
120 binmode($in); |
121 local $/ = \$o{blocksize}; |
121 local $/ = \$o{blocksize}; |
149 $ext = ""; |
149 $ext = ""; |
150 $ext .= $o{compress} ? ".gz" : ""; |
150 $ext .= $o{compress} ? ".gz" : ""; |
151 $ext .= $o{pass} ? ".x" : ""; |
151 $ext .= $o{pass} ? ".x" : ""; |
152 |
152 |
153 # the extension we do not put into the index |
153 # the extension we do not put into the index |
154 push @{$index{BLOCKS}}, |
154 push @{ $index{BLOCKS} }, sprintf "%12d %s %s" => ($. - 1), |
155 sprintf "%12d %s %s" => ($. - 1), $cs, $file; |
155 $cs, $file; |
156 |
156 |
157 if ( |
157 if ( |
158 not( -e "$data/$file" |
158 not( -e "$data/$file" |
159 or -e "$data/$file.gz" |
159 or -e "$data/$file.gz" |
160 or -e "$data/$file.x" |
160 or -e "$data/$file.x" |
181 ) or die $GzipError; |
181 ) or die $GzipError; |
182 } |
182 } |
183 else { print {$out} $buffer } |
183 else { print {$out} $buffer } |
184 close($out); |
184 close($out); |
185 rename($out => "$data/$file$ext"); |
185 rename($out => "$data/$file$ext"); |
186 $index{BLOCKS}[$. - 1] .= " *"; |
186 $index{BLOCKS}[$. - 1] .= " *"; |
187 $stats{written}++; |
187 $stats{written}++; |
188 } |
188 } |
189 else { |
189 else { |
190 $stats{skipped}++; |
190 $stats{skipped}++; |
191 } |
191 } |
192 } |
192 } |
193 $SIG{ALRM}->(); |
193 $SIG{ALRM}->(); |
194 alarm 0; |
194 alarm 0; |
195 |
195 |
196 $index{META}{blocks} = @{$index{BLOCKS}}; |
196 $index{META}{blocks} = @{ $index{BLOCKS} }; |
197 $index{META}{runtime} = time() - $^T . "s"; |
197 $index{META}{runtime} = time() - $^T . "s"; |
198 |
198 |
199 my $index = File::Temp->new(DIR => $idx); |
199 my $index = File::Temp->new(DIR => $idx); |
200 say $index join "\n" => |
200 say $index join "\n" => "# imager", |
201 "# imager", |
201 (map { "$_: $index{META}{$_}" } sort(keys %{ $index{META} })), |
202 (map { "$_: $index{META}{$_}" } sort(keys %{$index{META}})), |
202 "", |
203 "", |
203 @{ $index{BLOCKS} }; |
204 @{$index{BLOCKS}}; |
|
205 close($index); |
204 close($index); |
206 rename $index->filename => "$idx/" . DATETIME; |
205 rename $index->filename => "$idx/" . DATETIME; |
207 |
206 |
208 say "# $src DONE (runtime " . (time() - $^T) . "s)"; |
207 say "# $src DONE (runtime " . (time() - $^T) . "s)"; |
209 say "# $src WRITTEN $stats{written}, SKIPPED $stats{skipped} blocks"; |
208 say "# $src WRITTEN $stats{written}, SKIPPED $stats{skipped} blocks"; |