File: changes-file

package info (click to toggle)
lintian 2.4.3%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 8,228 kB
  • ctags: 457
  • sloc: perl: 8,492; sh: 5,561; makefile: 1,971; ansic: 143; python: 19; tcl: 4; sed: 2
file content (154 lines) | stat: -rw-r--r-- 4,733 bytes parent folder | download
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# changes-file -- lintian check script -*- perl -*-

# Copyright (C) 1998 Christian Schwarz and Richard Braakman
#
# This program is free software.  It is distributed under the terms of
# the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, you can find it on the World Wide
# Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.

package Lintian::changes_file;
use strict;
use Util;

use Lintian::Tags qw(tag);
use Lintian::Check qw(check_maintainer);

my $check_checksums = $main::check_checksums;

sub run {

my $pkg = shift;
my $type = shift;
my $info = shift;

# If we don't have a Format key, something went seriously wrong.
# Tag the file and skip remaining processing.
if (!$info->field('format')) {
    tag('malformed-changes-file');
    return 0;
}

# Description is mandated by dak, but only makes sense if binary
# packages are included.  Don't tag pure source uploads.
if (!$info->field('description') && $info->field('architecture') ne 'source') {
    tag("no-description-in-changes-file");
}

# check distribution field
if (defined $info->field('distribution')) {
    my $ubuntu_dists = Lintian::Data->new ('changelog-file/ubuntu-dists');
    my $ubuntu_regex = join('|', $ubuntu_dists->all);
    my @distributions = split /\s+/o, $info->field('distribution');
    for my $distribution (@distributions) {
	if ($distribution eq 'UNRELEASED') {
	    # ignore
	} elsif ($info->field('version') =~ /ubuntu|$ubuntu_regex/
	    or $distribution =~ /$ubuntu_regex/) {
		if ($distribution !~ /^($ubuntu_regex)(-(proposed|updates|backports|security))?$/ ) {
		    tag("bad-ubuntu-distribution-in-changes-file",
			$distribution);
		}
	} elsif (! (($distribution eq 'oldstable')
		     or ($distribution eq 'stable')
		     or ($distribution eq 'testing')
		     or ($distribution eq 'unstable')
		     or ($distribution eq 'experimental')
		     or ($distribution =~ /^\w+-backports$/)
		     or ($distribution =~ /^\w+-proposed-updates$/)
		     or ($distribution =~ /^\w+-security$/)
		     or ($distribution =~ /^\w+-volatile$/))
		) {
	    # bad distribution entry
	    tag("bad-distribution-in-changes-file", $distribution);
	}
    }

    if ($#distributions > 0) {
	tag("multiple-distributions-in-changes-file",
	    $info->field('distribution'));
	}
    }

    # Urgency is only recommended by Policy.
    if (!$info->field('urgency')) {
	tag("no-urgency-in-changes-file");
    } else {
	my $urgency = lc $info->field('urgency');
	$urgency =~ s/ .*//;
	unless ($urgency =~ /^(low|medium|high|critical|emergency)$/i) {
	    tag("bad-urgency-in-changes-file", $info->field('urgency'));
	}
    }

    # Changed-By is optional in Policy, but if set, must be
    # syntactically correct.  It's also used by dak.
    if ($info->field('changed-by')) {
	check_maintainer($info->field('changed-by'), 'changed-by');
    }

    my $files = $info->files;
    foreach my $file (keys %$files) {
        my $file_info = $files->{$file};

	# check section
	if (($file_info->{section} eq 'non-free') or
	    ($file_info->{section} eq 'contrib')) {
	    tag("bad-section-in-changes-file", $file, $file_info->{section});
	}

	foreach my $alg (qw(sha1 sha256)) {
	    my $checksum_info = $file_info->{checksums}{$alg};
	    if (defined $checksum_info) {
		if ($file_info->{size} != $checksum_info->{filesize}) {
		    tag( "file-size-mismatch-in-changes-file", $file,
			$file_info->{size} . ' != ' .
			$checksum_info->{filesize} );
		}
	    }
	}

	# check size
	my $path = readlink('changes');
	$path =~ s#/[^/]+$##;
	my $filename = "$path/$file";
	my $size = -s $filename;

	if ($size ne $file_info->{size}) {
	    tag( "file-size-mismatch-in-changes-file", $file,
		 $file_info->{size} . " != $size");
	}

	# check checksums
	if ($check_checksums or $file =~ /\.dsc$/) {
	    foreach my $alg (qw(md5 sha1 sha256)) {
		next unless exists $file_info->{checksums}{$alg};

		my $real_checksum = get_file_checksum($alg, $filename);

		if ($real_checksum ne $file_info->{checksums}{$alg}{sum}) {
		    tag( "checksum-mismatch-in-changes-file", $alg, $file );
		}
	    }
	}
    }
}

1;

# Local Variables:
# indent-tabs-mode: t
# cperl-indent-level: 4
# End:
# vim: sw=4 ts=8 noet fdm=marker