Brackup
view release on metacpan or search on metacpan
lib/Brackup/StoredChunk.pm view on Meta::CPAN
backlength => $len,
lite => 1,
}, $class;
# normal
return $sc unless $range;
# in case of little file in a composite chunk,
# we gotta be a range.
my ($from, $to) = $range =~ /^(\d+)-(\d+)$/
or die "bogus range: $range";
$sc->{compfrom} = $from;
$sc->{compto} = $to;
return $sc;
}
sub clone_but_for_pchunk {
my ($self, $pchunk) = @_;
my $copy = bless {}, ref $self;
foreach my $f (qw(backlength backdigest compchunk compfrom compto)) {
$copy->{$f} = $self->{$f};
}
$copy->{pchunk} = $pchunk;
return $copy;
}
sub set_composite_chunk {
my ($self, $cchunk, $from, $to) = @_;
$self->{compchunk} = $cchunk;
# forget our backup length/digest. this handle information
# to the stored chunk should be asked of our composite
# chunk in the future, when it's done populating.
$self->{backdigest} = undef;
$self->{backlength} = undef;
$self->forget_chunkref;
$self->{compfrom} = $from;
$self->{compto} = $to;
}
sub range_in_composite {
my $self = shift;
return undef unless $self->{compfrom} || $self->{compto};
return "$self->{compfrom}-$self->{compto}";
}
sub file {
my $self = shift;
return $self->{pchunk}->file;
}
sub root {
my $self = shift;
return $self->file->root;
}
# returns true if encrypted, false otherwise
sub encrypted {
my $self = shift;
return $self->root->gpg_rcpts ? 1 : 0;
}
sub compressed {
my $self = shift;
# TODO/FUTURE: support compressed chunks (for non-encrypted
# content; gpg already compresses)
return 0;
}
# the original length, pre-encryption
sub length {
my $self = shift;
return $self->{pchunk}->length;
}
# the length, either encrypted or not
sub backup_length {
my $self = shift;
return $self->{backlength} if defined $self->{backlength};
$self->_populate_lengthdigest;
return $self->{backlength};
}
# the digest, either encrypted or not
sub backup_digest {
my $self = shift;
return $self->{backdigest} if $self->{backdigest};
$self->_populate_lengthdigest;
return $self->{backdigest};
}
sub _populate_lengthdigest {
my $self = shift;
# Composite chunk version
if (my $cchunk = $self->{compchunk}) {
$self->{backlength} = $cchunk->backup_length;
$self->{backdigest} = $cchunk->digest;
return 1;
}
die "ASSERT: encrypted length or digest not set" if $self->encrypted;
# Unencrypted version
$self->{backdigest} = "sha1:" . io_sha1($self->{pchunk}->raw_chunkref);
$self->{backlength} = $self->{pchunk}->length; # length of raw data
return 1;
}
sub chunkref {
my $self = shift;
if ($self->{_chunkref}) {
$self->{_chunkref}->seek(0, SEEK_SET);
return $self->{_chunkref};
}
# encrypting case: chunkref gets set via set_encrypted_chunkref in Backup::backup
croak "ASSERT: encrypted but no chunkref set" if $self->encrypted;
# caller/consistency check:
Carp::confess("Can't access chunkref on lite StoredChunk instance (handle only)")
if $self->{lite};
# non-encrypting case
return $self->{_chunkref} = $self->{pchunk}->raw_chunkref;
}
( run in 1.219 second using v1.01-cache-2.11-cpan-df04353d9ac )