Check that pkg is installed before removing.
--HG-- extra : convert_revision : 4ea85e367ecbc0d39dcba1c8ee63392f0e1177f7
This commit is contained in:
parent
edfeec4622
commit
fe8ea8c21c
2 changed files with 32 additions and 1 deletions
|
@ -354,7 +354,12 @@ main(int argc, char **argv)
|
||||||
} else {
|
} else {
|
||||||
rv = xbps_remove_binary_pkg(argv[1], root);
|
rv = xbps_remove_binary_pkg(argv[1], root);
|
||||||
if (rv) {
|
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);
|
exit(rv);
|
||||||
}
|
}
|
||||||
printf("Package %s removed successfully.\n", argv[1]);
|
printf("Package %s removed successfully.\n", argv[1]);
|
||||||
|
|
26
lib/remove.c
26
lib/remove.c
|
@ -35,6 +35,28 @@
|
||||||
|
|
||||||
#include <xbps_api.h>
|
#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
|
int
|
||||||
xbps_unregister_pkg(const char *pkgname)
|
xbps_unregister_pkg(const char *pkgname)
|
||||||
{
|
{
|
||||||
|
@ -69,6 +91,10 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir)
|
||||||
if (destdir == NULL)
|
if (destdir == NULL)
|
||||||
destdir = "";
|
destdir = "";
|
||||||
|
|
||||||
|
/* Check if pkg is installed */
|
||||||
|
if (check_installed_pkgname(pkgname) == false)
|
||||||
|
return ENOENT;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This length is '%s%s/metadata/%s/prepost-action' not
|
* This length is '%s%s/metadata/%s/prepost-action' not
|
||||||
* including nul.
|
* including nul.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue