2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2011-01-21 21:46:58 +05:30
|
|
|
* Copyright (c) 2009-2011 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 {
|
|
|
|
prop_dictionary_t dict;
|
|
|
|
prop_object_iterator_t iter;
|
2009-12-22 19:13:38 +05:30
|
|
|
bool yes;
|
2011-01-27 19:06:33 +05:30
|
|
|
bool only_show;
|
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
|
|
|
prop_object_t obj;
|
|
|
|
size_t i;
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
fprintf(stderr,
|
|
|
|
"xbps-bin: unable to locate some required packages:\n");
|
2011-01-30 22:53:33 +05:30
|
|
|
|
|
|
|
for (i = 0; i < prop_array_count(a); i++) {
|
|
|
|
obj = prop_array_get(a, i);
|
|
|
|
fprintf(stderr, " * Missing binary package for: %s\n",
|
|
|
|
prop_string_cstring_nocopy(obj));
|
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
}
|
|
|
|
|
2011-01-18 22:51:55 +05:30
|
|
|
static int
|
2011-01-30 22:53:33 +05:30
|
|
|
check_binpkg_hash(const char *path,
|
|
|
|
const char *filename,
|
2009-11-28 07:08:41 +05:30
|
|
|
const char *sha256)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-01-18 22:51:55 +05:30
|
|
|
int rv;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-11-28 07:08:41 +05:30
|
|
|
printf("Checking %s integrity... ", filename);
|
2011-06-01 13:07:32 +05:30
|
|
|
rv = xbps_file_hash_check(path, sha256);
|
2009-11-28 07:08:41 +05:30
|
|
|
if (rv != 0 && rv != ERANGE) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("\nxbps-bin: unexpected error: %s\n",
|
2010-01-15 19:49:16 +05:30
|
|
|
strerror(rv));
|
2011-01-18 22:51:55 +05:30
|
|
|
return rv;
|
2009-11-28 07:08:41 +05:30
|
|
|
} else if (rv == ERANGE) {
|
2010-01-25 07:44:54 +05:30
|
|
|
printf("hash mismatch!\n");
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_warn_printf("Package '%s' has wrong checksum, removing "
|
2011-01-18 22:51:55 +05:30
|
|
|
"and refetching it again...\n", filename);
|
|
|
|
(void)remove(path);
|
|
|
|
return rv;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2009-11-28 07:08:41 +05:30
|
|
|
printf("OK.\n");
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-01-18 22:51:55 +05:30
|
|
|
return 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2009-10-27 06:16:00 +05:30
|
|
|
static int
|
2011-01-27 19:06:33 +05:30
|
|
|
download_package_list(prop_object_iterator_t iter, bool only_show)
|
2009-10-27 06:16:00 +05:30
|
|
|
{
|
2011-02-21 22:12:47 +05:30
|
|
|
const struct xbps_handle *xhp;
|
2009-10-27 06:16:00 +05:30
|
|
|
prop_object_t obj;
|
2011-02-24 04:13:45 +05:30
|
|
|
const char *pkgver, *repoloc, *filename, *sha256, *trans;
|
2011-01-18 22:51:55 +05:30
|
|
|
char *binfile;
|
2009-10-27 06:16:00 +05:30
|
|
|
int rv = 0;
|
2011-01-18 22:51:55 +05:30
|
|
|
bool cksum;
|
2009-11-28 07:08:41 +05:30
|
|
|
|
2011-02-21 22:12:47 +05:30
|
|
|
xhp = xbps_handle_get();
|
2011-01-18 22:51:55 +05:30
|
|
|
again:
|
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-01-18 22:51:55 +05:30
|
|
|
cksum = false;
|
|
|
|
prop_dictionary_get_bool(obj, "checksum_ok", &cksum);
|
|
|
|
if (cksum == true)
|
|
|
|
continue;
|
|
|
|
|
2011-02-01 05:51:54 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"repository", &repoloc))
|
|
|
|
continue;
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"filename-sha256", &sha256);
|
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
|
|
|
/*
|
|
|
|
* If downloaded package is in cachedir, check its hash
|
2011-01-18 22:51:55 +05:30
|
|
|
* and refetch the binpkg again if didn't match.
|
2009-11-28 07:08:41 +05:30
|
|
|
*/
|
2011-01-18 22:51:55 +05:30
|
|
|
if (access(binfile, R_OK) == 0) {
|
|
|
|
rv = check_binpkg_hash(binfile, filename, sha256);
|
|
|
|
free(binfile);
|
|
|
|
if (rv != 0 && rv != ERANGE) {
|
|
|
|
return rv;
|
|
|
|
} else if (rv == ERANGE) {
|
|
|
|
break;
|
2009-11-28 07:08:41 +05:30
|
|
|
}
|
2011-01-18 22:51:55 +05:30
|
|
|
prop_dictionary_set_bool(obj, "checksum_ok", true);
|
|
|
|
continue;
|
2009-11-28 07:08:41 +05:30
|
|
|
}
|
2011-01-27 19:06:33 +05:30
|
|
|
if (only_show) {
|
|
|
|
printf("%s\n", binfile);
|
|
|
|
free(binfile);
|
|
|
|
continue;
|
|
|
|
}
|
2011-02-21 22:12:47 +05:30
|
|
|
if (xbps_mkpath(xhp->cachedir, 0755) == -1) {
|
2011-06-04 20:07:05 +05:30
|
|
|
xbps_error_printf("xbps-bin: cannot mkdir cachedir "
|
|
|
|
"`%s': %s.\n", xhp->cachedir, strerror(errno));
|
2011-01-18 22:51:55 +05:30
|
|
|
free(binfile);
|
2009-10-27 06:16:00 +05:30
|
|
|
return errno;
|
|
|
|
}
|
2009-11-22 09:45:47 +05:30
|
|
|
printf("Downloading %s binary package ...\n", pkgver);
|
2011-02-21 22:12:47 +05:30
|
|
|
rv = xbps_fetch_file(binfile, xhp->cachedir, false, NULL);
|
2009-11-24 10:33:26 +05:30
|
|
|
if (rv == -1) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-bin: couldn't download `%s'\n",
|
2010-01-21 07:40:19 +05:30
|
|
|
filename);
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-bin: %s returned: `%s'\n",
|
2010-01-21 07:40:19 +05:30
|
|
|
repoloc, xbps_fetch_error_string());
|
2011-01-18 22:51:55 +05:30
|
|
|
free(binfile);
|
2010-01-21 07:40:19 +05:30
|
|
|
return -1;
|
2009-10-27 06:16:00 +05:30
|
|
|
}
|
2011-01-18 22:51:55 +05:30
|
|
|
free(binfile);
|
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-11-23 15:16:51 +05:30
|
|
|
return errno;
|
2011-01-18 22:51:55 +05:30
|
|
|
|
|
|
|
rv = check_binpkg_hash(binfile, filename, sha256);
|
|
|
|
free(binfile);
|
|
|
|
if (rv != 0 && rv != ERANGE) {
|
|
|
|
return rv;
|
|
|
|
} else if (rv == ERANGE) {
|
|
|
|
break;
|
2009-11-23 15:16:51 +05:30
|
|
|
}
|
2011-01-18 22:51:55 +05:30
|
|
|
prop_dictionary_set_bool(obj, "checksum_ok", true);
|
2009-10-27 06:16:00 +05:30
|
|
|
}
|
|
|
|
prop_object_iterator_reset(iter);
|
2011-01-18 22:51:55 +05:30
|
|
|
if (rv == ERANGE)
|
|
|
|
goto again;
|
2009-10-27 06:16:00 +05:30
|
|
|
|
|
|
|
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
|
|
|
{
|
2010-01-21 07:40:19 +05:30
|
|
|
uint64_t dlsize = 0, instsize = 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-24 21:13:17 +05:30
|
|
|
if (prop_dictionary_get_uint32(trans->dict, "total-install-pkgs",
|
|
|
|
&trans->inst_pkgcnt)) {
|
|
|
|
printf("%u package%s will be installed:\n\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");
|
2009-08-17 22:37:20 +05:30
|
|
|
printf("\n\n");
|
|
|
|
}
|
2011-07-24 21:13:17 +05:30
|
|
|
if (prop_dictionary_get_uint32(trans->dict, "total-update-pkgs",
|
|
|
|
&trans->up_pkgcnt)) {
|
|
|
|
printf("%u package%s will be updated:\n\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");
|
2009-08-17 22:37:20 +05:30
|
|
|
printf("\n\n");
|
|
|
|
}
|
2011-07-24 21:13:17 +05:30
|
|
|
if (prop_dictionary_get_uint32(trans->dict, "total-configure-pkgs",
|
|
|
|
&trans->cf_pkgcnt)) {
|
|
|
|
printf("%u package%s will be configured:\n\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");
|
2009-11-26 07:52:50 +05:30
|
|
|
printf("\n\n");
|
|
|
|
}
|
2011-07-24 21:13:17 +05:30
|
|
|
if (prop_dictionary_get_uint32(trans->dict, "total-remove-pkgs",
|
|
|
|
&trans->rm_pkgcnt)) {
|
|
|
|
printf("%u package%s will be removed:\n\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");
|
|
|
|
printf("\n\n");
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Show total download/installed size for all required packages.
|
|
|
|
*/
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_uint64(trans->dict, "total-download-size", &dlsize);
|
|
|
|
prop_dictionary_get_uint64(trans->dict, "total-installed-size",
|
|
|
|
&instsize);
|
2011-01-19 03:40:07 +05:30
|
|
|
if (xbps_humanize_number(size, (int64_t)dlsize) == -1) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-bin: error: humanize_number returns "
|
2010-01-15 19:49:16 +05:30
|
|
|
"%s\n", strerror(errno));
|
2009-08-17 22:37:20 +05:30
|
|
|
return -1;
|
|
|
|
}
|
2011-01-30 17:10:16 +05:30
|
|
|
printf("Total download size:\t%6s\n", size);
|
2011-01-19 03:40:07 +05:30
|
|
|
if (xbps_humanize_number(size, (int64_t)instsize) == -1) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-bin: error: humanize_number2 returns "
|
2010-01-15 19:49:16 +05:30
|
|
|
"%s\n", strerror(errno));
|
2009-08-17 22:37:20 +05:30
|
|
|
return -1;
|
|
|
|
}
|
2011-01-30 17:10:16 +05:30
|
|
|
printf("Total installed size:\t%6s\n\n", size);
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-23 17:31:54 +05:30
|
|
|
int
|
2011-01-27 19:06:33 +05:30
|
|
|
xbps_autoupdate_pkgs(bool yes, 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".
|
|
|
|
*/
|
|
|
|
printf("Finding new packages...\n");
|
2011-06-01 13:07:32 +05:30
|
|
|
if ((rv = xbps_repository_update_packages()) != 0) {
|
2009-12-22 17:07:36 +05:30
|
|
|
if (rv == ENOENT) {
|
|
|
|
printf("No packages currently registered.\n");
|
|
|
|
return 0;
|
2010-11-19 18:10:13 +05:30
|
|
|
} else if (rv == ENXIO) {
|
2009-12-22 17:07:36 +05:30
|
|
|
printf("All packages are up-to-date.\n");
|
|
|
|
return 0;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-27 19:06:33 +05:30
|
|
|
return xbps_exec_transaction(yes, show_download_pkglist_url);
|
2009-12-22 17:07:36 +05:30
|
|
|
}
|
|
|
|
|
2010-01-14 10:55:01 +05:30
|
|
|
int
|
|
|
|
xbps_install_new_pkg(const char *pkg)
|
|
|
|
{
|
|
|
|
prop_dictionary_t pkgd;
|
2010-02-26 10:43:33 +05:30
|
|
|
char *pkgname = NULL, *pkgpatt = NULL;
|
2010-01-14 10:55:01 +05:30
|
|
|
int rv = 0;
|
|
|
|
bool pkgmatch = false;
|
2011-02-22 15:37:34 +05:30
|
|
|
pkg_state_t state;
|
2010-01-14 10:55:01 +05:30
|
|
|
|
2011-06-01 13:07:32 +05:30
|
|
|
if (xbps_pkgpattern_version(pkg)) {
|
2010-02-26 10:43:33 +05:30
|
|
|
pkgpatt = __UNCONST(pkg);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If only pkgname has been specified, always append
|
|
|
|
* '>=0' at the end, will be easier to parse.
|
|
|
|
*/
|
2010-01-14 10:55:01 +05:30
|
|
|
pkgmatch = true;
|
2010-02-26 10:43:33 +05:30
|
|
|
pkgpatt = xbps_xasprintf("%s%s", pkg, ">=0");
|
|
|
|
if (pkgpatt == NULL)
|
|
|
|
return -1;
|
|
|
|
}
|
2011-06-01 13:07:32 +05:30
|
|
|
pkgname = xbps_pkgpattern_name(pkgpatt);
|
2010-02-26 10:43:33 +05:30
|
|
|
if (pkgname == NULL)
|
|
|
|
return -1;
|
2009-12-22 17:07:36 +05:30
|
|
|
/*
|
|
|
|
* Find a package in a repository and prepare for installation.
|
|
|
|
*/
|
2010-01-21 07:40:19 +05:30
|
|
|
if ((pkgd = xbps_find_pkg_dict_installed(pkgname, false))) {
|
2011-06-01 13:07:32 +05:30
|
|
|
if ((rv = xbps_pkg_state_dictionary(pkgd, &state)) != 0) {
|
2011-02-22 15:37:34 +05:30
|
|
|
prop_object_release(pkgd);
|
|
|
|
goto out;
|
|
|
|
}
|
2009-12-22 17:07:36 +05:30
|
|
|
prop_object_release(pkgd);
|
2011-02-22 15:37:34 +05:30
|
|
|
if (state == XBPS_PKG_STATE_INSTALLED) {
|
|
|
|
printf("Package '%s' is already installed.\n", pkgname);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
printf("Package `%s' needs to be configured.\n", pkgname);
|
2009-12-22 17:07:36 +05:30
|
|
|
}
|
2010-11-19 18:10:13 +05:30
|
|
|
if ((rv = xbps_repository_install_pkg(pkgpatt)) != 0) {
|
2011-01-24 23:19:24 +05:30
|
|
|
if (rv == ENOENT) {
|
2010-11-19 18:10:13 +05:30
|
|
|
fprintf(stderr, "xbps-bin: unable to locate '%s' in "
|
|
|
|
"repository pool.\n", pkg);
|
|
|
|
} 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
|
|
|
}
|
2011-02-22 15:37:34 +05:30
|
|
|
out:
|
2010-01-14 06:44:31 +05:30
|
|
|
if (pkgmatch)
|
2010-02-26 10:43:33 +05:30
|
|
|
free(pkgpatt);
|
|
|
|
free(pkgname);
|
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
|
|
|
|
xbps_update_pkg(const char *pkgname)
|
|
|
|
{
|
|
|
|
int rv = 0;
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = xbps_repository_update_pkg(pkgname);
|
|
|
|
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);
|
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
|
|
|
}
|
2010-11-19 18:10:13 +05:30
|
|
|
return 0;
|
2009-12-22 17:07:36 +05:30
|
|
|
}
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
static int
|
|
|
|
exec_transaction(struct transaction *trans)
|
|
|
|
{
|
|
|
|
prop_dictionary_t instpkgd;
|
2009-10-17 08:29:59 +05:30
|
|
|
prop_object_t obj;
|
2011-01-21 21:46:58 +05:30
|
|
|
const char *pkgname, *version, *pkgver, *instver, *filen, *tract;
|
2011-02-21 22:12:47 +05:30
|
|
|
int rv = 0;
|
2011-04-11 18:12:06 +05:30
|
|
|
bool update, preserve;
|
2011-02-01 05:51:54 +05:30
|
|
|
pkg_state_t state;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-01-27 19:06:33 +05:30
|
|
|
/*
|
|
|
|
* Only show the URLs to download the binary packages.
|
|
|
|
*/
|
|
|
|
if (trans->only_show)
|
|
|
|
return download_package_list(trans->iter, true);
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Show download/installed size for the transaction.
|
|
|
|
*/
|
2010-01-21 07:40:19 +05:30
|
|
|
if ((rv = show_transaction_sizes(trans)) != 0)
|
2009-08-17 22:37:20 +05:30
|
|
|
return rv;
|
|
|
|
/*
|
2009-12-22 19:13:38 +05:30
|
|
|
* Ask interactively (if -y not set).
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2009-12-22 19:13:38 +05:30
|
|
|
if (trans->yes == false) {
|
2009-08-17 22:37:20 +05:30
|
|
|
if (xbps_noyes("Do you want to continue?") == false) {
|
|
|
|
printf("Aborting!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2009-10-27 06:16:00 +05:30
|
|
|
/*
|
2009-11-28 07:08:41 +05:30
|
|
|
* Download binary packages (if they come from a remote repository)
|
|
|
|
* and check its SHA256 hash.
|
2009-10-27 06:16:00 +05:30
|
|
|
*/
|
2011-02-22 15:37:34 +05:30
|
|
|
printf("[*] Downloading/integrity check ...\n");
|
2011-01-27 19:06:33 +05:30
|
|
|
if ((rv = download_package_list(trans->iter, false)) != 0)
|
2009-10-27 06:16:00 +05:30
|
|
|
return rv;
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
2011-02-18 21:09:42 +05:30
|
|
|
* Remove packages to be replaced.
|
|
|
|
*/
|
2011-07-24 21:13:17 +05:30
|
|
|
if (trans->rm_pkgcnt) {
|
2011-02-22 15:37:34 +05:30
|
|
|
printf("\n[*] Removing packages to be replaced ...\n");
|
2011-02-18 21:09:42 +05:30
|
|
|
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
2011-02-22 15:37:34 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "transaction",
|
|
|
|
&tract);
|
|
|
|
if (strcmp(tract, "remove"))
|
|
|
|
continue;
|
|
|
|
|
2011-02-18 21:09:42 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname",
|
|
|
|
&pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version",
|
|
|
|
&version);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgver",
|
|
|
|
&pkgver);
|
|
|
|
update = false;
|
|
|
|
prop_dictionary_get_bool(obj, "remove-and-update",
|
|
|
|
&update);
|
|
|
|
|
2011-06-23 15:16:15 +05:30
|
|
|
/* Remove and purge packages that shall be replaced */
|
2011-02-22 15:37:34 +05:30
|
|
|
printf("Removing `%s' package ...\n", pkgver);
|
|
|
|
rv = xbps_remove_pkg(pkgname, version, update);
|
|
|
|
if (rv != 0) {
|
|
|
|
xbps_error_printf("xbps-bin: failed to "
|
2011-06-23 15:16:15 +05:30
|
|
|
"remove `%s': %s\n", pkgver, strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
2011-06-26 02:23:47 +05:30
|
|
|
if (!update)
|
|
|
|
continue;
|
2011-06-23 15:16:15 +05:30
|
|
|
printf("Purging `%s' package...\n", pkgver);
|
|
|
|
if ((rv = xbps_purge_pkg(pkgname, false)) != 0) {
|
|
|
|
xbps_error_printf("xbps-bin: failed to "
|
|
|
|
"purge `%s': %s\n", pkgver, strerror(rv));
|
2011-02-22 15:37:34 +05:30
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prop_object_iterator_reset(trans->iter);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Configure pending packages.
|
|
|
|
*/
|
2011-07-24 21:13:17 +05:30
|
|
|
if (trans->cf_pkgcnt) {
|
2011-02-22 15:37:34 +05:30
|
|
|
printf("\n[*] Reconfigure unpacked packages ...\n");
|
|
|
|
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "transaction",
|
|
|
|
&tract);
|
|
|
|
if (strcmp(tract, "configure"))
|
|
|
|
continue;
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname",
|
|
|
|
&pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version",
|
|
|
|
&version);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgver",
|
|
|
|
&pkgver);
|
|
|
|
rv = xbps_configure_pkg(pkgname, version, false, false);
|
|
|
|
if (rv != 0) {
|
|
|
|
xbps_error_printf("xbps-bin: failed to "
|
|
|
|
"configure `%s': %s\n", pkgver, strerror(rv));
|
|
|
|
return rv;
|
2011-02-18 21:09:42 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
prop_object_iterator_reset(trans->iter);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Install or update packages in transaction.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2011-02-22 15:37:34 +05:30
|
|
|
printf("\n[*] Unpacking packages to be installed/updated ...\n");
|
2009-08-17 22:37:20 +05:30
|
|
|
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
2011-02-18 21:09:42 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
|
2011-02-22 03:58:39 +05:30
|
|
|
/* Match only packages to be installed or updated */
|
|
|
|
if ((strcmp(tract, "remove") == 0) ||
|
|
|
|
(strcmp(tract, "configure") == 0))
|
2011-02-18 21:09:42 +05:30
|
|
|
continue;
|
2011-04-11 18:12:06 +05:30
|
|
|
preserve = false;
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
2011-01-21 21:46:58 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "filename", &filen);
|
2010-10-23 21:39:35 +05:30
|
|
|
prop_dictionary_get_bool(obj, "preserve", &preserve);
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* If dependency is already unpacked skip this phase.
|
|
|
|
*/
|
|
|
|
state = 0;
|
2011-06-01 13:07:32 +05:30
|
|
|
if (xbps_pkg_state_dictionary(obj, &state) != 0)
|
2009-08-17 22:37:20 +05:30
|
|
|
return EINVAL;
|
|
|
|
if (state == XBPS_PKG_STATE_UNPACKED)
|
|
|
|
continue;
|
|
|
|
|
2011-02-18 21:09:42 +05:30
|
|
|
if (strcmp(tract, "update") == 0) {
|
2011-02-01 05:51:54 +05:30
|
|
|
/* Update a package */
|
2010-01-21 07:40:19 +05:30
|
|
|
instpkgd = xbps_find_pkg_dict_installed(pkgname, false);
|
2009-08-17 22:37:20 +05:30
|
|
|
if (instpkgd == NULL) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-bin: error: unable to "
|
2010-01-15 19:49:16 +05:30
|
|
|
"find %s installed dict!\n", pkgname);
|
2009-08-17 22:37:20 +05:30
|
|
|
return EINVAL;
|
|
|
|
}
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(instpkgd,
|
|
|
|
"version", &instver);
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_object_release(instpkgd);
|
2010-01-28 20:38:50 +05:30
|
|
|
if (preserve)
|
2010-01-25 20:46:48 +05:30
|
|
|
printf("Conserving %s-%s files, installing new "
|
|
|
|
"version ...\n", pkgname, instver);
|
2010-01-21 07:40:19 +05:30
|
|
|
else
|
2010-01-28 20:38:50 +05:30
|
|
|
printf("Replacing %s files (%s -> %s) ...\n",
|
|
|
|
pkgname, instver, version);
|
2010-01-21 07:40:19 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
if ((rv = xbps_remove_pkg(pkgname, version, true)) != 0) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-bin: error "
|
2010-01-28 20:38:50 +05:30
|
|
|
"replacing %s-%s (%s)\n", pkgname,
|
2010-01-21 07:40:19 +05:30
|
|
|
instver, strerror(rv));
|
|
|
|
return rv;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Unpack binary package.
|
|
|
|
*/
|
2011-02-22 21:03:54 +05:30
|
|
|
printf("Unpacking `%s' (from ../%s) ...\n", pkgver, filen);
|
2011-02-21 18:08:44 +05:30
|
|
|
if ((rv = xbps_unpack_binary_pkg(obj)) != 0) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-bin: error unpacking %s "
|
2010-01-15 19:49:16 +05:30
|
|
|
"(%s)\n", pkgver, strerror(rv));
|
2009-08-17 22:37:20 +05:30
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Register binary package.
|
|
|
|
*/
|
2011-04-11 18:12:06 +05:30
|
|
|
if ((rv = xbps_register_pkg(obj)) != 0) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-bin: error registering %s "
|
2010-01-15 19:49:16 +05:30
|
|
|
"(%s)\n", pkgver, strerror(rv));
|
2009-08-17 22:37:20 +05:30
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prop_object_iterator_reset(trans->iter);
|
|
|
|
/*
|
|
|
|
* Configure all unpacked packages.
|
|
|
|
*/
|
2011-02-22 15:37:34 +05:30
|
|
|
printf("\n[*] Configuring packages installed/updated ...\n");
|
2009-08-17 22:37:20 +05:30
|
|
|
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
2011-02-05 16:51:04 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
|
2011-02-24 04:13:45 +05:30
|
|
|
if ((strcmp(tract, "remove") == 0) ||
|
|
|
|
(strcmp(tract, "configure") == 0))
|
2011-02-01 05:51:54 +05:30
|
|
|
continue;
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
2009-12-09 20:44:35 +05:30
|
|
|
update = false;
|
|
|
|
if (strcmp(tract, "update") == 0)
|
|
|
|
update = true;
|
|
|
|
rv = xbps_configure_pkg(pkgname, version, false, update);
|
|
|
|
if (rv != 0) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-bin: error configuring "
|
2010-01-15 19:49:16 +05:30
|
|
|
"package %s (%s)\n", pkgname, strerror(rv));
|
2009-08-17 22:37:20 +05:30
|
|
|
return rv;
|
|
|
|
}
|
2011-02-24 04:13:45 +05:30
|
|
|
trans->cf_pkgcnt++;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2011-07-24 21:13:17 +05:30
|
|
|
|
|
|
|
printf("\nxbps-bin: %u installed, %u updated, "
|
|
|
|
"%u configured, %u removed.\n", trans->inst_pkgcnt,
|
2011-02-01 05:51:54 +05:30
|
|
|
trans->up_pkgcnt, trans->cf_pkgcnt, trans->rm_pkgcnt);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
|
|
|
|
int
|
2011-01-27 19:06:33 +05:30
|
|
|
xbps_exec_transaction(bool yes, bool show_download_pkglist_url)
|
2010-01-21 07:40:19 +05:30
|
|
|
{
|
|
|
|
struct transaction *trans;
|
|
|
|
prop_array_t array;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
trans = calloc(1, sizeof(struct transaction));
|
|
|
|
if (trans == NULL)
|
2011-02-25 16:57:42 +05:30
|
|
|
return errno;
|
2010-01-21 07:40:19 +05:30
|
|
|
|
2011-01-24 21:25:58 +05:30
|
|
|
trans->dict = xbps_transaction_prepare();
|
2010-11-19 18:10:13 +05:30
|
|
|
if (trans->dict == NULL) {
|
2011-01-24 21:25:58 +05:30
|
|
|
if (errno == ENODEV) {
|
|
|
|
/* missing packages */
|
|
|
|
array = xbps_transaction_missingdeps_get();
|
2011-01-25 07:25:34 +05:30
|
|
|
show_missing_deps(array);
|
2011-07-03 03:14:51 +05:30
|
|
|
rv = errno;
|
2011-01-24 21:25:58 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2011-02-25 16:57:42 +05:30
|
|
|
rv = errno;
|
2010-11-24 03:47:04 +05:30
|
|
|
xbps_dbg_printf("Empty transaction dictionary: %s\n",
|
|
|
|
strerror(errno));
|
2010-01-21 07:40:19 +05:30
|
|
|
goto out;
|
2010-11-19 18:10:13 +05:30
|
|
|
}
|
2010-12-03 22:06:07 +05:30
|
|
|
xbps_dbg_printf("Dictionary before transaction happens:\n");
|
|
|
|
xbps_dbg_printf_append("%s", prop_dictionary_externalize(trans->dict));
|
2010-01-21 07:40:19 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* It's time to run the transaction!
|
|
|
|
*/
|
2011-06-01 13:07:32 +05:30
|
|
|
trans->iter = xbps_array_iter_from_dict(trans->dict, "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;
|
|
|
|
}
|
|
|
|
|
|
|
|
trans->yes = yes;
|
2011-01-27 19:06:33 +05:30
|
|
|
trans->only_show = show_download_pkglist_url;
|
2010-01-21 07:40:19 +05:30
|
|
|
rv = exec_transaction(trans);
|
|
|
|
out:
|
|
|
|
if (trans->iter)
|
|
|
|
prop_object_iterator_release(trans->iter);
|
|
|
|
if (trans->dict)
|
|
|
|
prop_object_release(trans->dict);
|
|
|
|
if (trans)
|
|
|
|
free(trans);
|
2011-01-24 21:25:58 +05:30
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
return rv;
|
|
|
|
}
|