2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2014-02-09 16:24:49 +05:30
|
|
|
* Copyright (c) 2009-2014 Juan Romero Pardines.
|
2009-08-17 22:37:20 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <dirent.h>
|
2010-11-06 11:14:00 +05:30
|
|
|
#include <libgen.h>
|
2014-02-26 14:35:19 +05:30
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-11-13 07:48:58 +05:30
|
|
|
#include "xbps_api_impl.h"
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2014-02-09 17:23:15 +05:30
|
|
|
static bool
|
|
|
|
check_remove_pkg_files(struct xbps_handle *xhp,
|
|
|
|
xbps_dictionary_t pkgd, const char *pkgver)
|
|
|
|
{
|
|
|
|
xbps_array_t array;
|
|
|
|
xbps_object_iterator_t iter;
|
|
|
|
xbps_object_t obj;
|
|
|
|
const char *objs[] = { "files", "conf_files", "links", "dirs" };
|
|
|
|
const char *file;
|
2014-05-22 14:12:27 +05:30
|
|
|
char path[PATH_MAX];
|
2014-02-09 17:23:15 +05:30
|
|
|
bool fail = false;
|
2014-02-26 14:35:19 +05:30
|
|
|
int fd = 0;
|
2013-11-28 14:57:36 +05:30
|
|
|
|
2014-02-09 17:23:15 +05:30
|
|
|
for (uint8_t i = 0; i < __arraycount(objs); i++) {
|
|
|
|
array = xbps_dictionary_get(pkgd, objs[i]);
|
|
|
|
if (array == NULL || xbps_array_count(array) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
iter = xbps_array_iter_from_dict(pkgd, objs[i]);
|
|
|
|
if (iter == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "file", &file);
|
2014-05-22 14:12:27 +05:30
|
|
|
snprintf(path, sizeof(path), "%s/%s", xhp->rootdir, file);
|
2014-02-26 14:35:19 +05:30
|
|
|
if (faccessat(fd, path, W_OK, AT_SYMLINK_NOFOLLOW) == -1) {
|
2014-02-09 17:23:15 +05:30
|
|
|
if (errno != ENOENT) {
|
|
|
|
/*
|
|
|
|
* only bail out if something else than ENOENT
|
|
|
|
* is returned.
|
|
|
|
*/
|
|
|
|
fail = true;
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE_FAIL,
|
|
|
|
errno, pkgver,
|
|
|
|
"%s: cannot remove `%s': %s",
|
|
|
|
pkgver, file, strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xbps_object_iterator_release(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
remove_pkg_files(struct xbps_handle *xhp,
|
|
|
|
xbps_dictionary_t dict,
|
|
|
|
const char *key,
|
|
|
|
const char *pkgver)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t array;
|
|
|
|
xbps_object_iterator_t iter;
|
|
|
|
xbps_object_t obj;
|
2013-03-05 08:38:42 +05:30
|
|
|
const char *file, *sha256, *curobj = NULL;
|
2014-02-09 17:23:15 +05:30
|
|
|
/* These are symlinks in Void and must not be removed */
|
|
|
|
const char *basesymlinks[] = {
|
|
|
|
"/bin",
|
|
|
|
"/sbin",
|
|
|
|
"/lib",
|
|
|
|
"/lib32",
|
|
|
|
"/lib64",
|
2014-03-31 13:46:18 +05:30
|
|
|
"/usr/lib32",
|
2014-02-09 17:23:15 +05:30
|
|
|
"/usr/lib64",
|
|
|
|
"/var/run",
|
|
|
|
};
|
2014-05-22 14:12:27 +05:30
|
|
|
char path[PATH_MAX];
|
2011-02-21 22:12:47 +05:30
|
|
|
int rv = 0;
|
2013-11-28 14:57:36 +05:30
|
|
|
bool found;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
assert(xbps_object_type(dict) == XBPS_TYPE_DICTIONARY);
|
2009-12-07 11:00:06 +05:30
|
|
|
assert(key != NULL);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
array = xbps_dictionary_get(dict, key);
|
|
|
|
if (xbps_array_count(array) == 0)
|
2009-08-17 22:37:20 +05:30
|
|
|
return 0;
|
|
|
|
|
2011-06-01 13:07:32 +05:30
|
|
|
iter = xbps_array_iter_from_dict(dict, key);
|
2009-08-17 22:37:20 +05:30
|
|
|
if (iter == NULL)
|
2010-11-19 18:10:13 +05:30
|
|
|
return ENOMEM;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-11-06 11:14:00 +05:30
|
|
|
if (strcmp(key, "files") == 0)
|
|
|
|
curobj = "file";
|
|
|
|
else if (strcmp(key, "conf_files") == 0)
|
|
|
|
curobj = "configuration file";
|
|
|
|
else if (strcmp(key, "links") == 0)
|
|
|
|
curobj = "link";
|
|
|
|
else if (strcmp(key, "dirs") == 0)
|
|
|
|
curobj = "directory";
|
|
|
|
|
2014-02-09 16:24:49 +05:30
|
|
|
xbps_object_iterator_reset(iter);
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "file", &file);
|
2014-05-22 14:12:27 +05:30
|
|
|
snprintf(path, sizeof(path), "%s/%s", xhp->rootdir, file);
|
2010-11-19 18:10:13 +05:30
|
|
|
|
2009-12-07 11:00:06 +05:30
|
|
|
if ((strcmp(key, "files") == 0) ||
|
|
|
|
(strcmp(key, "conf_files") == 0)) {
|
|
|
|
/*
|
|
|
|
* Check SHA256 hash in regular files and
|
|
|
|
* configuration files.
|
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj,
|
2010-11-06 11:14:00 +05:30
|
|
|
"sha256", &sha256);
|
2011-06-01 13:07:32 +05:30
|
|
|
rv = xbps_file_hash_check(path, sha256);
|
2009-12-07 11:00:06 +05:30
|
|
|
if (rv == ENOENT) {
|
2011-11-24 15:53:08 +05:30
|
|
|
/* missing file, ignore it */
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp,
|
2011-11-24 15:53:08 +05:30
|
|
|
XBPS_STATE_REMOVE_FILE_HASH_FAIL,
|
2013-03-05 08:38:42 +05:30
|
|
|
rv, pkgver,
|
2011-11-24 15:53:08 +05:30
|
|
|
"%s: failed to check hash for %s `%s': %s",
|
|
|
|
pkgver, curobj, file, strerror(rv));
|
2009-12-07 11:00:06 +05:30
|
|
|
rv = 0;
|
|
|
|
continue;
|
|
|
|
} else if (rv == ERANGE) {
|
|
|
|
rv = 0;
|
2011-11-24 16:20:53 +05:30
|
|
|
if ((xhp->flags &
|
|
|
|
XBPS_FLAG_FORCE_REMOVE_FILES) == 0) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp,
|
2011-11-24 15:53:08 +05:30
|
|
|
XBPS_STATE_REMOVE_FILE_HASH_FAIL,
|
2013-03-05 08:38:42 +05:30
|
|
|
0, pkgver,
|
2011-11-24 15:53:08 +05:30
|
|
|
"%s: %s `%s' SHA256 mismatch, "
|
|
|
|
"preserving file", pkgver,
|
|
|
|
curobj, file);
|
2010-01-25 12:39:48 +05:30
|
|
|
continue;
|
2011-11-24 15:53:08 +05:30
|
|
|
} else {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp,
|
2011-11-24 15:53:08 +05:30
|
|
|
XBPS_STATE_REMOVE_FILE_HASH_FAIL,
|
2013-03-05 08:38:42 +05:30
|
|
|
0, pkgver,
|
2011-11-24 15:53:08 +05:30
|
|
|
"%s: %s `%s' SHA256 mismatch, "
|
|
|
|
"forcing removal", pkgver,
|
|
|
|
curobj, file);
|
2010-01-25 12:39:48 +05:30
|
|
|
}
|
2009-12-07 11:00:06 +05:30
|
|
|
} else if (rv != 0 && rv != ERANGE) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp,
|
2011-11-24 15:53:08 +05:30
|
|
|
XBPS_STATE_REMOVE_FILE_HASH_FAIL,
|
2013-03-05 08:38:42 +05:30
|
|
|
rv, pkgver,
|
2011-11-24 15:53:08 +05:30
|
|
|
"%s: [remove] failed to check hash for "
|
|
|
|
"%s `%s': %s", pkgver, curobj, file,
|
|
|
|
strerror(rv));
|
2009-12-07 11:00:06 +05:30
|
|
|
break;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2010-11-06 11:14:00 +05:30
|
|
|
}
|
2013-11-28 14:57:36 +05:30
|
|
|
/*
|
|
|
|
* Make sure to not remove any symlink of root directory.
|
|
|
|
*/
|
|
|
|
found = false;
|
|
|
|
for (uint8_t i = 0; i < __arraycount(basesymlinks); i++) {
|
|
|
|
if (strcmp(file, basesymlinks[i]) == 0) {
|
|
|
|
found = true;
|
|
|
|
xbps_dbg_printf(xhp, "[remove] %s ignoring "
|
|
|
|
"%s removal\n", pkgver, file);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-11-06 11:14:00 +05:30
|
|
|
/*
|
|
|
|
* Remove the object if possible.
|
|
|
|
*/
|
|
|
|
if (remove(path) == -1) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE_FAIL,
|
2013-03-05 08:38:42 +05:30
|
|
|
errno, pkgver,
|
2011-11-24 15:53:08 +05:30
|
|
|
"%s: failed to remove %s `%s': %s", pkgver,
|
|
|
|
curobj, file, strerror(errno));
|
2010-11-06 11:14:00 +05:30
|
|
|
} else {
|
2011-11-24 15:53:08 +05:30
|
|
|
/* success */
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE,
|
2013-03-05 08:38:42 +05:30
|
|
|
0, pkgver, "Removed %s `%s'", curobj, file);
|
2010-11-06 11:14:00 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_iterator_release(iter);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-12-07 11:00:06 +05:30
|
|
|
return rv;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2013-03-05 08:38:42 +05:30
|
|
|
int HIDDEN
|
2013-12-25 15:42:52 +05:30
|
|
|
xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t pkgd = NULL;
|
2014-05-22 14:12:27 +05:30
|
|
|
char *pkgname, metafile[PATH_MAX];
|
2009-08-17 22:37:20 +05:30
|
|
|
int rv = 0;
|
2011-12-24 05:35:26 +05:30
|
|
|
pkg_state_t state = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
assert(xhp);
|
|
|
|
assert(pkgver);
|
|
|
|
|
|
|
|
pkgname = xbps_pkg_name(pkgver);
|
|
|
|
assert(pkgname);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2013-11-17 16:03:16 +05:30
|
|
|
if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0) {
|
2014-03-14 01:37:44 +05:30
|
|
|
xbps_dbg_printf(xhp, "[remove] cannot find %s in pkgdb: %s\n",
|
2013-11-17 16:03:16 +05:30
|
|
|
pkgver, strerror(rv));
|
|
|
|
goto out;
|
|
|
|
}
|
2014-03-14 01:37:44 +05:30
|
|
|
xbps_dbg_printf(xhp, "attempting to remove %s state %d\n", pkgver, state);
|
2012-11-19 18:38:01 +05:30
|
|
|
|
2011-12-24 05:35:26 +05:30
|
|
|
if (!update)
|
2013-03-05 08:38:42 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE, 0, pkgver, NULL);
|
2011-12-24 05:35:26 +05:30
|
|
|
|
2011-12-15 15:49:20 +05:30
|
|
|
if (chdir(xhp->rootdir) == -1) {
|
2011-11-24 15:53:08 +05:30
|
|
|
rv = errno;
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
2013-03-05 08:38:42 +05:30
|
|
|
rv, pkgver,
|
2011-11-24 15:53:08 +05:30
|
|
|
"%s: [remove] failed to chdir to rootdir `%s': %s",
|
2011-12-15 15:49:20 +05:30
|
|
|
pkgver, xhp->rootdir, strerror(rv));
|
2011-12-24 05:35:26 +05:30
|
|
|
goto out;
|
2010-11-06 11:14:00 +05:30
|
|
|
}
|
2012-11-27 03:55:41 +05:30
|
|
|
|
|
|
|
/* internalize pkg dictionary from metadir */
|
2014-05-22 14:19:01 +05:30
|
|
|
snprintf(metafile, sizeof(metafile), "%s/.%s.plist", xhp->metadir, pkgname);
|
2014-05-22 14:12:27 +05:30
|
|
|
pkgd = xbps_dictionary_internalize_from_file(metafile);
|
2012-11-19 17:59:09 +05:30
|
|
|
if (pkgd == NULL)
|
2012-11-19 18:38:01 +05:30
|
|
|
xbps_dbg_printf(xhp, "WARNING: metaplist for %s "
|
2013-03-05 08:38:42 +05:30
|
|
|
"doesn't exist!\n", pkgver);
|
2012-11-16 21:25:35 +05:30
|
|
|
|
2011-12-24 05:35:26 +05:30
|
|
|
/* If package was "half-removed", remove it fully. */
|
|
|
|
if (state == XBPS_PKG_STATE_HALF_REMOVED)
|
|
|
|
goto purge;
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
2014-07-27 14:54:49 +05:30
|
|
|
* Run the pre remove action and show pre-remove message if exists.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2012-11-19 18:38:01 +05:30
|
|
|
if (pkgd) {
|
2014-07-27 14:54:49 +05:30
|
|
|
xbps_data_t rmsg;
|
|
|
|
|
2012-12-28 15:12:13 +05:30
|
|
|
rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script",
|
|
|
|
"pre", update);
|
2012-11-19 18:38:01 +05:30
|
|
|
if (rv != 0) {
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
2013-03-05 08:38:42 +05:30
|
|
|
errno, pkgver,
|
2012-11-19 18:38:01 +05:30
|
|
|
"%s: [remove] REMOVE script failed to "
|
|
|
|
"execute pre ACTION: %s",
|
2013-01-14 18:31:35 +05:30
|
|
|
pkgver, strerror(rv));
|
|
|
|
goto out;
|
2012-11-19 18:38:01 +05:30
|
|
|
}
|
2014-07-27 14:54:49 +05:30
|
|
|
/* show remove-msg if exists */
|
|
|
|
rmsg = xbps_dictionary_get(pkgd, "remove-msg");
|
|
|
|
if (xbps_object_type(rmsg) == XBPS_TYPE_DATA) {
|
|
|
|
FILE *f;
|
|
|
|
const void *data;
|
|
|
|
char *buf;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
data = xbps_data_data_nocopy(rmsg);
|
|
|
|
len = xbps_data_size(rmsg);
|
|
|
|
if ((f = fmemopen(__UNCONST(data), len, "r")) == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
xbps_dbg_printf(xhp, "[remove] %s: fmemopen %s\n", pkgver, strerror(rv));
|
|
|
|
goto out;
|
|
|
|
};
|
|
|
|
buf = malloc(len);
|
|
|
|
assert(buf);
|
|
|
|
if (fread(buf, len, 1, f) != len) {
|
|
|
|
if (ferror(f)) {
|
|
|
|
rv = errno;
|
|
|
|
xbps_dbg_printf(xhp, "[remove] %s: fread %s\n", pkgver, strerror(rv));
|
|
|
|
free(buf);
|
|
|
|
fclose(f);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* terminate buffer and notify client to show the pre-remove message */
|
|
|
|
buf[len] = '\0';
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_SHOW_REMOVE_MSG, 0, pkgver, "%s", buf);
|
|
|
|
free(buf);
|
|
|
|
fclose(f);
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
/*
|
2010-01-28 20:38:50 +05:30
|
|
|
* If updating a package, we just need to execute the current
|
2012-11-30 22:10:52 +05:30
|
|
|
* pre-remove action target and we are done. Its files will be
|
|
|
|
* overwritten later in unpack phase.
|
2010-01-21 07:40:19 +05:30
|
|
|
*/
|
2010-01-28 20:38:50 +05:30
|
|
|
if (update) {
|
2012-11-30 11:41:51 +05:30
|
|
|
if (pkgd)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(pkgd);
|
2012-11-30 11:41:51 +05:30
|
|
|
free(pkgname);
|
2012-11-30 22:10:52 +05:30
|
|
|
return 0;
|
2010-01-25 10:57:54 +05:30
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
|
2012-05-22 02:33:29 +05:30
|
|
|
if (pkgd) {
|
2014-02-09 17:23:15 +05:30
|
|
|
/*
|
|
|
|
* Do the removal in 2 phases:
|
|
|
|
* 1- check if user has enough perms to remove all entries
|
|
|
|
* 2- perform removal
|
|
|
|
*/
|
|
|
|
if (check_remove_pkg_files(xhp, pkgd, pkgver)) {
|
|
|
|
rv = EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-05-22 02:33:29 +05:30
|
|
|
/* Remove regular files */
|
2014-02-09 17:23:15 +05:30
|
|
|
if ((rv = remove_pkg_files(xhp, pkgd, "files", pkgver)) != 0)
|
2012-05-22 02:33:29 +05:30
|
|
|
goto out;
|
|
|
|
/* Remove configuration files */
|
2014-02-09 17:23:15 +05:30
|
|
|
if ((rv = remove_pkg_files(xhp, pkgd, "conf_files", pkgver)) != 0)
|
2012-05-22 02:33:29 +05:30
|
|
|
goto out;
|
2012-05-25 18:01:42 +05:30
|
|
|
/* Remove links */
|
2014-02-09 17:23:15 +05:30
|
|
|
if ((rv = remove_pkg_files(xhp, pkgd, "links", pkgver)) != 0)
|
2012-05-25 18:01:42 +05:30
|
|
|
goto out;
|
2012-05-22 02:33:29 +05:30
|
|
|
/* Remove dirs */
|
2014-02-09 17:23:15 +05:30
|
|
|
if ((rv = remove_pkg_files(xhp, pkgd, "dirs", pkgver)) != 0)
|
2012-05-22 02:33:29 +05:30
|
|
|
goto out;
|
2012-11-19 18:38:01 +05:30
|
|
|
/*
|
|
|
|
* Execute the post REMOVE action if file exists and we aren't
|
|
|
|
* updating the package.
|
|
|
|
*/
|
|
|
|
rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "post", false);
|
|
|
|
if (rv != 0) {
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
2013-03-05 08:38:42 +05:30
|
|
|
rv, pkgver,
|
2012-11-19 18:38:01 +05:30
|
|
|
"%s: [remove] REMOVE script failed to execute "
|
|
|
|
"post ACTION: %s", pkgver, strerror(rv));
|
|
|
|
goto out;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2012-05-25 20:54:36 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
2011-12-24 05:35:26 +05:30
|
|
|
* Set package state to "half-removed".
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2013-03-05 08:38:42 +05:30
|
|
|
rv = xbps_set_pkg_state_installed(xhp, pkgver,
|
2011-12-24 05:35:26 +05:30
|
|
|
XBPS_PKG_STATE_HALF_REMOVED);
|
2011-11-24 15:53:08 +05:30
|
|
|
if (rv != 0) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
2013-03-05 08:38:42 +05:30
|
|
|
rv, pkgver,
|
2011-12-24 05:35:26 +05:30
|
|
|
"%s: [remove] failed to set state to half-removed: %s",
|
2011-11-24 15:53:08 +05:30
|
|
|
pkgver, strerror(rv));
|
2011-12-24 05:35:26 +05:30
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
purge:
|
|
|
|
/*
|
|
|
|
* Execute the purge REMOVE action if file exists.
|
|
|
|
*/
|
2012-11-19 18:38:01 +05:30
|
|
|
if (pkgd) {
|
|
|
|
rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "purge", false);
|
|
|
|
if (rv != 0) {
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
2013-03-05 08:38:42 +05:30
|
|
|
rv, pkgver,
|
2012-11-19 18:38:01 +05:30
|
|
|
"%s: REMOVE script failed to execute "
|
|
|
|
"purge ACTION: %s", pkgver, strerror(rv));
|
|
|
|
goto out;
|
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(pkgd);
|
2011-11-24 15:53:08 +05:30
|
|
|
}
|
2011-12-24 05:35:26 +05:30
|
|
|
/*
|
2012-11-16 21:25:35 +05:30
|
|
|
* Remove package metadata plist.
|
2011-12-24 05:35:26 +05:30
|
|
|
*/
|
2014-05-22 14:12:27 +05:30
|
|
|
if (remove(metafile) == -1) {
|
2012-11-19 19:10:41 +05:30
|
|
|
if (errno != ENOENT) {
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
2013-03-05 08:38:42 +05:30
|
|
|
rv, pkgver,
|
2012-11-19 19:10:41 +05:30
|
|
|
"%s: failed to remove metadata file: %s",
|
|
|
|
pkgver, strerror(errno));
|
|
|
|
}
|
2011-12-24 05:35:26 +05:30
|
|
|
}
|
|
|
|
/*
|
2012-01-20 15:40:52 +05:30
|
|
|
* Unregister package from pkgdb.
|
2011-12-24 05:35:26 +05:30
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_remove(xhp->pkgdb, pkgname);
|
2012-11-19 19:15:09 +05:30
|
|
|
xbps_dbg_printf(xhp, "[remove] unregister %s returned %d\n", pkgver, rv);
|
2013-03-05 08:38:42 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_DONE, 0, pkgver, NULL);
|
2011-12-24 05:35:26 +05:30
|
|
|
out:
|
2012-11-30 11:41:51 +05:30
|
|
|
if (pkgname != NULL)
|
|
|
|
free(pkgname);
|
2014-02-09 16:24:49 +05:30
|
|
|
if (rv != 0) {
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver,
|
|
|
|
"%s: failed to remove package: %s", pkgver, strerror(rv));
|
|
|
|
}
|
2010-11-19 18:10:13 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
return rv;
|
|
|
|
}
|