From fe8ea8c21ccae5a16711c9075754900d0a47b533 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 3 Feb 2009 16:51:42 +0100 Subject: [PATCH] Check that pkg is installed before removing. --HG-- extra : convert_revision : 4ea85e367ecbc0d39dcba1c8ee63392f0e1177f7 --- bin/xbps-bin.c | 7 ++++++- lib/remove.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/bin/xbps-bin.c b/bin/xbps-bin.c index 0a28fa07e99..81da5df228e 100644 --- a/bin/xbps-bin.c +++ b/bin/xbps-bin.c @@ -354,7 +354,12 @@ main(int argc, char **argv) } else { rv = xbps_remove_binary_pkg(argv[1], root); if (rv) { - printf("ERROR: unable to remove %s.\n", argv[1]); + if (rv == ENOENT) + printf("Package %s is not installed.\n", + argv[1]); + else + printf("ERROR: unable to remove %s.\n", + argv[1]); exit(rv); } printf("Package %s removed successfully.\n", argv[1]); diff --git a/lib/remove.c b/lib/remove.c index 5e8f881c71d..fe07155403a 100644 --- a/lib/remove.c +++ b/lib/remove.c @@ -35,6 +35,28 @@ #include +static bool +check_installed_pkgname(const char *pkgname) +{ + prop_dictionary_t pkgd; + char *plist; + + assert(pkgname != NULL); + + plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB); + if (plist == NULL) + return EINVAL; + + pkgd = xbps_find_pkg_from_plist(plist, pkgname); + free(plist); + if (pkgd) { + prop_object_release(pkgd); + return true; + } + + return false; +} + int xbps_unregister_pkg(const char *pkgname) { @@ -69,6 +91,10 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir) if (destdir == NULL) destdir = ""; + /* Check if pkg is installed */ + if (check_installed_pkgname(pkgname) == false) + return ENOENT; + /* * This length is '%s%s/metadata/%s/prepost-action' not * including nul.