summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2014-05-23 07:01:32 +0200
committerGuillem Jover <guillem@debian.org>2014-05-23 07:01:32 +0200
commite6c1af78ae46aa989dcc16f90694f4bd15a1bc3e (patch)
tree383cb4b6c904b886e158c6af816bc80013234c24 /src
parentc52a62fdf86b571f75c903523da5f5ea8bdb3c13 (diff)
downloaddpkg-e6c1af78ae46aa989dcc16f90694f4bd15a1bc3e.tar.gz
dpkg: Add support for per-package --audit
This allows to check for specific issues with a requested package.
Diffstat (limited to 'src')
-rw-r--r--src/enquiry.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/enquiry.c b/src/enquiry.c
index 623b8570b..d8369c56a 100644
--- a/src/enquiry.c
+++ b/src/enquiry.c
@@ -21,8 +21,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-/* FIXME: per-package audit. */
-
#include <config.h>
#include <compat.h>
@@ -40,6 +38,7 @@
#include <dpkg/dpkg.h>
#include <dpkg/dpkg-db.h>
#include <dpkg/arch.h>
+#include <dpkg/pkg-array.h>
#include <dpkg/pkg-show.h>
#include <dpkg/string.h>
#include <dpkg/options.h>
@@ -176,24 +175,41 @@ static void describebriefly(struct pkginfo *pkg) {
printf(" %-20s %.*s\n", pkg_name(pkg, pnaw_nonambig), l, pdesc);
}
+static struct pkginfo *
+pkg_array_mapper(const char *name)
+{
+ struct pkginfo *pkg;
+
+ pkg = dpkg_options_parse_pkgname(cipaction, name);
+ if (pkg->status == stat_notinstalled)
+ notice(_("package '%s' is not installed"), pkg_name(pkg, pnaw_nonambig));
+
+ return pkg;
+}
+
int
audit(const char *const *argv)
{
const struct audit_problem *problem;
+ struct pkg_array array;
bool head_running = false;
-
- if (*argv)
- badusage(_("--%s takes no arguments"), cipaction->olong);
+ int i;
modstatdb_open(msdbrw_readonly);
+ if (!*argv)
+ pkg_array_init_from_db(&array);
+ else
+ pkg_array_init_from_names(&array, pkg_array_mapper, (const char **)argv);
+
+ pkg_array_sort(&array, pkg_sorter_by_nonambig_name_arch);
+
for (problem = audit_problems; problem->check; problem++) {
- struct pkgiterator *it;
- struct pkginfo *pkg;
bool head = false;
- it = pkg_db_iter_new();
- while ((pkg = pkg_db_iter_next_pkg(it))) {
+ for (i = 0; i < array.n_pkgs; i++) {
+ struct pkginfo *pkg = array.pkgs[i];
+
if (!problem->check(pkg, problem))
continue;
if (!head_running) {
@@ -209,10 +225,12 @@ audit(const char *const *argv)
}
describebriefly(pkg);
}
- pkg_db_iter_free(it);
+
if (head) putchar('\n');
}
+ pkg_array_destroy(&array);
+
m_output(stdout, _("<standard output>"));
return 0;