2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2012-01-20 15:40:52 +05:30
|
|
|
* Copyright (c) 2009-2012 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>
|
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
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
/**
|
2011-01-19 05:01:22 +05:30
|
|
|
* @file lib/package_remove.c
|
2010-01-21 07:40:19 +05:30
|
|
|
* @brief Package removal routines
|
|
|
|
* @defgroup pkg_remove Package removal functions
|
|
|
|
*
|
|
|
|
* These functions will remove a package or only a subset of its
|
|
|
|
* files. Package removal steps:
|
2010-01-23 07:07:19 +05:30
|
|
|
* -# Its <b>pre-remove</b> target specified in the REMOVE script
|
|
|
|
* will be executed.
|
2011-12-24 05:35:26 +05:30
|
|
|
* -# Its links, files, conf_files and dirs will be removed.
|
|
|
|
* Modified files (not matchings its sha256 hash) are preserved, unless
|
2011-11-24 16:20:53 +05:30
|
|
|
* XBPS_FLAG_FORCE_REMOVE_FILES flag is set via xbps_init::flags member.
|
2010-01-23 07:07:19 +05:30
|
|
|
* -# Its <b>post-remove</b> target specified in the REMOVE script
|
|
|
|
* will be executed.
|
|
|
|
* -# Its requiredby objects will be removed from the installed packages
|
|
|
|
* database.
|
2011-12-24 05:35:26 +05:30
|
|
|
* -# Its state will be changed to XBPS_PKG_STATE_HALF_UNPACKED.
|
|
|
|
* -# Its <b>purge-remove</b> target specified in the REMOVE script
|
|
|
|
* will be executed.
|
|
|
|
* -# Its package metadata directory will be removed.
|
|
|
|
* -# Package will be unregistered from package database.
|
2010-01-21 07:40:19 +05:30
|
|
|
*
|
2010-01-23 04:29:55 +05:30
|
|
|
* @note
|
2010-01-28 20:38:50 +05:30
|
|
|
* -# If a package is going to be updated, only steps <b>1</b> and <b>4</b>
|
|
|
|
* will be executed.
|
2010-01-23 07:07:19 +05:30
|
|
|
* -# If a package is going to be removed, all steps will be executed.
|
2010-01-21 07:40:19 +05:30
|
|
|
*
|
2010-01-23 04:29:55 +05:30
|
|
|
* The following image shows the structure of an internalized package's
|
|
|
|
* files.plist dictionary:
|
2010-01-21 07:40:19 +05:30
|
|
|
*
|
2010-01-23 04:29:55 +05:30
|
|
|
* @image html images/xbps_pkg_files_dictionary.png
|
2010-01-21 07:40:19 +05:30
|
|
|
*
|
2010-01-23 04:29:55 +05:30
|
|
|
* Legend:
|
|
|
|
* - <b>Salmon bg box</b>: XBPS_PKGFILES plist file.
|
|
|
|
* - <b>White bg box</b>: mandatory objects.
|
|
|
|
* - <b>Grey bg box</b>: optional objects.
|
2010-01-21 07:40:19 +05:30
|
|
|
*
|
2010-01-23 04:29:55 +05:30
|
|
|
* Text inside of white boxes are the key associated with the object, its
|
|
|
|
* data type is specified on its edge, i.e string, array, integer, dictionary.
|
2010-01-21 07:40:19 +05:30
|
|
|
*/
|
2011-12-24 05:35:26 +05:30
|
|
|
static int
|
2012-06-14 11:52:11 +05:30
|
|
|
remove_pkg_metadata(struct xbps_handle *xhp,
|
|
|
|
const char *pkgname,
|
2011-12-24 05:35:26 +05:30
|
|
|
const char *version,
|
2012-06-14 11:52:11 +05:30
|
|
|
const char *pkgver)
|
2011-12-24 05:35:26 +05:30
|
|
|
{
|
|
|
|
struct dirent *dp;
|
|
|
|
DIR *dirp;
|
|
|
|
char *metadir, *path;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
assert(pkgname != NULL);
|
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
metadir = xbps_xasprintf("%s/%s/metadata/%s", xhp->rootdir,
|
2011-12-24 05:35:26 +05:30
|
|
|
XBPS_META_PATH, pkgname);
|
|
|
|
if (metadir == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
dirp = opendir(metadir);
|
|
|
|
if (dirp == NULL) {
|
|
|
|
free(metadir);
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((dp = readdir(dirp)) != NULL) {
|
|
|
|
if ((strcmp(dp->d_name, ".") == 0) ||
|
|
|
|
(strcmp(dp->d_name, "..") == 0))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
path = xbps_xasprintf("%s/%s", metadir, dp->d_name);
|
|
|
|
if (path == NULL) {
|
|
|
|
(void)closedir(dirp);
|
|
|
|
free(metadir);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlink(path) == -1) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_PURGE_FAIL,
|
2011-12-24 05:35:26 +05:30
|
|
|
errno, pkgname, version,
|
|
|
|
"%s: [purge] failed to remove metafile `%s': %s",
|
|
|
|
pkgver, path, strerror(errno));
|
|
|
|
}
|
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
(void)closedir(dirp);
|
|
|
|
rv = rmdir(metadir);
|
|
|
|
free(metadir);
|
2012-06-09 13:35:29 +05:30
|
|
|
if (rv != 0)
|
|
|
|
rv = errno;
|
2011-12-24 05:35:26 +05:30
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_remove_pkg_files(struct xbps_handle *xhp,
|
|
|
|
prop_dictionary_t dict,
|
2011-11-24 15:53:08 +05:30
|
|
|
const char *key,
|
|
|
|
const char *pkgver)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2012-05-25 18:01:42 +05:30
|
|
|
struct stat st;
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_array_t array;
|
|
|
|
prop_object_iterator_t iter;
|
|
|
|
prop_object_t obj;
|
2011-11-24 15:53:08 +05:30
|
|
|
const char *file, *sha256, *version, *curobj = NULL;
|
|
|
|
char *path = NULL, *pkgname = NULL;
|
2012-05-25 18:01:42 +05:30
|
|
|
char buf[PATH_MAX];
|
2011-02-21 22:12:47 +05:30
|
|
|
int rv = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-10-19 20:23:38 +05:30
|
|
|
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
|
2009-12-07 11:00:06 +05:30
|
|
|
assert(key != NULL);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-12-07 11:00:06 +05:30
|
|
|
array = prop_dictionary_get(dict, key);
|
2011-12-24 05:35:26 +05:30
|
|
|
if ((prop_object_type(array) != PROP_TYPE_ARRAY) ||
|
|
|
|
prop_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";
|
|
|
|
|
2011-11-24 15:53:08 +05:30
|
|
|
pkgname = xbps_pkg_name(pkgver);
|
|
|
|
version = xbps_pkg_version(pkgver);
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
2011-12-15 15:49:20 +05:30
|
|
|
path = xbps_xasprintf("%s/%s", xhp->rootdir, file);
|
2009-08-17 22:37:20 +05:30
|
|
|
if (path == NULL) {
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = ENOMEM;
|
2009-12-07 11:00:06 +05:30
|
|
|
break;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
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.
|
|
|
|
*/
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"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,
|
|
|
|
rv, pkgname, version,
|
|
|
|
"%s: failed to check hash for %s `%s': %s",
|
|
|
|
pkgver, curobj, file, strerror(rv));
|
2009-12-07 11:00:06 +05:30
|
|
|
free(path);
|
|
|
|
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,
|
|
|
|
0, pkgname, version,
|
|
|
|
"%s: %s `%s' SHA256 mismatch, "
|
|
|
|
"preserving file", pkgver,
|
|
|
|
curobj, file);
|
2010-01-25 12:39:48 +05:30
|
|
|
free(path);
|
|
|
|
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,
|
|
|
|
0, pkgname, version,
|
|
|
|
"%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,
|
|
|
|
rv, pkgname, version,
|
|
|
|
"%s: [remove] failed to check hash for "
|
|
|
|
"%s `%s': %s", pkgver, curobj, file,
|
|
|
|
strerror(rv));
|
2009-12-07 11:00:06 +05:30
|
|
|
free(path);
|
|
|
|
break;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2012-05-25 18:01:42 +05:30
|
|
|
} else if (strcmp(key, "links") == 0) {
|
|
|
|
/*
|
|
|
|
* All regular files from package were removed at this
|
|
|
|
* point, so we will only remove dangling symlinks.
|
|
|
|
*/
|
|
|
|
if (realpath(path, buf) == NULL) {
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
free(path);
|
|
|
|
rv = errno;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (stat(buf, &st) == 0) {
|
|
|
|
free(path);
|
|
|
|
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,
|
2011-11-24 15:53:08 +05:30
|
|
|
errno, pkgname, version,
|
|
|
|
"%s: failed to remove %s `%s': %s", pkgver,
|
|
|
|
curobj, file, strerror(errno));
|
2011-12-24 05:35:26 +05:30
|
|
|
errno = 0;
|
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,
|
2011-11-24 15:53:08 +05:30
|
|
|
0, pkgname, version,
|
|
|
|
"Removed %s `%s'", curobj, file);
|
2010-11-06 11:14:00 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
2011-11-24 15:53:08 +05:30
|
|
|
if (pkgname)
|
|
|
|
free(pkgname);
|
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
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_remove_pkg(struct xbps_handle *xhp,
|
|
|
|
const char *pkgname,
|
|
|
|
const char *version,
|
|
|
|
bool update,
|
2012-05-25 20:54:36 +05:30
|
|
|
bool soft_replace)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-12-24 05:35:26 +05:30
|
|
|
prop_dictionary_t pkgd = NULL;
|
|
|
|
char *buf = NULL, *pkgver = NULL;
|
2009-08-17 22:37:20 +05:30
|
|
|
int rv = 0;
|
2010-11-19 18:10:13 +05:30
|
|
|
bool rmfile_exists = false;
|
2011-12-24 05:35:26 +05:30
|
|
|
pkg_state_t state = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
assert(pkgname != NULL);
|
|
|
|
assert(version != NULL);
|
|
|
|
|
2011-12-16 15:04:05 +05:30
|
|
|
buf = xbps_xasprintf("%s/metadata/%s/REMOVE",
|
2009-08-17 22:37:20 +05:30
|
|
|
XBPS_META_PATH, pkgname);
|
2011-11-24 15:53:08 +05:30
|
|
|
if (buf == NULL) {
|
|
|
|
rv = ENOMEM;
|
2011-12-24 05:35:26 +05:30
|
|
|
goto out;
|
2011-11-24 15:53:08 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-12-24 05:35:26 +05:30
|
|
|
pkgver = xbps_xasprintf("%s-%s", pkgname, version);
|
|
|
|
if (pkgver == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0)
|
2011-12-24 05:35:26 +05:30
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!update)
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE, 0, pkgname, version, 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,
|
2011-11-24 15:53:08 +05:30
|
|
|
rv, pkgname, version,
|
|
|
|
"%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
|
|
|
}
|
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
|
|
|
/*
|
2010-11-06 11:14:00 +05:30
|
|
|
* Run the pre remove action.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2010-11-19 18:10:13 +05:30
|
|
|
if (access(buf, X_OK) == 0) {
|
|
|
|
rmfile_exists = true;
|
2012-06-14 11:52:11 +05:30
|
|
|
if (xbps_file_exec(xhp, buf, "pre", pkgname, version,
|
2011-12-15 16:54:59 +05:30
|
|
|
update ? "yes" : "no", xhp->conffile, NULL) != 0) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
errno, pkgname, version,
|
|
|
|
"%s: [remove] REMOVE script failed to "
|
|
|
|
"execute pre ACTION: %s",
|
|
|
|
pkgver, strerror(errno));
|
2011-12-24 05:35:26 +05:30
|
|
|
rv = errno;
|
|
|
|
goto out;
|
2010-11-19 18:10:13 +05:30
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (errno != ENOENT) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
2011-12-24 06:00:57 +05:30
|
|
|
errno, pkgname, version,
|
|
|
|
"%s: [remove] REMOVE script failed to "
|
|
|
|
"execute pre ACTION: %s",
|
|
|
|
pkgver, strerror(errno));
|
2011-12-24 05:35:26 +05:30
|
|
|
rv = errno;
|
|
|
|
goto out;
|
2010-11-19 18:10:13 +05:30
|
|
|
}
|
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
|
|
|
|
* pre-remove action target, unregister its requiredby entries and
|
|
|
|
* continue. 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) {
|
2011-11-24 15:53:08 +05:30
|
|
|
free(pkgver);
|
2010-01-25 10:57:54 +05:30
|
|
|
free(buf);
|
2012-06-14 11:52:11 +05:30
|
|
|
return xbps_requiredby_pkg_remove(xhp, pkgname);
|
2012-05-25 20:54:36 +05:30
|
|
|
} else if (soft_replace) {
|
|
|
|
/*
|
|
|
|
* Soft replace a package. Do not remove its files, but
|
|
|
|
* execute PURGE action, remove metadata files and unregister
|
|
|
|
* from pkgdb.
|
|
|
|
*/
|
|
|
|
goto softreplace;
|
2010-01-25 10:57:54 +05:30
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
pkgd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES);
|
2012-05-22 02:33:29 +05:30
|
|
|
if (pkgd) {
|
|
|
|
/* Remove regular files */
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = xbps_remove_pkg_files(xhp, pkgd, "files", pkgver)) != 0)
|
2012-05-22 02:33:29 +05:30
|
|
|
goto out;
|
|
|
|
/* Remove configuration files */
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = xbps_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 */
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = xbps_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 */
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = xbps_remove_pkg_files(xhp, pkgd, "dirs", pkgver)) != 0)
|
2012-05-22 02:33:29 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
/*
|
2010-11-06 11:14:00 +05:30
|
|
|
* Execute the post REMOVE action if file exists and we aren't
|
|
|
|
* updating the package.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2010-11-19 18:10:13 +05:30
|
|
|
if (rmfile_exists &&
|
2012-06-14 11:52:11 +05:30
|
|
|
((rv = xbps_file_exec(xhp, buf, "post", pkgname, version, "no",
|
2012-05-22 02:33:29 +05:30
|
|
|
xhp->conffile, NULL)) != 0)) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
2012-05-22 02:33:29 +05:30
|
|
|
rv, pkgname, version,
|
2011-11-24 15:53:08 +05:30
|
|
|
"%s: [remove] REMOVE script failed to execute "
|
2012-05-22 02:33:29 +05:30
|
|
|
"post ACTION: %s", pkgver, strerror(rv));
|
2011-12-24 05:35:26 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Update the requiredby array of all required dependencies.
|
|
|
|
*/
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = xbps_requiredby_pkg_remove(xhp, pkgname)) != 0) {
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
2011-11-24 15:53:08 +05:30
|
|
|
rv, pkgname, version,
|
|
|
|
"%s: [remove] failed to remove requiredby entries: %s",
|
|
|
|
pkgver, strerror(rv));
|
2011-12-24 05:35:26 +05:30
|
|
|
goto out;
|
2011-11-24 15:53:08 +05:30
|
|
|
}
|
2012-05-25 20:54:36 +05:30
|
|
|
|
|
|
|
softreplace:
|
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
|
|
|
*/
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = xbps_set_pkg_state_installed(xhp, pkgname, version,
|
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,
|
2011-11-24 15:53:08 +05:30
|
|
|
rv, pkgname, version,
|
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.
|
|
|
|
*/
|
|
|
|
if (access(buf, X_OK) == 0) {
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = xbps_file_exec(xhp, buf, "purge", pkgname, version, "no",
|
2012-05-22 02:33:29 +05:30
|
|
|
xhp->conffile, NULL)) != 0) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
2012-05-22 02:33:29 +05:30
|
|
|
rv, pkgname, version,
|
2011-12-24 05:35:26 +05:30
|
|
|
"%s: REMOVE script failed to execute "
|
2012-05-22 02:33:29 +05:30
|
|
|
"purge ACTION: %s", pkgver, strerror(rv));
|
2011-12-24 05:35:26 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2011-11-24 15:53:08 +05:30
|
|
|
}
|
2011-12-24 05:35:26 +05:30
|
|
|
/*
|
|
|
|
* Remove package metadata directory.
|
|
|
|
*/
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = remove_pkg_metadata(xhp, pkgname, version, pkgver);
|
2011-12-24 05:35:26 +05:30
|
|
|
if (rv != 0) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
2011-12-24 05:35:26 +05:30
|
|
|
rv, pkgname, version,
|
|
|
|
"%s: failed to remove metadata files: %s",
|
|
|
|
pkgver, strerror(rv));
|
|
|
|
if (rv != ENOENT)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
2012-01-20 15:40:52 +05:30
|
|
|
* Unregister package from pkgdb.
|
2011-12-24 05:35:26 +05:30
|
|
|
*/
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = xbps_unregister_pkg(xhp, pkgname, version, false)) != 0)
|
2011-12-24 05:35:26 +05:30
|
|
|
goto out;
|
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_DONE,
|
2011-12-24 05:35:26 +05:30
|
|
|
0, pkgname, version, NULL);
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (buf != NULL)
|
|
|
|
free(buf);
|
|
|
|
if (pkgver != NULL)
|
|
|
|
free(pkgver);
|
|
|
|
if (pkgd != NULL)
|
|
|
|
prop_object_release(pkgd);
|
2010-11-19 18:10:13 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
return rv;
|
|
|
|
}
|