Package: dpkg
Version: 1.14.18
Tags: patch
Severity: wishlist
dpkg-divert should provide an option to find out what package diverts a
given file (currently the only way to extract this information is to parse
the dpkg-divert output, which is not ideal).
I've attached a patch against current git to add this functionality.
-Tim Abbottdiff --git a/man/dpkg-divert.8 b/man/dpkg-divert.8
index 2e9662f..00f312b 100644
--- a/man/dpkg-divert.8
+++ b/man/dpkg-divert.8
@@ -32,6 +32,10 @@ Remove a diversion for \fIfile\fP.
.BI \-\-list " glob-pattern"
List diversions matching \fIglob-pattern\fP.
.TP
+.BI \-\-listpackage " file"
+Print the name of the package the diverts \fIfile\fP. Prints LOCAL if
+\fIfile\fP is locally diverted and nothing if \fIfile\fP is not diverted.
+.TP
.BI \-\-truename " file"
Print the real name for a diverted file.
.
diff --git a/scripts/dpkg-divert.pl b/scripts/dpkg-divert.pl
index 8c13cb8..03ee7af 100755
--- a/scripts/dpkg-divert.pl
+++ b/scripts/dpkg-divert.pl
@@ -30,6 +30,7 @@ Commands:
[--add] <file> add a diversion.
--remove <file> remove the diversion.
--list [<glob-pattern>] show file diversions.
+ --listpackage <file> show what package diverts the file.
--truename <file> return the diverted file.
Options:
@@ -98,6 +99,9 @@ while (@ARGV) {
} elsif (m/^--list$/) {
&checkmanymodes;
$mode= 'list';
+ } elsif (m/^--listpackage$/) {
+ &checkmanymodes;
+ $mode= 'listpackage';
} elsif (m/^--truename$/) {
&checkmanymodes;
$mode= 'truename';
@@ -210,6 +214,21 @@ if ($mode eq 'add') {
}
print $file, "\n";
exit(0);
+} elsif ($mode eq 'listpackage') {
+ @ARGV == 1 || &badusage(sprintf(_g("--%s needs a single argument"), "truename"));
+ $file= $ARGV[0];
+ for (my $i = 0; $i <= $#contest; $i++) {
+ next unless $file eq $contest[$i];
+ if ($package[$i] eq ':') {
+ # indicate package is local using something not in package namespace
+ print "LOCAL\n";
+ } else {
+ print $package[$i], "\n";
+ }
+ exit(0);
+ }
+ # print nothing if file is not diverted
+ exit(0);
} else {
&quit(sprintf(_g("internal error - bad mode \`%s'"), $mode));
}