Check that pkg is installed before removing.
--HG-- extra : convert_revision : 4ea85e367ecbc0d39dcba1c8ee63392f0e1177f7
This commit is contained in:
parent
edfeec4622
commit
fe8ea8c21c
|
@ -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]);
|
||||
|
|
26
lib/remove.c
26
lib/remove.c
|
@ -35,6 +35,28 @@
|
|||
|
||||
#include <xbps_api.h>
|
||||
|
||||
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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user