2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
|
|
|
* Copyright (c) 2009 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <xbps_api.h>
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
struct transaction {
|
|
|
|
prop_dictionary_t dict;
|
|
|
|
prop_object_iterator_t iter;
|
|
|
|
const char *originpkgname;
|
|
|
|
bool force;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int exec_transaction(struct transaction *);
|
|
|
|
static void show_missing_deps(prop_dictionary_t, const char *);
|
|
|
|
static int show_missing_dep_cb(prop_object_t, void *, bool *);
|
|
|
|
static void show_package_list(prop_object_iterator_t, const char *);
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_missing_deps(prop_dictionary_t d, const char *pkgname)
|
|
|
|
{
|
|
|
|
printf("Unable to locate some required packages for %s:\n",
|
|
|
|
pkgname);
|
|
|
|
(void)xbps_callback_array_iter_in_dict(d, "missing_deps",
|
|
|
|
show_missing_dep_cb, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
show_missing_dep_cb(prop_object_t obj, void *arg, bool *loop_done)
|
|
|
|
{
|
|
|
|
const char *pkgname, *version;
|
|
|
|
|
|
|
|
(void)arg;
|
|
|
|
(void)loop_done;
|
|
|
|
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
|
|
|
if (pkgname && version) {
|
|
|
|
printf(" * Missing binary package for: %s >= %s\n",
|
|
|
|
pkgname, version);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
check_pkg_hashes(prop_object_iterator_t iter)
|
|
|
|
{
|
|
|
|
prop_object_t obj;
|
|
|
|
const char *pkgname, *repoloc, *filename;
|
|
|
|
int rv = 0;
|
|
|
|
pkg_state_t state = 0;
|
|
|
|
|
|
|
|
printf("Checking binary package file(s) integrity...\n");
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
state = 0;
|
|
|
|
if (xbps_get_pkg_state_dictionary(obj, &state) != 0)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
if (state == XBPS_PKG_STATE_UNPACKED)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
|
|
|
|
rv = xbps_check_pkg_file_hash(obj, repoloc);
|
|
|
|
if (rv != 0 && rv != ERANGE) {
|
|
|
|
printf("Unexpected error while checking hash for "
|
|
|
|
"%s (%s)\n", filename, strerror(rv));
|
|
|
|
return -1;
|
|
|
|
} else if (rv != 0 && rv == ERANGE) {
|
|
|
|
printf("Hash mismatch for %s, exiting.\n",
|
|
|
|
filename);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prop_object_iterator_reset(iter);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-27 06:16:00 +05:30
|
|
|
static int
|
|
|
|
download_package_list(prop_object_iterator_t iter)
|
|
|
|
{
|
|
|
|
prop_object_t obj;
|
|
|
|
const char *pkgname, *version, *repoloc, *filename, *arch;
|
|
|
|
char *savedir, *binfile, *lbinfile, *repoloc_trans;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
printf("Downloading binary package file(s)...\n");
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
|
|
|
|
/*
|
|
|
|
* Skip packages in local repositories.
|
|
|
|
*/
|
|
|
|
if ((strncmp(repoloc, "http://", 7)) &&
|
|
|
|
(strncmp(repoloc, "ftp://", 6)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
|
|
|
|
|
|
|
|
repoloc_trans = xbps_get_remote_repo_string(repoloc);
|
|
|
|
if (repoloc_trans == NULL)
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
savedir = xbps_xasprintf("%s/%s/repo/%s/%s",
|
|
|
|
xbps_get_rootdir(), XBPS_META_PATH, repoloc_trans, arch);
|
|
|
|
if (savedir == NULL) {
|
|
|
|
free(repoloc_trans);
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
lbinfile = xbps_xasprintf("%s/%s", savedir, filename);
|
|
|
|
if (lbinfile == NULL) {
|
|
|
|
free(repoloc_trans);
|
|
|
|
free(savedir);
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (access(lbinfile, R_OK) == 0) {
|
|
|
|
free(savedir);
|
|
|
|
free(lbinfile);
|
|
|
|
goto change_repodir;
|
|
|
|
}
|
|
|
|
free(lbinfile);
|
|
|
|
|
|
|
|
binfile = xbps_xasprintf("%s/%s/%s", repoloc, arch, filename);
|
|
|
|
if (binfile == NULL) {
|
|
|
|
free(repoloc_trans);
|
|
|
|
free(savedir);
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
printf("Downloading %s-%s binary package ...\n",
|
|
|
|
pkgname, version);
|
|
|
|
rv = xbps_fetch_file(binfile, savedir);
|
|
|
|
free(savedir);
|
|
|
|
free(binfile);
|
|
|
|
if (rv != 0) {
|
|
|
|
printf("Couldn't download %s from %s (%s)\n",
|
|
|
|
filename, repoloc, strerror(rv));
|
|
|
|
free(repoloc_trans);
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
change_repodir:
|
|
|
|
/*
|
|
|
|
* If it was downloaded successfully, override repository
|
|
|
|
* path in transaction dictionary.
|
|
|
|
*/
|
|
|
|
savedir = xbps_xasprintf("%s/%s/repo/%s",
|
|
|
|
xbps_get_rootdir(), XBPS_META_PATH, repoloc_trans);
|
|
|
|
free(repoloc_trans);
|
|
|
|
if (savedir == NULL)
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
prop_dictionary_set_cstring(obj, "repository", savedir);
|
|
|
|
free(savedir);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
const char *pkgname, *version, *tract;
|
|
|
|
bool first = false;
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
|
|
|
|
if (strcmp(match, tract))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cols += strlen(pkgname) + strlen(version) + 4;
|
|
|
|
if (cols <= 80) {
|
|
|
|
if (first == false) {
|
|
|
|
printf(" ");
|
|
|
|
first = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf("\n ");
|
|
|
|
cols = strlen(pkgname) + strlen(version) + 4;
|
|
|
|
}
|
|
|
|
printf("%s-%s ", pkgname, version);
|
|
|
|
}
|
|
|
|
prop_object_iterator_reset(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
show_transaction_sizes(prop_object_iterator_t iter)
|
|
|
|
{
|
|
|
|
prop_object_t obj;
|
|
|
|
uint64_t tsize = 0, dlsize = 0, instsize = 0;
|
|
|
|
const char *tract;
|
|
|
|
char size[64];
|
|
|
|
bool trans_inst = false, trans_up = false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over the list of packages that are going to be
|
|
|
|
* installed and check the file hash.
|
|
|
|
*/
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
|
|
|
prop_dictionary_get_uint64(obj, "filename-size", &tsize);
|
|
|
|
dlsize += tsize;
|
|
|
|
tsize = 0;
|
|
|
|
prop_dictionary_get_uint64(obj, "installed_size", &tsize);
|
|
|
|
instsize += tsize;
|
|
|
|
tsize = 0;
|
|
|
|
}
|
|
|
|
prop_object_iterator_reset(iter);
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
|
|
|
|
if (strcmp(tract, "install") == 0)
|
|
|
|
trans_inst = true;
|
|
|
|
else if (strcmp(tract, "update") == 0)
|
|
|
|
trans_up = true;
|
|
|
|
}
|
|
|
|
prop_object_iterator_reset(iter);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Show the list of packages that will be installed.
|
|
|
|
*/
|
|
|
|
if (trans_inst) {
|
|
|
|
printf("The following packages will be installed:\n\n");
|
|
|
|
show_package_list(iter, "install");
|
|
|
|
printf("\n\n");
|
|
|
|
}
|
|
|
|
if (trans_up) {
|
|
|
|
printf("The following packages will be updated:\n\n");
|
|
|
|
show_package_list(iter, "update");
|
|
|
|
printf("\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Show total download/installed size for all required packages.
|
|
|
|
*/
|
|
|
|
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) {
|
2009-08-17 22:37:20 +05:30
|
|
|
printf("error: humanize_number returns %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
printf("Total download size: %s\n", size);
|
|
|
|
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) {
|
2009-08-17 22:37:20 +05:30
|
|
|
printf("error: humanize_number2 returns %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
printf("Total installed size: %s\n\n", size);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-23 17:31:54 +05:30
|
|
|
int
|
2009-10-16 21:07:32 +05:30
|
|
|
xbps_exec_transaction(const char *pkgname, bool force, bool update)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
|
|
|
struct transaction *trans;
|
|
|
|
prop_dictionary_t pkgd;
|
|
|
|
prop_array_t array;
|
|
|
|
int rv = 0;
|
|
|
|
|
2009-10-16 21:07:32 +05:30
|
|
|
assert(pkgname != NULL);
|
|
|
|
|
|
|
|
if (update && (strcasecmp(pkgname, "all") == 0)) {
|
|
|
|
/*
|
|
|
|
* Update all currently installed packages, aka
|
|
|
|
* "xbps-bin autoupdate".
|
|
|
|
*/
|
|
|
|
printf("Finding new packages...\n");
|
|
|
|
if ((rv = xbps_find_new_packages()) != 0) {
|
|
|
|
if (rv == ENOENT) {
|
|
|
|
printf("No packages currently registered.\n");
|
2009-10-23 17:31:54 +05:30
|
|
|
return 0;
|
2009-10-17 09:48:20 +05:30
|
|
|
} else if (rv == ENOPKG) {
|
|
|
|
printf("All packages are up-to-date.\n");
|
2009-10-23 17:31:54 +05:30
|
|
|
return 0;
|
2009-10-16 21:07:32 +05:30
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pkgd = xbps_find_pkg_installed_from_plist(pkgname);
|
|
|
|
if (update) {
|
|
|
|
/*
|
|
|
|
* Update a single package, aka
|
|
|
|
* "xbps-bin update pkgname"
|
|
|
|
*/
|
|
|
|
printf("Finding new '%s' package...\n", pkgname);
|
|
|
|
if (pkgd) {
|
|
|
|
rv = xbps_find_new_pkg(pkgname, pkgd);
|
|
|
|
if (rv == EEXIST) {
|
|
|
|
printf("Package '%s' is up to date.\n",
|
|
|
|
pkgname);
|
|
|
|
prop_object_release(pkgd);
|
2009-10-23 17:31:54 +05:30
|
|
|
return rv;
|
2009-10-16 21:07:32 +05:30
|
|
|
} else if (rv == ENOENT) {
|
|
|
|
printf("Package '%s' not found in "
|
|
|
|
"repository pool.\n", pkgname);
|
|
|
|
prop_object_release(pkgd);
|
2009-10-23 17:31:54 +05:30
|
|
|
return rv;
|
2009-10-16 21:07:32 +05:30
|
|
|
} else if (rv != 0) {
|
|
|
|
prop_object_release(pkgd);
|
2009-10-23 17:31:54 +05:30
|
|
|
return rv;
|
2009-10-16 21:07:32 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_object_release(pkgd);
|
2009-10-16 21:07:32 +05:30
|
|
|
} else {
|
|
|
|
printf("Package '%s' not installed.\n",
|
|
|
|
pkgname);
|
2009-10-23 17:31:54 +05:30
|
|
|
return rv;
|
2009-10-16 21:07:32 +05:30
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Install a single package, aka
|
|
|
|
* "xbps-bin install pkgname"
|
|
|
|
*/
|
|
|
|
if (pkgd) {
|
|
|
|
printf("Package '%s' is already installed.\n",
|
|
|
|
pkgname);
|
2009-10-16 19:01:57 +05:30
|
|
|
prop_object_release(pkgd);
|
2009-10-23 17:31:54 +05:30
|
|
|
return rv;
|
2009-10-16 21:07:32 +05:30
|
|
|
}
|
|
|
|
rv = xbps_prepare_pkg(pkgname);
|
|
|
|
if (rv != 0 && rv == EAGAIN) {
|
|
|
|
printf("Unable to locate '%s' in "
|
|
|
|
"repository pool.\n", pkgname);
|
2009-10-23 17:31:54 +05:30
|
|
|
return rv;
|
2009-10-16 21:07:32 +05:30
|
|
|
} else if (rv != 0 && rv != ENOENT) {
|
|
|
|
printf("Unexpected error: %s", strerror(rv));
|
2009-10-23 17:31:54 +05:30
|
|
|
return rv;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trans = calloc(1, sizeof(struct transaction));
|
|
|
|
if (trans == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
trans->dict = xbps_get_pkg_props();
|
|
|
|
if (trans->dict == NULL) {
|
|
|
|
printf("error: unexistent props dictionary!\n");
|
|
|
|
goto out1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bail out if there are unresolved deps.
|
|
|
|
*/
|
|
|
|
array = prop_dictionary_get(trans->dict, "missing_deps");
|
|
|
|
if (prop_array_count(array) > 0) {
|
2009-10-16 21:07:32 +05:30
|
|
|
show_missing_deps(trans->dict, pkgname);
|
2009-08-17 22:37:20 +05:30
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop_dictionary_get_cstring_nocopy(trans->dict,
|
|
|
|
"origin", &trans->originpkgname);
|
|
|
|
|
2009-10-16 19:25:13 +05:30
|
|
|
if (update) {
|
|
|
|
/*
|
|
|
|
* Sort the package transaction dictionary.
|
|
|
|
*/
|
|
|
|
if ((rv = xbps_sort_pkg_deps(trans->dict)) != 0) {
|
|
|
|
printf("Error while sorting packages: %s\n",
|
|
|
|
strerror(rv));
|
|
|
|
goto out2;
|
|
|
|
}
|
2009-10-16 19:01:57 +05:30
|
|
|
}
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* It's time to run the transaction!
|
|
|
|
*/
|
|
|
|
trans->iter = xbps_get_array_iter_from_dict(trans->dict, "packages");
|
|
|
|
if (trans->iter == NULL) {
|
2009-10-16 19:01:57 +05:30
|
|
|
printf("error: allocating array mem! (%s)\n",
|
2009-08-17 22:37:20 +05:30
|
|
|
strerror(errno));
|
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
|
|
|
|
trans->force = force;
|
|
|
|
rv = exec_transaction(trans);
|
|
|
|
|
|
|
|
prop_object_iterator_release(trans->iter);
|
|
|
|
out2:
|
|
|
|
prop_object_release(trans->dict);
|
|
|
|
out1:
|
|
|
|
free(trans);
|
|
|
|
out:
|
2009-10-23 17:31:54 +05:30
|
|
|
return rv;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2009-10-17 08:29:59 +05:30
|
|
|
static int
|
|
|
|
replace_packages(prop_object_iterator_t iter, const char *pkgname,
|
|
|
|
const char *version)
|
|
|
|
{
|
|
|
|
prop_dictionary_t instd;
|
|
|
|
prop_object_t obj;
|
|
|
|
const char *reppkgn;
|
|
|
|
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))) {
|
|
|
|
reppkgn = prop_string_cstring_nocopy(obj);
|
|
|
|
instd = xbps_find_pkg_installed_from_plist(reppkgn);
|
|
|
|
if (instd == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
printf("Replacing package '%s' with '%s-%s' ...\n",
|
|
|
|
reppkgn, pkgname, version);
|
|
|
|
if ((rv = xbps_remove_pkg(reppkgn, NULL, false)) != 0) {
|
|
|
|
printf("Couldn't remove %s (%s)\n",
|
|
|
|
reppkgn, strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if ((rv = xbps_purge_pkg(reppkgn, false)) != 0) {
|
|
|
|
printf("Couldn't purge %s (%s)\n",
|
|
|
|
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-08-17 22:37:20 +05:30
|
|
|
const char *pkgname, *version, *instver, *filename, *tract;
|
|
|
|
int rv = 0;
|
2009-10-22 18:02:21 +05:30
|
|
|
bool essential, 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);
|
|
|
|
|
2009-10-22 18:02:21 +05:30
|
|
|
essential = autoinst = false;
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Show download/installed size for the transaction.
|
|
|
|
*/
|
|
|
|
rv = show_transaction_sizes(trans->iter);
|
|
|
|
if (rv != 0)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ask interactively (if -f not set).
|
|
|
|
*/
|
|
|
|
if (trans->force == false) {
|
|
|
|
if (xbps_noyes("Do you want to continue?") == false) {
|
|
|
|
printf("Aborting!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-27 06:16:00 +05:30
|
|
|
/*
|
|
|
|
* Download binary packages if they are in a remote repository.
|
|
|
|
*/
|
|
|
|
if ((rv = download_package_list(trans->iter)) != 0)
|
|
|
|
return rv;
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Check the SHA256 hash for all required packages.
|
|
|
|
*/
|
|
|
|
if ((rv = check_pkg_hashes(trans->iter)) != 0)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate over the transaction dictionary.
|
|
|
|
*/
|
|
|
|
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
|
|
|
prop_dictionary_get_bool(obj, "essential", &essential);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
|
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
|
|
|
|
2009-10-22 18:02:21 +05:30
|
|
|
/*
|
|
|
|
* Set automatic-install bool if we are updating all packages,
|
|
|
|
* and a new package is going to be installed, and
|
|
|
|
* if we updating a package required new updating dependent
|
|
|
|
* packages.
|
|
|
|
*/
|
2009-08-17 22:37:20 +05:30
|
|
|
if (trans->originpkgname &&
|
|
|
|
strcmp(trans->originpkgname, pkgname))
|
2009-10-22 18:02:21 +05:30
|
|
|
autoinst = true;
|
|
|
|
else if (!trans->originpkgname && strcmp(tract, "install") == 0)
|
|
|
|
autoinst = true;
|
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-10-17 08:29:59 +05:30
|
|
|
rv = replace_packages(replaces_iter, pkgname, version);
|
|
|
|
if (rv != 0) {
|
|
|
|
printf("Couldn't replace some packages! "
|
|
|
|
"(%s)\n", strerror(rv));
|
|
|
|
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) {
|
|
|
|
instpkgd = xbps_find_pkg_installed_from_plist(pkgname);
|
|
|
|
if (instpkgd == NULL) {
|
|
|
|
printf("error: unable to find %s installed "
|
|
|
|
"dict!\n", pkgname);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop_dictionary_get_cstring_nocopy(instpkgd,
|
|
|
|
"version", &instver);
|
|
|
|
autoinst = false;
|
|
|
|
prop_dictionary_get_bool(instpkgd, "automatic-install",
|
|
|
|
&autoinst);
|
|
|
|
prop_object_release(instpkgd);
|
|
|
|
|
|
|
|
/*
|
2009-10-01 11:05:42 +05:30
|
|
|
* If package is marked as 'essential' remove old
|
|
|
|
* requiredby entries and overwrite pkg files; otherwise
|
|
|
|
* remove old package and install new one.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2009-10-01 11:05:42 +05:30
|
|
|
if (essential) {
|
|
|
|
rv = xbps_requiredby_pkg_remove(pkgname);
|
|
|
|
if (rv != 0) {
|
|
|
|
printf("error: couldn't remove reqby"
|
|
|
|
" entries for %s-%s (%s)\n",
|
|
|
|
pkgname, instver, strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
} else {
|
2009-10-02 20:53:14 +05:30
|
|
|
printf("Removing %s-%s ...\n",
|
|
|
|
pkgname, instver);
|
2009-08-17 22:37:20 +05:30
|
|
|
rv = xbps_remove_pkg(pkgname, version, true);
|
|
|
|
if (rv != 0) {
|
|
|
|
printf("error: removing %s-%s (%s)\n",
|
|
|
|
pkgname, instver, strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Unpack binary package.
|
|
|
|
*/
|
|
|
|
printf("Unpacking %s-%s (from .../%s) ...\n", pkgname, version,
|
|
|
|
filename);
|
|
|
|
if ((rv = xbps_unpack_binary_pkg(obj, essential)) != 0) {
|
|
|
|
printf("error: unpacking %s-%s (%s)\n", pkgname,
|
|
|
|
version, strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Register binary package.
|
|
|
|
*/
|
2009-10-22 18:02:21 +05:30
|
|
|
if ((rv = xbps_register_pkg(obj, autoinst)) != 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
printf("error: registering %s-%s! (%s)\n",
|
|
|
|
pkgname, version, strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
2009-10-22 18:02:21 +05:30
|
|
|
autoinst = false;
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Set package state to unpacked in the transaction
|
|
|
|
* dictionary.
|
|
|
|
*/
|
|
|
|
if ((rv = xbps_set_pkg_state_dictionary(obj,
|
|
|
|
XBPS_PKG_STATE_UNPACKED)) != 0)
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
prop_object_iterator_reset(trans->iter);
|
|
|
|
/*
|
|
|
|
* Configure all unpacked packages.
|
|
|
|
*/
|
|
|
|
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
2009-08-25 09:33:02 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
|
|
|
if ((rv = xbps_configure_pkg(pkgname, version, false)) != 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
printf("Error configuring package %s (%s)\n",
|
|
|
|
pkgname, strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|