Added xbps_repository_pkg_replaces() to handle pkg "replaces" in the transaction.

The frontend (in that case xbps-bin(8)) is only responsible to remove
those packages that have the "trans-action" string object set to "remove".
This commit is contained in:
Juan RP
2011-02-01 01:21:54 +01:00
parent 7b159d6f33
commit fdc496e8f1
8 changed files with 163 additions and 123 deletions

View File

@@ -40,8 +40,8 @@ endif
OBJS = package_configure.o package_config_files.o package_orphans.o
OBJS += package_remove.o package_remove_obsoletes.o package_state.o
OBJS += package_unpack.o package_requiredby.o package_register.o
OBJS += package_purge.o initend.o transaction_dictionary.o
OBJS += transaction_sortdeps.o
OBJS += package_purge.o package_replaces.o initend.o
OBJS += transaction_dictionary.o transaction_sortdeps.o
OBJS += cmpver.o download.o fexec.o humanize_number.o plist.o
OBJS += util.o pkgmatch.o mkpath.o
OBJS += regpkgdb_dictionary.o repository_register.o

97
lib/package_replaces.c Normal file
View File

@@ -0,0 +1,97 @@
/*-
* 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.h>
#include "xbps_api_impl.h"
int HIDDEN
xbps_repository_pkg_replaces(prop_dictionary_t transd,
prop_dictionary_t pkg_repod)
{
prop_array_t replaces, unsorted;
prop_dictionary_t instd;
prop_object_t obj;
prop_object_iterator_t iter;
const char *pattern;
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;
unsorted = prop_dictionary_get(transd, "unsorted_deps");
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);
if (instd == NULL)
continue;
/*
* If the package to be replaced is in the transaction due to
* an update, do not remove it; just overwrite its files.
*/
transd = xbps_find_pkg_in_dict_by_pattern(transd,
"unsorted_deps", pattern);
if (transd) {
/*
* Set the bool property 'replace-files-in-pkg-update',
* will be used in xbps_unpack_binary_pkg().
*/
prop_dictionary_set_bool(pkg_repod,
"replace-files-in-pkg-update", true);
prop_object_release(instd);
continue;
}
/*
* Add package dictionary into the transaction and mark it
* as to be "removed".
*/
prop_dictionary_set_cstring_nocopy(instd,
"trans-action", "remove");
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;
}

View File

@@ -48,6 +48,11 @@ store_dependency(prop_dictionary_t transd, prop_dictionary_t repo_pkgd)
prop_dictionary_get_cstring_nocopy(repo_pkgd, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(repo_pkgd, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(repo_pkgd, "repository", &repoloc);
/*
* Check if this package should replace other installed packages.
*/
if ((rv = xbps_repository_pkg_replaces(transd, repo_pkgd)) != 0)
return rv;
dict = prop_dictionary_copy(repo_pkgd);
if (dict == NULL)

View File

@@ -183,6 +183,12 @@ repository_find_pkg(const char *pattern, const char *reason)
rv = EINVAL;
goto out;
}
/*
* Check if this package should replace other installed packages.
*/
if ((rv = xbps_repository_pkg_replaces(transd, origin_pkgrd)) != 0)
goto out;
/*
* Add the pkg dictionary from repository's index dictionary into
* the "unsorted" array in transaction dictionary.