2012-11-02 19:34:25 +05:30
|
|
|
/*-
|
2020-04-29 17:42:10 +05:30
|
|
|
* Copyright (c) 2009-2019 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.
|
2012-11-02 19:34:25 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
2013-06-20 16:01:02 +05:30
|
|
|
#include <xbps.h>
|
2012-11-02 19:34:25 +05:30
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
static void
|
2014-07-13 13:04:54 +05:30
|
|
|
print_array(xbps_array_t a)
|
2012-11-02 19:34:25 +05:30
|
|
|
{
|
2019-06-27 20:39:43 +05:30
|
|
|
const char *str = NULL;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(a); i++) {
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_get_cstring_nocopy(a, i, &str);
|
2013-06-27 20:22:31 +05:30
|
|
|
fprintf(stderr, "%s\n", str);
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-06-20 13:56:12 +05:30
|
|
|
show_actions(xbps_object_iterator_t iter)
|
2012-11-02 19:34:25 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_t obj;
|
2013-03-05 08:38:42 +05:30
|
|
|
const char *repoloc, *trans, *pkgver, *arch;
|
2015-10-19 22:32:26 +05:30
|
|
|
uint64_t isize, dsize;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
while ((obj = xbps_object_iterator_next(iter)) != NULL) {
|
2020-02-21 13:38:22 +05:30
|
|
|
repoloc = trans = pkgver = arch = NULL;
|
|
|
|
isize = dsize = 0;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
2020-02-21 13:38:22 +05:30
|
|
|
printf("%s %s", pkgver, ttype2str(obj));
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
|
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
|
2013-03-11 16:42:03 +05:30
|
|
|
if (repoloc && arch)
|
|
|
|
printf(" %s %s", arch, repoloc);
|
2015-10-19 22:32:26 +05:30
|
|
|
xbps_dictionary_get_uint64(obj, "installed_size", &isize);
|
|
|
|
xbps_dictionary_get_uint64(obj, "filename-size", &dsize);
|
|
|
|
if (isize)
|
|
|
|
printf(" %ju", isize);
|
|
|
|
if (dsize)
|
|
|
|
printf(" %ju", dsize);
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-22 15:59:18 +05:30
|
|
|
show_package_list(struct transaction *trans, xbps_trans_type_t ttype, unsigned int cols)
|
2012-11-02 19:34:25 +05:30
|
|
|
{
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_dictionary_t ipkgd;
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_t obj;
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_trans_type_t tt;
|
|
|
|
const char *pkgver, *pkgname, *ipkgver, *version, *iversion;
|
|
|
|
char *buf = NULL;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2014-09-11 15:13:15 +05:30
|
|
|
while ((obj = xbps_object_iterator_next(trans->iter)) != NULL) {
|
2014-07-14 13:13:52 +05:30
|
|
|
bool dload = false;
|
|
|
|
|
2020-02-21 13:38:22 +05:30
|
|
|
pkgver = ipkgver = version = iversion = NULL;
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
2020-02-21 13:38:22 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
2014-07-14 13:13:52 +05:30
|
|
|
xbps_dictionary_get_bool(obj, "download", &dload);
|
2020-04-23 09:33:56 +05:30
|
|
|
if (ttype == XBPS_TRANS_DOWNLOAD && dload) {
|
|
|
|
tt = XBPS_TRANS_DOWNLOAD;
|
|
|
|
} else {
|
|
|
|
tt = xbps_transaction_pkg_type(obj);
|
2020-08-20 17:38:29 +05:30
|
|
|
if (ttype == XBPS_TRANS_INSTALL && tt == XBPS_TRANS_REINSTALL) {
|
|
|
|
tt = XBPS_TRANS_INSTALL;
|
|
|
|
}
|
2020-04-23 09:33:56 +05:30
|
|
|
}
|
2014-07-14 13:13:52 +05:30
|
|
|
|
2020-03-04 17:16:44 +05:30
|
|
|
buf = NULL;
|
2020-02-21 13:38:22 +05:30
|
|
|
if (tt == XBPS_TRANS_UPDATE) {
|
2014-09-11 15:13:15 +05:30
|
|
|
/* get installed pkgver */
|
|
|
|
ipkgd = xbps_pkgdb_get_pkg(trans->xhp, pkgname);
|
|
|
|
assert(ipkgd);
|
|
|
|
xbps_dictionary_get_cstring_nocopy(ipkgd, "pkgver", &ipkgver);
|
|
|
|
version = xbps_pkg_version(pkgver);
|
|
|
|
iversion = xbps_pkg_version(ipkgver);
|
|
|
|
buf = xbps_xasprintf("%s (%s -> %s)", pkgname, iversion, version);
|
|
|
|
}
|
2020-04-23 09:33:56 +05:30
|
|
|
if (ttype == tt) {
|
2014-09-11 15:13:15 +05:30
|
|
|
if (buf) {
|
|
|
|
print_package_line(buf, cols, false);
|
|
|
|
free(buf);
|
|
|
|
} else {
|
|
|
|
print_package_line(pkgver, cols, false);
|
|
|
|
}
|
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
2014-09-11 15:13:15 +05:30
|
|
|
xbps_object_iterator_reset(trans->iter);
|
2012-11-02 19:34:25 +05:30
|
|
|
print_package_line(NULL, cols, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-06-12 13:34:10 +05:30
|
|
|
show_transaction_sizes(struct transaction *trans, int cols)
|
2012-11-02 19:34:25 +05:30
|
|
|
{
|
2014-07-13 15:15:04 +05:30
|
|
|
uint64_t dlsize = 0, instsize = 0, rmsize = 0, disk_free_size = 0;
|
2012-11-02 19:34:25 +05:30
|
|
|
char size[8];
|
|
|
|
|
2020-04-23 09:33:56 +05:30
|
|
|
/*
|
|
|
|
* Get stats from transaction dictionary.
|
|
|
|
*/
|
|
|
|
xbps_dictionary_get_uint32(trans->d, "total-download-pkgs",
|
|
|
|
&trans->dl_pkgcnt);
|
|
|
|
xbps_dictionary_get_uint32(trans->d, "total-install-pkgs",
|
|
|
|
&trans->inst_pkgcnt);
|
|
|
|
xbps_dictionary_get_uint32(trans->d, "total-update-pkgs",
|
|
|
|
&trans->up_pkgcnt);
|
|
|
|
xbps_dictionary_get_uint32(trans->d, "total-configure-pkgs",
|
|
|
|
&trans->cf_pkgcnt);
|
|
|
|
xbps_dictionary_get_uint32(trans->d, "total-remove-pkgs",
|
|
|
|
&trans->rm_pkgcnt);
|
|
|
|
xbps_dictionary_get_uint32(trans->d, "total-hold-pkgs",
|
|
|
|
&trans->hold_pkgcnt);
|
|
|
|
|
2014-10-30 15:53:10 +05:30
|
|
|
if (!print_trans_colmode(trans, cols)) {
|
|
|
|
/*
|
2020-04-23 09:33:56 +05:30
|
|
|
* Show the list of packages and its action.
|
2014-10-30 15:53:10 +05:30
|
|
|
*/
|
|
|
|
if (trans->dl_pkgcnt) {
|
|
|
|
printf("%u package%s will be downloaded:\n",
|
|
|
|
trans->dl_pkgcnt, trans->dl_pkgcnt == 1 ? "" : "s");
|
2020-02-21 13:38:22 +05:30
|
|
|
show_package_list(trans, XBPS_TRANS_DOWNLOAD, cols);
|
2014-10-30 15:53:10 +05:30
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
if (trans->inst_pkgcnt) {
|
|
|
|
printf("%u package%s will be installed:\n",
|
|
|
|
trans->inst_pkgcnt, trans->inst_pkgcnt == 1 ? "" : "s");
|
2020-02-21 13:38:22 +05:30
|
|
|
show_package_list(trans, XBPS_TRANS_INSTALL, cols);
|
2014-10-30 15:53:10 +05:30
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
if (trans->up_pkgcnt) {
|
|
|
|
printf("%u package%s will be updated:\n",
|
|
|
|
trans->up_pkgcnt, trans->up_pkgcnt == 1 ? "" : "s");
|
2020-02-21 13:38:22 +05:30
|
|
|
show_package_list(trans, XBPS_TRANS_UPDATE, cols);
|
2014-10-30 15:53:10 +05:30
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
if (trans->cf_pkgcnt) {
|
|
|
|
printf("%u package%s will be configured:\n",
|
|
|
|
trans->cf_pkgcnt, trans->cf_pkgcnt == 1 ? "" : "s");
|
2020-02-21 13:38:22 +05:30
|
|
|
show_package_list(trans, XBPS_TRANS_CONFIGURE, cols);
|
2014-10-30 15:53:10 +05:30
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
if (trans->rm_pkgcnt) {
|
|
|
|
printf("%u package%s will be removed:\n",
|
|
|
|
trans->rm_pkgcnt, trans->rm_pkgcnt == 1 ? "" : "s");
|
2020-02-21 13:38:22 +05:30
|
|
|
show_package_list(trans, XBPS_TRANS_REMOVE, cols);
|
2014-10-30 15:53:10 +05:30
|
|
|
printf("\n");
|
|
|
|
}
|
2020-04-23 09:33:56 +05:30
|
|
|
if (trans->hold_pkgcnt) {
|
|
|
|
printf("%u package%s are on hold:\n",
|
|
|
|
trans->hold_pkgcnt, trans->hold_pkgcnt == 1 ? "" : "s");
|
|
|
|
show_package_list(trans, XBPS_TRANS_HOLD, cols);
|
|
|
|
printf("\n");
|
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Show total download/installed/removed size for all required packages.
|
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_uint64(trans->d, "total-download-size", &dlsize);
|
2014-07-13 15:15:04 +05:30
|
|
|
xbps_dictionary_get_uint64(trans->d, "total-installed-size", &instsize);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_uint64(trans->d, "total-removed-size", &rmsize);
|
2014-07-13 15:15:04 +05:30
|
|
|
xbps_dictionary_get_uint64(trans->d, "disk-free-size", &disk_free_size);
|
2019-06-21 19:56:08 +05:30
|
|
|
|
2014-07-13 15:15:04 +05:30
|
|
|
if (dlsize || instsize || rmsize || disk_free_size)
|
2013-03-08 14:31:19 +05:30
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
if (dlsize) {
|
2012-11-02 19:34:25 +05:30
|
|
|
if (xbps_humanize_number(size, (int64_t)dlsize) == -1) {
|
|
|
|
xbps_error_printf("humanize_number returns "
|
|
|
|
"%s\n", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
2013-12-16 11:54:17 +05:30
|
|
|
printf("Size to download: %6s\n", size);
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
2013-03-08 14:31:19 +05:30
|
|
|
if (instsize) {
|
2013-12-16 11:54:17 +05:30
|
|
|
if (xbps_humanize_number(size, (int64_t)instsize) == -1) {
|
2012-11-02 19:34:25 +05:30
|
|
|
xbps_error_printf("humanize_number2 returns "
|
|
|
|
"%s\n", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
2013-12-16 11:54:17 +05:30
|
|
|
printf("Size required on disk: %6s\n", size);
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
2013-03-08 14:31:19 +05:30
|
|
|
if (rmsize) {
|
2012-11-02 19:34:25 +05:30
|
|
|
if (xbps_humanize_number(size, (int64_t)rmsize) == -1) {
|
|
|
|
xbps_error_printf("humanize_number3 returns "
|
|
|
|
"%s\n", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
2013-12-16 11:54:17 +05:30
|
|
|
printf("Size freed on disk: %6s\n", size);
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
2014-07-13 15:15:04 +05:30
|
|
|
if (disk_free_size) {
|
|
|
|
if (xbps_humanize_number(size, (int64_t)disk_free_size) == -1) {
|
|
|
|
xbps_error_printf("humanize_number3 returns "
|
|
|
|
"%s\n", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
2018-05-02 04:15:24 +05:30
|
|
|
printf("Space available on disk: %6s\n", size);
|
2014-07-13 15:15:04 +05:30
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-10 15:56:26 +05:30
|
|
|
static bool
|
2019-12-27 19:03:53 +05:30
|
|
|
all_pkgs_on_hold(struct transaction *trans)
|
|
|
|
{
|
2019-12-10 15:56:26 +05:30
|
|
|
xbps_object_t obj;
|
|
|
|
bool all_on_hold = true;
|
|
|
|
|
|
|
|
while ((obj = xbps_object_iterator_next(trans->iter)) != NULL) {
|
2020-02-22 15:21:27 +05:30
|
|
|
if (xbps_transaction_pkg_type(obj) != XBPS_TRANS_HOLD) {
|
2019-12-10 15:56:26 +05:30
|
|
|
all_on_hold = false;
|
2020-02-21 13:38:22 +05:30
|
|
|
break;
|
2019-12-10 15:56:26 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
xbps_object_iterator_reset(trans->iter);
|
|
|
|
return all_on_hold;
|
|
|
|
}
|
|
|
|
|
2012-11-02 19:34:25 +05:30
|
|
|
int
|
2020-02-22 15:59:18 +05:30
|
|
|
dist_upgrade(struct xbps_handle *xhp, unsigned int cols, bool yes, bool drun)
|
2012-11-02 19:34:25 +05:30
|
|
|
{
|
|
|
|
int rv = 0;
|
|
|
|
|
2019-12-27 19:03:53 +05:30
|
|
|
rv = xbps_transaction_update_packages(xhp);
|
|
|
|
if (rv == ENOENT) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("No packages currently registered.\n");
|
2019-12-27 19:03:53 +05:30
|
|
|
return 0;
|
|
|
|
} else if (rv == EBUSY) {
|
|
|
|
if (drun) {
|
|
|
|
rv = 0;
|
2012-11-02 19:34:25 +05:30
|
|
|
} else {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("The 'xbps' package must be updated, please run `xbps-install -u xbps`\n");
|
2019-12-27 19:03:53 +05:30
|
|
|
return rv;
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
2019-12-27 19:03:53 +05:30
|
|
|
} else if (rv == EEXIST) {
|
|
|
|
return 0;
|
|
|
|
} else if (rv == ENOTSUP) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("No repositories currently registered!\n");
|
2019-12-27 19:03:53 +05:30
|
|
|
return rv;
|
|
|
|
} else if (rv != 0) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Unexpected error: %s\n", strerror(rv));
|
2019-12-27 19:03:53 +05:30
|
|
|
return -1;
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return exec_transaction(xhp, cols, yes, drun);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-04-23 09:33:56 +05:30
|
|
|
install_new_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
|
2012-11-02 19:34:25 +05:30
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
2020-04-23 09:33:56 +05:30
|
|
|
rv = xbps_transaction_install_pkg(xhp, pkg, force);
|
2019-12-27 19:03:53 +05:30
|
|
|
if (rv == EEXIST)
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Package `%s' already installed.\n", pkg);
|
2019-12-27 19:03:53 +05:30
|
|
|
else if (rv == ENOENT)
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Package '%s' not found in repository pool.\n", pkg);
|
2019-12-27 19:03:53 +05:30
|
|
|
else if (rv == ENOTSUP)
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("No repositories currently registered!\n");
|
2019-12-27 19:03:53 +05:30
|
|
|
else if (rv == ENXIO)
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Package `%s' contains invalid dependencies, exiting.\n", pkg);
|
2019-12-27 19:03:53 +05:30
|
|
|
else if (rv == EBUSY)
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("The 'xbps' package must be updated, please run `xbps-install -u xbps`\n");
|
2019-12-27 19:03:53 +05:30
|
|
|
else if (rv != 0) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Unexpected error: %s\n", strerror(rv));
|
2019-12-27 19:03:53 +05:30
|
|
|
rv = -1;
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-04-23 09:33:56 +05:30
|
|
|
update_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
|
2012-11-02 19:34:25 +05:30
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
2020-04-23 09:33:56 +05:30
|
|
|
rv = xbps_transaction_update_pkg(xhp, pkg, force);
|
2019-12-27 19:03:53 +05:30
|
|
|
if (rv == EEXIST)
|
|
|
|
printf("Package '%s' is up to date.\n", pkg);
|
|
|
|
else if (rv == ENOENT)
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Package '%s' not found in repository pool.\n", pkg);
|
2012-11-02 19:34:25 +05:30
|
|
|
else if (rv == ENODEV)
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Package '%s' not installed.\n", pkg);
|
2012-11-02 19:34:25 +05:30
|
|
|
else if (rv == ENOTSUP)
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("No repositories currently registered!\n");
|
2019-12-27 19:03:53 +05:30
|
|
|
else if (rv == ENXIO)
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Package `%s' contains invalid dependencies, exiting.\n", pkg);
|
2019-12-27 19:03:53 +05:30
|
|
|
else if (rv == EBUSY)
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("The 'xbps' package must be updated, please run `xbps-install -u xbps`\n");
|
2012-11-02 19:34:25 +05:30
|
|
|
else if (rv != 0) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Unexpected error: %s\n", strerror(rv));
|
2012-11-02 19:34:25 +05:30
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-02-22 15:59:18 +05:30
|
|
|
exec_transaction(struct xbps_handle *xhp, unsigned int maxcols, bool yes, bool drun)
|
2012-11-02 19:34:25 +05:30
|
|
|
{
|
2014-07-13 13:04:54 +05:30
|
|
|
xbps_array_t array;
|
2012-11-02 19:34:25 +05:30
|
|
|
struct transaction *trans;
|
2015-05-09 10:32:21 +05:30
|
|
|
uint64_t fsize = 0, isize = 0;
|
|
|
|
char freesize[8], instsize[8];
|
2012-11-02 19:34:25 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
trans = calloc(1, sizeof(*trans));
|
|
|
|
if (trans == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
if ((rv = xbps_transaction_prepare(xhp)) != 0) {
|
|
|
|
if (rv == ENODEV) {
|
2014-07-13 13:04:54 +05:30
|
|
|
array = xbps_dictionary_get(xhp->transd, "missing_deps");
|
2014-09-11 03:42:12 +05:30
|
|
|
if (xbps_array_count(array)) {
|
|
|
|
/* missing dependencies */
|
|
|
|
print_array(array);
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Transaction aborted due to unresolved dependencies.\n");
|
2014-09-11 03:42:12 +05:30
|
|
|
}
|
2014-09-12 15:19:34 +05:30
|
|
|
} else if (rv == ENOEXEC) {
|
2014-09-11 03:42:12 +05:30
|
|
|
array = xbps_dictionary_get(xhp->transd, "missing_shlibs");
|
|
|
|
if (xbps_array_count(array)) {
|
|
|
|
/* missing shlibs */
|
|
|
|
print_array(array);
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Transaction aborted due to unresolved shlibs.\n");
|
2014-09-11 03:42:12 +05:30
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
} else if (rv == EAGAIN) {
|
|
|
|
/* conflicts */
|
2014-07-13 13:04:54 +05:30
|
|
|
array = xbps_dictionary_get(xhp->transd, "conflicts");
|
|
|
|
print_array(array);
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Transaction aborted due to conflicting packages.\n");
|
2014-09-18 15:41:02 +05:30
|
|
|
} else if (rv == ENOSPC) {
|
|
|
|
/* not enough free space */
|
2015-05-09 10:32:21 +05:30
|
|
|
xbps_dictionary_get_uint64(xhp->transd,
|
|
|
|
"total-installed-size", &isize);
|
|
|
|
if (xbps_humanize_number(instsize, (int64_t)isize) == -1) {
|
|
|
|
xbps_error_printf("humanize_number2 returns "
|
|
|
|
"%s\n", strerror(errno));
|
2015-07-26 11:48:49 +05:30
|
|
|
rv = -1;
|
|
|
|
goto out;
|
2015-05-09 10:32:21 +05:30
|
|
|
}
|
|
|
|
xbps_dictionary_get_uint64(xhp->transd,
|
|
|
|
"disk-free-size", &fsize);
|
|
|
|
if (xbps_humanize_number(freesize, (int64_t)fsize) == -1) {
|
|
|
|
xbps_error_printf("humanize_number2 returns "
|
|
|
|
"%s\n", strerror(errno));
|
2015-07-26 11:48:49 +05:30
|
|
|
rv = -1;
|
|
|
|
goto out;
|
2015-05-09 10:32:21 +05:30
|
|
|
}
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Transaction aborted due to insufficient disk "
|
2015-05-09 10:32:21 +05:30
|
|
|
"space (need %s, got %s free).\n", instsize, freesize);
|
2020-08-20 17:29:17 +05:30
|
|
|
if (drun) {
|
|
|
|
goto proceed;
|
|
|
|
}
|
2014-09-12 15:19:34 +05:30
|
|
|
} else {
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("Empty transaction dictionary: %s\n",
|
2014-09-12 15:19:34 +05:30
|
|
|
strerror(errno));
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
2014-04-20 13:32:54 +05:30
|
|
|
goto out;
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
2020-08-20 17:29:17 +05:30
|
|
|
proceed:
|
2015-05-28 14:32:40 +05:30
|
|
|
#ifdef FULL_DEBUG
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("Dictionary before transaction happens:\n");
|
|
|
|
xbps_dbg_printf_append("%s",
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_externalize(xhp->transd));
|
2015-05-28 14:32:40 +05:30
|
|
|
#endif
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2014-09-11 15:13:15 +05:30
|
|
|
trans->xhp = xhp;
|
2012-11-02 19:34:25 +05:30
|
|
|
trans->d = xhp->transd;
|
|
|
|
trans->iter = xbps_array_iter_from_dict(xhp->transd, "packages");
|
|
|
|
assert(trans->iter);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dry-run mode, show what would be done but don't run anything.
|
|
|
|
*/
|
|
|
|
if (drun) {
|
|
|
|
show_actions(trans->iter);
|
|
|
|
goto out;
|
|
|
|
}
|
2019-12-10 15:56:26 +05:30
|
|
|
/*
|
|
|
|
* No need to do anything if all packages are on hold.
|
|
|
|
*/
|
|
|
|
if (all_pkgs_on_hold(trans)) {
|
|
|
|
goto out;
|
|
|
|
}
|
2020-02-22 15:21:27 +05:30
|
|
|
/*
|
|
|
|
* Show download/installed size for the transaction.
|
|
|
|
*/
|
|
|
|
if ((rv = show_transaction_sizes(trans, maxcols)) != 0)
|
|
|
|
goto out;
|
2022-02-21 02:07:49 +05:30
|
|
|
|
|
|
|
fflush(stdout);
|
2012-11-02 19:34:25 +05:30
|
|
|
/*
|
|
|
|
* Ask interactively (if -y not set).
|
|
|
|
*/
|
|
|
|
if (!yes && !yesno("Do you want to continue?")) {
|
|
|
|
printf("Aborting!\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* It's time to run the transaction!
|
|
|
|
*/
|
|
|
|
if ((rv = xbps_transaction_commit(xhp)) == 0) {
|
2014-07-14 13:00:28 +05:30
|
|
|
printf("\n%u downloaded, %u installed, %u updated, "
|
2020-04-23 09:33:56 +05:30
|
|
|
"%u configured, %u removed, %u on hold.\n",
|
2014-07-14 13:00:28 +05:30
|
|
|
trans->dl_pkgcnt, trans->inst_pkgcnt,
|
2020-03-31 20:56:38 +05:30
|
|
|
trans->up_pkgcnt,
|
|
|
|
trans->cf_pkgcnt + trans->inst_pkgcnt + trans->up_pkgcnt,
|
2020-04-23 09:33:56 +05:30
|
|
|
trans->rm_pkgcnt,
|
|
|
|
trans->hold_pkgcnt);
|
2019-06-21 14:36:45 +05:30
|
|
|
} else {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Transaction failed! see above for errors.\n");
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
out:
|
|
|
|
if (trans->iter)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_iterator_release(trans->iter);
|
2012-11-02 19:34:25 +05:30
|
|
|
if (trans)
|
|
|
|
free(trans);
|
|
|
|
return rv;
|
|
|
|
}
|