[SCM] Debian package checker branch, master, updated. 2.2.9-17-g566abd6
The following commit has been merged in the master branch:
commit a521d5949cf3f6affeac0ac9f5e02f99946244f1
Author: Raphael Geissert <atomo64@gmail.com>
Date: Thu Apr 9 18:16:04 2009 -0500
Handle more special cases for diversions
In the divert-related checks correctly handle:
* the ;, &&, and || shell expression delimiters
* expressions in the $() form within the path
* expressions inside braces and parenthesis (sub shells)
diff --git a/checks/scripts b/checks/scripts
index c51883a..e841667 100644
--- a/checks/scripts
+++ b/checks/scripts
@@ -871,7 +871,7 @@ 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 (m,$LEADIN(?:/usr/sbin/)?dpkg-divert\s, && ! /--(?:help|list|truename|version)/) {
if (/--local/ or !/--package/) {
tag 'package-uses-local-diversion', "$file:$.";
} else {
@@ -879,6 +879,26 @@ while (<SCRIPTS>) {
my ($divert) = /dpkg-divert\s*(.*)$/;
$divert =~ s/\s*--(?:add|quiet|remove|rename|test|(:?admindir|divert|package)\s+\S+)//g;
$divert =~ s/\s+//g;
+ # Remove unpaired opening or closing parenthesis
+ while($divert =~ m/\G.*?\(.+?\)/gc) {}
+ $divert =~ s/\G(.*?)[()]/$1/;
+ pos($divert) = undef;
+ # Remove unpaired opening or closing braces
+ while($divert =~ m/\G.*?{.+?}/gc) {}
+ $divert =~ s/\G(.*?)[{}]/$1/;
+ pos($divert) = undef;
+
+ # position after the last pair of quotation marks, if any
+ while($divert =~ m/\G.*?("|').+?\1/gc) {} #"
+ # Strip anything matching and after '&&', '||', or ';'
+ # this is safe only after we are positioned after the last pair
+ # of quotation marks
+ $divert =~ s/\G.+?\K(?: && | \|\| | ;).*$//x;
+ pos($divert) = undef;
+ # Remove quotation marks, they affect:
+ # * our var to regex trick
+ # * stripping the initial slash if the path was quoted
+ $divert =~ s/["']//g; #"
# remove the leading / because it's not in the index hash
$divert =~ s,^/,,;
@@ -886,7 +906,9 @@ while (<SCRIPTS>) {
# For now just replace variables, they will later be normalised
$expand_diversions = 1 if $divert =~ s/\\\$\w+/.+/g;
- $expand_diversions = 1 if $divert =~ s/\\\$\\{\w+\\}/.+/g;
+ $expand_diversions = 1 if $divert =~ s/\\\$\\{\w+.*?\\}/.+/g;
+ # handle $() the same way:
+ $expand_diversions = 1 if $divert =~ s/\\\$\\\(.+?\\\)/.+/g;
if ($mode eq 'add') {
$added_diversions{$divert} = {'script' => $file, 'line' => $.};
diff --git a/t/tests/scripts-diversions-variables/debian/debian/postrm b/t/tests/scripts-diversions-variables/debian/debian/postrm
index 6a5800a..73b8ee9 100644
--- a/t/tests/scripts-diversions-variables/debian/debian/postrm
+++ b/t/tests/scripts-diversions-variables/debian/debian/postrm
@@ -5,20 +5,22 @@ if [ remove = "$1" ]; then
# Clean up the correct diversion from preinst.
dpkg-divert --package scripts-diversions --remove --rename \
--divert /usr/share/scripts/t2/foo/some-file.real \
- /usr/share/scripts/t2/foo/some-file
+ "/usr/share/scripts/t2/foo/some-file"
d=scripts
# Clean up some other diversion that we didn't create.
dpkg-divert --package scripts-diversions --remove --rename \
- /usr/lib/$d/old-file
+ /usr/lib/$d/old-file; echo hi
# Clean up a diversion we did not create for a non-existent file.
dpkg-divert --remove --package scripts-diversions --rename \
--divert /usr/share/scripts/$v/no-such-file.real \
- /usr/share/scripts/$v/no-such-file
+ /usr/share/scripts/$v/no-such-file && echo hello
# Clean up a diversion we did create for a non-existent file.
- dpkg-divert --package foo --remove /etc/scripts/orphan
+ (dpkg-divert --package foo --remove /etc/scripts/orphan)
+ # another one:
+ { dpkg-divert --package foo --remove /usr/share/foo/$(echo bar); }
fi
#DEBHELPER#
diff --git a/t/tests/scripts-diversions-variables/debian/debian/preinst b/t/tests/scripts-diversions-variables/debian/debian/preinst
index ad7ec6c..b9ac6c8 100644
--- a/t/tests/scripts-diversions-variables/debian/debian/preinst
+++ b/t/tests/scripts-diversions-variables/debian/debian/preinst
@@ -18,12 +18,16 @@ if [ install = "$1" ]; then
# This is also correct, but we're not going to clean it up.
dpkg-divert --package scripts-diversions --add --rename \
--divert /usr/share/scripts/t1/$f.real \
- /usr/share/scripts/t1/$f
+ /usr/share/scripts/t1/"$f"
# Try to divert a file we don't ship
dpkg-divert --package scripts-diversions --add --rename \
--divert /etc/scripts/$f.real \
- /etc/scripts/$f
+ /etc/scripts/$f|| true
+ # Another one
+ dpkg-divert --package scripts-diversions --add --rename \
+ --divert /usr/share/foo/$f.real \
+ /usr/share/foo/${f#f}
fi
#DEBHELPER#
diff --git a/t/tests/scripts-diversions-variables/tags b/t/tests/scripts-diversions-variables/tags
index 5fba84f..3e321b3 100644
--- a/t/tests/scripts-diversions-variables/tags
+++ b/t/tests/scripts-diversions-variables/tags
@@ -1,4 +1,5 @@
E: scripts-diversions-variables: diversion-for-unknown-file etc/scripts/* preinst:26
+E: scripts-diversions-variables: diversion-for-unknown-file usr/share/foo/* preinst:30
E: scripts-diversions-variables: orphaned-diversion usr/share/scripts/t1/* preinst
E: scripts-diversions-variables: package-uses-local-diversion preinst:15
E: scripts-diversions-variables: remove-of-unknown-diversion usr/lib/*/old-file postrm:13
--
Debian package checker
Reply to: