2011-10-20 18:09:58 +05:30
|
|
|
/*-
|
2014-09-11 21:25:05 +05:30
|
|
|
* Copyright (c) 2011-2014 Juan Romero Pardines.
|
2011-10-20 18:09:58 +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 <unistd.h>
|
2012-05-26 02:14:58 +05:30
|
|
|
#include <libgen.h>
|
2011-10-20 18:09:58 +05:30
|
|
|
|
|
|
|
#include "xbps_api_impl.h"
|
|
|
|
|
|
|
|
int HIDDEN
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_transaction_package_replace(struct xbps_handle *xhp)
|
2011-10-20 18:09:58 +05:30
|
|
|
{
|
2014-09-11 21:25:05 +05:30
|
|
|
xbps_array_t unsorted;
|
2011-10-20 18:09:58 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
unsorted = xbps_dictionary_get(xhp->transd, "unsorted_deps");
|
2011-10-20 18:09:58 +05:30
|
|
|
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(unsorted); i++) {
|
2014-09-11 21:25:05 +05:30
|
|
|
xbps_array_t replaces;
|
|
|
|
xbps_object_t obj, obj2;
|
|
|
|
xbps_object_iterator_t iter;
|
|
|
|
const char *pkgver;
|
|
|
|
char *pkgname;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
obj = xbps_array_get(unsorted, i);
|
|
|
|
replaces = xbps_dictionary_get(obj, "replaces");
|
|
|
|
if (replaces == NULL || xbps_array_count(replaces) == 0)
|
2011-10-20 18:09:58 +05:30
|
|
|
continue;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
iter = xbps_array_iterator(replaces);
|
2012-11-30 14:34:36 +05:30
|
|
|
assert(iter);
|
2011-10-20 18:09:58 +05:30
|
|
|
|
2014-09-11 21:25:05 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
|
|
|
pkgname = xbps_pkg_name(pkgver);
|
|
|
|
assert(pkgname);
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
while ((obj2 = xbps_object_iterator_next(iter)) != NULL) {
|
2014-09-11 21:25:05 +05:30
|
|
|
xbps_dictionary_t instd, reppkgd;
|
|
|
|
const char *tract, *pattern, *curpkgver;
|
|
|
|
char *curpkgname;
|
|
|
|
bool instd_auto = false;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
pattern = xbps_string_cstring_nocopy(obj2);
|
2011-10-20 18:09:58 +05:30
|
|
|
/*
|
|
|
|
* Find the installed package that matches the pattern
|
|
|
|
* to be replaced.
|
|
|
|
*/
|
2012-11-30 14:34:36 +05:30
|
|
|
if (((instd = xbps_pkgdb_get_pkg(xhp, pattern)) == NULL) &&
|
|
|
|
((instd = xbps_pkgdb_get_virtualpkg(xhp, pattern)) == NULL))
|
|
|
|
continue;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(instd,
|
2012-01-24 23:13:43 +05:30
|
|
|
"pkgver", &curpkgver);
|
2013-03-05 08:38:42 +05:30
|
|
|
curpkgname = xbps_pkg_name(curpkgver);
|
|
|
|
assert(curpkgver);
|
2012-01-24 23:13:43 +05:30
|
|
|
/*
|
|
|
|
* Check that we are not replacing the same package,
|
|
|
|
* due to virtual packages.
|
|
|
|
*/
|
2013-03-05 08:38:42 +05:30
|
|
|
if (strcmp(pkgname, curpkgname) == 0) {
|
|
|
|
free(curpkgname);
|
2011-10-20 18:09:58 +05:30
|
|
|
continue;
|
2013-03-05 08:38:42 +05:30
|
|
|
}
|
2013-12-12 22:54:24 +05:30
|
|
|
/*
|
|
|
|
* Make sure to not add duplicates.
|
|
|
|
*/
|
2014-09-14 16:20:17 +05:30
|
|
|
reppkgd = xbps_find_pkg_in_array(unsorted, curpkgname, NULL);
|
2013-12-12 22:54:24 +05:30
|
|
|
if (reppkgd) {
|
|
|
|
xbps_dictionary_get_cstring_nocopy(reppkgd,
|
|
|
|
"transaction", &tract);
|
|
|
|
if (strcmp(tract, "remove") == 0)
|
|
|
|
continue;
|
|
|
|
}
|
2011-10-20 18:09:58 +05:30
|
|
|
/*
|
|
|
|
* Package contains replaces="pkgpattern", but the
|
|
|
|
* package that should be replaced is also in the
|
|
|
|
* transaction and it's going to be updated.
|
|
|
|
*/
|
2013-12-12 22:54:24 +05:30
|
|
|
xbps_dictionary_get_bool(instd, "automatic-install", &instd_auto);
|
2014-09-14 16:20:17 +05:30
|
|
|
if ((reppkgd = xbps_find_pkg_in_array(unsorted, curpkgname, NULL))) {
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_bool(instd,
|
2011-10-20 18:09:58 +05:30
|
|
|
"remove-and-update", true);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_bool(reppkgd,
|
2011-10-20 18:09:58 +05:30
|
|
|
"automatic-install", instd_auto);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_bool(reppkgd,
|
2012-02-21 00:53:33 +05:30
|
|
|
"skip-obsoletes", true);
|
2012-11-30 11:41:51 +05:30
|
|
|
xbps_array_replace_dict_by_name(unsorted,
|
2013-12-12 22:54:24 +05:30
|
|
|
reppkgd, curpkgname);
|
2011-10-20 18:09:58 +05:30
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If new package is providing a virtual package to the
|
|
|
|
* package that we want to replace we should respect
|
2012-11-30 22:10:52 +05:30
|
|
|
* the automatic-install object.
|
2011-10-20 18:09:58 +05:30
|
|
|
*/
|
2014-04-20 20:24:50 +05:30
|
|
|
if (xbps_match_virtual_pkg_in_dict(obj, pattern)) {
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_bool(obj,
|
2011-10-20 18:09:58 +05:30
|
|
|
"automatic-install", instd_auto);
|
|
|
|
}
|
2013-12-12 22:54:24 +05:30
|
|
|
xbps_dbg_printf(xhp,
|
|
|
|
"Package `%s' will be replaced by `%s', "
|
|
|
|
"matched with `%s'\n", curpkgver, pkgver, pattern);
|
2011-10-20 18:09:58 +05:30
|
|
|
/*
|
|
|
|
* Add package dictionary into the transaction and mark
|
|
|
|
* it as to be "removed".
|
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_cstring_nocopy(instd,
|
2011-10-20 18:09:58 +05:30
|
|
|
"transaction", "remove");
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_add(unsorted, instd);
|
2013-03-05 08:38:42 +05:30
|
|
|
free(curpkgname);
|
2011-10-20 18:09:58 +05:30
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_iterator_release(iter);
|
2014-09-11 21:25:05 +05:30
|
|
|
free(pkgname);
|
2011-10-20 18:09:58 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|