2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2012-01-18 12:55:28 +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>
|
|
|
|
|
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,
|
|
|
|
TRANS_UPDATE
|
|
|
|
};
|
|
|
|
|
2011-01-24 23:19:24 +05:30
|
|
|
static int
|
2012-06-14 11:52:11 +05:30
|
|
|
transaction_find_pkg(struct xbps_handle *xhp,
|
|
|
|
const char *pkg,
|
|
|
|
bool bypattern,
|
|
|
|
bool best,
|
|
|
|
bool exact,
|
2012-06-02 21:05:21 +05:30
|
|
|
int action)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2012-06-02 20:22:01 +05:30
|
|
|
prop_dictionary_t pkg_pkgdb, pkg_repod;
|
2012-01-22 14:30:46 +05:30
|
|
|
prop_array_t unsorted;
|
2012-06-02 21:05:21 +05:30
|
|
|
const char *pkgname, *repoloc, *repover, *instver, *reason;
|
2009-08-17 22:37:20 +05:30
|
|
|
int rv = 0;
|
2011-02-22 15:01:16 +05:30
|
|
|
pkg_state_t state = 0;
|
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
|
|
|
|
2012-01-17 20:47:03 +05:30
|
|
|
if (action == TRANS_INSTALL) {
|
2011-01-24 23:19:24 +05:30
|
|
|
/* install */
|
2012-01-17 20:47:03 +05:30
|
|
|
reason = "install";
|
2011-01-24 23:19:24 +05:30
|
|
|
} else {
|
|
|
|
/* update */
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((pkg_pkgdb = xbps_pkgdb_get_pkgd(xhp, pkg, false)) == NULL)
|
2012-06-02 20:22:01 +05:30
|
|
|
return ENODEV;
|
|
|
|
|
2012-01-17 20:47:03 +05:30
|
|
|
reason = "update";
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
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
|
|
|
*/
|
2012-06-02 20:22:01 +05:30
|
|
|
if (action == TRANS_INSTALL) {
|
2012-06-02 21:05:21 +05:30
|
|
|
if (exact) {
|
2012-06-14 11:52:11 +05:30
|
|
|
pkg_repod = xbps_rpool_find_pkg_exact(xhp, pkg);
|
|
|
|
if (pkg_repod == NULL) {
|
2012-06-02 21:05:21 +05:30
|
|
|
/* not found */
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
2012-06-14 11:52:11 +05:30
|
|
|
if (((pkg_repod = xbps_rpool_find_pkg(xhp, pkg, bypattern, best)) == NULL) &&
|
|
|
|
((pkg_repod = xbps_rpool_find_virtualpkg_conf(xhp, pkg, bypattern)) == NULL) &&
|
|
|
|
((pkg_repod = xbps_rpool_find_virtualpkg(xhp, pkg, bypattern)) == NULL)) {
|
2012-06-02 21:05:21 +05:30
|
|
|
/* not found */
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-06-02 20:22:01 +05:30
|
|
|
}
|
|
|
|
} else {
|
2012-06-14 11:52:11 +05:30
|
|
|
pkg_repod = xbps_rpool_find_pkg(xhp, pkg, false, true);
|
|
|
|
if (pkg_repod == NULL) {
|
2012-06-02 20:22:01 +05:30
|
|
|
/* not found */
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
2012-01-17 20:47:03 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
|
2012-06-02 20:22:01 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &repover);
|
|
|
|
prop_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
|
|
|
/*
|
|
|
|
* Compare installed version vs best pkg available in repos.
|
|
|
|
*/
|
2012-01-20 15:40:52 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_pkgdb,
|
2012-01-17 20:47:03 +05:30
|
|
|
"version", &instver);
|
2012-01-20 15:40:52 +05:30
|
|
|
prop_object_release(pkg_pkgdb);
|
2012-01-17 20:47:03 +05:30
|
|
|
if (xbps_cmpver(repover, instver) <= 0) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(xhp, "[rpool] Skipping `%s-%s' "
|
2012-06-02 20:22:01 +05:30
|
|
|
"(installed: %s-%s) from repository `%s'\n",
|
|
|
|
pkgname, repover, pkgname, instver, repoloc);
|
2012-01-17 20:47:03 +05:30
|
|
|
rv = EEXIST;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
*/
|
2012-01-22 14:30:46 +05:30
|
|
|
if ((rv = xbps_transaction_init(xhp)) != 0)
|
2011-01-24 21:25:58 +05:30
|
|
|
goto out;
|
2012-06-11 19:44:03 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Find out if package has matched conflicts.
|
|
|
|
*/
|
|
|
|
xbps_pkg_find_conflicts(xhp, pkg_repod);
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
2010-11-19 18:10:13 +05:30
|
|
|
* Prepare required package dependencies and add them into the
|
|
|
|
* "unsorted" array in transaction dictionary.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2012-06-05 02:52:33 +05:30
|
|
|
if ((rv = xbps_repository_find_pkg_deps(xhp, pkg_repod)) != 0)
|
2012-06-11 19:44:03 +05:30
|
|
|
goto out;
|
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) {
|
2011-02-23 21:44:33 +05:30
|
|
|
if (rv != ENOENT)
|
2011-02-22 15:01:16 +05:30
|
|
|
goto out;
|
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
|
|
|
}
|
2011-10-20 18:09:58 +05:30
|
|
|
if ((rv = xbps_set_pkg_state_dictionary(pkg_repod, state)) != 0)
|
2009-08-17 22:37:20 +05:30
|
|
|
goto out;
|
|
|
|
|
2011-02-22 15:01:16 +05:30
|
|
|
if (state == XBPS_PKG_STATE_UNPACKED)
|
|
|
|
reason = "configure";
|
2011-07-28 19:55:01 +05:30
|
|
|
else if (state == XBPS_PKG_STATE_NOT_INSTALLED ||
|
|
|
|
state == XBPS_PKG_STATE_HALF_UNPACKED)
|
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
|
|
|
*/
|
2011-10-20 18:09:58 +05:30
|
|
|
if (!prop_dictionary_set_cstring_nocopy(pkg_repod,
|
2011-02-05 16:51:04 +05:30
|
|
|
"transaction", reason)) {
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = EINVAL;
|
2009-11-23 15:16:51 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2011-01-18 19:14:39 +05:30
|
|
|
/*
|
2011-01-24 23:19:24 +05:30
|
|
|
* Add required package dictionary into the unsorted array.
|
2011-01-18 19:14:39 +05:30
|
|
|
*/
|
2012-01-22 14:30:46 +05:30
|
|
|
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
|
2011-01-18 19:14:39 +05:30
|
|
|
if (unsorted == NULL) {
|
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
|
|
|
* Add the pkg dictionary from repository's index dictionary into
|
|
|
|
* the "unsorted" array in transaction dictionary.
|
|
|
|
*/
|
2011-10-20 18:09:58 +05:30
|
|
|
if (!prop_array_add(unsorted, pkg_repod)) {
|
2009-08-17 22:37:20 +05:30
|
|
|
rv = errno;
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(xhp, "%s-%s: added into the transaction (%s).\n",
|
2012-06-02 20:22:01 +05:30
|
|
|
pkgname, repover, repoloc);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
out:
|
2012-01-22 14:30:46 +05:30
|
|
|
if (pkg_repod != NULL)
|
2011-01-18 19:14:39 +05:30
|
|
|
prop_object_release(pkg_repod);
|
2009-11-26 07:52:50 +05:30
|
|
|
|
2011-01-24 23:19:24 +05:30
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-06-02 20:22:01 +05:30
|
|
|
prop_object_t obj;
|
2012-05-08 12:49:43 +05:30
|
|
|
const char *pkgname, *holdpkgname;
|
2012-06-02 20:22:01 +05:30
|
|
|
bool newpkg_found = false;
|
2011-01-24 23:19:24 +05:30
|
|
|
int rv = 0;
|
2012-06-02 20:22:01 +05:30
|
|
|
size_t i, x;
|
2011-01-24 23:19:24 +05:30
|
|
|
|
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
|
|
|
|
2012-06-02 20:22:01 +05:30
|
|
|
for (i = 0; i < prop_array_count(xhp->pkgdb); i++) {
|
|
|
|
obj = prop_array_get(xhp->pkgdb, i);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
for (x = 0; x < cfg_size(xhp->cfg, "PackagesOnHold"); x++) {
|
|
|
|
holdpkgname = cfg_getnstr(xhp->cfg, "PackagesOnHold", x);
|
|
|
|
if (strcmp(pkgname, holdpkgname) == 0) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(xhp, "[rpool] package %s on hold, "
|
2012-06-02 20:22:01 +05:30
|
|
|
"ignoring updates.\n", pkgname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = transaction_find_pkg(xhp, pkgname, false, true,
|
2012-06-02 21:05:21 +05:30
|
|
|
false, TRANS_UPDATE);
|
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
|
|
|
}
|
|
|
|
}
|
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-06-14 11:52:11 +05:30
|
|
|
xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkgname)
|
2011-01-24 23:19:24 +05:30
|
|
|
{
|
2012-06-14 11:52:11 +05:30
|
|
|
return transaction_find_pkg(xhp, pkgname, false,
|
|
|
|
true, false, TRANS_UPDATE);
|
2011-01-24 23:19:24 +05:30
|
|
|
}
|
|
|
|
|
2011-02-24 20:18:50 +05:30
|
|
|
int
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_transaction_install_pkg(struct xbps_handle *xhp,
|
|
|
|
const char *pkg,
|
|
|
|
bool reinstall)
|
2011-01-24 23:19:24 +05:30
|
|
|
{
|
2012-06-06 02:24:46 +05:30
|
|
|
prop_dictionary_t pkgd = NULL;
|
2012-01-25 06:44:04 +05:30
|
|
|
pkg_state_t state;
|
2012-06-06 02:24:46 +05:30
|
|
|
char *pkgname;
|
2012-06-02 21:05:21 +05:30
|
|
|
bool bypattern, best, exact;
|
2012-06-03 10:56:48 +05:30
|
|
|
int rv;
|
2012-01-25 06:44:04 +05:30
|
|
|
|
|
|
|
if (xbps_pkgpattern_version(pkg)) {
|
|
|
|
bypattern = true;
|
2012-06-02 21:05:21 +05:30
|
|
|
best = false;
|
|
|
|
exact = false;
|
2012-06-06 02:24:46 +05:30
|
|
|
} else if ((pkgname = xbps_pkg_name(pkg)) != NULL) {
|
2012-06-02 21:05:21 +05:30
|
|
|
exact = true;
|
|
|
|
bypattern = false;
|
|
|
|
best = false;
|
2012-06-02 21:09:36 +05:30
|
|
|
} else {
|
|
|
|
exact = false;
|
|
|
|
bypattern = false;
|
|
|
|
best = true;
|
|
|
|
}
|
|
|
|
|
2012-06-06 02:24:46 +05:30
|
|
|
if (exact) {
|
2012-06-14 11:52:11 +05:30
|
|
|
pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false);
|
2012-06-06 02:24:46 +05:30
|
|
|
free(pkgname);
|
|
|
|
} else
|
2012-06-14 11:52:11 +05:30
|
|
|
pkgd = xbps_pkgdb_get_pkgd(xhp, pkg, bypattern);
|
2012-06-06 02:24:46 +05:30
|
|
|
|
|
|
|
if (pkgd) {
|
2012-01-25 06:44:04 +05:30
|
|
|
if (xbps_pkg_state_dictionary(pkgd, &state) != 0) {
|
|
|
|
prop_object_release(pkgd);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
prop_object_release(pkgd);
|
|
|
|
if ((state == XBPS_PKG_STATE_INSTALLED) && !reinstall) {
|
|
|
|
/* error out if pkg installed and no reinstall */
|
2012-02-14 05:04:26 +05:30
|
|
|
return EEXIST;
|
2012-01-25 06:44:04 +05:30
|
|
|
}
|
|
|
|
}
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = transaction_find_pkg(xhp, pkg, bypattern, best, exact, TRANS_INSTALL);
|
2012-06-03 10:56:48 +05:30
|
|
|
return rv;
|
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
|
|
|
{
|
2012-01-22 14:30:46 +05:30
|
|
|
prop_dictionary_t pkgd;
|
|
|
|
prop_array_t orphans, orphans_pkg, unsorted, reqby;
|
2011-11-27 13:35:18 +05:30
|
|
|
prop_object_t obj;
|
|
|
|
const char *pkgver;
|
|
|
|
size_t count;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
assert(pkgname != NULL);
|
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false)) == 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)
|
2011-11-27 13:35:18 +05:30
|
|
|
goto out;
|
2012-01-22 14:30:46 +05:30
|
|
|
|
|
|
|
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
|
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.
|
|
|
|
*/
|
|
|
|
orphans_pkg = prop_array_create();
|
|
|
|
if (orphans_pkg == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-12-24 05:35:26 +05:30
|
|
|
|
2011-11-27 13:35:18 +05:30
|
|
|
prop_array_set_cstring_nocopy(orphans_pkg, 0, pkgname);
|
2012-06-14 11:52:11 +05:30
|
|
|
orphans = xbps_find_pkg_orphans(xhp, orphans_pkg);
|
2011-11-27 13:35:18 +05:30
|
|
|
prop_object_release(orphans_pkg);
|
|
|
|
if (prop_object_type(orphans) != PROP_TYPE_ARRAY) {
|
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-12-24 05:35:26 +05:30
|
|
|
|
2011-11-27 13:35:18 +05:30
|
|
|
count = prop_array_count(orphans);
|
|
|
|
while (count--) {
|
|
|
|
obj = prop_array_get(orphans, count);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
|
|
|
prop_dictionary_set_cstring_nocopy(obj, "transaction", "remove");
|
|
|
|
prop_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
|
|
|
}
|
|
|
|
prop_object_release(orphans);
|
|
|
|
rmpkg:
|
|
|
|
/*
|
|
|
|
* Add pkg dictionary into the unsorted_deps array.
|
|
|
|
*/
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
|
|
|
prop_dictionary_set_cstring_nocopy(pkgd, "transaction", "remove");
|
|
|
|
prop_array_add(unsorted, pkgd);
|
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
|
|
|
reqby = prop_dictionary_get(pkgd, "requiredby");
|
|
|
|
/*
|
|
|
|
* If target pkg is required by any installed pkg, the client must be aware
|
|
|
|
* of this to take appropiate action.
|
|
|
|
*/
|
|
|
|
if ((prop_object_type(reqby) == PROP_TYPE_ARRAY) &&
|
|
|
|
(prop_array_count(reqby) > 0))
|
|
|
|
rv = EEXIST;
|
2011-12-24 05:35:26 +05:30
|
|
|
|
2011-11-27 13:35:18 +05:30
|
|
|
out:
|
2011-12-24 05:35:26 +05:30
|
|
|
prop_object_release(pkgd);
|
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
|
|
|
{
|
2012-01-22 14:30:46 +05:30
|
|
|
prop_array_t orphans, unsorted;
|
2011-11-25 15:50:03 +05:30
|
|
|
prop_object_t obj;
|
|
|
|
const char *pkgver;
|
|
|
|
size_t count;
|
|
|
|
int rv = 0;
|
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
orphans = xbps_find_pkg_orphans(xhp, NULL);
|
2011-11-25 15:50:03 +05:30
|
|
|
if (prop_object_type(orphans) != PROP_TYPE_ARRAY)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
count = prop_array_count(orphans);
|
|
|
|
if (count == 0) {
|
|
|
|
/* 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;
|
|
|
|
/*
|
|
|
|
* Add pkg orphan dictionary into the unsorted_deps array.
|
|
|
|
*/
|
2012-01-22 14:30:46 +05:30
|
|
|
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
|
2011-11-25 15:50:03 +05:30
|
|
|
while (count--) {
|
|
|
|
obj = prop_array_get(orphans, count);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
|
|
|
prop_dictionary_set_cstring_nocopy(obj,
|
|
|
|
"transaction", "remove");
|
|
|
|
prop_array_add(unsorted, obj);
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n",
|
2011-11-25 15:50:03 +05:30
|
|
|
pkgver);
|
|
|
|
}
|
|
|
|
out:
|
2012-01-22 14:30:46 +05:30
|
|
|
if (orphans != NULL)
|
2011-11-25 15:50:03 +05:30
|
|
|
prop_object_release(orphans);
|
|
|
|
return rv;
|
|
|
|
}
|