39#include "xbps_api_impl.h"
43 xbps_array_t obsoletes,
const char *pkgver, uid_t euid)
51 for (
unsigned int i = 0; i < xbps_array_count(obsoletes); i++) {
52 const char *file = NULL;
53 xbps_array_get_cstring_nocopy(obsoletes, i, &file);
59 if (lstat(file, &st) == 0 && euid == st.st_uid) {
63 if (errno != ENOENT) {
74 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE_FAIL,
76 "%s: cannot remove `%s': %s",
77 pkgver, file, strerror(rv));
86 xbps_array_t obsoletes,
91 for (
unsigned int i = 0; i < xbps_array_count(obsoletes); i++) {
92 const char *file = NULL;
93 xbps_array_get_cstring_nocopy(obsoletes, i, &file);
97 if (remove(file) == -1) {
98 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE_FAIL,
100 "%s: failed to remove `%s': %s", pkgver,
101 file, strerror(errno));
104 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE,
105 0, pkgver,
"Removed `%s'", file);
113xbps_remove_pkg(
struct xbps_handle *xhp,
const char *pkgver,
bool update)
115 xbps_dictionary_t pkgd = NULL, obsd = NULL;
116 xbps_array_t obsoletes = NULL;
117 char pkgname[XBPS_NAME_SIZE], metafile[PATH_MAX];
133 xbps_dbg_printf(
"[remove] cannot find %s in pkgdb: %s\n",
134 pkgver, strerror(rv));
138 xbps_dbg_printf(
"[remove] cannot find %s in pkgdb: %s\n",
139 pkgver, strerror(rv));
142 xbps_dbg_printf(
"attempting to remove %s state %d\n", pkgver, state);
145 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE, 0, pkgver, NULL);
147 if (chdir(xhp->
rootdir) == -1) {
149 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
151 "%s: [remove] failed to chdir to rootdir `%s': %s",
152 pkgver, xhp->
rootdir, strerror(rv));
157 if (state == XBPS_PKG_STATE_HALF_REMOVED)
161 if ((rv = xbps_cb_message(xhp, pkgd,
"remove-msg")) != 0)
166 xbps_dictionary_set_bool(pkgd,
"alternatives-update",
true);
180 if (xbps_dictionary_get_dict(xhp->
transd,
"obsolete_files", &obsd))
181 obsoletes = xbps_dictionary_get(obsd, pkgname);
183 if (xbps_array_count(obsoletes) > 0) {
189 if (check_remove_pkg_files(xhp, obsoletes, pkgver, euid)) {
194 if ((rv = remove_pkg_files(xhp, obsoletes, pkgver)) != 0)
202 XBPS_PKG_STATE_HALF_REMOVED);
204 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
206 "%s: [remove] failed to set state to half-removed: %s",
207 pkgver, strerror(rv));
216 snprintf(metafile,
sizeof(metafile),
"%s/.%s-files.plist", xhp->
metadir, pkgname);
217 if (remove(metafile) == -1) {
218 if (errno != ENOENT) {
219 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
221 "%s: failed to remove metadata file: %s",
222 pkgver, strerror(errno));
228 xbps_dbg_printf(
"[remove] unregister %s returned %d\n", pkgver, rv);
229 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_DONE, 0, pkgver, NULL);
230 xbps_dictionary_remove(xhp->
pkgdb, pkgname);
233 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver,
234 "%s: failed to remove package: %s", pkgver, strerror(rv));
int xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
char metadir[XBPS_MAXPATH+sizeof(XBPS_META_PATH)]
char rootdir[XBPS_MAXPATH]
Generic XBPS structure handler for initialization.
xbps_dictionary_t xbps_pkgdb_get_pkg(struct xbps_handle *xhp, const char *pkg)
int xbps_set_pkg_state_dictionary(xbps_dictionary_t dict, pkg_state_t state)
int xbps_pkg_state_dictionary(xbps_dictionary_t dict, pkg_state_t *state)
bool xbps_pkg_name(char *dst, size_t len, const char *pkg)