34 #include "xbps_api_impl.h"
76 prop_dictionary_t dict,
82 prop_object_iterator_t iter;
84 const char *file, *sha256, *version, *curobj = NULL;
85 char *path = NULL, *pkgname = NULL;
89 assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
92 array = prop_dictionary_get(dict, key);
93 if ((prop_object_type(array) != PROP_TYPE_ARRAY) ||
94 prop_array_count(array) == 0)
101 if (strcmp(key,
"files") == 0)
103 else if (strcmp(key,
"conf_files") == 0)
104 curobj =
"configuration file";
105 else if (strcmp(key,
"links") == 0)
107 else if (strcmp(key,
"dirs") == 0)
108 curobj =
"directory";
114 while ((obj = prop_object_iterator_next(iter))) {
115 prop_dictionary_get_cstring_nocopy(obj,
"file", &file);
118 if ((strcmp(key,
"files") == 0) ||
119 (strcmp(key,
"conf_files") == 0)) {
124 prop_dictionary_get_cstring_nocopy(obj,
129 xbps_set_cb_state(xhp,
130 XBPS_STATE_REMOVE_FILE_HASH_FAIL,
131 rv, pkgname, version,
132 "%s: failed to check hash for %s `%s': %s",
133 pkgver, curobj, file, strerror(rv));
137 }
else if (rv == ERANGE) {
140 XBPS_FLAG_FORCE_REMOVE_FILES) == 0) {
141 xbps_set_cb_state(xhp,
142 XBPS_STATE_REMOVE_FILE_HASH_FAIL,
144 "%s: %s `%s' SHA256 mismatch, "
145 "preserving file", pkgver,
150 xbps_set_cb_state(xhp,
151 XBPS_STATE_REMOVE_FILE_HASH_FAIL,
153 "%s: %s `%s' SHA256 mismatch, "
154 "forcing removal", pkgver,
157 }
else if (rv != 0 && rv != ERANGE) {
158 xbps_set_cb_state(xhp,
159 XBPS_STATE_REMOVE_FILE_HASH_FAIL,
160 rv, pkgname, version,
161 "%s: [remove] failed to check hash for "
162 "%s `%s': %s", pkgver, curobj, file,
167 }
else if (strcmp(key,
"links") == 0) {
172 if (realpath(path, buf) == NULL) {
173 if (errno != ENOENT) {
179 if (stat(buf, &st) == 0) {
187 if (
remove(path) == -1) {
188 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE_FAIL,
189 errno, pkgname, version,
190 "%s: failed to remove %s `%s': %s", pkgver,
191 curobj, file, strerror(errno));
195 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE,
197 "Removed %s `%s'", curobj, file);
201 prop_object_iterator_release(iter);
213 prop_dictionary_t pkgd = NULL;
214 char *pkgname, *buf = NULL;
230 xbps_dbg_printf(xhp,
"attempting to remove %s state %d\n",
234 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE, 0, pkgname, version, NULL);
238 if (chdir(xhp->
rootdir) == -1) {
240 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
241 rv, pkgname, version,
242 "%s: [remove] failed to chdir to rootdir `%s': %s",
243 pkgver, xhp->
rootdir, strerror(rv));
249 pkgd = prop_dictionary_internalize_from_file(buf);
252 xbps_dbg_printf(xhp,
"WARNING: metaplist for %s "
253 "doesn't exist!\n", pkgname);
256 if (state == XBPS_PKG_STATE_HALF_REMOVED)
264 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
265 errno, pkgname, version,
266 "%s: [remove] REMOVE script failed to "
267 "execute pre ACTION: %s",
268 pkgver, strerror(errno));
280 prop_object_release(pkgd);
283 }
else if (soft_replace) {
311 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
312 rv, pkgname, version,
313 "%s: [remove] REMOVE script failed to execute "
314 "post ACTION: %s", pkgver, strerror(rv));
324 XBPS_PKG_STATE_HALF_REMOVED);
326 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
327 rv, pkgname, version,
328 "%s: [remove] failed to set state to half-removed: %s",
329 pkgver, strerror(rv));
340 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
341 rv, pkgname, version,
342 "%s: REMOVE script failed to execute "
343 "purge ACTION: %s", pkgver, strerror(rv));
346 prop_object_release(pkgd);
352 if (
remove(buf) == -1) {
353 if (errno != ENOENT) {
354 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
355 rv, pkgname, version,
356 "%s: failed to remove metadata file: %s",
357 pkgver, strerror(errno));
366 xbps_dbg_printf(xhp,
"[remove] unregister %s returned %d\n", pkgver, rv);
368 xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_DONE,
369 0, pkgname, version, NULL);