XBPS Library API  0.19
The X Binary Package System
package_conflicts.c
1 /*-
2  * Copyright (c) 2012 Juan Romero Pardines.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include <stdio.h>
27 #include <stdbool.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <errno.h>
31 
32 #include "xbps_api_impl.h"
33 
34 void HIDDEN
35 xbps_pkg_find_conflicts(struct xbps_handle *xhp,
36  prop_array_t unsorted,
37  prop_dictionary_t pkg_repod)
38 {
39  prop_array_t pkg_cflicts, trans_cflicts;
40  prop_dictionary_t pkgd;
41  prop_object_t obj;
42  prop_object_iterator_t iter;
43  const char *cfpkg, *repopkgver, *pkgver;
44  char *buf;
45 
46  pkg_cflicts = prop_dictionary_get(pkg_repod, "conflicts");
47  if (pkg_cflicts == NULL || prop_array_count(pkg_cflicts) == 0)
48  return;
49 
50  trans_cflicts = prop_dictionary_get(xhp->transd, "conflicts");
51  prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &repopkgver);
52 
53  iter = prop_array_iterator(trans_cflicts);
54  assert(iter);
55  while ((obj = prop_object_iterator_next(iter))) {
56  cfpkg = prop_string_cstring_nocopy(obj);
57  /*
58  * Check if current pkg conflicts with an installed package.
59  */
60  if ((pkgd = xbps_pkgdb_get_pkg(xhp, cfpkg)) ||
61  (pkgd = xbps_pkgdb_get_virtualpkg(xhp, cfpkg))) {
62  prop_dictionary_get_cstring_nocopy(pkgd,
63  "pkgver", &pkgver);
64  buf = xbps_xasprintf("%s conflicts with "
65  "installed pkg %s", repopkgver, pkgver);
66  prop_array_add_cstring(trans_cflicts, buf);
67  free(buf);
68  continue;
69  }
70  /*
71  * Check if current pkg conflicts with any pkg in transaction.
72  */
73  if ((pkgd = xbps_find_pkg_in_array(unsorted, cfpkg)) ||
74  (pkgd = xbps_find_virtualpkg_in_array(xhp, unsorted, cfpkg))) {
75  prop_dictionary_get_cstring_nocopy(pkgd,
76  "pkgver", &pkgver);
77  buf = xbps_xasprintf("%s conflicts with "
78  "%s in transaction", repopkgver, pkgver);
79  prop_array_add_cstring(trans_cflicts, buf);
80  free(buf);
81  continue;
82  }
83  }
84  prop_object_iterator_release(iter);
85 }