#1076155 dpkg-query --search does not use partial pathnames as pattern

Package:
dpkg
Source:
dpkg
Description:
Debian package management system
Submitter:
Date:
2025-05-07 09:45:02 UTC
Severity:
normal
#1076155#5
Date:
2024-07-11 16:32:44 UTC
From:
To:
Dear Maintainer,

===========================================================================

dpkg-query does not use a partial pathname as a pattern to search.

Example:
  => which exiftool
   /bin/exiftool
  => dpkg-query --search `which exiftool`
   dpkg-query: no path found matching pattern /bin/exiftool
  => dlocate `which exiftool`
   libimage-exiftool-perl: /usr/bin/exiftool
  => dpkg-query --search /usr/bin/exiftool
   libimage-exiftool-perl: /usr/bin/exiftool
  => /bin/ls -lt /usr/bin/exiftool /bin/exiftool
   -rwxr-xr-x 1 root root 320936 Feb  2 19:43 /bin/exiftool
   -rwxr-xr-x 1 root root 320936 Feb  2 19:43 /usr/bin/exiftool

The behavior of dlocate, which takes "/bin/exiftool" as an argument and
returns the package containing /usr/bin/exiftool is more useful.

===========================================================================

#1076155#10
Date:
2025-05-07 09:43:33 UTC
From:
To:
This seems to be the intended behavior. In the dpkg-query(1) man page:

       -S, --search filename-search-pattern...
[...]
           If the first character in the filename-search-pattern is
           none of ‘*[?/’ then it will be considered a substring match
           and will be implicitly surrounded by ‘*’ (as in
           *filename-search-pattern*).

Since your searches start with "/", you are requesting an exact match.

Using realpath solves the issue:

$ dpkg-query --search $(realpath /bin/exiftool)
libimage-exiftool-perl: /usr/bin/exiftool

You could write a small script that does what you want.