Imported Upstream version 1.16.10
[services/dpkg.git] / lib / dpkg / depcon.c
1 /*
2  * libdpkg - Debian packaging suite library routines
3  * depcon.c - dependency and conflict checking
4  *
5  * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
6  * Copyright © 2009 Canonical Ltd.
7  *
8  * This is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #include <config.h>
23 #include <compat.h>
24
25 #include <dpkg/dpkg.h>
26 #include <dpkg/dpkg-db.h>
27 #include <dpkg/arch.h>
28
29 bool
30 versionsatisfied(struct pkgbin *it, struct deppossi *against)
31 {
32         return dpkg_version_relate(&it->version,
33                                    against->verrel,
34                                    &against->version);
35 }
36
37 /**
38  * Check if the architecture qualifier in the dependency is satisfied.
39  *
40  * The rules are supposed to be:
41  * - unqualified Depends/Pre-Depends/Recommends/Suggests are only
42  *   satisfied by a package of a different architecture if the target
43  *   package is Multi-Arch: foreign.
44  * - Depends/Pre-Depends/Recommends/Suggests on pkg:any are satisfied by
45  *   a package of a different architecture if the target package is
46  *   Multi-Arch: allowed.
47  * - all other Depends/Pre-Depends/Recommends/Suggests are only
48  *   satisfied by packages of the same architecture.
49  * - Architecture: all packages are treated the same as packages of the
50  *   native architecture.
51  * - Conflicts/Replaces/Breaks are assumed to apply to packages of any arch.
52  */
53 bool
54 deparchsatisfied(struct pkgbin *it, const struct dpkg_arch *it_arch,
55                  struct deppossi *against)
56 {
57         const struct dpkg_arch *dep_arch, *pkg_arch;
58
59         if (against->arch_is_implicit &&
60             it->multiarch == multiarch_foreign)
61                 return true;
62
63         dep_arch = against->arch;
64         if (dep_arch->type == arch_wildcard &&
65             (it->multiarch == multiarch_allowed ||
66              against->up->type == dep_conflicts ||
67              against->up->type == dep_replaces ||
68              against->up->type == dep_breaks))
69                 return true;
70
71         pkg_arch = it_arch;
72         if (dep_arch->type == arch_none || dep_arch->type == arch_all)
73                 dep_arch = dpkg_arch_get(arch_native);
74         if (pkg_arch->type == arch_none || pkg_arch->type == arch_all)
75                 pkg_arch = dpkg_arch_get(arch_native);
76
77         return (dep_arch == pkg_arch);
78 }
79
80 bool
81 archsatisfied(struct pkgbin *it, struct deppossi *against)
82 {
83         return deparchsatisfied(it, it->arch, against);
84 }