Changeset 98
- Timestamp:
- 05/12/07 00:59:22 (3 years ago)
- Location:
- trunk/lib/Brackup
- Files:
-
- 2 modified
-
Backup.pm (modified) (2 diffs)
-
ChunkIterator.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Brackup/Backup.pm
r97 r98 48 48 my $chunk_iterator = Brackup::ChunkIterator->new(@files); 49 49 50 my $gpg_iter; 51 if ($gpg_rcpt) { 52 ($chunk_iterator, $gpg_iter) = $chunk_iterator->mux_into(2); 53 } 54 50 55 my $cur_file; # current (last seen) file 51 56 my @stored_chunks; … … 66 71 $cur_file->path, $n_files_done, $n_files, ($n_kb_done/$n_kb)*100, 67 72 ($n_kb - $n_kb_done) / 1024)); 73 74 if ($gpg_iter) { 75 # catch our gpg iterator up. we want it to be ahead of us, 76 # nothing iteresting is behind us. 77 $gpg_iter->next while $gpg_iter->behind_by > 1; 78 } 68 79 }; 69 80 -
trunk/lib/Brackup/ChunkIterator.pm
r95 r98 31 31 } 32 32 33 sub mux_into { 34 my ($self, $n_copies) = @_; 35 my @iters; 36 for (1..$n_copies) { 37 push @iters, Brackup::ChunkIterator::SlaveIterator->new; 38 } 39 my $on_empty = sub { 40 my $next = $self->next; 41 foreach my $peer (@iters) { 42 push @{$peer->{mag}}, $next; 43 } 44 }; 45 foreach (@iters) { 46 $_->{on_empty} = $on_empty; 47 } 48 return @iters; 49 } 50 51 package Brackup::ChunkIterator::SlaveIterator; 52 use strict; 53 use warnings; 54 use Carp qw(croak); 55 56 sub new { 57 my $class = shift; 58 return bless { 59 'on_empty' => undef, # subref 60 'mag' => [], 61 }, $class; 62 } 63 64 sub next { 65 my $self = shift; 66 # the magazine itself could be true, but contain only undef: (undef), 67 # which signals the end. 68 return shift @{$self->{mag}} if @{$self->{mag}}; 69 $self->{on_empty}->(); 70 return shift @{$self->{mag}}; 71 } 72 73 sub behind_by { 74 my $self = shift; 75 return scalar @{$self->{mag}}; 76 } 77 33 78 1;
