2
# pristine-tar delta file library
3
# See delta-format.txt for details about the contents of delta files.
4
package Pristine::Tar::Delta;
10
# Checks if a field of a delta should be stored in the delta hash using
11
# a filename. (Normally the hash stores the whole field value, but
12
# using filenames makes sense for a few fields.)
13
my %delta_files=map { $_ => 1 } qw(manifest delta wrapper);
16
return $delta_files{$field};
23
my $class="Pristine::Tar::Delta::$type";
26
error "unsupported delta file format $type";
31
# After the type of delta and the file to create (which can be "-"
32
# to send it to stdout), this takes a hashref containing the contents of
39
my $tempdir=tempdir();
42
if ($deltafile eq "-") {
44
$deltafile="$tempdir/tmpout";
47
handler('write', $type, $deltafile, $delta);
50
doit("cat", $deltafile);
57
# Returns a hashref of the contents of the delta.
62
my $tempdir=tempdir();
65
if ($deltafile eq "-") {
66
$deltafile="$tempdir/tmpin";
67
open (my $out, ">", $deltafile) || die "$deltafile: $!";
74
my $delta=handler('read', $type, $deltafile);
76
unlink($deltafile) if $stdin;
81
# Checks the type, maxversion, minversion of a delta hashref.
82
# Checks that the delta contains all specified fields.
83
# Returns the hashref if it is ok.
88
if (! exists $delta->{version}) {
89
error "delta lacks version";
91
if (defined $params{maxversion}) {
92
if ($delta->{version} > $params{maxversion}) {
93
error "delta is version ".$delta->{version}.", newer than maximum supported version $params{maxversion}";
96
if (defined $params{minversion}) {
97
if ($delta->{version} < $params{minversion}) {
98
error "delta is version ".$delta->{version}.", older than minimum supported version $params{minversion}";
102
if (! exists $delta->{type}) {
103
error "delta lacks type";
105
if (defined $params{type}) {
106
if ($delta->{type} ne $params{type}) {
107
error "delta is for a ".$delta->{type}.", not a $params{type}";
111
if ($params{fields}) {
112
foreach my $key (@{$params{fields}}) {
113
if (! exists $delta->{$key}) {
114
error "delta lacks $key";