LEFT | RIGHT |
1 package Brackup::Restore; | 1 package Brackup::Restore; |
2 use strict; | 2 use strict; |
3 use warnings; | 3 use warnings; |
4 use Carp qw(croak); | 4 use Carp qw(croak); |
5 use Digest::SHA1; | 5 use Digest::SHA1; |
6 use POSIX qw(mkfifo); | 6 use POSIX qw(mkfifo); |
7 use Brackup::DecryptedFile; | 7 use Brackup::DecryptedFile; |
| 8 use Brackup::Decrypt; |
8 | 9 |
9 sub new { | 10 sub new { |
10 my ($class, %opts) = @_; | 11 my ($class, %opts) = @_; |
11 my $self = bless {}, $class; | 12 my $self = bless {}, $class; |
12 | 13 |
13 $self->{to} = delete $opts{to}; # directory we're restoring to | 14 $self->{to} = delete $opts{to}; # directory we're restoring to |
14 $self->{prefix} = delete $opts{prefix}; # directory/file filename prefix,
or "" for all | 15 $self->{prefix} = delete $opts{prefix}; # directory/file filename prefix,
or "" for all |
15 $self->{filename}= delete $opts{file}; # filename we're restoring from | 16 $self->{filename}= delete $opts{file}; # filename we're restoring from |
16 $self->{verbose} = delete $opts{verbose}; | 17 $self->{verbose} = delete $opts{verbose}; |
17 | 18 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 my $region = substr($$dataref, $from, $to-$from); | 196 my $region = substr($$dataref, $from, $to-$from); |
196 $dataref = \$region; | 197 $dataref = \$region; |
197 } else { | 198 } else { |
198 # using the whole chunk, so make sure fetched size matches | 199 # using the whole chunk, so make sure fetched size matches |
199 # expected size | 200 # expected size |
200 unless ($len_chunk == $enc_len) { | 201 unless ($len_chunk == $enc_len) { |
201 die "Backup chunk $dig isn't of expected length: got $len_chunk,
expecting $enc_len\n"; | 202 die "Backup chunk $dig isn't of expected length: got $len_chunk,
expecting $enc_len\n"; |
202 } | 203 } |
203 } | 204 } |
204 | 205 |
205 my $decrypted_ref = $self->decrypt_data($dataref,meta => $self->{_meta})
; | 206 my $decrypted_ref = Brackup::Decrypt::decrypt_data($dataref, meta => $se
lf->{_meta}); |
206 print $fh $$decrypted_ref; | 207 print $fh $$decrypted_ref; |
207 } | 208 } |
208 close($fh) or die "Close failed"; | 209 close($fh) or die "Close failed"; |
209 | 210 |
210 if (my $good_dig = $it->{Digest}) { | 211 if (my $good_dig = $it->{Digest}) { |
211 die "not capable of verifying digests of from anything but sha1" | 212 die "not capable of verifying digests of from anything but sha1" |
212 unless $good_dig =~ /^sha1:(.+)/; | 213 unless $good_dig =~ /^sha1:(.+)/; |
213 $good_dig = $1; | 214 $good_dig = $1; |
214 | 215 |
215 open (my $readfh, $full) or die "Couldn't reopen file for verification"; | 216 open (my $readfh, $full) or die "Couldn't reopen file for verification"; |
(...skipping 12 matching lines...) Expand all Loading... |
228 } | 229 } |
229 | 230 |
230 # returns iterator subref which returns hashrefs or undef on EOF | 231 # returns iterator subref which returns hashrefs or undef on EOF |
231 sub parser { | 232 sub parser { |
232 my $self = shift; | 233 my $self = shift; |
233 return Brackup::Metafile->open($self->{metafile}->name); | 234 return Brackup::Metafile->open($self->{metafile}->name); |
234 } | 235 } |
235 | 236 |
236 1; | 237 1; |
237 | 238 |
LEFT | RIGHT |