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
|
# $Id$
package RPM4::Header::Checks;
use strict;
use warnings;
my @tagstocheck = (
{
tag => 'NAME',
type => 'STRING',
count => 1,
mandatory => 1,
},
{
tag => 'VERSION',
type => 'STRING',
count => 1,
mandatory => 1,
},
{
tag => 'RELEASE',
type => 'STRING',
count => 1,
mandatory => 1,
},
{ tag => 'EPOCH', type => 'INT32', count => 1, },
{
tag => 'CHANGELOGTEXT', type => 'STRING_ARRAY',
countof => [ qw(CHANGELOGNAME CHANGELOGTIME) ],
},
{ tag => 'CHANGELOGNAME', type => 'STRING_ARRAY', },
{ tag => 'CHANGELOGTIME', type => 'INT32', },
{ tag => 'PACKAGER', type => 'STRING', },
{ tag => 'DISTRIBUTION', type => 'STRING', },
{ tag => 'SUMMARY', type => 'STRING', count => 1, mandatory => 1, },
{ tag => 'DESCRIPTION', type => 'STRING', count => 1, mandatory => 1, },
);
sub reporterror {
printf(@_);
print "\n";
}
sub check {
my ($header) = @_;
foreach my $check (@tagstocheck) {
$check->{tag} or next; # buggy check
if (!$header->hastag($check->{tag})) {
reporterror(
"tag %s not found",
$check->{tag},
) if($check->{mandatory});
} elsif (defined($check->{count})) {
my @t = $header->tag($check->{tag});
if(scalar(@t) != $check->{count}) {
reporterror(
"Wrong count for tag %s: %d, %d is expected",
$check->{tag},
scalar(@t),
$check->{count},
);
}
}
if ($check->{countof}) {
my @t = $header->tag($check->{tag});
foreach my $co (@{$check->{countof}}) {
my @t2 = $header->tag($co);
if (scalar(@t) != scalar(@t2)) {
reporterror(
"count of tag %s is not the same than %s, %d vs %d",
$check->{tag},
$co,
scalar(@t),
scalar(@t2),
);
}
}
}
$header->hastag($check->{tag}) or next;
if ($check->{type}) {
if ($header->tagtype($check->{tag}) != RPM4::tagtypevalue($check->{type})) {
reporterror(
"Wrong tagtype for tag %s: %d, %d is expected",
$check->{tag},
$header->tagtype($check->{tag}),
RPM4::tagtypevalue($check->{type})
);
}
}
}
}
|