[SCM] Debian package checker branch, master, updated. 2.2.6-68-ga710092
The following commit has been merged in the master branch:
commit a710092ed19ed6740cbda037e17a3f9c213ea2eb
Author: Russ Allbery <rra@debian.org>
Date: Sun Mar 8 18:30:33 2009 -0700
Add various checks for diversion handling
* checks/scripts:
+ [RA] Diagnose various problems with creating and removing
diversions. Based on a patch by Jörg Sommer. (Closes: #516221)
diff --git a/checks/scripts b/checks/scripts
index dbcdfa5..8f89194 100644
--- a/checks/scripts
+++ b/checks/scripts
@@ -526,6 +526,7 @@ open(SCRIPTS, '<', "control-scripts")
# normal scripts above, because there were just enough differences to
# make a shared function awkward.
+my %added_diversions;
while (<SCRIPTS>) {
chop;
@@ -721,7 +722,7 @@ while (<SCRIPTS>) {
}
}
}
-
+
# Ignore anything inside single quotes; it could be an
# argument to grep or the like.
@@ -869,6 +870,39 @@ while (<SCRIPTS>) {
if (m,/var/lib/dpkg/status\b, && $pkg ne 'base-files' && $pkg ne 'dpkg') {
tag "maintainer-script-uses-dpkg-status-directly", "$file";
}
+ if (m,^$LEADIN(?:/usr/sbin/)?dpkg-divert\s, && ! /--(?:help|list|truename|version)/) {
+ if (/--local/ or !/--package/) {
+ tag 'package-uses-local-diversion', "$file:$.";
+ } else {
+ my $mode = /--remove/ ? 'remove' : 'add';
+ my ($divert) = /dpkg-divert\s*(.*)$/;
+ $divert =~ s/\s*--(?:add|quiet|remove|rename|test|(:?admindir|divert|package)\s+\S+)//g;
+ $divert =~ s/\s+//g;
+ # remove the leading / because it's not in the index hash
+ $divert =~ s,^/,,;
+
+ if ($mode eq 'add') {
+ $added_diversions{$divert} = $file;
+ tag 'diversion-for-unknown-file', $divert, "$file:$."
+ unless (exists $info->index->{$divert});
+ } elsif ($mode eq 'remove') {
+ if (exists $added_diversions{$divert}) {
+ # do not really delete the entry, because a --remove
+ # might happen in two branches in the script, i.e. we
+ # see it twice, which is not a bug
+ undef $added_diversions{$divert};
+ } elsif ($file eq 'postrm') {
+ # Allow preinst and postinst to remove diversions the
+ # package doesn't add to clean up after previous
+ # versions of the package.
+ tag 'remove-of-unknown-diversion', $divert, "$file:$.";
+ }
+ } else {
+ fail "Internal error: \$mode has unknown value: ".
+ "$mode";
+ }
+ }
+ }
}
if ($saw_init && ! $saw_invoke) {
@@ -890,6 +924,9 @@ while (<SCRIPTS>) {
}
close(SCRIPTS);
+for my $file (grep { defined $added_diversions{$_} } keys %added_diversions) {
+ tag 'orphaned-diversion', $file, $added_diversions{$file};
+}
}
# -----------------------------------
diff --git a/checks/scripts.desc b/checks/scripts.desc
index 96a5bfe..dabc470 100644
--- a/checks/scripts.desc
+++ b/checks/scripts.desc
@@ -551,3 +551,30 @@ Certainty: certain
Info: The package calls dpkg --assert-multi-conrep in a maintainer
script. This check is obsolete and has always returned true since dpkg
1.4.1.19, released 1999-10-30.
+
+Tag: package-uses-local-diversion
+Severity: serious
+Certainty: certain
+Info: The maintainer script calls dpkg-divert with <tt>--local</tt> or
+ without <tt>--package</tt>. This option is reserved for local
+ administrators and must never be used by a Debian package.
+
+Tag: diversion-for-unknown-file
+Severity: important
+Certainty: certain
+Info: The maintainer script adds a diversion for a file that is not
+ provided by this package.
+
+Tag: orphaned-diversion
+Severity: important
+Certainty: certain
+Info: A diversion was added for the file, but not removed. This means
+ your package doesn't restore the previous state after removal.
+
+Tag: remove-of-unknown-diversion
+Severity: important
+Certainty: certain
+Info: The maintainer script removes a diversion that it didn't add. If
+ you're cleaning up unnecessary diversions from older versions of the
+ package, remove them in <tt>preinst</tt> or <tt>postinst</tt> instead of
+ waiting for <tt>postrm</tt> to do it.
diff --git a/debian/changelog b/debian/changelog
index fffed15..976ca10 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,8 +5,12 @@ lintian (2.2.7) UNRELEASED; urgency=low
- apparently-truncated-elf-binary
- copyright-refers-to-nonexistent-license-file
- debian-control-has-unusual-field-spacing (pedantic)
+ - diversion-for-unknown-file
- embedded-zlib
- incorrect-libdir-in-la-file
+ - orphaned-diversion
+ - package-uses-local-diversion
+ - remove-of-unknown-diversion
+ Removed
- description-synopsis-has-leading-spaces
@@ -97,6 +101,8 @@ lintian (2.2.7) UNRELEASED; urgency=low
+ [ADB] Use Lintian::Relation rather than Dep.
+ [ADB] Update lists of known interpreter versions (add jruby1.1,
octave3.1 and remove jruby0.9)
+ + [RA] Diagnose various problems with creating and removing
+ diversions. Based on a patch by Jörg Sommer. (Closes: #516221)
* checks/shared-libs{,.desc}:
+ [ADB] When parsing symbols files, correctly ensure that meta-information
occurs between the end of the dependency template(s) and the start of
diff --git a/t/tests/scripts-diversions/debian/debian/install b/t/tests/scripts-diversions/debian/debian/install
new file mode 100644
index 0000000..d9ecc9c
--- /dev/null
+++ b/t/tests/scripts-diversions/debian/debian/install
@@ -0,0 +1,2 @@
+orphan usr/share/scripts
+some-file usr/share/scripts
diff --git a/t/tests/scripts-diversions/debian/debian/postinst b/t/tests/scripts-diversions/debian/debian/postinst
new file mode 100644
index 0000000..f397e7d
--- /dev/null
+++ b/t/tests/scripts-diversions/debian/debian/postinst
@@ -0,0 +1,11 @@
+#!/bin/sh
+set -e
+
+# This isn't a diversion we create anywhere, but we're allowed to do this in
+# postinst in case we're cleaning up after a previous version.
+if [ configure = "$1" ] && dpkg-divert --list '*old-file' >/dev/null ; then
+ dpkg-divert --package scripts-diversions --remove --rename \
+ /usr/share/scripts/old-file
+fi
+
+#DEBHELPER#
diff --git a/t/tests/scripts-diversions/debian/debian/postrm b/t/tests/scripts-diversions/debian/debian/postrm
new file mode 100644
index 0000000..d34360a
--- /dev/null
+++ b/t/tests/scripts-diversions/debian/debian/postrm
@@ -0,0 +1,20 @@
+#!/bin/sh
+set -e
+
+if [ remove = "$1" ]; then
+ # Clean up the correct diversion from preinst.
+ dpkg-divert --package scripts-diversions --remove --rename \
+ --divert /usr/share/scripts/some-file.real \
+ /usr/share/scripts/some-file
+
+ # Clean up some other diversion that we didn't create.
+ dpkg-divert --package scripts-diversions --remove --rename \
+ /usr/share/scripts/old-file
+
+ # Clean up a diversion we did create for a non-existent file.
+ dpkg-divert --remove --package scripts-diversions --rename \
+ --divert /usr/share/scripts/no-such-file.real \
+ /usr/share/scripts/no-such-file
+fi
+
+#DEBHELPER#
diff --git a/t/tests/scripts-diversions/debian/debian/preinst b/t/tests/scripts-diversions/debian/debian/preinst
new file mode 100644
index 0000000..0c87031
--- /dev/null
+++ b/t/tests/scripts-diversions/debian/debian/preinst
@@ -0,0 +1,36 @@
+#!/bin/sh
+set -e
+
+if [ install = "$1" ]; then
+ # This is a correct diversion.
+ dpkg-divert --package scripts-diversions --add --rename \
+ --divert /usr/share/scripts/some-file.real \
+ /usr/share/scripts/some-file
+
+ # This is broken -- can't use local.
+ dpkg-divert --local --add --divert /usr/share/scripts/other-file.real \
+ /usr/share/scripts/other-file
+
+ # This is also broken; the default is --local if --package isn't there.
+ dpkg-divert --add --divert /usr/share/scripts/another-file.real \
+ /usr/share/scripts/another-file
+
+ # This is also correct, but we're not going to clean it up.
+ dpkg-divert --package scripts-diversions --add --rename \
+ --divert /usr/share/scripts/orphan.real \
+ /usr/share/scripts/orphan
+
+ # This is broken because the file doesn't exist.
+ dpkg-divert --add --package scripts-diversions --rename \
+ --divert /usr/share/scripts/no-such-file.real \
+ /usr/share/scripts/no-such-file
+fi
+
+# This isn't a diversion we create anywhere, but we're allowed to do this in
+# preinst in case we're cleaning up after a previous version.
+if [ upgrade = "$1" ] && dpkg-divert --list '*old-file' >/dev/null ; then
+ dpkg-divert --package scripts-diversions --remove --rename \
+ /usr/share/scripts/old-file
+fi
+
+#DEBHELPER#
diff --git a/t/tests/scripts-diversions/debian/orphan b/t/tests/scripts-diversions/debian/orphan
new file mode 100644
index 0000000..934fd74
--- /dev/null
+++ b/t/tests/scripts-diversions/debian/orphan
@@ -0,0 +1 @@
+Some file that we're going to divert and not clean up.
diff --git a/t/tests/scripts-diversions/debian/some-file b/t/tests/scripts-diversions/debian/some-file
new file mode 100644
index 0000000..649e369
--- /dev/null
+++ b/t/tests/scripts-diversions/debian/some-file
@@ -0,0 +1 @@
+Some random file that we're going to install after diverting.
diff --git a/t/tests/scripts-diversions/desc b/t/tests/scripts-diversions/desc
new file mode 100644
index 0000000..1416fa9
--- /dev/null
+++ b/t/tests/scripts-diversions/desc
@@ -0,0 +1,9 @@
+Testname: scripts-diversions
+Sequence: 0000
+Version: 1.0
+Description: Tests of dpkg-divert checks
+Test-For:
+ diversion-for-unknown-file
+ package-uses-local-diversion
+ orphaned-diversion
+ remove-of-unknown-diversion
diff --git a/t/tests/scripts-diversions/tags b/t/tests/scripts-diversions/tags
new file mode 100644
index 0000000..10cf291
--- /dev/null
+++ b/t/tests/scripts-diversions/tags
@@ -0,0 +1,5 @@
+E: scripts-diversions: diversion-for-unknown-file usr/share/scripts/no-such-file preinst:26
+E: scripts-diversions: orphaned-diversion usr/share/scripts/orphan preinst
+E: scripts-diversions: package-uses-local-diversion preinst:12
+E: scripts-diversions: package-uses-local-diversion preinst:16
+E: scripts-diversions: remove-of-unknown-diversion usr/share/scripts/old-file postrm:12
--
Debian package checker
Reply to: