/usr/share/perl5/Pristine/Tar/Delta.pm is in pristine-tar 1.38.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | #!/usr/bin/perl
# pristine-tar delta file library
# See delta-format.txt for details about the contents of delta files.
package Pristine::Tar::Delta;
use Pristine::Tar;
use warnings;
use strict;
# Checks if a field of a delta should be stored in the delta hash using
# a filename. (Normally the hash stores the whole field value, but
# using filenames makes sense for a few fields.)
my %delta_files = map { $_ => 1 } qw(manifest delta wrapper);
sub is_filename {
my $field = shift;
return $delta_files{$field};
}
sub handler {
my $action = shift;
my $type = shift;
my $class = "Pristine::Tar::Delta::$type";
eval "use $class";
if ($@) {
error "unsupported delta file format $type";
}
$class->$action(@_);
}
# After the type of delta and the file to create (which can be "-"
# to send it to stdout), this takes a hashref containing the contents of
# the delta to write.
sub write {
my $type = shift;
my $deltafile = shift;
my $delta = shift;
my $tempdir = tempdir();
my $stdout = 0;
if ($deltafile eq "-") {
$stdout = 1;
$deltafile = "$tempdir/tmpout";
}
handler('write', $type, $deltafile, $delta);
if ($stdout) {
doit("cat", $deltafile);
unlink($deltafile);
}
return $delta;
}
# Returns a hashref of the contents of the delta.
sub read {
my $type = shift;
my $deltafile = shift;
my $tempdir = tempdir();
my $stdin = 0;
if ($deltafile eq "-") {
$deltafile = "$tempdir/tmpin";
open(my $out, ">", $deltafile) || die "$deltafile: $!";
while (<STDIN>) {
print $out $_;
}
close $out;
}
my $delta = handler('read', $type, $deltafile);
unlink($deltafile) if $stdin;
return $delta;
}
# Checks the type, maxversion, minversion of a delta hashref.
# Checks that the delta contains all specified fields.
# Returns the hashref if it is ok.
sub assert {
my $delta = shift;
my %params = @_;
if (!exists $delta->{version}) {
error "delta lacks version";
}
if (defined $params{maxversion}) {
if ($delta->{version} > $params{maxversion}) {
error "delta is version "
. $delta->{version}
. ", newer than maximum supported version $params{maxversion}";
}
}
if (defined $params{minversion}) {
if ($delta->{version} < $params{minversion}) {
error "delta is version "
. $delta->{version}
. ", older than minimum supported version $params{minversion}";
}
}
if (!exists $delta->{type}) {
error "delta lacks type";
}
if (defined $params{type}) {
if ($delta->{type} ne $params{type}) {
error "delta is for a " . $delta->{type} . ", not a $params{type}";
}
}
if ($params{fields}) {
foreach my $key (@{ $params{fields} }) {
if (!exists $delta->{$key}) {
error "delta lacks $key";
}
}
}
return $delta;
}
1
|