2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2010-01-14 06:44:31 +05:30
|
|
|
* Copyright (c) 2009-2010 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>
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
#include <xbps_api.h>
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
struct transaction {
|
|
|
|
prop_dictionary_t dict;
|
|
|
|
prop_object_iterator_t iter;
|
2009-12-22 19:13:38 +05:30
|
|
|
bool yes;
|
2010-01-21 07:40:19 +05:30
|
|
|
size_t inst_pkgcnt;
|
|
|
|
size_t up_pkgcnt;
|
|
|
|
size_t cf_pkgcnt;
|
2009-08-17 22:37:20 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
show_missing_dep_cb(prop_object_t obj, void *arg, bool *loop_done)
|
|
|
|
{
|
2009-11-29 07:47:35 +05:30
|
|
|
const char *reqpkg;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
(void)arg;
|
|
|
|
(void)loop_done;
|
|
|
|
|
2009-11-29 07:47:35 +05:30
|
|
|
reqpkg = prop_string_cstring_nocopy(obj);
|
|
|
|
if (reqpkg == NULL)
|
|
|
|
return EINVAL;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr, " * Missing binary package for: %s\n", reqpkg);
|
2009-11-29 07:47:35 +05:30
|
|
|
return 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
static void
|
|
|
|
show_missing_deps(prop_dictionary_t d)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"xbps-bin: unable to locate some required packages:\n");
|
|
|
|
(void)xbps_callback_array_iter_in_dict(d, "missing_deps",
|
|
|
|
show_missing_dep_cb, NULL);
|
|
|
|
}
|
|
|
|
|
2009-11-28 07:08:41 +05:30
|
|
|
static bool
|
|
|
|
check_binpkg_hash(const char *path, const char *filename,
|
|
|
|
const char *sha256)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
|
|
|
int rv = 0;
|
|
|
|
|
2009-11-28 07:08:41 +05:30
|
|
|
printf("Checking %s integrity... ", filename);
|
|
|
|
rv = xbps_check_file_hash(path, sha256);
|
|
|
|
errno = rv;
|
|
|
|
if (rv != 0 && rv != ERANGE) {
|
2010-01-25 07:44:54 +05:30
|
|
|
fprintf(stderr, "\nxbps-bin: unexpected error: %s\n",
|
2010-01-15 19:49:16 +05:30
|
|
|
strerror(rv));
|
2009-11-28 07:08:41 +05:30
|
|
|
return false;
|
|
|
|
} else if (rv == ERANGE) {
|
2010-01-25 07:44:54 +05:30
|
|
|
printf("hash mismatch!\n");
|
2009-11-28 07:08:41 +05:30
|
|
|
return false;
|
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
|
|
|
|
2009-11-28 07:08:41 +05:30
|
|
|
return true;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2009-10-27 06:16:00 +05:30
|
|
|
static int
|
|
|
|
download_package_list(prop_object_iterator_t iter)
|
|
|
|
{
|
|
|
|
prop_object_t obj;
|
2009-11-28 07:08:41 +05:30
|
|
|
const char *pkgver, *repoloc, *filename, *cachedir, *sha256;
|
|
|
|
char *binfile, *lbinfile;
|
2009-10-27 06:16:00 +05:30
|
|
|
int rv = 0;
|
2009-11-28 07:08:41 +05:30
|
|
|
|
|
|
|
cachedir = xbps_get_cachedir();
|
|
|
|
if (cachedir == NULL)
|
|
|
|
return EINVAL;
|
2009-10-27 06:16:00 +05:30
|
|
|
|
2010-01-24 21:01:56 +05:30
|
|
|
/* Set default limit of global and per-host cached connections */
|
|
|
|
xbps_fetch_set_cache_connection(0, 0);
|
|
|
|
|
2009-10-27 06:16:00 +05:30
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"repository", &repoloc))
|
|
|
|
return errno;
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"pkgver", &pkgver))
|
|
|
|
return errno;
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"filename", &filename))
|
|
|
|
return errno;
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
2009-11-28 07:08:41 +05:30
|
|
|
"filename-sha256", &sha256))
|
2009-11-23 15:16:51 +05:30
|
|
|
return errno;
|
2009-10-27 06:16:00 +05:30
|
|
|
|
2009-11-28 07:51:29 +05:30
|
|
|
lbinfile = xbps_get_binpkg_local_path(obj, repoloc);
|
2009-11-28 07:08:41 +05:30
|
|
|
if (lbinfile == NULL)
|
2009-10-27 06:16:00 +05:30
|
|
|
return errno;
|
|
|
|
|
2009-11-28 07:08:41 +05:30
|
|
|
/*
|
|
|
|
* If package is in a local repository, check its hash
|
2010-01-21 07:40:19 +05:30
|
|
|
* and pass to next one.
|
2009-11-28 07:08:41 +05:30
|
|
|
*/
|
|
|
|
if (!xbps_check_is_repo_string_remote(repoloc)) {
|
|
|
|
if (!check_binpkg_hash(lbinfile, filename, sha256)) {
|
|
|
|
free(lbinfile);
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
free(lbinfile);
|
|
|
|
continue;
|
2009-10-27 06:16:00 +05:30
|
|
|
}
|
2009-11-28 07:08:41 +05:30
|
|
|
/*
|
|
|
|
* If downloaded package is in cachedir, check its hash
|
|
|
|
* and restart it again if doesn't match.
|
|
|
|
*/
|
2009-10-27 06:16:00 +05:30
|
|
|
if (access(lbinfile, R_OK) == 0) {
|
2009-11-28 07:08:41 +05:30
|
|
|
if (check_binpkg_hash(lbinfile, filename, sha256)) {
|
|
|
|
free(lbinfile);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (errno && errno != ERANGE) {
|
|
|
|
free(lbinfile);
|
|
|
|
return errno;
|
|
|
|
} else if (errno == ERANGE) {
|
|
|
|
(void)remove(lbinfile);
|
|
|
|
printf("Refetching %s again...\n",
|
|
|
|
filename);
|
|
|
|
errno = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (xbps_mkpath(__UNCONST(cachedir), 0755) == -1) {
|
2009-10-27 06:16:00 +05:30
|
|
|
free(lbinfile);
|
2009-11-28 07:08:41 +05:30
|
|
|
return errno;
|
2009-10-27 06:16:00 +05:30
|
|
|
}
|
2009-11-30 17:05:38 +05:30
|
|
|
binfile = xbps_repository_get_path_from_pkg_dict(obj, repoloc);
|
2009-10-27 06:16:00 +05:30
|
|
|
if (binfile == NULL) {
|
2009-11-28 07:08:41 +05:30
|
|
|
free(lbinfile);
|
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);
|
2009-11-28 07:08:41 +05:30
|
|
|
rv = xbps_fetch_file(binfile, cachedir, false, NULL);
|
2009-10-27 06:16:00 +05:30
|
|
|
free(binfile);
|
2009-11-24 10:33:26 +05:30
|
|
|
if (rv == -1) {
|
2010-01-21 07:40:19 +05:30
|
|
|
fprintf(stderr, "xbps-bin: couldn't download `%s'\n",
|
|
|
|
filename);
|
|
|
|
fprintf(stderr, "xbps-bin: %s returned: `%s'\n",
|
|
|
|
repoloc, xbps_fetch_error_string());
|
2009-11-28 07:08:41 +05:30
|
|
|
free(lbinfile);
|
2010-01-21 07:40:19 +05:30
|
|
|
return -1;
|
2009-10-27 06:16:00 +05:30
|
|
|
}
|
2009-11-28 07:08:41 +05:30
|
|
|
if (!check_binpkg_hash(lbinfile, filename, sha256)) {
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr, "W: removing wrong %s file ...\n",
|
|
|
|
filename);
|
2009-11-28 07:08:41 +05:30
|
|
|
(void)remove(lbinfile);
|
|
|
|
free(lbinfile);
|
2009-11-23 15:16:51 +05:30
|
|
|
return errno;
|
|
|
|
}
|
2009-11-28 07:08:41 +05:30
|
|
|
free(lbinfile);
|
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;
|
|
|
|
size_t cols = 0;
|
2009-11-22 09:45:47 +05:30
|
|
|
const char *pkgver, *tract;
|
2009-08-17 22:37:20 +05:30
|
|
|
bool first = false;
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"pkgver", &pkgver))
|
|
|
|
return;
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"trans-action", &tract))
|
|
|
|
return;
|
2009-08-17 22:37:20 +05:30
|
|
|
if (strcmp(match, tract))
|
|
|
|
continue;
|
|
|
|
|
2009-11-22 09:45:47 +05:30
|
|
|
cols += strlen(pkgver) + 4;
|
2009-08-17 22:37:20 +05:30
|
|
|
if (cols <= 80) {
|
|
|
|
if (first == false) {
|
|
|
|
printf(" ");
|
|
|
|
first = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf("\n ");
|
2009-11-22 09:45:47 +05:30
|
|
|
cols = strlen(pkgver) + 4;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2009-11-22 09:45:47 +05:30
|
|
|
printf("%s ", pkgver);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
prop_object_iterator_reset(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-01-21 07:40:19 +05:30
|
|
|
show_transaction_sizes(struct transaction *trans)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
|
|
|
prop_object_t obj;
|
2010-01-21 07:40:19 +05:30
|
|
|
uint64_t dlsize = 0, instsize = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
const char *tract;
|
|
|
|
char size[64];
|
2009-11-26 07:52:50 +05:30
|
|
|
bool trans_inst, trans_up, trans_conf;
|
|
|
|
|
|
|
|
trans_inst = trans_up = trans_conf = false;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
while ((obj = prop_object_iterator_next(trans->iter))) {
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"trans-action", &tract))
|
|
|
|
return errno;
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
if (strcmp(tract, "install") == 0) {
|
|
|
|
trans->inst_pkgcnt++;
|
2009-08-17 22:37:20 +05:30
|
|
|
trans_inst = true;
|
2010-01-21 07:40:19 +05:30
|
|
|
} else if (strcmp(tract, "update") == 0) {
|
|
|
|
trans->up_pkgcnt++;
|
2009-08-17 22:37:20 +05:30
|
|
|
trans_up = true;
|
2010-01-21 07:40:19 +05:30
|
|
|
} else if (strcmp(tract, "configure") == 0) {
|
|
|
|
trans->cf_pkgcnt++;
|
2009-11-26 07:52:50 +05:30
|
|
|
trans_conf = true;
|
2010-01-21 07:40:19 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
prop_object_iterator_reset(trans->iter);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Show the list of packages that will be installed.
|
|
|
|
*/
|
|
|
|
if (trans_inst) {
|
|
|
|
printf("The following packages will be installed:\n\n");
|
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");
|
|
|
|
}
|
|
|
|
if (trans_up) {
|
|
|
|
printf("The following packages will be updated:\n\n");
|
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");
|
|
|
|
}
|
2009-11-26 07:52:50 +05:30
|
|
|
if (trans_conf) {
|
|
|
|
printf("The following packages will be configured:\n\n");
|
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");
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Show total download/installed size for all required packages.
|
|
|
|
*/
|
2010-01-21 07:40:19 +05:30
|
|
|
if (!prop_dictionary_get_uint64(trans->dict,
|
|
|
|
"total-download-size", &dlsize))
|
|
|
|
return errno;
|
|
|
|
if (!prop_dictionary_get_uint64(trans->dict,
|
|
|
|
"total-installed-size", &instsize))
|
|
|
|
return errno;
|
2009-08-17 22:37:20 +05:30
|
|
|
if (xbps_humanize_number(size, 5, (int64_t)dlsize,
|
2009-10-23 12:15:59 +05:30
|
|
|
"", HN_AUTOSCALE, HN_B|HN_DECIMAL|HN_NOSPACE) == -1) {
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr, "xbps-bin: error: humanize_number returns "
|
|
|
|
"%s\n", strerror(errno));
|
2009-08-17 22:37:20 +05:30
|
|
|
return -1;
|
|
|
|
}
|
2010-01-25 20:46:48 +05:30
|
|
|
printf("Total download size: %sB\n", size);
|
2009-08-17 22:37:20 +05:30
|
|
|
if (xbps_humanize_number(size, 5, (int64_t)instsize,
|
2009-10-23 12:15:59 +05:30
|
|
|
"", HN_AUTOSCALE, HN_B|HN_DECIMAL|HN_NOSPACE) == -1) {
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr, "xbps-bin: error: humanize_number2 returns "
|
|
|
|
"%s\n", strerror(errno));
|
2009-08-17 22:37:20 +05:30
|
|
|
return -1;
|
|
|
|
}
|
2010-01-25 20:46:48 +05:30
|
|
|
printf("Total installed size: %sB\n\n", size);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-23 17:31:54 +05:30
|
|
|
int
|
2009-12-22 19:13:38 +05:30
|
|
|
xbps_autoupdate_pkgs(bool yes)
|
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");
|
|
|
|
if ((rv = xbps_repository_update_allpkgs()) != 0) {
|
|
|
|
if (rv == ENOENT) {
|
|
|
|
printf("No packages currently registered.\n");
|
|
|
|
return 0;
|
|
|
|
} else if (rv == ENOPKG) {
|
|
|
|
printf("All packages are up-to-date.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-12-22 19:13:38 +05:30
|
|
|
return xbps_exec_transaction(yes);
|
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;
|
|
|
|
|
2010-02-26 10:43:33 +05:30
|
|
|
if (xbps_get_pkgpattern_version(pkg)) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
pkgname = xbps_get_pkgpattern_name(pkgpatt);
|
|
|
|
if (pkgname == NULL)
|
|
|
|
return -1;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
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))) {
|
2009-12-22 17:07:36 +05:30
|
|
|
printf("Package '%s' is already installed.\n", pkgname);
|
|
|
|
prop_object_release(pkgd);
|
2010-01-14 06:44:31 +05:30
|
|
|
if (pkgmatch)
|
|
|
|
free(pkgname);
|
2009-12-22 19:13:38 +05:30
|
|
|
return 0;
|
2009-12-22 17:07:36 +05:30
|
|
|
}
|
2010-02-26 10:43:33 +05:30
|
|
|
rv = xbps_repository_install_pkg(pkgpatt, true);
|
2010-01-14 06:44:31 +05:30
|
|
|
if (rv == EAGAIN) {
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr, "xbps-bin: unable to locate '%s' in "
|
2010-01-14 06:44:31 +05:30
|
|
|
"repository pool.\n", pkg);
|
2010-01-15 19:49:16 +05:30
|
|
|
rv = 1;
|
2009-12-22 17:07:36 +05:30
|
|
|
} else if (rv != 0 && rv != ENOENT) {
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr, "xbps-bin: unexpected error: %s",
|
|
|
|
strerror(errno));
|
|
|
|
rv = -1;
|
2009-12-22 17:07:36 +05:30
|
|
|
}
|
2010-02-26 10:43:33 +05:30
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
prop_dictionary_t pkgd;
|
|
|
|
int rv = 0;
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
|
2009-12-22 17:07:36 +05:30
|
|
|
printf("Finding new '%s' package...\n", pkgname);
|
|
|
|
if (pkgd) {
|
|
|
|
rv = xbps_repository_update_pkg(pkgname, pkgd);
|
|
|
|
if (rv == EEXIST) {
|
|
|
|
printf("Package '%s' is up to date.\n", pkgname);
|
2009-12-22 19:13:38 +05:30
|
|
|
rv = 0;
|
2009-12-22 17:07:36 +05:30
|
|
|
} else if (rv == ENOENT) {
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr, "Package '%s' not found in "
|
2009-12-22 17:07:36 +05:30
|
|
|
"repository pool.\n", pkgname);
|
2009-12-22 19:13:38 +05:30
|
|
|
rv = 0;
|
2009-10-16 21:07:32 +05:30
|
|
|
}
|
2009-12-22 17:07:36 +05:30
|
|
|
prop_object_release(pkgd);
|
2009-10-16 21:07:32 +05:30
|
|
|
} else {
|
2009-12-22 17:07:36 +05:30
|
|
|
printf("Package '%s' not installed.\n", pkgname);
|
2009-12-22 19:13:38 +05:30
|
|
|
return 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2009-12-22 17:07:36 +05:30
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-10-17 08:29:59 +05:30
|
|
|
static int
|
2009-11-22 09:45:47 +05:30
|
|
|
replace_packages(prop_object_iterator_t iter, const char *pkgver)
|
2009-10-17 08:29:59 +05:30
|
|
|
{
|
|
|
|
prop_dictionary_t instd;
|
|
|
|
prop_object_t obj;
|
2010-01-21 07:40:19 +05:30
|
|
|
const char *pattern, *reppkgn, *reppkgver, *version;
|
2009-10-17 08:29:59 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This package replaces other package(s), so we remove
|
|
|
|
* them before upgrading or installing new one.
|
|
|
|
*/
|
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
2010-01-21 07:40:19 +05:30
|
|
|
pattern = prop_string_cstring_nocopy(obj);
|
|
|
|
if (pattern == NULL)
|
2009-11-23 15:16:51 +05:30
|
|
|
return errno;
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
/*
|
|
|
|
* If pattern matches an installed package, replace it.
|
|
|
|
*/
|
|
|
|
instd = xbps_find_pkg_dict_installed(pattern, true);
|
2009-10-17 08:29:59 +05:30
|
|
|
if (instd == NULL)
|
|
|
|
continue;
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(instd, "pkgname", &reppkgn);
|
|
|
|
prop_dictionary_get_cstring_nocopy(instd, "pkgver", &reppkgver);
|
|
|
|
printf("Replacing package '%s' with '%s' "
|
|
|
|
"(matched by '%s')...\n", reppkgver, pkgver, pattern);
|
|
|
|
prop_object_release(instd);
|
|
|
|
|
2009-11-29 10:21:49 +05:30
|
|
|
version = xbps_get_pkg_version(pkgver);
|
2010-01-28 20:38:50 +05:30
|
|
|
rv = xbps_remove_pkg(reppkgn, version, false);
|
2010-01-25 10:57:54 +05:30
|
|
|
if (rv != 0) {
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr, "xbps-bin: couldn't remove %s (%s)\n",
|
2009-10-17 08:29:59 +05:30
|
|
|
reppkgn, strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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;
|
2009-10-17 07:56:43 +05:30
|
|
|
prop_object_iterator_t replaces_iter;
|
2009-11-22 09:45:47 +05:30
|
|
|
const char *pkgname, *version, *pkgver, *instver, *filename, *tract;
|
2009-08-17 22:37:20 +05:30
|
|
|
int rv = 0;
|
2010-01-28 20:38:50 +05:30
|
|
|
bool update, preserve, autoinst;
|
2009-08-17 22:37:20 +05:30
|
|
|
pkg_state_t state = 0;
|
|
|
|
|
|
|
|
assert(trans != NULL);
|
|
|
|
assert(trans->dict != NULL);
|
|
|
|
assert(trans->iter != NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
*/
|
2010-01-24 18:37:57 +05:30
|
|
|
printf("[1/3] Downloading/integrity check\n");
|
2009-10-27 06:16:00 +05:30
|
|
|
if ((rv = download_package_list(trans->iter)) != 0)
|
|
|
|
return rv;
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Iterate over the transaction dictionary.
|
|
|
|
*/
|
2010-01-24 18:37:57 +05:30
|
|
|
printf("\n[2/3] Unpacking\n");
|
2009-08-17 22:37:20 +05:30
|
|
|
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
2010-04-29 01:03:36 +05:30
|
|
|
autoinst = preserve = false;
|
2010-02-17 09:49:41 +05:30
|
|
|
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"pkgname", &pkgname))
|
|
|
|
return errno;
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"version", &version))
|
|
|
|
return errno;
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"pkgver", &pkgver))
|
|
|
|
return errno;
|
2009-12-22 17:07:36 +05:30
|
|
|
prop_dictionary_get_bool(obj, "automatic-install", &autoinst);
|
2010-01-25 20:46:48 +05:30
|
|
|
prop_dictionary_get_bool(obj, "preserve", &preserve);
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"filename", &filename))
|
|
|
|
return errno;
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"trans-action", &tract))
|
|
|
|
return errno;
|
2009-10-17 07:56:43 +05:30
|
|
|
replaces_iter = xbps_get_array_iter_from_dict(obj, "replaces");
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* If dependency is already unpacked skip this phase.
|
|
|
|
*/
|
|
|
|
state = 0;
|
|
|
|
if (xbps_get_pkg_state_dictionary(obj, &state) != 0)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
if (state == XBPS_PKG_STATE_UNPACKED)
|
|
|
|
continue;
|
|
|
|
|
2009-10-17 07:56:43 +05:30
|
|
|
/*
|
2009-10-17 08:29:59 +05:30
|
|
|
* Replace package(s) if necessary.
|
2009-10-17 07:56:43 +05:30
|
|
|
*/
|
|
|
|
if (replaces_iter != NULL) {
|
2009-11-22 09:45:47 +05:30
|
|
|
rv = replace_packages(replaces_iter, pkgver);
|
2009-10-17 08:29:59 +05:30
|
|
|
if (rv != 0) {
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr,
|
|
|
|
"xbps-bin: couldn't replace some "
|
|
|
|
"packages! (%s)\n", strerror(rv));
|
2009-10-17 08:29:59 +05:30
|
|
|
return rv;
|
2009-10-17 07:56:43 +05:30
|
|
|
}
|
|
|
|
replaces_iter = NULL;
|
|
|
|
}
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
if (strcmp(tract, "update") == 0) {
|
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) {
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr, "xbps-bin: error: unable to "
|
|
|
|
"find %s installed dict!\n", pkgname);
|
2009-08-17 22:37:20 +05:30
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(instpkgd,
|
|
|
|
"version", &instver)) {
|
|
|
|
prop_object_release(instpkgd);
|
|
|
|
return errno;
|
|
|
|
}
|
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-01-28 20:38:50 +05:30
|
|
|
rv = xbps_remove_pkg(pkgname, version, true);
|
2010-01-21 07:40:19 +05:30
|
|
|
if (rv != 0) {
|
|
|
|
fprintf(stderr, "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.
|
|
|
|
*/
|
2009-11-22 09:45:47 +05:30
|
|
|
printf("Unpacking %s (from .../%s) ...\n", pkgver, filename);
|
2009-12-02 11:01:03 +05:30
|
|
|
if ((rv = xbps_unpack_binary_pkg(obj)) != 0) {
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr, "xbps-bin: error unpacking %s "
|
|
|
|
"(%s)\n", pkgver, strerror(rv));
|
2009-08-17 22:37:20 +05:30
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Register binary package.
|
|
|
|
*/
|
2009-10-22 18:02:21 +05:30
|
|
|
if ((rv = xbps_register_pkg(obj, autoinst)) != 0) {
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr, "xbps-bin: error registering %s "
|
|
|
|
"(%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.
|
|
|
|
*/
|
2010-01-24 18:37:57 +05:30
|
|
|
printf("\n[3/3] Configuring\n");
|
2009-08-17 22:37:20 +05:30
|
|
|
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"pkgname", &pkgname))
|
|
|
|
return errno;
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"version", &version))
|
|
|
|
return errno;
|
2009-12-09 20:44:35 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"trans-action", &tract))
|
|
|
|
return errno;
|
|
|
|
update = false;
|
|
|
|
if (strcmp(tract, "update") == 0)
|
|
|
|
update = true;
|
|
|
|
rv = xbps_configure_pkg(pkgname, version, false, update);
|
|
|
|
if (rv != 0) {
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr, "xbps-bin: error configuring "
|
|
|
|
"package %s (%s)\n", pkgname, strerror(rv));
|
2009-08-17 22:37:20 +05:30
|
|
|
return rv;
|
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
trans->cf_pkgcnt++;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
printf("\nxbps-bin: %zu installed, %zu updated, "
|
|
|
|
"%zu configured.\n", trans->inst_pkgcnt, trans->up_pkgcnt,
|
|
|
|
trans->cf_pkgcnt);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-01-21 07:40:19 +05:30
|
|
|
|
|
|
|
int
|
|
|
|
xbps_exec_transaction(bool yes)
|
|
|
|
{
|
|
|
|
struct transaction *trans;
|
|
|
|
prop_array_t array;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
trans = calloc(1, sizeof(struct transaction));
|
|
|
|
if (trans == NULL)
|
2010-04-28 22:01:37 +05:30
|
|
|
return rv;
|
2010-01-21 07:40:19 +05:30
|
|
|
|
|
|
|
trans->dict = xbps_repository_get_transaction_dict();
|
|
|
|
if (trans->dict == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bail out if there are unresolved deps.
|
|
|
|
*/
|
|
|
|
array = prop_dictionary_get(trans->dict, "missing_deps");
|
|
|
|
if (prop_array_count(array) > 0) {
|
|
|
|
show_missing_deps(trans->dict);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(("%s", prop_dictionary_externalize(trans->dict)));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It's time to run the transaction!
|
|
|
|
*/
|
|
|
|
trans->iter = xbps_get_array_iter_from_dict(trans->dict, "packages");
|
|
|
|
if (trans->iter == NULL) {
|
|
|
|
fprintf(stderr, "xbps-bin: error allocating array mem! (%s)\n",
|
|
|
|
strerror(errno));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
trans->yes = yes;
|
|
|
|
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);
|
|
|
|
return rv;
|
|
|
|
}
|