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
|
2011-01-24 21:25:58 +05:30
|
|
|
* @brief Repository package handling routines
|
|
|
|
* @defgroup repo_pkgs Repository package handling functions
|
2010-01-23 04:29:55 +05:30
|
|
|
*
|
|
|
|
* The following image shows off the full transaction dictionary returned
|
2011-01-24 21:25:58 +05:30
|
|
|
* by xbps_transaction_prepare().
|
2010-01-23 04:29:55 +05:30
|
|
|
*
|
|
|
|
* @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
|
|
|
*/
|
2011-01-24 23:19:24 +05:30
|
|
|
static int
|
|
|
|
repository_find_pkg(const char *pattern, const char *reason)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-01-24 23:19:24 +05:30
|
|
|
prop_dictionary_t pkg_repod = NULL, origin_pkgrd = NULL;
|
2011-02-18 21:07:16 +05:30
|
|
|
prop_dictionary_t transd, tmpd;
|
2011-01-24 23:19:24 +05:30
|
|
|
prop_array_t mdeps, unsorted;
|
2009-08-17 22:37:20 +05:30
|
|
|
const char *pkgname;
|
|
|
|
int rv = 0;
|
2011-02-18 21:07:16 +05:30
|
|
|
bool install, bypattern, bestpkg;
|
2011-02-22 15:01:16 +05:30
|
|
|
pkg_state_t state = 0;
|
2011-01-24 23:19:24 +05:30
|
|
|
|
|
|
|
assert(pattern != NULL);
|
|
|
|
assert(reason != NULL);
|
2011-02-03 22:19:43 +05:30
|
|
|
install = bypattern = false;
|
2011-01-24 23:19:24 +05:30
|
|
|
|
|
|
|
if (strcmp(reason, "install") == 0) {
|
|
|
|
/* install */
|
|
|
|
install = true;
|
|
|
|
bypattern = true;
|
|
|
|
bestpkg = false;
|
|
|
|
} else {
|
|
|
|
/* update */
|
|
|
|
pkg_repod = xbps_find_pkg_dict_installed(pattern, false);
|
|
|
|
if (pkg_repod == NULL) {
|
|
|
|
rv = ENODEV;
|
2010-11-19 18:10:13 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2011-01-24 23:19:24 +05:30
|
|
|
prop_object_release(pkg_repod);
|
|
|
|
pkg_repod = NULL;
|
|
|
|
bestpkg = true;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2010-11-19 18:10:13 +05:30
|
|
|
|
|
|
|
/*
|
2011-01-24 23:19:24 +05:30
|
|
|
* Find out if the pkg has been found in repository pool.
|
2010-11-19 18:10:13 +05:30
|
|
|
*/
|
2011-01-24 23:19:24 +05:30
|
|
|
pkg_repod = xbps_repository_pool_find_pkg(pattern,
|
|
|
|
bypattern, bestpkg);
|
2011-01-18 19:14:39 +05:30
|
|
|
if (pkg_repod == NULL) {
|
2011-01-24 23:19:24 +05:30
|
|
|
/* not found */
|
2011-01-18 19:14:39 +05:30
|
|
|
rv = errno;
|
|
|
|
errno = 0;
|
2009-11-26 07:52:50 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
2011-01-24 21:25:58 +05:30
|
|
|
* Prepare transaction dictionary and missing deps array.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2011-01-24 21:25:58 +05:30
|
|
|
if ((transd = xbps_transaction_dictionary_get()) == NULL) {
|
|
|
|
rv = EINVAL;
|
2009-08-17 22:37:20 +05:30
|
|
|
goto out;
|
2011-01-24 21:25:58 +05:30
|
|
|
}
|
|
|
|
if ((mdeps = xbps_transaction_missingdeps_get()) == NULL) {
|
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
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.
|
|
|
|
*/
|
2011-01-24 23:19:24 +05:30
|
|
|
if (install) {
|
2011-02-18 21:07:16 +05:30
|
|
|
tmpd = xbps_find_pkg_in_dict_by_pattern(transd,
|
2011-01-24 23:19:24 +05:30
|
|
|
"unsorted_pkgs", pattern);
|
|
|
|
} else {
|
2011-02-18 21:07:16 +05:30
|
|
|
tmpd = xbps_find_pkg_in_dict_by_name(transd,
|
2011-01-24 23:19:24 +05:30
|
|
|
"unsorted_pkgs", pattern);
|
2011-02-18 21:07:16 +05:30
|
|
|
|
2011-01-24 23:19:24 +05:30
|
|
|
}
|
2011-02-18 21:07:16 +05:30
|
|
|
if (tmpd) {
|
2011-01-18 19:14:39 +05:30
|
|
|
xbps_dbg_printf("package '%s' already queued in transaction\n",
|
2011-01-24 23:19:24 +05:30
|
|
|
pattern);
|
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-24 23:19:24 +05:30
|
|
|
rv = xbps_repository_find_pkg_deps(transd, mdeps, origin_pkgrd);
|
|
|
|
if (rv != 0)
|
2009-12-22 17:07:36 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-01-24 23:19:24 +05:30
|
|
|
/*
|
2011-02-23 21:44:33 +05:30
|
|
|
* Set package state in dictionary with same state than the
|
|
|
|
* package currently uses, otherwise not-installed.
|
2011-01-24 23:19:24 +05:30
|
|
|
*/
|
2011-02-22 15:01:16 +05:30
|
|
|
if ((rv = xbps_get_pkg_state_installed(pkgname, &state)) != 0) {
|
2011-02-23 21:44:33 +05:30
|
|
|
if (rv != ENOENT)
|
2011-02-22 15:01:16 +05:30
|
|
|
goto out;
|
2011-02-23 21:44:33 +05:30
|
|
|
/* Package not installed, don't error out */
|
|
|
|
rv = 0;
|
|
|
|
state = XBPS_PKG_STATE_NOT_INSTALLED;
|
2011-02-22 15:01:16 +05:30
|
|
|
}
|
2011-02-23 21:44:33 +05:30
|
|
|
if ((rv = xbps_set_pkg_state_dictionary(origin_pkgrd, state)) != 0)
|
2009-08-17 22:37:20 +05:30
|
|
|
goto out;
|
|
|
|
|
2011-02-22 15:01:16 +05:30
|
|
|
if (state == XBPS_PKG_STATE_UNPACKED)
|
|
|
|
reason = "configure";
|
2010-11-19 18:10:13 +05:30
|
|
|
/*
|
2011-02-22 15:01:16 +05:30
|
|
|
* Set transaction obj in pkg dictionary to "install", "configure"
|
|
|
|
* or "update".
|
2010-11-19 18:10:13 +05:30
|
|
|
*/
|
2009-11-26 07:52:50 +05:30
|
|
|
if (!prop_dictionary_set_cstring_nocopy(origin_pkgrd,
|
2011-02-05 16:51:04 +05:30
|
|
|
"transaction", reason)) {
|
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
|
|
|
/*
|
2011-01-24 23:19:24 +05:30
|
|
|
* Add required package dictionary into the unsorted array.
|
2011-01-18 19:14:39 +05:30
|
|
|
*/
|
2011-01-24 21:25:58 +05:30
|
|
|
unsorted = prop_dictionary_get(transd, "unsorted_deps");
|
2011-01-18 19:14:39 +05:30
|
|
|
if (unsorted == NULL) {
|
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-02-01 05:51:54 +05:30
|
|
|
/*
|
|
|
|
* Check if this package should replace other installed packages.
|
|
|
|
*/
|
|
|
|
if ((rv = xbps_repository_pkg_replaces(transd, origin_pkgrd)) != 0)
|
|
|
|
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-24 23:19:24 +05:30
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xbps_repository_update_allpkgs(void)
|
|
|
|
{
|
|
|
|
prop_dictionary_t dict;
|
|
|
|
prop_object_t obj;
|
|
|
|
prop_object_iterator_t iter;
|
|
|
|
const char *pkgname;
|
|
|
|
int rv = 0;
|
|
|
|
bool newpkg_found = false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare dictionary with all registered packages.
|
|
|
|
*/
|
|
|
|
dict = xbps_regpkgdb_dictionary_get();
|
|
|
|
if (dict == NULL)
|
2011-02-03 14:04:38 +05:30
|
|
|
return ENOENT;
|
2011-01-24 23:19:24 +05:30
|
|
|
|
|
|
|
iter = xbps_get_array_iter_from_dict(dict, "packages");
|
|
|
|
if (iter == NULL) {
|
|
|
|
xbps_regpkgdb_dictionary_release();
|
2011-02-03 14:04:38 +05:30
|
|
|
return ENOENT;
|
2011-01-24 23:19:24 +05:30
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Find out if there is a newer version for all currently
|
|
|
|
* installed packages.
|
|
|
|
*/
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
if ((rv = xbps_repository_update_pkg(pkgname)) != 0) {
|
|
|
|
if (rv == ENOENT || rv == EEXIST) {
|
|
|
|
/*
|
|
|
|
* missing pkg or installed version is
|
|
|
|
* greater than or equal than pkg
|
|
|
|
* in repositories.
|
|
|
|
*/
|
|
|
|
rv = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
xbps_dbg_printf("[update-all] '%s' returned: %s\n",
|
|
|
|
pkgname, strerror(rv));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
newpkg_found = true;
|
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
xbps_regpkgdb_dictionary_release();
|
|
|
|
|
|
|
|
if (!newpkg_found)
|
|
|
|
rv = ENXIO;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2011-01-24 23:19:24 +05:30
|
|
|
|
2011-02-23 21:57:51 +05:30
|
|
|
inline int
|
2011-01-24 23:19:24 +05:30
|
|
|
xbps_repository_update_pkg(const char *pkgname)
|
|
|
|
{
|
|
|
|
return repository_find_pkg(pkgname, "update");
|
|
|
|
}
|
|
|
|
|
2011-02-23 21:57:51 +05:30
|
|
|
inline int
|
2011-01-24 23:19:24 +05:30
|
|
|
xbps_repository_install_pkg(const char *pkgpattern)
|
|
|
|
{
|
|
|
|
return repository_find_pkg(pkgpattern, "install");
|
|
|
|
}
|