2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2015-01-28 16:37:47 +05:30
|
|
|
* Copyright (c) 2009-2015 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
|
2015-01-28 16:37:47 +05:30
|
|
|
trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall,
|
|
|
|
bool hold)
|
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-10-19 14:30:40 +05:30
|
|
|
xbps_array_t pkgs;
|
2013-03-07 13:42:47 +05:30
|
|
|
const char *repoloc, *repopkgver, *instpkgver, *reason;
|
2014-10-19 14:30:40 +05:30
|
|
|
char *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;
|
2015-03-03 16:41:28 +05:30
|
|
|
bool autoinst = false, repolock = 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.
|
|
|
|
*/
|
2014-09-11 14:43:20 +05:30
|
|
|
if ((pkgname = xbps_pkg_name(pkg))) {
|
|
|
|
pkg_pkgdb = xbps_pkgdb_get_pkg(xhp, pkgname);
|
|
|
|
free(pkgname);
|
|
|
|
} else {
|
|
|
|
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";
|
|
|
|
}
|
2015-03-03 16:41:28 +05:30
|
|
|
xbps_dictionary_get_bool(pkg_pkgdb, "repolock", &repolock);
|
|
|
|
if (repolock) {
|
|
|
|
struct xbps_repo *repo;
|
|
|
|
/* find update from repo */
|
|
|
|
xbps_dictionary_get_cstring_nocopy(pkg_pkgdb, "repository", &repoloc);
|
|
|
|
assert(repoloc);
|
2015-03-06 01:53:58 +05:30
|
|
|
if ((repo = xbps_regget_repo(xhp, repoloc)) == NULL) {
|
|
|
|
/* not found */
|
|
|
|
return ENOENT;
|
|
|
|
}
|
2015-03-03 16:41:28 +05:30
|
|
|
pkg_repod = xbps_repo_get_pkg(repo, pkg);
|
|
|
|
} else {
|
|
|
|
/* find update from rpool */
|
|
|
|
pkg_repod = xbps_rpool_get_pkg(xhp, pkg);
|
|
|
|
}
|
|
|
|
if (pkg_repod == 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);
|
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);
|
2014-09-23 01:04:28 +05:30
|
|
|
if (xbps_cmpver(repopkgver, instpkgver) <= 0 &&
|
2014-09-29 01:47:33 +05:30
|
|
|
!xbps_pkg_reverts(pkg_repod, instpkgver)) {
|
2015-02-16 15:48:58 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(pkg_repod,
|
|
|
|
"repository", &repoloc);
|
2013-03-05 08:38:42 +05:30
|
|
|
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) {
|
|
|
|
/*
|
2015-03-03 16:41:28 +05:30
|
|
|
* If pkg is already installed, respect some properties.
|
2014-01-15 20:47:41 +05:30
|
|
|
*/
|
2014-09-11 03:42:12 +05:30
|
|
|
if (xbps_dictionary_get_bool(pkg_pkgdb, "automatic-install", &autoinst))
|
|
|
|
xbps_dictionary_set_bool(pkg_repod, "automatic-install", autoinst);
|
2015-03-03 16:41:28 +05:30
|
|
|
if (xbps_dictionary_get_bool(pkg_pkgdb, "repolock", &repolock))
|
|
|
|
xbps_dictionary_set_bool(pkg_repod, "repolock", repolock);
|
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
|
|
|
|
2014-10-18 16:05:47 +05:30
|
|
|
pkgs = xbps_dictionary_get(xhp->transd, "packages");
|
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) {
|
2014-10-18 16:05:47 +05:30
|
|
|
if (xbps_find_pkg_in_array(pkgs, repopkgver, NULL)) {
|
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
|
|
|
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";
|
2015-01-28 16:37:47 +05:30
|
|
|
else if ((action == TRANS_UPDATE) && hold)
|
|
|
|
reason = "hold";
|
2011-07-08 18:58:57 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
2015-01-28 16:37:47 +05:30
|
|
|
* Set transaction obj reason.
|
2010-11-19 18:10:13 +05:30
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
if (!xbps_dictionary_set_cstring_nocopy(pkg_repod,
|
2014-10-19 14:30:40 +05:30
|
|
|
"transaction", reason)) {
|
2014-08-22 16:14:18 +05:30
|
|
|
free(pkgname);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2014-10-20 11:29:06 +05:30
|
|
|
if ((rv = xbps_transaction_store(xhp, pkgs, pkg_repod, false)) != 0) {
|
2014-08-22 16:14:18 +05:30
|
|
|
free(pkgname);
|
2014-10-19 14:30:40 +05:30
|
|
|
return rv;
|
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
|
|
|
{
|
2015-03-29 13:26:28 +05:30
|
|
|
xbps_dictionary_t pkgd;
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_t obj;
|
|
|
|
xbps_object_iterator_t iter;
|
2015-03-29 13:26:28 +05:30
|
|
|
const char *pkgver;
|
|
|
|
char *pkgname;
|
|
|
|
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
|
|
|
|
2015-03-29 13:26:28 +05:30
|
|
|
/*
|
|
|
|
* Check if there's a new update for XBPS before starting
|
|
|
|
* a full system upgrade.
|
|
|
|
*/
|
|
|
|
if ((pkgd = xbps_pkgdb_get_pkg(xhp, "xbps")) ||
|
|
|
|
(pkgd = xbps_pkgdb_get_virtualpkg(xhp, "xbps"))) {
|
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
|
|
|
pkgname = xbps_pkg_name(pkgver);
|
|
|
|
assert(pkgname);
|
2015-03-29 14:36:18 +05:30
|
|
|
if (trans_find_pkg(xhp, pkgname, false, false) == 0) {
|
|
|
|
free(pkgname);
|
|
|
|
return rv;
|
|
|
|
}
|
2015-03-29 13:26:28 +05:30
|
|
|
free(pkgname);
|
|
|
|
}
|
|
|
|
|
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))) {
|
2015-03-29 13:26:28 +05:30
|
|
|
hold = false;
|
2013-06-20 13:56:12 +05:30
|
|
|
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
|
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
2013-08-12 18:16:54 +05:30
|
|
|
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
|
|
|
}
|
2013-08-12 18:16:54 +05:30
|
|
|
pkgname = xbps_pkg_name(pkgver);
|
|
|
|
assert(pkgname);
|
2015-01-28 16:37:47 +05:30
|
|
|
rv = trans_find_pkg(xhp, pkgname, false, hold);
|
|
|
|
if (rv == 0) {
|
2012-06-02 20:22:01 +05:30
|
|
|
newpkg_found = true;
|
2015-01-28 16:37:47 +05:30
|
|
|
} else if (rv == ENOENT || rv == EEXIST || rv == ENODEV) {
|
2012-06-02 20:22:01 +05:30
|
|
|
/*
|
|
|
|
* 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
|
|
|
{
|
2015-01-28 16:37:47 +05:30
|
|
|
return trans_find_pkg(xhp, pkg, false, 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
|
|
|
{
|
2015-01-28 16:37:47 +05:30
|
|
|
return trans_find_pkg(xhp, pkg, reinstall, false);
|
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;
|
2015-02-03 14:50:13 +05:30
|
|
|
xbps_array_t pkgs, orphans, orphans_pkg;
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_t obj;
|
2011-11-27 13:35:18 +05:30
|
|
|
const char *pkgver;
|
|
|
|
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
|
|
|
|
2014-10-18 16:05:47 +05:30
|
|
|
pkgs = xbps_dictionary_get(xhp->transd, "packages");
|
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
|
|
|
|
2014-11-06 14:28:04 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(orphans); i++) {
|
|
|
|
obj = xbps_array_get(orphans, i);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
|
|
|
xbps_dictionary_set_cstring_nocopy(obj, "transaction", "remove");
|
2014-10-20 11:29:06 +05:30
|
|
|
if ((rv = xbps_transaction_store(xhp, pkgs, obj, false)) != 0)
|
2014-10-19 14:52:17 +05:30
|
|
|
return EINVAL;
|
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-03-11 16:43:02 +05:30
|
|
|
return rv;
|
|
|
|
|
2011-11-27 13:35:18 +05:30
|
|
|
rmpkg:
|
|
|
|
/*
|
2014-10-18 16:05:47 +05:30
|
|
|
* Add pkg dictionary into the transaction pkgs 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");
|
2014-10-20 11:29:06 +05:30
|
|
|
if ((rv = xbps_transaction_store(xhp, pkgs, pkgd, false)) != 0)
|
2014-10-19 14:52:17 +05:30
|
|
|
return EINVAL;
|
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
|
|
|
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
|
|
|
{
|
2014-10-18 16:05:47 +05:30
|
|
|
xbps_array_t orphans, pkgs;
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_t obj;
|
2011-11-25 15:50:03 +05:30
|
|
|
const char *pkgver;
|
|
|
|
int rv = 0;
|
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
orphans = xbps_find_pkg_orphans(xhp, NULL);
|
2014-11-06 14:28:04 +05:30
|
|
|
if (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
|
|
|
|
2014-10-18 16:05:47 +05:30
|
|
|
pkgs = xbps_dictionary_get(xhp->transd, "packages");
|
2011-11-25 15:50:03 +05:30
|
|
|
/*
|
2014-10-18 16:05:47 +05:30
|
|
|
* Add pkg orphan dictionary into the transaction pkgs queue.
|
2011-11-25 15:50:03 +05:30
|
|
|
*/
|
2014-11-06 14:28:04 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(orphans); i++) {
|
|
|
|
obj = xbps_array_get(orphans, i);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
|
|
|
xbps_dictionary_set_cstring_nocopy(obj,
|
2011-11-25 15:50:03 +05:30
|
|
|
"transaction", "remove");
|
2014-10-18 16:05:47 +05:30
|
|
|
xbps_array_add(pkgs, 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;
|
|
|
|
}
|