2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2014-05-27 15:03:45 +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>
|
2012-11-11 20:41:40 +05:30
|
|
|
#include <fnmatch.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-11-25 14:42:03 +05:30
|
|
|
* @file lib/transaction_ops.c
|
2012-01-20 16:47:27 +05:30
|
|
|
* @brief Transaction handling routines
|
|
|
|
* @defgroup transaction Transaction handling functions
|
2010-01-23 04:29:55 +05:30
|
|
|
*
|
|
|
|
* The following image shows off the full transaction dictionary returned
|
2011-01-24 21:25:58 +05:30
|
|
|
* by xbps_transaction_prepare().
|
2010-01-23 04:29:55 +05:30
|
|
|
*
|
|
|
|
* @image html images/xbps_transaction_dictionary.png
|
|
|
|
*
|
|
|
|
* Legend:
|
|
|
|
* - <b>Salmon bg box</b>: The transaction dictionary.
|
|
|
|
* - <b>White bg box</b>: mandatory objects.
|
|
|
|
* - <b>Grey bg box</b>: optional objects.
|
|
|
|
* - <b>Green bg box</b>: possible value set in the object, only one of them
|
|
|
|
* will be set.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
2012-01-17 20:47:03 +05:30
|
|
|
enum {
|
|
|
|
TRANS_INSTALL = 1,
|
2014-05-27 15:03:45 +05:30
|
|
|
TRANS_UPDATE,
|
|
|
|
TRANS_REINSTALL
|
2012-01-17 20:47:03 +05:30
|
|
|
};
|
|
|
|
|
2011-01-24 23:19:24 +05:30
|
|
|
static int
|
2014-05-27 15:03:45 +05:30
|
|
|
trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2014-05-27 15:03:45 +05:30
|
|
|
xbps_dictionary_t pkg_pkgdb = NULL, pkg_repod = NULL;
|
2014-08-22 16:14:18 +05:30
|
|
|
xbps_array_t unsorted, replaces;
|
2013-03-07 13:42:47 +05:30
|
|
|
const char *repoloc, *repopkgver, *instpkgver, *reason;
|
2014-08-22 16:14:18 +05:30
|
|
|
char *self_replaced, *pkgname;
|
2014-05-27 15:03:45 +05:30
|
|
|
int action = 0, rv = 0;
|
2011-02-22 15:01:16 +05:30
|
|
|
pkg_state_t state = 0;
|
2013-03-07 14:33:59 +05:30
|
|
|
bool autoinst = false;
|
2011-01-24 23:19:24 +05:30
|
|
|
|
2012-01-25 06:44:04 +05:30
|
|
|
assert(pkg != NULL);
|
2011-01-24 23:19:24 +05:30
|
|
|
|
2014-01-15 20:47:41 +05:30
|
|
|
/*
|
|
|
|
* Find out if pkg is installed first.
|
|
|
|
*/
|
|
|
|
pkg_pkgdb = xbps_pkgdb_get_pkg(xhp, pkg);
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
2011-01-24 23:19:24 +05:30
|
|
|
* Find out if the pkg has been found in repository pool.
|
2010-11-19 18:10:13 +05:30
|
|
|
*/
|
2014-05-27 15:03:45 +05:30
|
|
|
if (pkg_pkgdb == NULL) {
|
|
|
|
/* pkg not installed, perform installation */
|
|
|
|
action = TRANS_INSTALL;
|
2012-11-11 20:41:40 +05:30
|
|
|
reason = "install";
|
2012-11-30 11:41:51 +05:30
|
|
|
if (((pkg_repod = xbps_rpool_get_pkg(xhp, pkg)) == NULL) &&
|
|
|
|
((pkg_repod = xbps_rpool_get_virtualpkg(xhp, pkg)) == NULL)) {
|
|
|
|
/* not found */
|
|
|
|
return ENOENT;
|
2012-06-02 20:22:01 +05:30
|
|
|
}
|
|
|
|
} else {
|
2014-05-27 15:03:45 +05:30
|
|
|
/* pkg installed, update or reinstall */
|
|
|
|
if (!reinstall) {
|
|
|
|
action = TRANS_UPDATE;
|
|
|
|
reason = "update";
|
|
|
|
} else {
|
|
|
|
action = TRANS_REINSTALL;
|
|
|
|
reason = "install";
|
|
|
|
}
|
2012-11-30 11:41:51 +05:30
|
|
|
if ((pkg_repod = xbps_rpool_get_pkg(xhp, pkg)) == NULL) {
|
2012-06-02 20:22:01 +05:30
|
|
|
/* not found */
|
2012-11-28 22:05:03 +05:30
|
|
|
return ENOENT;
|
2012-06-02 20:22:01 +05:30
|
|
|
}
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
2014-05-27 15:03:45 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &repopkgver);
|
|
|
|
xbps_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc);
|
2012-01-17 20:47:03 +05:30
|
|
|
|
2012-06-05 02:52:33 +05:30
|
|
|
if (action == TRANS_UPDATE) {
|
2012-01-17 20:47:03 +05:30
|
|
|
/*
|
2014-05-27 15:03:45 +05:30
|
|
|
* Compare installed version vs best pkg available in repos
|
|
|
|
* for pkg updates.
|
2012-01-17 20:47:03 +05:30
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(pkg_pkgdb,
|
2013-03-05 08:38:42 +05:30
|
|
|
"pkgver", &instpkgver);
|
|
|
|
if (xbps_cmpver(repopkgver, instpkgver) <= 0) {
|
|
|
|
xbps_dbg_printf(xhp, "[rpool] Skipping `%s' "
|
|
|
|
"(installed: %s) from repository `%s'\n",
|
|
|
|
repopkgver, instpkgver, repoloc);
|
2012-07-04 15:26:01 +05:30
|
|
|
return EEXIST;
|
2012-01-17 20:47:03 +05:30
|
|
|
}
|
2014-05-27 15:03:45 +05:30
|
|
|
} else if (action == TRANS_REINSTALL) {
|
|
|
|
/*
|
|
|
|
* For reinstallation check if installed version is less than
|
|
|
|
* or equal to the pkg in repos, if true, continue with reinstallation;
|
|
|
|
* otherwise perform an update.
|
|
|
|
*/
|
|
|
|
xbps_dictionary_get_cstring_nocopy(pkg_pkgdb, "pkgver", &instpkgver);
|
|
|
|
if (xbps_cmpver(repopkgver, instpkgver) == 1) {
|
|
|
|
action = TRANS_UPDATE;
|
|
|
|
reason = "update";
|
|
|
|
}
|
2014-01-15 20:47:41 +05:30
|
|
|
}
|
2014-05-27 15:03:45 +05:30
|
|
|
|
2014-01-15 20:47:41 +05:30
|
|
|
if (pkg_pkgdb) {
|
|
|
|
/*
|
|
|
|
* If pkg is already installed, respect its automatic-install
|
|
|
|
* property.
|
|
|
|
*/
|
2014-05-27 15:03:45 +05:30
|
|
|
xbps_dictionary_get_bool(pkg_pkgdb, "automatic-install", &autoinst);
|
|
|
|
xbps_dictionary_set_bool(pkg_repod, "automatic-install", autoinst);
|
2012-01-17 20:47:03 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
2012-06-11 19:44:03 +05:30
|
|
|
* Prepare transaction dictionary.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2013-03-07 13:42:47 +05:30
|
|
|
if ((rv = xbps_transaction_init(xhp)) != 0)
|
2012-07-04 15:26:01 +05:30
|
|
|
return rv;
|
2012-06-11 19:44:03 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
unsorted = xbps_dictionary_get(xhp->transd, "unsorted_deps");
|
2012-07-04 15:26:01 +05:30
|
|
|
/*
|
|
|
|
* Find out if package being updated matches the one already
|
|
|
|
* in transaction, in that case ignore it.
|
|
|
|
*/
|
|
|
|
if (action == TRANS_UPDATE) {
|
2012-11-30 11:41:51 +05:30
|
|
|
if (xbps_find_pkg_in_array(unsorted, repopkgver)) {
|
2012-07-04 15:26:01 +05:30
|
|
|
xbps_dbg_printf(xhp, "[update] `%s' already queued in "
|
|
|
|
"transaction.\n", repopkgver);
|
|
|
|
return EEXIST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-07 13:42:47 +05:30
|
|
|
if ((rv = xbps_repository_find_deps(xhp, unsorted, pkg_repod)) != 0)
|
2012-07-04 15:26:01 +05:30
|
|
|
return rv;
|
2013-03-07 13:42:47 +05:30
|
|
|
|
|
|
|
pkgname = xbps_pkg_name(repopkgver);
|
|
|
|
assert(pkgname);
|
2011-01-24 23:19:24 +05:30
|
|
|
/*
|
2011-02-23 21:44:33 +05:30
|
|
|
* Set package state in dictionary with same state than the
|
|
|
|
* package currently uses, otherwise not-installed.
|
2011-01-24 23:19:24 +05:30
|
|
|
*/
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0) {
|
2013-03-05 08:38:42 +05:30
|
|
|
if (rv != ENOENT) {
|
|
|
|
free(pkgname);
|
2012-07-04 15:26:01 +05:30
|
|
|
return rv;
|
2013-03-05 08:38:42 +05:30
|
|
|
}
|
2011-02-23 21:44:33 +05:30
|
|
|
/* Package not installed, don't error out */
|
|
|
|
state = XBPS_PKG_STATE_NOT_INSTALLED;
|
2011-02-22 15:01:16 +05:30
|
|
|
}
|
2014-08-22 16:14:18 +05:30
|
|
|
if ((rv = xbps_set_pkg_state_dictionary(pkg_repod, state)) != 0) {
|
|
|
|
free(pkgname);
|
2012-07-04 15:26:01 +05:30
|
|
|
return rv;
|
2014-08-22 16:14:18 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2012-12-20 16:38:55 +05:30
|
|
|
if ((action == TRANS_INSTALL) && (state == XBPS_PKG_STATE_UNPACKED))
|
2011-02-22 15:01:16 +05:30
|
|
|
reason = "configure";
|
2012-11-11 14:12:30 +05:30
|
|
|
else if (state == XBPS_PKG_STATE_NOT_INSTALLED)
|
2011-07-08 18:58:57 +05:30
|
|
|
reason = "install";
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
2011-02-22 15:01:16 +05:30
|
|
|
* Set transaction obj in pkg dictionary to "install", "configure"
|
|
|
|
* or "update".
|
2010-11-19 18:10:13 +05:30
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
if (!xbps_dictionary_set_cstring_nocopy(pkg_repod,
|
2012-07-04 15:26:01 +05:30
|
|
|
"transaction", reason))
|
|
|
|
return EINVAL;
|
2014-07-12 19:55:12 +05:30
|
|
|
|
2014-08-22 16:14:18 +05:30
|
|
|
/*
|
|
|
|
* Set a replaces to itself, so that virtual packages are always replaced.
|
|
|
|
*/
|
|
|
|
if ((replaces = xbps_dictionary_get(pkg_repod, "replaces")) == NULL)
|
|
|
|
replaces = xbps_array_create();
|
|
|
|
|
|
|
|
self_replaced = xbps_xasprintf("%s>=0", pkgname);
|
|
|
|
xbps_array_add_cstring(replaces, self_replaced);
|
|
|
|
free(self_replaced);
|
|
|
|
|
|
|
|
if (!xbps_dictionary_set(pkg_repod, "replaces", replaces)) {
|
|
|
|
free(pkgname);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
|
|
|
* Add the pkg dictionary from repository's index dictionary into
|
2012-11-30 11:41:51 +05:30
|
|
|
* the "unsorted" queue.
|
2010-11-19 18:10:13 +05:30
|
|
|
*/
|
2014-08-22 16:14:18 +05:30
|
|
|
if (!xbps_array_add(unsorted, pkg_repod)) {
|
|
|
|
free(pkgname);
|
2012-11-28 22:05:03 +05:30
|
|
|
return EINVAL;
|
2014-08-22 16:14:18 +05:30
|
|
|
}
|
2013-03-05 08:38:42 +05:30
|
|
|
xbps_dbg_printf(xhp, "%s: added into the transaction (%s).\n",
|
|
|
|
repopkgver, repoloc);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2014-08-22 16:14:18 +05:30
|
|
|
free(pkgname);
|
2012-11-28 22:05:03 +05:30
|
|
|
return 0;
|
2011-01-24 23:19:24 +05:30
|
|
|
}
|
|
|
|
|
2012-06-02 20:22:01 +05:30
|
|
|
int
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_transaction_update_packages(struct xbps_handle *xhp)
|
2011-01-24 23:19:24 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t pkgd;
|
|
|
|
xbps_object_t obj;
|
|
|
|
xbps_object_iterator_t iter;
|
2013-08-12 18:16:54 +05:30
|
|
|
const char *pkgver;
|
|
|
|
char *pkgname = NULL;
|
|
|
|
bool hold, newpkg_found = false;
|
2011-01-24 23:19:24 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
2012-06-02 20:22:01 +05:30
|
|
|
if ((rv = xbps_pkgdb_init(xhp)) != 0)
|
|
|
|
return rv;
|
2011-12-23 12:46:25 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
iter = xbps_dictionary_iterator(xhp->pkgdb);
|
2012-11-30 14:19:09 +05:30
|
|
|
assert(iter);
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
|
|
|
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
|
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
2013-08-12 18:16:54 +05:30
|
|
|
hold = false;
|
|
|
|
xbps_dictionary_get_bool(pkgd, "hold", &hold);
|
|
|
|
if (hold) {
|
|
|
|
xbps_dbg_printf(xhp, "[rpool] package `%s' "
|
|
|
|
"on hold, ignoring updates.\n", pkgver);
|
2012-09-25 18:32:57 +05:30
|
|
|
continue;
|
|
|
|
}
|
2013-08-12 18:16:54 +05:30
|
|
|
pkgname = xbps_pkg_name(pkgver);
|
|
|
|
assert(pkgname);
|
2014-05-27 15:03:45 +05:30
|
|
|
rv = trans_find_pkg(xhp, pkgname, false);
|
2012-06-02 20:22:01 +05:30
|
|
|
if (rv == 0)
|
|
|
|
newpkg_found = true;
|
|
|
|
else if (rv == ENOENT || rv == EEXIST || rv == ENODEV) {
|
|
|
|
/*
|
|
|
|
* missing pkg or installed version is greater than or
|
|
|
|
* equal than pkg in repositories.
|
|
|
|
*/
|
|
|
|
rv = 0;
|
2012-05-08 12:49:43 +05:30
|
|
|
}
|
2013-03-05 08:38:42 +05:30
|
|
|
free(pkgname);
|
2012-05-08 12:49:43 +05:30
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_iterator_release(iter);
|
2011-01-24 23:19:24 +05:30
|
|
|
|
2012-06-02 20:22:01 +05:30
|
|
|
return newpkg_found ? rv : EEXIST;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2011-01-24 23:19:24 +05:30
|
|
|
|
2011-02-24 20:18:50 +05:30
|
|
|
int
|
2012-11-30 11:41:51 +05:30
|
|
|
xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkg)
|
2011-01-24 23:19:24 +05:30
|
|
|
{
|
2014-05-27 15:03:45 +05:30
|
|
|
return trans_find_pkg(xhp, pkg, false);
|
2011-01-24 23:19:24 +05:30
|
|
|
}
|
|
|
|
|
2011-02-24 20:18:50 +05:30
|
|
|
int
|
2012-11-30 11:41:51 +05:30
|
|
|
xbps_transaction_install_pkg(struct xbps_handle *xhp, const char *pkg,
|
2012-06-14 11:52:11 +05:30
|
|
|
bool reinstall)
|
2011-01-24 23:19:24 +05:30
|
|
|
{
|
2014-05-27 15:03:45 +05:30
|
|
|
return trans_find_pkg(xhp, pkg, reinstall);
|
2011-01-24 23:19:24 +05:30
|
|
|
}
|
2011-11-25 15:50:03 +05:30
|
|
|
|
2011-11-27 13:35:18 +05:30
|
|
|
int
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_transaction_remove_pkg(struct xbps_handle *xhp,
|
|
|
|
const char *pkgname,
|
|
|
|
bool recursive)
|
2011-11-27 13:35:18 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t pkgd;
|
|
|
|
xbps_array_t unsorted, orphans, orphans_pkg, reqby;
|
|
|
|
xbps_object_t obj;
|
2011-11-27 13:35:18 +05:30
|
|
|
const char *pkgver;
|
2013-06-12 13:34:10 +05:30
|
|
|
unsigned int count;
|
2011-11-27 13:35:18 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
assert(pkgname != NULL);
|
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
if ((pkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL) {
|
2011-11-27 13:35:18 +05:30
|
|
|
/* pkg not installed */
|
2011-12-24 05:35:26 +05:30
|
|
|
return ENOENT;
|
2011-11-27 13:35:18 +05:30
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Prepare transaction dictionary and missing deps array.
|
|
|
|
*/
|
2012-01-22 14:30:46 +05:30
|
|
|
if ((rv = xbps_transaction_init(xhp)) != 0)
|
2012-06-16 12:32:07 +05:30
|
|
|
return rv;
|
2012-01-22 14:30:46 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
unsorted = xbps_dictionary_get(xhp->transd, "unsorted_deps");
|
2012-11-30 11:41:51 +05:30
|
|
|
|
2011-11-27 13:35:18 +05:30
|
|
|
if (!recursive)
|
|
|
|
goto rmpkg;
|
|
|
|
/*
|
|
|
|
* If recursive is set, find out which packages would be orphans
|
|
|
|
* if the supplied package were already removed.
|
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
if ((orphans_pkg = xbps_array_create()) == NULL)
|
2012-06-16 12:32:07 +05:30
|
|
|
return ENOMEM;
|
2011-12-24 05:35:26 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_set_cstring_nocopy(orphans_pkg, 0, pkgname);
|
2012-06-14 11:52:11 +05:30
|
|
|
orphans = xbps_find_pkg_orphans(xhp, orphans_pkg);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(orphans_pkg);
|
|
|
|
if (xbps_object_type(orphans) != XBPS_TYPE_ARRAY)
|
2012-06-16 12:32:07 +05:30
|
|
|
return EINVAL;
|
2011-12-24 05:35:26 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
count = xbps_array_count(orphans);
|
2011-11-27 13:35:18 +05:30
|
|
|
while (count--) {
|
2013-06-20 13:56:12 +05:30
|
|
|
obj = xbps_array_get(orphans, count);
|
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
|
|
|
xbps_dictionary_set_cstring_nocopy(obj, "transaction", "remove");
|
|
|
|
xbps_array_add(unsorted, obj);
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n", pkgver);
|
2011-11-27 13:35:18 +05:30
|
|
|
}
|
2013-04-04 12:52:40 +05:30
|
|
|
reqby = xbps_pkgdb_get_pkg_revdeps(xhp, pkgname);
|
2013-03-11 16:43:02 +05:30
|
|
|
/*
|
|
|
|
* If target pkg is required by any installed pkg, the client must be aware
|
|
|
|
* of this to take appropiate action.
|
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
if ((xbps_object_type(reqby) == XBPS_TYPE_ARRAY) &&
|
|
|
|
(xbps_array_count(reqby) > 0))
|
2013-03-11 16:43:02 +05:30
|
|
|
rv = EEXIST;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(orphans);
|
2013-03-11 16:43:02 +05:30
|
|
|
return rv;
|
|
|
|
|
2011-11-27 13:35:18 +05:30
|
|
|
rmpkg:
|
|
|
|
/*
|
2012-11-30 11:41:51 +05:30
|
|
|
* Add pkg dictionary into the transaction unsorted queue.
|
2011-11-27 13:35:18 +05:30
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
|
|
|
xbps_dictionary_set_cstring_nocopy(pkgd, "transaction", "remove");
|
|
|
|
xbps_array_add(unsorted, pkgd);
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n", pkgver);
|
2012-11-30 22:10:52 +05:30
|
|
|
reqby = xbps_pkgdb_get_pkg_revdeps(xhp, pkgver);
|
2011-11-27 13:35:18 +05:30
|
|
|
/*
|
|
|
|
* If target pkg is required by any installed pkg, the client must be aware
|
|
|
|
* of this to take appropiate action.
|
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
if ((xbps_object_type(reqby) == XBPS_TYPE_ARRAY) &&
|
|
|
|
(xbps_array_count(reqby) > 0))
|
2011-11-27 13:35:18 +05:30
|
|
|
rv = EEXIST;
|
2011-12-24 05:35:26 +05:30
|
|
|
|
2011-11-27 13:35:18 +05:30
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-11-25 15:50:03 +05:30
|
|
|
int
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_transaction_autoremove_pkgs(struct xbps_handle *xhp)
|
2011-11-25 15:50:03 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t orphans, unsorted;
|
|
|
|
xbps_object_t obj;
|
2011-11-25 15:50:03 +05:30
|
|
|
const char *pkgver;
|
2013-06-12 13:34:10 +05:30
|
|
|
unsigned int count;
|
2011-11-25 15:50:03 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
orphans = xbps_find_pkg_orphans(xhp, NULL);
|
2013-06-20 13:56:12 +05:30
|
|
|
if ((count = xbps_array_count(orphans)) == 0) {
|
2011-11-25 15:50:03 +05:30
|
|
|
/* no orphans? we are done */
|
|
|
|
rv = ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Prepare transaction dictionary and missing deps array.
|
|
|
|
*/
|
2012-01-22 14:30:46 +05:30
|
|
|
if ((rv = xbps_transaction_init(xhp)) != 0)
|
2011-11-25 15:50:03 +05:30
|
|
|
goto out;
|
2012-11-30 11:41:51 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
unsorted = xbps_dictionary_get(xhp->transd, "unsorted_deps");
|
2011-11-25 15:50:03 +05:30
|
|
|
/*
|
2012-11-30 11:41:51 +05:30
|
|
|
* Add pkg orphan dictionary into the transaction unsorted queue.
|
2011-11-25 15:50:03 +05:30
|
|
|
*/
|
|
|
|
while (count--) {
|
2013-06-20 13:56:12 +05:30
|
|
|
obj = xbps_array_get(orphans, count);
|
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
|
|
|
xbps_dictionary_set_cstring_nocopy(obj,
|
2011-11-25 15:50:03 +05:30
|
|
|
"transaction", "remove");
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_add(unsorted, obj);
|
2012-11-30 11:41:51 +05:30
|
|
|
xbps_dbg_printf(xhp, "%s: added (remove).\n", pkgver);
|
2011-11-25 15:50:03 +05:30
|
|
|
}
|
|
|
|
out:
|
2012-01-22 14:30:46 +05:30
|
|
|
if (orphans != NULL)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(orphans);
|
2012-11-30 11:41:51 +05:30
|
|
|
|
2011-11-25 15:50:03 +05:30
|
|
|
return rv;
|
|
|
|
}
|