2 # changelog-file -- lintian collector script
4 # Copyright (C) 1998 Richard Braakman
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, you can find it on the World Wide
18 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
19 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
24 ($#ARGV == 1) or fail("syntax: changelog-file <pkg> <type>");
28 -f "fields/package" or fail("changelog-file invoked in wrong directory");
32 # Pick the first of these files that exists.
33 my @changelogs = ("unpacked/usr/share/doc/$pkg/changelog.Debian.gz",
34 "unpacked/usr/share/doc/$pkg/changelog.Debian",
35 "unpacked/usr/share/doc/$pkg/changelog.debian.gz",
36 "unpacked/usr/share/doc/$pkg/changelog.debian",
37 "unpacked/usr/share/doc/$pkg/changelog.gz",
38 "unpacked/usr/share/doc/$pkg/changelog",
39 "unpacked/usr/doc/$pkg/changelog.Debian.gz",
40 "unpacked/usr/doc/$pkg/changelog.Debian",
41 "unpacked/usr/doc/$pkg/changelog.debian.gz",
42 "unpacked/usr/doc/$pkg/changelog.debian",
43 "unpacked/usr/doc/$pkg/changelog.gz",
44 "unpacked/usr/doc/$pkg/changelog");
55 # If the changelog file we found was a symlink, we have to be careful. It
56 # could be a symlink to some file outside of the laboratory and we don't want
57 # to end up reading that file by mistake. Relative links within the same
58 # directory or to a subdirectory we accept; anything else is replaced by an
59 # intentinally broken symlink so that checks can do the right thing.
60 if (defined ($chl) && -l $chl) {
61 my $link = readlink $chl or fail("cannot readlink $chl: $!");
62 if ($link =~ /\.\./ || ($link =~ m%/% && $link !~ m%^[^/]+(/+[^/]+)*\z%)) {
63 symlink('file-is-in-another-package', 'changelog')
64 or fail("cannot create changelog symlink: $!");
71 # If the changelog was a broken symlink, it will be undefined and we'll now
72 # treat it the same as if we didn't find a changelog and do nothing. If it
73 # was a symlink, copy the file, since otherwise the relative symlinks are
74 # going to break things.
75 if (not defined $chl) {
77 } elsif ($chl =~ /\.gz$/) {
78 use lib "$ENV{'LINTIAN_ROOT'}/lib";
81 pipeline((sub { exec 'gzip', '-dc', $chl }), "changelog") == 0
82 or fail("error in gzip");
83 } elsif (-f $chl && -l $chl) {
85 open (CHL, '<', $chl) or fail("cannot open $chl: $!");
86 open (COPY, '>', 'changelog') or fail("cannot create changelog: $!");
87 print COPY while <CHL>;
91 link($chl, "changelog")
92 or fail("cannot link $chl to changelog: $!");
95 # Extract NEWS.Debian files as well, with similar precautious. Ignore any
96 # symlinks to other packages here; in that case, we just won't check the file.
97 my $news = "unpacked/usr/share/doc/$pkg/NEWS.Debian.gz";
100 my $link = readlink $news or fail("cannot readlink $chl: $!");
101 if ($link =~ /\.\./ || ($link =~ m%/% && $link !~ m%^[^/]+(/+[^/]+)*\z%)) {
103 } elsif (! -f $news) {
108 use lib "$ENV{'LINTIAN_ROOT'}/lib";
111 pipeline((sub { exec 'gzip', '-dc', $news }), "NEWS.Debian") == 0
112 or fail("error in gzip");
118 # -----------------------------------
122 print STDERR "internal error: $_[0]\n";
124 print STDERR "internal error: $!\n";
126 print STDERR "internal error.\n";