2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2020-04-29 17:42:10 +05:30
|
|
|
* Copyright (c) 2009-2020 Juan Romero Pardines.
|
|
|
|
* 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.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
*/
|
2011-01-24 23:19:24 +05:30
|
|
|
static int
|
2020-04-23 09:33:56 +05:30
|
|
|
trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
|
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;
|
2020-04-22 15:50:38 +05:30
|
|
|
xbps_object_t obj;
|
2014-10-19 14:30:40 +05:30
|
|
|
xbps_array_t pkgs;
|
2011-02-22 15:01:16 +05:30
|
|
|
pkg_state_t state = 0;
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_trans_type_t ttype;
|
|
|
|
const char *repoloc, *repopkgver, *instpkgver, *pkgname;
|
|
|
|
char buf[XBPS_NAME_SIZE] = {0};
|
|
|
|
int rv = 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
|
|
|
|
2014-01-15 20:47:41 +05:30
|
|
|
/*
|
|
|
|
* Find out if pkg is installed first.
|
|
|
|
*/
|
2020-02-21 13:38:22 +05:30
|
|
|
if (xbps_pkg_name(buf, sizeof(buf), pkg)) {
|
|
|
|
pkg_pkgdb = xbps_pkgdb_get_pkg(xhp, buf);
|
2014-09-11 14:43:20 +05:30
|
|
|
} else {
|
|
|
|
pkg_pkgdb = xbps_pkgdb_get_pkg(xhp, pkg);
|
|
|
|
}
|
2020-01-25 17:35:46 +05:30
|
|
|
|
|
|
|
if (xhp->flags & XBPS_FLAG_DOWNLOAD_ONLY) {
|
|
|
|
pkg_pkgdb = NULL;
|
2020-02-21 13:38:22 +05:30
|
|
|
ttype = XBPS_TRANS_DOWNLOAD;
|
2020-01-25 17:35:46 +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
|
|
|
*/
|
2014-05-27 15:03:45 +05:30
|
|
|
if (pkg_pkgdb == NULL) {
|
|
|
|
/* pkg not installed, perform installation */
|
2020-02-21 13:38:22 +05:30
|
|
|
ttype = XBPS_TRANS_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 {
|
2020-04-23 09:33:56 +05:30
|
|
|
if (force) {
|
2020-02-21 13:38:22 +05:30
|
|
|
ttype = XBPS_TRANS_REINSTALL;
|
2014-05-27 15:03:45 +05:30
|
|
|
} else {
|
2020-02-21 13:38:22 +05:30
|
|
|
ttype = XBPS_TRANS_UPDATE;
|
2014-05-27 15:03:45 +05:30
|
|
|
}
|
2020-04-22 15:50:38 +05:30
|
|
|
if (xbps_dictionary_get(pkg_pkgdb, "repolock")) {
|
2015-03-03 16:41:28 +05:30
|
|
|
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
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
if (ttype == XBPS_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);
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("[rpool] Skipping `%s' "
|
2013-03-05 08:38:42 +05:30
|
|
|
"(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
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
} else if (ttype == XBPS_TRANS_REINSTALL) {
|
2014-05-27 15:03:45 +05:30
|
|
|
/*
|
|
|
|
* 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) {
|
2020-02-21 13:38:22 +05:30
|
|
|
ttype = XBPS_TRANS_UPDATE;
|
2014-05-27 15:03:45 +05:30
|
|
|
}
|
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
|
|
|
*/
|
2020-04-22 15:50:38 +05:30
|
|
|
if ((obj = xbps_dictionary_get(pkg_pkgdb, "automatic-install")))
|
|
|
|
xbps_dictionary_set(pkg_repod, "automatic-install", obj);
|
|
|
|
if ((obj = xbps_dictionary_get(pkg_pkgdb, "hold")))
|
|
|
|
xbps_dictionary_set(pkg_repod, "hold", obj);
|
|
|
|
if ((obj = xbps_dictionary_get(pkg_pkgdb, "repolock")))
|
|
|
|
xbps_dictionary_set(pkg_repod, "repolock", obj);
|
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.
|
|
|
|
*/
|
2020-02-21 13:38:22 +05:30
|
|
|
if (ttype == XBPS_TRANS_UPDATE) {
|
|
|
|
if (xbps_find_pkg_in_array(pkgs, repopkgver, 0)) {
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("[update] `%s' already queued in "
|
2012-07-04 15:26:01 +05:30
|
|
|
"transaction.\n", repopkgver);
|
|
|
|
return EEXIST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname)) {
|
|
|
|
return EINVAL;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
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) {
|
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) {
|
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
|
|
|
|
2021-06-12 19:24:09 +05:30
|
|
|
if (state == XBPS_PKG_STATE_NOT_INSTALLED)
|
2020-04-23 09:33:56 +05:30
|
|
|
ttype = XBPS_TRANS_INSTALL;
|
|
|
|
|
|
|
|
if (!force && xbps_dictionary_get(pkg_repod, "hold"))
|
|
|
|
ttype = XBPS_TRANS_HOLD;
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
2020-02-21 13:38:22 +05:30
|
|
|
* Store pkgd from repo into the transaction.
|
2010-11-19 18:10:13 +05:30
|
|
|
*/
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_transaction_pkg_type_set(pkg_repod, ttype)) {
|
2014-08-22 16:14:18 +05:30
|
|
|
return EINVAL;
|
|
|
|
}
|
2020-02-09 00:01:29 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_transaction_store(xhp, pkgs, pkg_repod, false)) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2011-01-24 23:19:24 +05:30
|
|
|
}
|
|
|
|
|
2019-06-17 15:32:02 +05:30
|
|
|
/*
|
|
|
|
* Returns 1 if there's an update, 0 if none or -1 on error.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
xbps_autoupdate(struct xbps_handle *xhp)
|
2011-01-24 23:19:24 +05:30
|
|
|
{
|
2019-06-17 15:32:02 +05:30
|
|
|
xbps_array_t rdeps;
|
2015-03-29 13:26:28 +05:30
|
|
|
xbps_dictionary_t pkgd;
|
2020-02-21 13:38:22 +05:30
|
|
|
const char *pkgver = NULL, *pkgname = NULL;
|
2019-06-17 15:32:02 +05:30
|
|
|
int 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
|
2019-06-17 15:32:02 +05:30
|
|
|
* another transaction.
|
2015-03-29 13:26:28 +05:30
|
|
|
*/
|
2019-06-17 15:32:02 +05:30
|
|
|
if (((pkgd = xbps_pkgdb_get_pkg(xhp, "xbps")) == NULL) &&
|
|
|
|
((pkgd = xbps_pkgdb_get_virtualpkg(xhp, "xbps")) == NULL))
|
|
|
|
return 0;
|
2019-04-19 22:22:44 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname)) {
|
|
|
|
return EINVAL;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
|
|
|
|
rv = trans_find_pkg(xhp, pkgname, false);
|
2019-06-13 17:37:32 +05:30
|
|
|
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("%s: trans_find_pkg xbps: %d\n", __func__, rv);
|
2019-04-19 22:22:44 +05:30
|
|
|
|
2019-06-17 15:32:02 +05:30
|
|
|
if (rv == 0) {
|
2020-01-25 17:35:46 +05:30
|
|
|
if (xhp->flags & XBPS_FLAG_DOWNLOAD_ONLY) {
|
2020-01-25 18:14:46 +05:30
|
|
|
return 0;
|
2020-01-25 17:35:46 +05:30
|
|
|
}
|
2019-06-17 15:32:02 +05:30
|
|
|
/* a new xbps version is available, check its revdeps */
|
|
|
|
rdeps = xbps_pkgdb_get_pkg_revdeps(xhp, "xbps");
|
|
|
|
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
|
2019-06-27 20:39:43 +05:30
|
|
|
const char *curpkgver = NULL;
|
2020-02-21 13:38:22 +05:30
|
|
|
char curpkgn[XBPS_NAME_SIZE] = {0};
|
2019-06-17 15:32:02 +05:30
|
|
|
|
|
|
|
xbps_array_get_cstring_nocopy(rdeps, i, &curpkgver);
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("%s: processing revdep %s\n", __func__, curpkgver);
|
2019-06-17 15:32:02 +05:30
|
|
|
|
2020-02-09 00:01:29 +05:30
|
|
|
if (!xbps_pkg_name(curpkgn, sizeof(curpkgn), curpkgver)) {
|
|
|
|
abort();
|
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
rv = trans_find_pkg(xhp, curpkgn, false);
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("%s: trans_find_pkg revdep %s: %d\n", __func__, curpkgver, rv);
|
2019-06-17 15:32:02 +05:30
|
|
|
if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV)
|
|
|
|
return -1;
|
2015-03-29 14:36:18 +05:30
|
|
|
}
|
2020-01-04 17:31:28 +05:30
|
|
|
/*
|
|
|
|
* Set XBPS_FLAG_FORCE_REMOVE_REVDEPS to ignore broken
|
|
|
|
* reverse dependencies in xbps_transaction_prepare().
|
|
|
|
*
|
|
|
|
* This won't skip revdeps of the xbps pkg, rather other
|
|
|
|
* packages in rootdir that could be broken indirectly.
|
|
|
|
*
|
|
|
|
* A sysup transaction after updating xbps should fix them
|
|
|
|
* again.
|
|
|
|
*/
|
|
|
|
xhp->flags |= XBPS_FLAG_FORCE_REMOVE_REVDEPS;
|
2019-06-17 15:32:02 +05:30
|
|
|
return 1;
|
|
|
|
} else if (rv == ENOENT || rv == EEXIST || rv == ENODEV) {
|
|
|
|
/* no update */
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
/* error */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xbps_transaction_update_packages(struct xbps_handle *xhp)
|
|
|
|
{
|
|
|
|
xbps_object_t obj;
|
|
|
|
xbps_object_iterator_t iter;
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_dictionary_t pkgd;
|
2020-02-09 00:01:29 +05:30
|
|
|
bool newpkg_found = false;
|
2019-06-17 15:32:02 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
rv = xbps_autoupdate(xhp);
|
|
|
|
switch (rv) {
|
|
|
|
case 1:
|
2019-12-27 19:03:53 +05:30
|
|
|
/* xbps needs to be updated, don't allow any other update */
|
|
|
|
return EBUSY;
|
2019-06-17 15:32:02 +05:30
|
|
|
case -1:
|
|
|
|
/* error */
|
|
|
|
return EINVAL;
|
|
|
|
default:
|
|
|
|
break;
|
2015-03-29 13:26:28 +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))) {
|
2020-02-21 13:38:22 +05:30
|
|
|
const char *pkgver = NULL;
|
|
|
|
char pkgname[XBPS_NAME_SIZE] = {0};
|
2020-02-09 00:01:29 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) {
|
2015-10-30 16:54:46 +05:30
|
|
|
continue;
|
2012-09-25 18:32:57 +05:30
|
|
|
}
|
2020-02-09 00:01:29 +05:30
|
|
|
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
2020-02-21 13:38:22 +05:30
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
rv = trans_find_pkg(xhp, pkgname, false);
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv);
|
2015-01-28 16:37:47 +05:30
|
|
|
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-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
|
2020-04-23 09:33:56 +05:30
|
|
|
xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
|
2011-01-24 23:19:24 +05:30
|
|
|
{
|
2019-08-05 15:18:11 +05:30
|
|
|
xbps_array_t rdeps;
|
2019-06-17 15:32:02 +05:30
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = xbps_autoupdate(xhp);
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("%s: xbps_autoupdate %d\n", __func__, rv);
|
2019-06-17 15:32:02 +05:30
|
|
|
switch (rv) {
|
|
|
|
case 1:
|
2019-12-27 19:03:53 +05:30
|
|
|
/* xbps needs to be updated, only allow xbps to be updated */
|
|
|
|
if (strcmp(pkg, "xbps"))
|
|
|
|
return EBUSY;
|
2019-06-17 15:32:02 +05:30
|
|
|
return 0;
|
|
|
|
case -1:
|
|
|
|
/* error */
|
|
|
|
return EINVAL;
|
|
|
|
default:
|
|
|
|
/* no update */
|
|
|
|
break;
|
|
|
|
}
|
2019-05-14 12:24:24 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
/* update its reverse dependencies */
|
2019-08-05 15:18:11 +05:30
|
|
|
rdeps = xbps_pkgdb_get_pkg_revdeps(xhp, pkg);
|
2020-01-25 18:14:46 +05:30
|
|
|
if (xhp->flags & XBPS_FLAG_DOWNLOAD_ONLY) {
|
|
|
|
rdeps = NULL;
|
|
|
|
}
|
2019-08-05 15:18:11 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
|
2020-02-09 00:01:29 +05:30
|
|
|
const char *pkgver = NULL;
|
2020-02-21 13:38:22 +05:30
|
|
|
char pkgname[XBPS_NAME_SIZE] = {0};
|
2020-02-09 00:01:29 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_array_get_cstring_nocopy(rdeps, i, &pkgver)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2020-02-09 00:01:29 +05:30
|
|
|
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
2020-02-21 13:38:22 +05:30
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
rv = trans_find_pkg(xhp, pkgname, false);
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv);
|
2020-02-21 13:38:22 +05:30
|
|
|
if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV) {
|
2019-08-05 15:18:11 +05:30
|
|
|
return rv;
|
2020-02-21 13:38:22 +05:30
|
|
|
}
|
2019-08-05 15:18:11 +05:30
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
/* add pkg repod */
|
2020-04-23 09:33:56 +05:30
|
|
|
rv = trans_find_pkg(xhp, pkg, force);
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("%s: trans_find_pkg %s: %d\n", __func__, pkg, rv);
|
2019-06-21 16:44:24 +05:30
|
|
|
return rv;
|
2011-01-24 23:19:24 +05:30
|
|
|
}
|
|
|
|
|
2011-02-24 20:18:50 +05:30
|
|
|
int
|
2020-04-23 09:33:56 +05:30
|
|
|
xbps_transaction_install_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
|
2011-01-24 23:19:24 +05:30
|
|
|
{
|
2019-08-05 15:18:11 +05:30
|
|
|
xbps_array_t rdeps;
|
2019-06-17 15:32:02 +05:30
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = xbps_autoupdate(xhp);
|
|
|
|
switch (rv) {
|
|
|
|
case 1:
|
2019-12-27 19:03:53 +05:30
|
|
|
/* xbps needs to be updated, only allow xbps to be updated */
|
|
|
|
if (strcmp(pkg, "xbps"))
|
|
|
|
return EBUSY;
|
2019-06-17 15:32:02 +05:30
|
|
|
return 0;
|
|
|
|
case -1:
|
|
|
|
/* error */
|
|
|
|
return EINVAL;
|
|
|
|
default:
|
|
|
|
/* no update */
|
|
|
|
break;
|
|
|
|
}
|
2019-05-14 12:24:24 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
/* update its reverse dependencies */
|
2019-08-05 15:18:11 +05:30
|
|
|
rdeps = xbps_pkgdb_get_pkg_revdeps(xhp, pkg);
|
2020-01-25 18:14:46 +05:30
|
|
|
if (xhp->flags & XBPS_FLAG_DOWNLOAD_ONLY) {
|
|
|
|
rdeps = NULL;
|
|
|
|
}
|
2019-08-05 15:18:11 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
|
2020-02-09 00:01:29 +05:30
|
|
|
const char *pkgver = NULL;
|
2020-02-21 13:38:22 +05:30
|
|
|
char pkgname[XBPS_NAME_SIZE] = {0};
|
2020-02-09 00:01:29 +05:30
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
if (!xbps_array_get_cstring_nocopy(rdeps, i, &pkgver)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2020-02-09 00:01:29 +05:30
|
|
|
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
|
2020-02-21 13:38:22 +05:30
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
2020-02-09 00:01:29 +05:30
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
rv = trans_find_pkg(xhp, pkgname, false);
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv);
|
2020-02-21 13:38:22 +05:30
|
|
|
if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV) {
|
2019-08-05 15:18:11 +05:30
|
|
|
return rv;
|
2020-02-21 13:38:22 +05:30
|
|
|
}
|
2019-08-05 15:18:11 +05:30
|
|
|
}
|
2020-04-23 09:33:56 +05:30
|
|
|
rv = trans_find_pkg(xhp, pkg, force);
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("%s: trans_find_pkg %s: %d\n", __func__, pkg, rv);
|
2019-06-21 16:44:24 +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
|
|
|
{
|
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
|
|
|
int rv = 0;
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
assert(xhp);
|
|
|
|
assert(pkgname);
|
2011-11-27 13:35:18 +05:30
|
|
|
|
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);
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_transaction_pkg_type_set(obj, XBPS_TRANS_REMOVE);
|
|
|
|
if (!xbps_transaction_store(xhp, pkgs, obj, false)) {
|
2014-10-19 14:52:17 +05:30
|
|
|
return EINVAL;
|
2020-02-21 13:38:22 +05:30
|
|
|
}
|
2011-11-27 13:35:18 +05:30
|
|
|
}
|
2020-02-09 00:42:11 +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:
|
|
|
|
/*
|
2014-10-18 16:05:47 +05:30
|
|
|
* Add pkg dictionary into the transaction pkgs queue.
|
2011-11-27 13:35:18 +05:30
|
|
|
*/
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_transaction_pkg_type_set(pkgd, XBPS_TRANS_REMOVE);
|
|
|
|
if (!xbps_transaction_store(xhp, pkgs, pkgd, false)) {
|
2014-10-19 14:52:17 +05:30
|
|
|
return EINVAL;
|
2020-02-21 13:38:22 +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
|
|
|
{
|
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
|
|
|
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 */
|
|
|
|
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);
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_transaction_pkg_type_set(obj, XBPS_TRANS_REMOVE);
|
|
|
|
if (!xbps_transaction_store(xhp, pkgs, obj, false)) {
|
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-11-25 15:50:03 +05:30
|
|
|
}
|
|
|
|
out:
|
2020-02-21 13:38:22 +05:30
|
|
|
if (orphans)
|
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;
|
|
|
|
}
|
2020-02-21 13:38:22 +05:30
|
|
|
|
|
|
|
xbps_trans_type_t
|
|
|
|
xbps_transaction_pkg_type(xbps_dictionary_t pkg_repod)
|
|
|
|
{
|
|
|
|
uint8_t r;
|
|
|
|
|
|
|
|
if (xbps_object_type(pkg_repod) != XBPS_TYPE_DICTIONARY)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!xbps_dictionary_get_uint8(pkg_repod, "transaction", &r))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
xbps_transaction_pkg_type_set(xbps_dictionary_t pkg_repod, xbps_trans_type_t ttype)
|
|
|
|
{
|
|
|
|
uint8_t r;
|
|
|
|
|
|
|
|
if (xbps_object_type(pkg_repod) != XBPS_TYPE_DICTIONARY)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (ttype) {
|
|
|
|
case XBPS_TRANS_INSTALL:
|
|
|
|
case XBPS_TRANS_UPDATE:
|
|
|
|
case XBPS_TRANS_CONFIGURE:
|
|
|
|
case XBPS_TRANS_REMOVE:
|
|
|
|
case XBPS_TRANS_REINSTALL:
|
|
|
|
case XBPS_TRANS_HOLD:
|
|
|
|
case XBPS_TRANS_DOWNLOAD:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
r = ttype;
|
|
|
|
if (!xbps_dictionary_set_uint8(pkg_repod, "transaction", r))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|