diff --git a/bin/xbps-bin/install.c b/bin/xbps-bin/install.c index 568d6adb..99950f27 100644 --- a/bin/xbps-bin/install.c +++ b/bin/xbps-bin/install.c @@ -474,7 +474,8 @@ replace_packages(prop_object_iterator_t iter, const char *pkgver) prop_object_release(instd); version = xbps_get_pkg_version(pkgver); - if ((rv = xbps_remove_pkg(reppkgn, version, false)) != 0) { + rv = xbps_remove_pkg(reppkgn, version, false, false); + if (rv != 0) { fprintf(stderr, "xbps-bin: couldn't remove %s (%s)\n", reppkgn, strerror(rv)); return rv; @@ -607,7 +608,7 @@ exec_transaction(struct transaction *trans) printf("Removing %s-%s before installing new " "version ...\n", pkgname, instver); - rv = xbps_remove_pkg(pkgname, version, true); + rv = xbps_remove_pkg(pkgname, version, true, essential); if (rv != 0) { fprintf(stderr, "xbps-bin: error " "%s %s-%s (%s)\n", essential ? diff --git a/bin/xbps-bin/remove.c b/bin/xbps-bin/remove.c index bf5dea0f..9208fc5e 100644 --- a/bin/xbps-bin/remove.c +++ b/bin/xbps-bin/remove.c @@ -105,7 +105,7 @@ xbps_autoremove_pkgs(bool force) goto out; } printf("Removing package %s-%s ...\n", pkgname, version); - if ((rv = xbps_remove_pkg(pkgname, version, false)) != 0) + if ((rv = xbps_remove_pkg(pkgname, version, false, false)) != 0) goto out2; } out2: @@ -185,7 +185,8 @@ xbps_remove_installed_pkgs(int argc, char **argv, bool force) continue; prop_dictionary_get_cstring_nocopy(dict, "version", &version); printf("Removing package %s-%s ...\n", argv[i], version); - if ((rv = xbps_remove_pkg(argv[i], version, false)) != 0) { + rv = xbps_remove_pkg(argv[i], version, false, false); + if (rv != 0) { fprintf(stderr, "E: unable to remove %s-%s (%s).\n", argv[i], version, strerror(errno)); return rv; diff --git a/include/xbps_api.h b/include/xbps_api.h index 223ef16d..637f993b 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -640,10 +640,12 @@ void xbps_regpkgs_dictionary_release(void); * @param[in] update If true, and depending if \a pkgname is an * essential package, some steps will be skipped. See in the * detailed description section for more information. + * @param[in] essential Set it to true if \a pkgname is essential. * * @return 0 on success, or an errno value otherwise. */ -int xbps_remove_pkg(const char *pkgname, const char *version, bool update); +int xbps_remove_pkg(const char *pkgname, const char *version, + bool update, bool essential); /** * Remove files defined in a proplib array as specified by \a key diff --git a/lib/remove.c b/lib/remove.c index 7619710b..815d3552 100644 --- a/lib/remove.c +++ b/lib/remove.c @@ -174,13 +174,14 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key) } int -xbps_remove_pkg(const char *pkgname, const char *version, bool update) +xbps_remove_pkg(const char *pkgname, const char *version, + bool update, bool essential) { - prop_dictionary_t dict, pkgd; + prop_dictionary_t dict; const char *rootdir = xbps_get_rootdir(); char *path, *buf; int rv = 0; - bool essential = false, prepostf = false; + bool prepostf = false; assert(pkgname != NULL); assert(version != NULL); @@ -188,12 +189,9 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update) /* * Check if pkg is installed before anything else. */ - if ((pkgd = xbps_find_pkg_dict_installed(pkgname, false)) == NULL) + if (!xbps_check_is_installed_pkgname(pkgname)) return ENOENT; - prop_dictionary_get_bool(pkgd, "essential", &essential); - prop_object_release(pkgd); - if (strcmp(rootdir, "") == 0) rootdir = "/"; @@ -230,8 +228,10 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update) * entries and continue. Its files will be overwritten later in * the unpack phase. */ - if (essential && update) + if (essential && update) { + free(buf); return xbps_requiredby_pkg_remove(pkgname); + } /* * Remove links, files and dirs.