2011-10-20 18:09:58 +05:30
|
|
|
/*-
|
2013-03-05 08:38:42 +05:30
|
|
|
* Copyright (c) 2011-2013 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
|
|
|
{
|
2012-11-30 22:10:52 +05:30
|
|
|
prop_array_t replaces, unsorted;
|
2012-11-30 14:19:09 +05:30
|
|
|
prop_dictionary_t instd, reppkgd, filesd;
|
|
|
|
prop_object_t obj, obj2;
|
2012-11-30 14:34:36 +05:30
|
|
|
prop_object_iterator_t iter;
|
2013-03-05 08:38:42 +05:30
|
|
|
const char *pattern, *pkgver, *curpkgver;
|
|
|
|
char *buf, *pkgname, *curpkgname;
|
2012-05-25 20:54:36 +05:30
|
|
|
bool instd_auto, sr;
|
2013-06-12 13:34:10 +05:30
|
|
|
unsigned int i;
|
2011-10-20 18:09:58 +05:30
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
|
2011-10-20 18:09:58 +05:30
|
|
|
|
2012-11-30 14:34:36 +05:30
|
|
|
for (i = 0; i < prop_array_count(unsorted); i++) {
|
|
|
|
obj = prop_array_get(unsorted, i);
|
2012-11-30 14:19:09 +05:30
|
|
|
replaces = prop_dictionary_get(obj, "replaces");
|
2011-10-20 18:09:58 +05:30
|
|
|
if (replaces == NULL || prop_array_count(replaces) == 0)
|
|
|
|
continue;
|
|
|
|
|
2012-11-30 14:34:36 +05:30
|
|
|
iter = prop_array_iterator(replaces);
|
|
|
|
assert(iter);
|
2011-10-20 18:09:58 +05:30
|
|
|
|
2012-11-30 14:34:36 +05:30
|
|
|
while ((obj2 = prop_object_iterator_next(iter)) != NULL) {
|
2012-11-30 14:19:09 +05:30
|
|
|
pattern = prop_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;
|
|
|
|
|
2012-11-30 14:19:09 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj,
|
2012-01-24 23:13:43 +05:30
|
|
|
"pkgver", &pkgver);
|
|
|
|
prop_dictionary_get_cstring_nocopy(instd,
|
|
|
|
"pkgver", &curpkgver);
|
2013-03-05 08:38:42 +05:30
|
|
|
pkgname = xbps_pkg_name(pkgver);
|
|
|
|
assert(pkgname);
|
|
|
|
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(pkgname);
|
|
|
|
free(curpkgname);
|
2011-10-20 18:09:58 +05:30
|
|
|
continue;
|
2013-03-05 08:38:42 +05:30
|
|
|
}
|
2012-07-04 15:24:37 +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
|
|
|
instd_auto = false;
|
|
|
|
prop_dictionary_get_bool(instd,
|
|
|
|
"automatic-install", &instd_auto);
|
|
|
|
/*
|
|
|
|
* Package contains replaces="pkgpattern", but the
|
|
|
|
* package that should be replaced is also in the
|
|
|
|
* transaction and it's going to be updated.
|
|
|
|
*/
|
2013-02-05 16:40:24 +05:30
|
|
|
if ((reppkgd = xbps_find_pkg_in_array(unsorted, curpkgname))) {
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(xhp,
|
|
|
|
"found replaced pkg "
|
2011-10-20 18:09:58 +05:30
|
|
|
"in transaction\n");
|
|
|
|
prop_dictionary_set_bool(instd,
|
|
|
|
"remove-and-update", true);
|
|
|
|
prop_dictionary_set_bool(reppkgd,
|
|
|
|
"automatic-install", instd_auto);
|
2012-02-21 00:53:33 +05:30
|
|
|
prop_dictionary_set_bool(reppkgd,
|
|
|
|
"skip-obsoletes", true);
|
2012-11-30 11:41:51 +05:30
|
|
|
xbps_array_replace_dict_by_name(unsorted,
|
2011-10-20 18:09:58 +05:30
|
|
|
reppkgd, curpkgname);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
*/
|
2012-11-30 14:19:09 +05:30
|
|
|
if (xbps_match_virtual_pkg_in_dict(obj,
|
2011-10-20 18:09:58 +05:30
|
|
|
pattern, true) ||
|
|
|
|
xbps_match_virtual_pkg_in_dict(instd,
|
|
|
|
pkgname, false)) {
|
2012-11-30 14:19:09 +05:30
|
|
|
prop_dictionary_set_bool(obj,
|
2011-10-20 18:09:58 +05:30
|
|
|
"automatic-install", instd_auto);
|
|
|
|
}
|
2012-05-25 20:54:36 +05:30
|
|
|
sr = false;
|
2012-11-30 14:19:09 +05:30
|
|
|
prop_dictionary_get_bool(obj, "softreplace", &sr);
|
2012-05-25 20:54:36 +05:30
|
|
|
if (sr) {
|
2012-11-30 14:19:09 +05:30
|
|
|
prop_dictionary_set_bool(obj,
|
2012-05-25 20:54:36 +05:30
|
|
|
"automatic-install", instd_auto);
|
2012-05-25 21:28:36 +05:30
|
|
|
prop_dictionary_set_bool(instd,
|
|
|
|
"softreplace", true);
|
2012-11-16 21:25:35 +05:30
|
|
|
buf = xbps_xasprintf("%s/.%s.plist",
|
|
|
|
xhp->metadir, curpkgname);
|
2013-03-05 08:38:42 +05:30
|
|
|
filesd = prop_dictionary_internalize_from_file(buf);
|
2012-05-26 02:14:58 +05:30
|
|
|
free(buf);
|
|
|
|
assert(filesd != NULL);
|
2012-11-16 21:25:35 +05:30
|
|
|
buf = xbps_xasprintf("%s/.%s.plist",
|
|
|
|
xhp->metadir, pkgname);
|
2013-03-05 08:38:42 +05:30
|
|
|
if (!prop_dictionary_externalize_to_file(filesd, buf)) {
|
2012-05-26 02:14:58 +05:30
|
|
|
free(buf);
|
|
|
|
prop_object_release(filesd);
|
|
|
|
prop_object_iterator_release(iter);
|
2013-03-05 08:38:42 +05:30
|
|
|
free(pkgname);
|
|
|
|
free(curpkgname);
|
2012-05-26 02:14:58 +05:30
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
prop_object_release(filesd);
|
|
|
|
free(buf);
|
2012-05-25 20:54:36 +05:30
|
|
|
}
|
2011-10-20 18:09:58 +05:30
|
|
|
/*
|
|
|
|
* Add package dictionary into the transaction and mark
|
|
|
|
* it as to be "removed".
|
|
|
|
*/
|
|
|
|
prop_dictionary_set_cstring_nocopy(instd,
|
|
|
|
"transaction", "remove");
|
2012-11-30 11:41:51 +05:30
|
|
|
prop_array_add(unsorted, instd);
|
2013-03-05 08:38:42 +05:30
|
|
|
free(pkgname);
|
|
|
|
free(curpkgname);
|
2011-10-20 18:09:58 +05:30
|
|
|
}
|
2012-11-30 14:34:36 +05:30
|
|
|
prop_object_iterator_release(iter);
|
2011-10-20 18:09:58 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|