2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2011-01-18 19:14:39 +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>
|
|
|
|
|
|
|
|
#include <xbps_api.h>
|
2010-11-13 07:48:58 +05:30
|
|
|
#include "xbps_api_impl.h"
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
/**
|
|
|
|
* @file lib/repository_findpkg.c
|
2010-01-23 04:29:55 +05:30
|
|
|
* @brief Repository transaction handling routines
|
|
|
|
* @defgroup repo_pkgs Repository transaction handling functions
|
|
|
|
*
|
|
|
|
* The following image shows off the full transaction dictionary returned
|
|
|
|
* by xbps_repository_get_transaction_dict().
|
|
|
|
*
|
|
|
|
* @image html images/xbps_transaction_dictionary.png
|
|
|
|
*
|
|
|
|
* Legend:
|
|
|
|
* - <b>Salmon bg box</b>: The transaction dictionary.
|
|
|
|
* - <b>White bg box</b>: mandatory objects.
|
|
|
|
* - <b>Grey bg box</b>: optional objects.
|
|
|
|
* - <b>Green bg box</b>: possible value set in the object, only one of them
|
|
|
|
* will be set.
|
|
|
|
*
|
|
|
|
* Text inside of white boxes are the key associated with the object, its
|
|
|
|
* data type is specified on its edge, i.e string, array, integer, dictionary.
|
2010-01-21 07:40:19 +05:30
|
|
|
*/
|
|
|
|
|
2009-11-30 16:38:46 +05:30
|
|
|
static prop_dictionary_t trans_dict;
|
|
|
|
static bool trans_dict_initialized;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
|
|
|
* This creates the transaction dictionary with two arrays, one for
|
|
|
|
* dependencies not yet sorted and another one for missing dependencies.
|
|
|
|
*
|
|
|
|
* Before returning the dictionary to the caller, package dependencies in
|
|
|
|
* the "unsorted_deps" array will be sorted and moved to another
|
|
|
|
* array called "packages". If there are no missing dependencies, the
|
|
|
|
* "missing_deps" array will be removed.
|
|
|
|
*
|
|
|
|
*/
|
2009-08-17 22:37:20 +05:30
|
|
|
static int
|
2009-11-30 16:38:46 +05:30
|
|
|
create_transaction_dictionary(void)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
|
|
|
prop_array_t unsorted, missing;
|
|
|
|
int rv = 0;
|
|
|
|
|
2009-11-30 16:38:46 +05:30
|
|
|
if (trans_dict_initialized)
|
2009-08-17 22:37:20 +05:30
|
|
|
return 0;
|
|
|
|
|
2009-11-30 16:38:46 +05:30
|
|
|
trans_dict = prop_dictionary_create();
|
|
|
|
if (trans_dict == NULL)
|
2009-08-17 22:37:20 +05:30
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
missing = prop_array_create();
|
|
|
|
if (missing == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsorted = prop_array_create();
|
|
|
|
if (unsorted == NULL) {
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = ENOMEM;
|
|
|
|
goto fail2;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
if (!xbps_add_obj_to_dict(trans_dict, missing, "missing_deps")) {
|
|
|
|
rv = EINVAL;
|
|
|
|
goto fail3;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2009-11-30 16:38:46 +05:30
|
|
|
if (!xbps_add_obj_to_dict(trans_dict, unsorted, "unsorted_deps")) {
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = EINVAL;
|
|
|
|
goto fail3;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-11-30 16:38:46 +05:30
|
|
|
trans_dict_initialized = true;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
return rv;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
fail3:
|
2010-11-19 18:10:13 +05:30
|
|
|
prop_object_release(unsorted);
|
2009-08-17 22:37:20 +05:30
|
|
|
fail2:
|
2010-11-19 18:10:13 +05:30
|
|
|
prop_object_release(missing);
|
2009-08-17 22:37:20 +05:30
|
|
|
fail:
|
2010-11-19 18:10:13 +05:30
|
|
|
prop_object_release(trans_dict);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
return rv;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
static int
|
|
|
|
compute_transaction_sizes(void)
|
|
|
|
{
|
|
|
|
prop_object_iterator_t iter;
|
|
|
|
prop_object_t obj;
|
|
|
|
uint64_t tsize = 0, dlsize = 0, instsize = 0;
|
|
|
|
int rv = 0;
|
|
|
|
const char *tract;
|
|
|
|
|
|
|
|
iter = xbps_get_array_iter_from_dict(trans_dict, "packages");
|
|
|
|
if (iter == NULL)
|
2010-11-19 18:10:13 +05:30
|
|
|
return EINVAL;
|
2010-01-21 07:40:19 +05:30
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
|
2010-01-21 07:40:19 +05:30
|
|
|
/*
|
|
|
|
* Skip pkgs that need to be configured.
|
|
|
|
*/
|
|
|
|
if (strcmp(tract, "configure") == 0)
|
|
|
|
continue;
|
|
|
|
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_uint64(obj, "filename-size", &tsize);
|
2010-01-21 07:40:19 +05:30
|
|
|
dlsize += tsize;
|
|
|
|
tsize = 0;
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_uint64(obj, "installed_size", &tsize);
|
2010-01-21 07:40:19 +05:30
|
|
|
instsize += tsize;
|
|
|
|
tsize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add object in transaction dictionary with total installed
|
|
|
|
* size that it will take.
|
|
|
|
*/
|
|
|
|
if (!prop_dictionary_set_uint64(trans_dict,
|
|
|
|
"total-installed-size", instsize)) {
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = EINVAL;
|
2010-01-21 07:40:19 +05:30
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Add object in transaction dictionary with total download
|
|
|
|
* size that needs to be sucked in.
|
|
|
|
*/
|
|
|
|
if (!prop_dictionary_set_uint64(trans_dict,
|
|
|
|
"total-download-size", dlsize)) {
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = EINVAL;
|
2010-01-21 07:40:19 +05:30
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_pkg_state(prop_dictionary_t pkgd, const char *pkgname)
|
|
|
|
{
|
|
|
|
pkg_state_t state = 0;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
rv = xbps_set_pkg_state_dictionary(pkgd, XBPS_PKG_STATE_NOT_INSTALLED);
|
|
|
|
if (rv != 0)
|
|
|
|
return rv;
|
|
|
|
/*
|
|
|
|
* Overwrite package state in dictionary if it was unpacked
|
|
|
|
* previously.
|
|
|
|
*/
|
|
|
|
rv = xbps_get_pkg_state_installed(pkgname, &state);
|
|
|
|
if (rv == 0) {
|
2010-11-19 18:10:13 +05:30
|
|
|
if (state == XBPS_PKG_STATE_INSTALLED)
|
|
|
|
return 0;
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
if ((rv = xbps_set_pkg_state_dictionary(pkgd, state)) != 0)
|
|
|
|
return rv;
|
2010-11-19 18:10:13 +05:30
|
|
|
} else if (rv == ENOENT)
|
2010-01-21 07:40:19 +05:30
|
|
|
rv = 0;
|
2010-11-19 18:10:13 +05:30
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop_dictionary_t
|
2009-11-30 16:38:46 +05:30
|
|
|
xbps_repository_get_transaction_dict(void)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2010-01-21 07:40:19 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
if (trans_dict_initialized == false) {
|
2010-11-19 18:10:13 +05:30
|
|
|
errno = ENXIO;
|
2010-01-21 07:40:19 +05:30
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-11-19 18:10:13 +05:30
|
|
|
* Sort package dependencies if necessary.
|
2010-01-21 07:40:19 +05:30
|
|
|
*/
|
|
|
|
if ((rv = xbps_sort_pkg_deps(trans_dict)) != 0) {
|
2010-11-19 18:10:13 +05:30
|
|
|
errno = rv;
|
2010-01-29 09:14:40 +05:30
|
|
|
/*
|
2010-11-19 18:10:13 +05:30
|
|
|
* If there are missing deps (ENOENT)
|
2010-01-29 09:14:40 +05:30
|
|
|
* return the dictionary, the client should always
|
|
|
|
* check if that's the case.
|
|
|
|
*/
|
2010-11-24 03:47:04 +05:30
|
|
|
return trans_dict;
|
2010-01-21 07:40:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add total transaction installed/download sizes
|
|
|
|
* to the transaction dictionary.
|
|
|
|
*/
|
2010-11-24 03:47:04 +05:30
|
|
|
if ((rv = compute_transaction_sizes()) != 0) {
|
|
|
|
errno = rv;
|
2009-08-17 22:37:20 +05:30
|
|
|
return NULL;
|
2010-11-24 03:47:04 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
|
|
|
* Remove the "missing_deps" array now that it's not needed.
|
|
|
|
*/
|
|
|
|
prop_dictionary_remove(trans_dict, "missing_deps");
|
|
|
|
|
2009-11-30 16:38:46 +05:30
|
|
|
return trans_dict;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int
|
2009-11-30 16:38:46 +05:30
|
|
|
xbps_repository_update_allpkgs(void)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
|
|
|
prop_dictionary_t dict;
|
|
|
|
prop_object_t obj;
|
|
|
|
prop_object_iterator_t iter;
|
|
|
|
const char *pkgname;
|
|
|
|
int rv = 0;
|
2009-10-17 09:48:20 +05:30
|
|
|
bool newpkg_found = false;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare dictionary with all registered packages.
|
|
|
|
*/
|
2010-11-19 18:10:13 +05:30
|
|
|
dict = xbps_regpkgdb_dictionary_get();
|
2009-08-17 22:37:20 +05:30
|
|
|
if (dict == NULL)
|
2010-11-19 18:10:13 +05:30
|
|
|
return errno;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
iter = xbps_get_array_iter_from_dict(dict, "packages");
|
2009-11-26 07:52:50 +05:30
|
|
|
if (iter == NULL) {
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = errno;
|
2009-11-26 07:52:50 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Find out if there is a newer version for all currently
|
|
|
|
* installed packages.
|
|
|
|
*/
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
2010-11-19 18:10:13 +05:30
|
|
|
if ((rv = xbps_repository_update_pkg(pkgname)) != 0) {
|
|
|
|
if (rv == ENOENT || rv == EEXIST)
|
|
|
|
continue;
|
2009-11-21 11:42:42 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
xbps_dbg_printf("[update-all] '%s' returned: %s\n",
|
|
|
|
pkgname, strerror(rv));
|
|
|
|
goto out;
|
|
|
|
}
|
2009-10-17 09:48:20 +05:30
|
|
|
newpkg_found = true;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
if (newpkg_found)
|
|
|
|
rv = 0;
|
|
|
|
else
|
|
|
|
rv = ENXIO;
|
|
|
|
|
2009-11-26 07:52:50 +05:30
|
|
|
out:
|
2010-11-19 18:10:13 +05:30
|
|
|
xbps_regpkgdb_dictionary_release();
|
2009-10-17 09:48:20 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int
|
2010-11-19 18:10:13 +05:30
|
|
|
xbps_repository_update_pkg(const char *pkgname)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
|
|
|
prop_array_t unsorted;
|
2011-01-18 19:14:39 +05:30
|
|
|
prop_dictionary_t pkg_repod;
|
2010-11-19 18:10:13 +05:30
|
|
|
int rv = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
assert(pkgname != NULL);
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
|
|
|
* Check if package is not installed.
|
|
|
|
*/
|
2011-01-18 19:14:39 +05:30
|
|
|
pkg_repod = xbps_find_pkg_dict_installed(pkgname, false);
|
|
|
|
if (pkg_repod == NULL) {
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = ENODEV;
|
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2011-01-18 19:14:39 +05:30
|
|
|
prop_object_release(pkg_repod);
|
2010-11-19 18:10:13 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Find out if a new package version exists in repositories.
|
|
|
|
*/
|
2011-01-18 19:14:39 +05:30
|
|
|
pkg_repod = xbps_repository_pool_find_pkg(pkgname, false, true);
|
|
|
|
xbps_dbg_printf("xbps_repository_pool_find_pkg returned %s for %s\n",
|
|
|
|
strerror(errno), pkgname);
|
|
|
|
if (pkg_repod == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
errno = 0;
|
2009-11-26 07:52:50 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
2009-11-30 16:38:46 +05:30
|
|
|
* Create the transaction dictionary.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2009-11-30 16:38:46 +05:30
|
|
|
if ((rv = create_transaction_dictionary()) != 0)
|
2009-08-17 22:37:20 +05:30
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct the dependency chain for this package.
|
|
|
|
*/
|
2011-01-18 19:14:39 +05:30
|
|
|
rv = xbps_repository_find_pkg_deps(trans_dict, pkg_repod);
|
2010-11-19 18:10:13 +05:30
|
|
|
if (rv != 0)
|
2009-08-17 22:37:20 +05:30
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add required package dictionary into the packages
|
|
|
|
* dictionary.
|
|
|
|
*/
|
2009-11-30 16:38:46 +05:30
|
|
|
unsorted = prop_dictionary_get(trans_dict, "unsorted_deps");
|
2009-08-17 22:37:20 +05:30
|
|
|
if (unsorted == NULL) {
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = errno;
|
2009-08-17 22:37:20 +05:30
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Always set "not-installed" package state. Will be overwritten
|
|
|
|
* to its correct state later.
|
|
|
|
*/
|
2011-01-18 19:14:39 +05:30
|
|
|
if ((rv = set_pkg_state(pkg_repod, pkgname)) != 0)
|
2009-08-17 22:37:20 +05:30
|
|
|
goto out;
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
|
|
|
* Set trans-action obj in pkg dictionary to "update".
|
|
|
|
*/
|
2011-01-18 19:14:39 +05:30
|
|
|
if (!prop_dictionary_set_cstring_nocopy(pkg_repod,
|
2009-11-23 15:16:51 +05:30
|
|
|
"trans-action", "update")) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
|
|
|
* Added package dictionary from repository into the "unsorted"
|
|
|
|
* array in the transaction dictionary.
|
|
|
|
*/
|
2011-01-18 19:14:39 +05:30
|
|
|
if (!prop_array_add(unsorted, pkg_repod)) {
|
2009-08-17 22:37:20 +05:30
|
|
|
rv = errno;
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
out:
|
2011-01-18 19:14:39 +05:30
|
|
|
if (pkg_repod)
|
|
|
|
prop_object_release(pkg_repod);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int
|
2010-11-19 18:10:13 +05:30
|
|
|
xbps_repository_install_pkg(const char *pkg)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-01-18 19:14:39 +05:30
|
|
|
prop_dictionary_t pkg_repod = NULL, origin_pkgrd = NULL;
|
2009-12-22 17:07:36 +05:30
|
|
|
prop_array_t unsorted;
|
2010-11-19 18:10:13 +05:30
|
|
|
const char *pkgname;
|
|
|
|
int rv = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-01-14 06:44:31 +05:30
|
|
|
assert(pkg != NULL);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
|
|
|
* Get the package dictionary from current repository.
|
|
|
|
* If it's not there, pass to the next repository.
|
|
|
|
*/
|
2011-01-18 19:14:39 +05:30
|
|
|
pkg_repod = xbps_repository_pool_find_pkg(pkg, true, false);
|
|
|
|
if (pkg_repod == NULL) {
|
|
|
|
/*
|
|
|
|
* Package couldn't be found in repository pool... EAGAIN.
|
|
|
|
*/
|
2009-08-17 22:37:20 +05:30
|
|
|
rv = EAGAIN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
2009-11-30 16:38:46 +05:30
|
|
|
* Create the transaction dictionary.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2010-11-19 18:10:13 +05:30
|
|
|
if ((rv = create_transaction_dictionary()) != 0)
|
2009-08-17 22:37:20 +05:30
|
|
|
goto out;
|
|
|
|
|
2011-01-18 19:14:39 +05:30
|
|
|
origin_pkgrd = prop_dictionary_copy(pkg_repod);
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
|
2010-01-14 18:27:13 +05:30
|
|
|
/*
|
|
|
|
* Check that this pkg hasn't been added previously into
|
|
|
|
* the transaction.
|
|
|
|
*/
|
2010-11-19 18:10:13 +05:30
|
|
|
if (xbps_find_pkg_in_dict_by_pattern(trans_dict,
|
2011-01-18 19:14:39 +05:30
|
|
|
"unsorted_deps", pkg)) {
|
|
|
|
xbps_dbg_printf("package '%s' already queued in transaction\n",
|
|
|
|
pkg);
|
2009-11-23 15:16:51 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
2010-11-19 18:10:13 +05:30
|
|
|
* Prepare required package dependencies and add them into the
|
|
|
|
* "unsorted" array in transaction dictionary.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2011-01-18 19:14:39 +05:30
|
|
|
rv = xbps_repository_find_pkg_deps(trans_dict, origin_pkgrd);
|
2010-11-19 18:10:13 +05:30
|
|
|
if (rv != 0)
|
2009-12-22 17:07:36 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-11-26 07:52:50 +05:30
|
|
|
if ((rv = set_pkg_state(origin_pkgrd, pkgname)) != 0)
|
2009-08-17 22:37:20 +05:30
|
|
|
goto out;
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
|
|
|
* Set trans-action obj in pkg dictionary to "install".
|
|
|
|
*/
|
2009-11-26 07:52:50 +05:30
|
|
|
if (!prop_dictionary_set_cstring_nocopy(origin_pkgrd,
|
2009-11-23 15:16:51 +05:30
|
|
|
"trans-action", "install")) {
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = EINVAL;
|
2009-11-23 15:16:51 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2011-01-18 19:14:39 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Add required package dictionary into the unsorted array and
|
|
|
|
* set package state as not yet installed.
|
|
|
|
*/
|
|
|
|
unsorted = prop_dictionary_get(trans_dict, "unsorted_deps");
|
|
|
|
if (unsorted == NULL) {
|
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
|
|
|
* Add the pkg dictionary from repository's index dictionary into
|
|
|
|
* the "unsorted" array in transaction dictionary.
|
|
|
|
*/
|
|
|
|
if (!prop_array_add(unsorted, origin_pkgrd)) {
|
2009-08-17 22:37:20 +05:30
|
|
|
rv = errno;
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
out:
|
2011-01-18 19:14:39 +05:30
|
|
|
if (pkg_repod)
|
|
|
|
prop_object_release(pkg_repod);
|
2009-11-26 07:52:50 +05:30
|
|
|
if (origin_pkgrd)
|
|
|
|
prop_object_release(origin_pkgrd);
|
|
|
|
|
2011-01-18 19:14:39 +05:30
|
|
|
xbps_dbg_printf("%s: returned %s for '%s'\n\n",
|
|
|
|
__func__, strerror(rv), pkg);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|