2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2012-01-22 15:22:35 +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-01-14 10:55:01 +05:30
|
|
|
#include <ctype.h>
|
2010-11-13 07:48:58 +05:30
|
|
|
#include <assert.h>
|
2010-11-19 18:10:13 +05:30
|
|
|
#include <unistd.h>
|
2011-01-21 21:46:58 +05:30
|
|
|
#include <limits.h>
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
#include <xbps_api.h>
|
2011-07-09 14:20:44 +05:30
|
|
|
#include "compat.h"
|
2009-08-17 22:37:20 +05:30
|
|
|
#include "defs.h"
|
2010-12-03 22:06:07 +05:30
|
|
|
#include "../xbps-repo/defs.h"
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
struct transaction {
|
2011-07-27 20:43:54 +05:30
|
|
|
prop_dictionary_t d;
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_object_iterator_t iter;
|
2011-07-24 21:13:17 +05:30
|
|
|
uint32_t inst_pkgcnt;
|
|
|
|
uint32_t up_pkgcnt;
|
|
|
|
uint32_t cf_pkgcnt;
|
|
|
|
uint32_t rm_pkgcnt;
|
2009-08-17 22:37:20 +05:30
|
|
|
};
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
static void
|
2011-01-25 07:25:34 +05:30
|
|
|
show_missing_deps(prop_array_t a)
|
2010-01-21 07:40:19 +05:30
|
|
|
{
|
2011-01-30 22:53:33 +05:30
|
|
|
size_t i;
|
2012-06-11 19:44:03 +05:30
|
|
|
const char *str;
|
2011-01-30 22:53:33 +05:30
|
|
|
|
2012-06-11 19:44:03 +05:30
|
|
|
fprintf(stderr, "xbps-bin: unable to locate some required packages:\n");
|
|
|
|
for (i = 0; i < prop_array_count(a); i++) {
|
|
|
|
prop_array_get_cstring_nocopy(a, i, &str);
|
|
|
|
fprintf(stderr, " * Missing binary package for: %s\n", str);
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 22:53:33 +05:30
|
|
|
|
2012-06-11 19:44:03 +05:30
|
|
|
static void
|
|
|
|
show_conflicts(prop_array_t a)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
fprintf(stderr, "xbps-bin: conflicting packages were found:\n");
|
2011-01-30 22:53:33 +05:30
|
|
|
for (i = 0; i < prop_array_count(a); i++) {
|
2012-06-11 19:44:03 +05:30
|
|
|
prop_array_get_cstring_nocopy(a, i, &str);
|
|
|
|
fprintf(stderr, " %s\n", str);
|
2011-01-30 22:53:33 +05:30
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
}
|
|
|
|
|
2012-02-03 19:23:28 +05:30
|
|
|
static void
|
|
|
|
show_actions(prop_object_iterator_t iter)
|
|
|
|
{
|
|
|
|
prop_object_t obj;
|
2012-06-01 14:58:30 +05:30
|
|
|
const char *repoloc, *trans, *pkgname, *version, *fname, *arch;
|
|
|
|
|
|
|
|
repoloc = trans = pkgname = version = fname = arch = NULL;
|
2012-02-03 19:23:28 +05:30
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "transaction", &trans);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
|
|
|
printf("%s %s %s", pkgname, trans, version);
|
2012-06-01 14:58:30 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "filename", &fname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
|
|
|
|
if (repoloc && fname && arch)
|
|
|
|
printf(" %s %s %s", repoloc, fname, arch);
|
2012-02-05 19:26:18 +05:30
|
|
|
|
2012-02-03 19:23:28 +05:30
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-18 22:51:55 +05:30
|
|
|
static int
|
2011-07-27 20:43:54 +05:30
|
|
|
show_binpkgs_url(prop_object_iterator_t iter)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2009-10-27 06:16:00 +05:30
|
|
|
prop_object_t obj;
|
2011-07-27 20:43:54 +05:30
|
|
|
const char *repoloc, *trans;
|
2011-01-18 22:51:55 +05:30
|
|
|
char *binfile;
|
2009-11-28 07:08:41 +05:30
|
|
|
|
2009-10-27 06:16:00 +05:30
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2011-02-24 04:13:45 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "transaction", &trans);
|
|
|
|
if ((strcmp(trans, "remove") == 0) ||
|
|
|
|
(strcmp(trans, "configure") == 0))
|
|
|
|
continue;
|
|
|
|
|
2011-02-01 05:51:54 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"repository", &repoloc))
|
|
|
|
continue;
|
2011-07-27 20:43:54 +05:30
|
|
|
|
|
|
|
/* ignore pkgs from local repositories */
|
|
|
|
if (!xbps_check_is_repository_uri_remote(repoloc))
|
|
|
|
continue;
|
2009-10-27 06:16:00 +05:30
|
|
|
|
2011-06-01 13:07:32 +05:30
|
|
|
binfile = xbps_path_from_repository_uri(obj, repoloc);
|
2011-01-18 22:51:55 +05:30
|
|
|
if (binfile == NULL)
|
2009-10-27 06:16:00 +05:30
|
|
|
return errno;
|
2009-11-28 07:08:41 +05:30
|
|
|
/*
|
2011-07-27 20:43:54 +05:30
|
|
|
* If downloaded package is in cachedir, ignore it.
|
2009-11-28 07:08:41 +05:30
|
|
|
*/
|
2011-01-18 22:51:55 +05:30
|
|
|
if (access(binfile, R_OK) == 0) {
|
2011-01-27 19:06:33 +05:30
|
|
|
free(binfile);
|
|
|
|
continue;
|
|
|
|
}
|
2011-07-27 20:43:54 +05:30
|
|
|
printf("%s\n", binfile);
|
2011-01-18 22:51:55 +05:30
|
|
|
free(binfile);
|
2009-10-27 06:16:00 +05:30
|
|
|
}
|
|
|
|
prop_object_iterator_reset(iter);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
static void
|
|
|
|
show_package_list(prop_object_iterator_t iter, const char *match)
|
|
|
|
{
|
|
|
|
prop_object_t obj;
|
2009-11-22 09:45:47 +05:30
|
|
|
const char *pkgver, *tract;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
2011-02-05 16:51:04 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
|
2009-08-17 22:37:20 +05:30
|
|
|
if (strcmp(match, tract))
|
|
|
|
continue;
|
2011-01-25 22:22:04 +05:30
|
|
|
print_package_line(pkgver, false);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
prop_object_iterator_reset(iter);
|
2011-01-25 22:22:04 +05:30
|
|
|
print_package_line(NULL, true);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-01-21 07:40:19 +05:30
|
|
|
show_transaction_sizes(struct transaction *trans)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-11-27 13:35:18 +05:30
|
|
|
uint64_t dlsize = 0, instsize = 0, rmsize = 0;
|
2011-01-19 03:40:07 +05:30
|
|
|
char size[8];
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Show the list of packages that will be installed.
|
|
|
|
*/
|
2011-07-27 20:43:54 +05:30
|
|
|
if (prop_dictionary_get_uint32(trans->d, "total-install-pkgs",
|
2011-07-24 21:13:17 +05:30
|
|
|
&trans->inst_pkgcnt)) {
|
2011-10-19 01:10:26 +05:30
|
|
|
printf("%u package%s will be installed:\n",
|
2011-02-05 16:17:02 +05:30
|
|
|
trans->inst_pkgcnt, trans->inst_pkgcnt == 1 ? "" : "s");
|
2010-01-21 07:40:19 +05:30
|
|
|
show_package_list(trans->iter, "install");
|
2011-10-19 19:55:06 +05:30
|
|
|
printf("\n");
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2011-07-27 20:43:54 +05:30
|
|
|
if (prop_dictionary_get_uint32(trans->d, "total-update-pkgs",
|
2011-07-24 21:13:17 +05:30
|
|
|
&trans->up_pkgcnt)) {
|
2011-10-19 01:10:26 +05:30
|
|
|
printf("%u package%s will be updated:\n",
|
2011-02-05 16:17:02 +05:30
|
|
|
trans->up_pkgcnt, trans->up_pkgcnt == 1 ? "" : "s");
|
2010-01-21 07:40:19 +05:30
|
|
|
show_package_list(trans->iter, "update");
|
2011-10-19 19:55:06 +05:30
|
|
|
printf("\n");
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2011-07-27 20:43:54 +05:30
|
|
|
if (prop_dictionary_get_uint32(trans->d, "total-configure-pkgs",
|
2011-07-24 21:13:17 +05:30
|
|
|
&trans->cf_pkgcnt)) {
|
2011-10-19 01:10:26 +05:30
|
|
|
printf("%u package%s will be configured:\n",
|
2011-02-05 16:17:02 +05:30
|
|
|
trans->cf_pkgcnt, trans->cf_pkgcnt == 1 ? "" : "s");
|
2010-01-21 07:40:19 +05:30
|
|
|
show_package_list(trans->iter, "configure");
|
2011-10-19 19:55:06 +05:30
|
|
|
printf("\n");
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
2011-07-27 20:43:54 +05:30
|
|
|
if (prop_dictionary_get_uint32(trans->d, "total-remove-pkgs",
|
2011-07-24 21:13:17 +05:30
|
|
|
&trans->rm_pkgcnt)) {
|
2011-10-19 01:10:26 +05:30
|
|
|
printf("%u package%s will be removed:\n",
|
2011-02-05 16:17:02 +05:30
|
|
|
trans->rm_pkgcnt, trans->rm_pkgcnt == 1 ? "" : "s");
|
2011-02-01 05:51:54 +05:30
|
|
|
show_package_list(trans->iter, "remove");
|
2011-10-19 01:10:26 +05:30
|
|
|
printf("\n");
|
2011-02-01 05:51:54 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
2011-11-27 13:35:18 +05:30
|
|
|
* Show total download/installed/removed size for all required packages.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2011-11-27 13:35:18 +05:30
|
|
|
printf("\n");
|
2011-07-27 20:43:54 +05:30
|
|
|
prop_dictionary_get_uint64(trans->d, "total-download-size", &dlsize);
|
2011-11-27 13:35:18 +05:30
|
|
|
if (dlsize > 0) {
|
|
|
|
if (xbps_humanize_number(size, (int64_t)dlsize) == -1) {
|
|
|
|
xbps_error_printf("xbps-bin: error: humanize_number returns "
|
|
|
|
"%s\n", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
printf("Total download size:\t%6s\n", size);
|
|
|
|
}
|
2011-07-27 20:43:54 +05:30
|
|
|
prop_dictionary_get_uint64(trans->d, "total-installed-size",
|
2010-11-06 11:14:00 +05:30
|
|
|
&instsize);
|
2011-11-27 13:35:18 +05:30
|
|
|
if (instsize > 0) {
|
|
|
|
if (xbps_humanize_number(size, (int64_t)instsize) == -1) {
|
|
|
|
xbps_error_printf("xbps-bin: error: humanize_number2 returns "
|
|
|
|
"%s\n", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
2011-12-18 05:40:24 +05:30
|
|
|
printf("Total installed size:\t%6s\n", size);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2011-11-27 13:35:18 +05:30
|
|
|
prop_dictionary_get_uint64(trans->d, "total-removed-size", &rmsize);
|
|
|
|
if (rmsize > 0) {
|
|
|
|
if (xbps_humanize_number(size, (int64_t)rmsize) == -1) {
|
|
|
|
xbps_error_printf("xbps-bin: error: humanize_number3 returns "
|
|
|
|
"%s\n", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
2012-01-25 09:26:54 +05:30
|
|
|
printf("Total freed size:\t%6s\n", size);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2011-12-18 05:40:24 +05:30
|
|
|
printf("\n");
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-23 17:31:54 +05:30
|
|
|
int
|
2012-05-08 13:24:06 +05:30
|
|
|
dist_upgrade(bool yes, bool dry_run, bool show_download_pkglist_url)
|
2009-12-22 17:07:36 +05:30
|
|
|
{
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update all currently installed packages, aka
|
|
|
|
* "xbps-bin autoupdate".
|
|
|
|
*/
|
2011-11-25 14:42:03 +05:30
|
|
|
if ((rv = xbps_transaction_update_packages()) != 0) {
|
2009-12-22 17:07:36 +05:30
|
|
|
if (rv == ENOENT) {
|
|
|
|
printf("No packages currently registered.\n");
|
|
|
|
return 0;
|
2011-07-29 14:47:34 +05:30
|
|
|
} else if (rv == EEXIST) {
|
2009-12-22 17:07:36 +05:30
|
|
|
printf("All packages are up-to-date.\n");
|
|
|
|
return 0;
|
2011-07-29 14:47:34 +05:30
|
|
|
} else if (rv == ENOTSUP) {
|
|
|
|
xbps_error_printf("xbps-bin: no repositories currently "
|
|
|
|
"registered!\n");
|
|
|
|
return -1;
|
2010-11-19 18:10:13 +05:30
|
|
|
} else {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-bin: unexpected error %s\n",
|
2010-11-19 18:10:13 +05:30
|
|
|
strerror(rv));
|
|
|
|
return -1;
|
2009-12-22 17:07:36 +05:30
|
|
|
}
|
|
|
|
}
|
2012-02-03 19:23:28 +05:30
|
|
|
return exec_transaction(yes, dry_run, show_download_pkglist_url);
|
2009-12-22 17:07:36 +05:30
|
|
|
}
|
|
|
|
|
2011-11-25 15:50:03 +05:30
|
|
|
int
|
2012-05-08 13:28:56 +05:30
|
|
|
remove_pkg_orphans(bool yes, bool dry_run)
|
2011-11-25 15:50:03 +05:30
|
|
|
{
|
2012-01-25 06:44:04 +05:30
|
|
|
int rv;
|
2011-11-25 15:50:03 +05:30
|
|
|
|
2011-12-24 05:35:26 +05:30
|
|
|
if ((rv = xbps_transaction_autoremove_pkgs()) != 0) {
|
2011-11-25 15:50:03 +05:30
|
|
|
if (rv == ENOENT) {
|
|
|
|
printf("No package orphans were found.\n");
|
|
|
|
return 0;
|
|
|
|
} else {
|
2012-05-08 13:28:56 +05:30
|
|
|
printf("Failed to remove package orphans: %s\n",
|
2011-11-25 15:50:03 +05:30
|
|
|
strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
2012-02-03 19:23:28 +05:30
|
|
|
return exec_transaction(yes, dry_run, false);
|
2011-11-25 15:50:03 +05:30
|
|
|
}
|
|
|
|
|
2010-01-14 10:55:01 +05:30
|
|
|
int
|
2011-12-20 20:38:23 +05:30
|
|
|
install_new_pkg(const char *pkg, bool reinstall)
|
2010-01-14 10:55:01 +05:30
|
|
|
{
|
2012-01-25 06:44:04 +05:30
|
|
|
int rv;
|
2010-01-14 10:55:01 +05:30
|
|
|
|
2012-01-25 06:44:04 +05:30
|
|
|
if ((rv = xbps_transaction_install_pkg(pkg, reinstall)) != 0) {
|
2012-02-18 20:45:54 +05:30
|
|
|
if (rv == EEXIST) {
|
2012-01-25 06:44:04 +05:30
|
|
|
printf("Package `%s' already installed.\n", pkg);
|
|
|
|
} else if (rv == ENOENT) {
|
2011-07-29 14:47:34 +05:30
|
|
|
xbps_error_printf("xbps-bin: unable to locate '%s' in "
|
2010-11-19 18:10:13 +05:30
|
|
|
"repository pool.\n", pkg);
|
2011-07-29 14:47:34 +05:30
|
|
|
} else if (rv == ENOTSUP) {
|
|
|
|
xbps_error_printf("xbps-bin: no repositories "
|
|
|
|
"currently registered!\n");
|
2010-11-19 18:10:13 +05:30
|
|
|
} else {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-bin: unexpected error: %s\n",
|
2010-11-19 18:10:13 +05:30
|
|
|
strerror(rv));
|
|
|
|
rv = -1;
|
|
|
|
}
|
2009-12-22 17:07:36 +05:30
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2009-10-16 21:07:32 +05:30
|
|
|
|
2009-12-22 17:07:36 +05:30
|
|
|
int
|
2011-07-27 20:43:54 +05:30
|
|
|
update_pkg(const char *pkgname)
|
2009-12-22 17:07:36 +05:30
|
|
|
{
|
2012-01-25 06:44:04 +05:30
|
|
|
int rv;
|
2009-12-22 17:07:36 +05:30
|
|
|
|
2011-11-25 14:42:03 +05:30
|
|
|
rv = xbps_transaction_update_pkg(pkgname);
|
2010-11-19 18:10:13 +05:30
|
|
|
if (rv == EEXIST)
|
|
|
|
printf("Package '%s' is up to date.\n", pkgname);
|
|
|
|
else if (rv == ENOENT)
|
|
|
|
fprintf(stderr, "Package '%s' not found in "
|
|
|
|
"repository pool.\n", pkgname);
|
|
|
|
else if (rv == ENODEV)
|
2009-12-22 17:07:36 +05:30
|
|
|
printf("Package '%s' not installed.\n", pkgname);
|
2011-07-29 14:47:34 +05:30
|
|
|
else if (rv == ENOTSUP)
|
|
|
|
xbps_error_printf("xbps-bin: no repositories currently "
|
|
|
|
"registered!\n");
|
2010-11-19 18:10:13 +05:30
|
|
|
else if (rv != 0) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-bin: unexpected error %s\n",
|
2010-11-19 18:10:13 +05:30
|
|
|
strerror(rv));
|
|
|
|
return -1;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2011-11-01 01:58:21 +05:30
|
|
|
return rv;
|
2009-12-22 17:07:36 +05:30
|
|
|
}
|
|
|
|
|
2011-11-27 13:35:18 +05:30
|
|
|
int
|
2011-12-24 05:35:26 +05:30
|
|
|
remove_pkg(const char *pkgname, bool recursive)
|
2011-11-27 13:35:18 +05:30
|
|
|
{
|
2011-11-27 14:29:39 +05:30
|
|
|
prop_dictionary_t pkgd;
|
|
|
|
prop_array_t reqby;
|
|
|
|
const char *pkgver;
|
|
|
|
size_t x;
|
2011-11-27 13:35:18 +05:30
|
|
|
int rv;
|
|
|
|
|
2011-12-24 05:35:26 +05:30
|
|
|
rv = xbps_transaction_remove_pkg(pkgname, recursive);
|
2011-11-27 14:29:39 +05:30
|
|
|
if (rv == EEXIST) {
|
|
|
|
/* pkg has revdeps */
|
|
|
|
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
|
|
|
reqby = prop_dictionary_get(pkgd, "requiredby");
|
|
|
|
prop_object_release(pkgd);
|
|
|
|
printf("WARNING: %s IS REQUIRED BY %u PACKAGE%s:\n\n",
|
|
|
|
pkgver, prop_array_count(reqby),
|
|
|
|
prop_array_count(reqby) > 1 ? "S" : "");
|
|
|
|
for (x = 0; x < prop_array_count(reqby); x++) {
|
|
|
|
prop_array_get_cstring_nocopy(reqby, x, &pkgver);
|
|
|
|
print_package_line(pkgver, false);
|
|
|
|
}
|
|
|
|
printf("\n\n");
|
|
|
|
print_package_line(NULL, true);
|
2011-11-27 13:35:18 +05:30
|
|
|
return rv;
|
2011-11-27 14:29:39 +05:30
|
|
|
} else if (rv == ENOENT) {
|
2011-11-27 13:35:18 +05:30
|
|
|
printf("Package `%s' is not currently installed.\n", pkgname);
|
|
|
|
return 0;
|
2011-11-27 13:59:13 +05:30
|
|
|
} else if (rv != 0) {
|
2011-11-27 13:35:18 +05:30
|
|
|
xbps_error_printf("Failed to queue `%s' for removing: %s\n",
|
|
|
|
pkgname, strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int
|
2012-02-03 19:23:28 +05:30
|
|
|
exec_transaction(bool yes, bool dry_run, bool show_download_urls)
|
2010-01-21 07:40:19 +05:30
|
|
|
{
|
2012-06-11 19:44:03 +05:30
|
|
|
prop_array_t mdeps, cflicts;
|
2010-01-21 07:40:19 +05:30
|
|
|
struct transaction *trans;
|
2012-01-22 14:30:46 +05:30
|
|
|
struct xbps_handle *xhp = xbps_handle_get();
|
2010-01-21 07:40:19 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
2011-07-27 20:43:54 +05:30
|
|
|
trans = calloc(1, sizeof(*trans));
|
2010-01-21 07:40:19 +05:30
|
|
|
if (trans == NULL)
|
2011-07-27 20:43:54 +05:30
|
|
|
return ENOMEM;
|
2010-01-21 07:40:19 +05:30
|
|
|
|
2012-01-22 14:30:46 +05:30
|
|
|
if ((rv = xbps_transaction_prepare()) != 0) {
|
|
|
|
if (rv == ENODEV) {
|
|
|
|
mdeps =
|
|
|
|
prop_dictionary_get(xhp->transd, "missing_deps");
|
2011-01-24 21:25:58 +05:30
|
|
|
/* missing packages */
|
2012-01-22 14:30:46 +05:30
|
|
|
show_missing_deps(mdeps);
|
2011-01-24 21:25:58 +05:30
|
|
|
goto out;
|
2012-06-11 19:44:03 +05:30
|
|
|
} else if (rv == EAGAIN) {
|
|
|
|
/* conflicts */
|
|
|
|
cflicts = prop_dictionary_get(xhp->transd, "conflicts");
|
|
|
|
show_conflicts(cflicts);
|
|
|
|
goto out;
|
2011-01-24 21:25:58 +05:30
|
|
|
}
|
2010-11-24 03:47:04 +05:30
|
|
|
xbps_dbg_printf("Empty transaction dictionary: %s\n",
|
|
|
|
strerror(errno));
|
2012-01-22 14:30:46 +05:30
|
|
|
return rv;
|
2010-11-19 18:10:13 +05:30
|
|
|
}
|
2010-12-03 22:06:07 +05:30
|
|
|
xbps_dbg_printf("Dictionary before transaction happens:\n");
|
2012-01-22 14:30:46 +05:30
|
|
|
xbps_dbg_printf_append("%s", prop_dictionary_externalize(xhp->transd));
|
2010-01-21 07:40:19 +05:30
|
|
|
|
2012-01-22 14:30:46 +05:30
|
|
|
trans->d = xhp->transd;
|
|
|
|
trans->iter = xbps_array_iter_from_dict(xhp->transd, "packages");
|
2010-01-21 07:40:19 +05:30
|
|
|
if (trans->iter == NULL) {
|
2011-02-25 16:57:42 +05:30
|
|
|
rv = errno;
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-bin: error allocating array mem! (%s)\n",
|
2010-01-21 07:40:19 +05:30
|
|
|
strerror(errno));
|
|
|
|
goto out;
|
|
|
|
}
|
2012-02-03 19:23:28 +05:30
|
|
|
/*
|
|
|
|
* dry-run mode, show what would be done but don't run anything.
|
|
|
|
*/
|
|
|
|
if (dry_run) {
|
|
|
|
show_actions(trans->iter);
|
|
|
|
goto out;
|
|
|
|
}
|
2011-07-27 20:43:54 +05:30
|
|
|
/*
|
|
|
|
* Only show URLs to download binary packages.
|
|
|
|
*/
|
|
|
|
if (show_download_urls) {
|
|
|
|
rv = show_binpkgs_url(trans->iter);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Show download/installed size for the transaction.
|
|
|
|
*/
|
|
|
|
if ((rv = show_transaction_sizes(trans)) != 0)
|
|
|
|
goto out;
|
|
|
|
/*
|
|
|
|
* Ask interactively (if -y not set).
|
|
|
|
*/
|
2012-05-31 11:33:54 +05:30
|
|
|
if (!yes && !yesno("Do you want to continue?")) {
|
2011-07-27 20:43:54 +05:30
|
|
|
printf("Aborting!\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* It's time to run the transaction!
|
|
|
|
*/
|
2012-01-22 14:30:46 +05:30
|
|
|
if ((rv = xbps_transaction_commit()) == 0) {
|
2011-07-27 20:43:54 +05:30
|
|
|
printf("\nxbps-bin: %u installed, %u updated, "
|
|
|
|
"%u configured, %u removed.\n", trans->inst_pkgcnt,
|
|
|
|
trans->up_pkgcnt, trans->cf_pkgcnt + trans->inst_pkgcnt,
|
|
|
|
trans->rm_pkgcnt);
|
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
out:
|
|
|
|
if (trans->iter)
|
|
|
|
prop_object_iterator_release(trans->iter);
|
|
|
|
if (trans)
|
|
|
|
free(trans);
|
2011-01-24 21:25:58 +05:30
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
return rv;
|
|
|
|
}
|