2 # list-udebpkg -- lintian helper script
4 # Copyright (C) 1998 Christian Schwarz
5 # Copyright (C) 2004 Frank Lichtenheld
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, you can find it on the World Wide
19 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
20 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
25 # turn file buffering off:
28 # parse command line options
30 print "list-udebpkg [-v] <output-list-file>\n";
32 print " -v verbose\n";
37 my $output_file = undef;
38 my $pkgdata = undef; # WTF?
40 while (my $arg = shift) {
41 if ($arg =~ s,^-,,o) {
45 print STDERR "error: unknown command line argument: $arg\n";
50 print STDERR "error: too many command line arguments: $arg\n";
57 unless ($output_file) {
58 print STDERR "error: no output file specified\n";
62 # import perl libraries
63 use lib "$ENV{'LINTIAN_ROOT'}/lib";
65 use vars qw(%udeb_info $UDEBLIST_FORMAT); # from the above
69 # get variables out of environment
70 my $LINTIAN_ARCHIVEDIR = $ENV{'LINTIAN_ARCHIVEDIR'};
71 my $LINTIAN_DIST = $ENV{'LINTIAN_DIST'};
72 my $LINTIAN_ARCH = $ENV{'LINTIAN_ARCH'};
73 my $LINTIAN_SECTION = $ENV{'LINTIAN_SECTION'};
74 my $LINTIAN_LAB = $ENV{'LINTIAN_LAB'};
76 # read old list file (this command does nothing if the file does not exist)
77 read_udeb_list($output_file,1);
80 # map filenames to package names
81 for my $pkg (keys %udeb_info) {
82 $pkgfile{$udeb_info{$pkg}->{'file'}} = $pkg;
86 open(OUT, '>', $output_file)
87 or fail("cannot open list file $output_file for writing: $!");
88 print OUT "$UDEBLIST_FORMAT\n";
90 # parse Packages file to get list of packages
91 my $packages = "$LINTIAN_ARCHIVEDIR/dists/$LINTIAN_DIST/$LINTIAN_SECTION/".
92 "debian-installer/binary-$LINTIAN_ARCH/Packages";
94 print "N: Parsing $packages ...\n" if $verbose;
95 open(IN, '<', $packages) or fail("cannot open Packages file $packages: $!");
96 } elsif (-e "$packages.gz") {
97 print "N: Parsing $packages.gz ...\n" if $verbose;
98 open(IN, '-|', 'gzip', '-dc', "$packages.gz")
99 or fail("cannot open Packages file $packages.gz: $!");
101 fail("No packages file $packages");
109 do { $line = <IN> } until ($line =~ m/^Architecture: (.*)$/m);
111 do { $line = <IN> } until ($line =~ m/^Filename: (.*)$/m);
113 do { $line = <IN> } until ($line =~ m/^\s*$/m);
117 unless (@stat = stat "$LINTIAN_ARCHIVEDIR/$deb_file") {
118 print "E: general: cannot stat $LINTIAN_ARCHIVEDIR/$deb_file\n";
121 my $timestamp = $stat[9];
122 my ($status, $pkg, $data);
124 # was package already included in last list?
125 if (exists $pkgfile{$deb_file}) {
127 $pkg = $pkgfile{$deb_file};
128 $data = $udeb_info{$pkg};
130 # file changed since last run?
131 if ($timestamp == $data->{'timestamp'}) {
133 $status = 'unchanged';
136 delete $udeb_info{$pkg};
139 # new package, get info
143 if (($status eq 'new') or ($status eq 'changed')) {
144 if (defined $pkgdata) {
145 # avoid collecting the info twice
148 $data = &safe_get_deb_info($deb_file);
150 next if not defined $data;
151 $pkg = $data->{'package'};
154 # check for duplicates
155 if (exists $packages{$pkg}) {
156 print "E: general: duplicate-udeb-package $pkg\n";
160 # write entry to output file
168 printf "N: Listed %s udeb package %s %s\n",$status,$pkg,$data->{'version'} if $verbose;
170 # remove record from hash
171 delete $udeb_info{$pkg} if $status eq 'unchanged';
175 close(IN) or fail("cannot close input pipe: $!");
176 close(OUT) or fail("cannot close output pipe: $!");
179 # all packages that are still included in %udeb_info have disappeared from the archive...
180 for my $pkg (sort keys %udeb_info) {
181 print "N: Removed udeb package $pkg from list\n";
183 printf "N: Listed %d udeb packages\n",$total;
188 sub safe_get_deb_info {
189 # use eval when calling get_deb_info, since we don't want to `die' just
190 # because of a single broken package
192 eval { $data = get_deb_info("$LINTIAN_ARCHIVEDIR/$_[0]"); };
196 print "E: general: bad-udeb-package $_[0]\n";
199 $data->{'source'} or ($data->{'source'} = $data->{'package'});