2011-02-01 05:51:54 +05:30
|
|
|
/*-
|
|
|
|
* Copyright (c) 2011 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 <unistd.h>
|
|
|
|
|
|
|
|
#include "xbps_api_impl.h"
|
|
|
|
|
|
|
|
int HIDDEN
|
|
|
|
xbps_repository_pkg_replaces(prop_dictionary_t transd,
|
|
|
|
prop_dictionary_t pkg_repod)
|
|
|
|
{
|
2011-10-15 20:13:27 +05:30
|
|
|
prop_array_t replaces, unsorted, instd_reqby;
|
2011-02-18 21:09:42 +05:30
|
|
|
prop_dictionary_t instd, reppkgd;
|
2011-02-01 05:51:54 +05:30
|
|
|
prop_object_t obj;
|
|
|
|
prop_object_iterator_t iter;
|
2011-06-04 17:07:53 +05:30
|
|
|
const char *pattern, *pkgname, *curpkgname;
|
2011-10-16 13:58:03 +05:30
|
|
|
bool instd_auto = false;
|
2011-02-01 05:51:54 +05:30
|
|
|
|
2011-10-19 20:23:38 +05:30
|
|
|
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY);
|
|
|
|
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
|
|
|
|
|
2011-02-01 05:51:54 +05:30
|
|
|
replaces = prop_dictionary_get(pkg_repod, "replaces");
|
|
|
|
if (replaces == NULL || prop_array_count(replaces) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
iter = prop_array_iterator(replaces);
|
|
|
|
if (iter == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
|
|
|
pattern = prop_string_cstring_nocopy(obj);
|
|
|
|
assert(pattern != NULL);
|
|
|
|
/*
|
|
|
|
* Find the installed package that matches the pattern
|
|
|
|
* to be replaced.
|
|
|
|
*/
|
|
|
|
instd = xbps_find_pkg_dict_installed(pattern, true);
|
2011-10-15 23:31:55 +05:30
|
|
|
if (instd == NULL) {
|
|
|
|
/*
|
|
|
|
* No package installed has been matched, try looking
|
|
|
|
* for a virtual package.
|
|
|
|
*/
|
|
|
|
instd = xbps_find_virtualpkg_dict_installed(pattern, true);
|
|
|
|
if (instd == NULL)
|
|
|
|
continue;
|
|
|
|
}
|
2011-06-04 17:07:53 +05:30
|
|
|
/*
|
|
|
|
* Check that we are not replacing the same package, due
|
|
|
|
* to virtual packages.
|
|
|
|
*/
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(instd, "pkgname", &curpkgname);
|
|
|
|
if (strcmp(pkgname, curpkgname) == 0) {
|
|
|
|
prop_object_release(instd);
|
|
|
|
continue;
|
|
|
|
}
|
2011-02-01 05:51:54 +05:30
|
|
|
/*
|
2011-02-18 21:09:42 +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.
|
2011-02-01 05:51:54 +05:30
|
|
|
*/
|
2011-02-18 21:09:42 +05:30
|
|
|
unsorted = prop_dictionary_get(transd, "unsorted_deps");
|
|
|
|
reppkgd = xbps_find_pkg_in_array_by_pattern(unsorted, pattern);
|
|
|
|
if (reppkgd) {
|
|
|
|
prop_dictionary_set_bool(reppkgd,
|
|
|
|
"remove-and-update", true);
|
2011-02-01 05:51:54 +05:30
|
|
|
prop_object_release(instd);
|
|
|
|
continue;
|
|
|
|
}
|
2011-10-15 20:13:27 +05:30
|
|
|
/*
|
|
|
|
* If new package is providing a virtual package to the
|
|
|
|
* package that we want to replace we should respect
|
2011-10-16 13:58:03 +05:30
|
|
|
* its requiredby and automatic-install objects, so copy
|
|
|
|
* them to the pkg's dictionary in transaction.
|
2011-10-15 20:13:27 +05:30
|
|
|
*/
|
2011-10-16 13:58:03 +05:30
|
|
|
if (xbps_match_virtual_pkg_in_dict(pkg_repod, pattern, true) ||
|
|
|
|
xbps_match_virtual_pkg_in_dict(instd, pkgname, false)) {
|
2011-10-15 20:13:27 +05:30
|
|
|
instd_reqby = prop_dictionary_get(instd, "requiredby");
|
2011-10-16 13:58:03 +05:30
|
|
|
if (instd_reqby && prop_array_count(instd_reqby)) {
|
2011-10-15 20:13:27 +05:30
|
|
|
prop_dictionary_set(pkg_repod,
|
|
|
|
"requiredby", instd_reqby);
|
2011-10-16 13:58:03 +05:30
|
|
|
}
|
|
|
|
if (prop_dictionary_get_bool(instd,
|
|
|
|
"automatic-install", &instd_auto)) {
|
|
|
|
prop_dictionary_set_bool(pkg_repod,
|
|
|
|
"automatic-install", instd_auto);
|
|
|
|
}
|
2011-10-15 20:13:27 +05:30
|
|
|
}
|
2011-02-01 05:51:54 +05:30
|
|
|
/*
|
|
|
|
* Add package dictionary into the transaction and mark it
|
|
|
|
* as to be "removed".
|
|
|
|
*/
|
|
|
|
prop_dictionary_set_cstring_nocopy(instd,
|
2011-02-05 16:51:04 +05:30
|
|
|
"transaction", "remove");
|
2011-02-01 05:51:54 +05:30
|
|
|
if (!xbps_add_obj_to_array(unsorted, instd)) {
|
|
|
|
prop_object_release(instd);
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|