Commit | Line | Data |
---|---|---|
1479465f GJ |
1 | /* |
2 | * libdpkg - Debian packaging suite library routines | |
3 | * pkg.c - primitives for pkg handling | |
4 | * | |
5 | * Copyright © 1995, 1996 Ian Jackson <ijackson@chiark.greenend.org.uk> | |
6 | * Copyright © 2009-2014 Guillem Jover <guillem@debian.org> | |
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 <https://www.gnu.org/licenses/>. | |
20 | */ | |
21 | ||
22 | #include <config.h> | |
23 | #include <compat.h> | |
24 | ||
25 | #include <assert.h> | |
26 | #include <string.h> | |
27 | ||
28 | #include <dpkg/string.h> | |
29 | #include <dpkg/dpkg-db.h> | |
30 | #include <dpkg/pkg.h> | |
31 | ||
32 | /** | |
33 | * Set the package installation status. | |
34 | */ | |
35 | void | |
36 | pkg_set_status(struct pkginfo *pkg, enum pkgstatus status) | |
37 | { | |
38 | if (pkg->status == status) | |
39 | return; | |
40 | else if (pkg->status == PKG_STAT_NOTINSTALLED) | |
41 | pkg->set->installed_instances++; | |
42 | else if (status == PKG_STAT_NOTINSTALLED) | |
43 | pkg->set->installed_instances--; | |
44 | ||
45 | assert(pkg->set->installed_instances >= 0); | |
46 | ||
47 | pkg->status = status; | |
48 | } | |
49 | ||
50 | /** | |
51 | * Set the specified flags to 1 in the package error flags. | |
52 | */ | |
53 | void | |
54 | pkg_set_eflags(struct pkginfo *pkg, enum pkgeflag eflag) | |
55 | { | |
56 | pkg->eflag |= eflag; | |
57 | } | |
58 | ||
59 | /** | |
60 | * Clear the specified flags to 0 in the package error flags. | |
61 | */ | |
62 | void | |
63 | pkg_clear_eflags(struct pkginfo *pkg, enum pkgeflag eflag) | |
64 | { | |
65 | pkg->eflag &= ~eflag; | |
66 | } | |
67 | ||
68 | /** | |
69 | * Reset the package error flags to 0. | |
70 | */ | |
71 | void | |
72 | pkg_reset_eflags(struct pkginfo *pkg) | |
73 | { | |
74 | pkg->eflag = PKG_EFLAG_OK; | |
75 | } | |
76 | ||
77 | /** | |
78 | * Copy the package error flags to another package. | |
79 | */ | |
80 | void | |
81 | pkg_copy_eflags(struct pkginfo *pkg_dst, struct pkginfo *pkg_src) | |
82 | { | |
83 | pkg_dst->eflag = pkg_src->eflag; | |
84 | } | |
85 | ||
86 | /** | |
87 | * Set the package selection status. | |
88 | */ | |
89 | void | |
90 | pkg_set_want(struct pkginfo *pkg, enum pkgwant want) | |
91 | { | |
92 | pkg->want = want; | |
93 | } | |
94 | ||
95 | void | |
96 | pkgbin_blank(struct pkgbin *pkgbin) | |
97 | { | |
98 | pkgbin->essential = false; | |
99 | pkgbin->depends = NULL; | |
100 | pkgbin->pkgname_archqual = NULL; | |
101 | pkgbin->description = NULL; | |
102 | pkgbin->maintainer = NULL; | |
103 | pkgbin->source = NULL; | |
104 | pkgbin->installedsize = NULL; | |
105 | pkgbin->bugs = NULL; | |
106 | pkgbin->origin = NULL; | |
107 | dpkg_version_blank(&pkgbin->version); | |
108 | pkgbin->conffiles = NULL; | |
109 | pkgbin->arbs = NULL; | |
110 | } | |
111 | ||
112 | void | |
113 | pkg_blank(struct pkginfo *pkg) | |
114 | { | |
115 | pkg->status = PKG_STAT_NOTINSTALLED; | |
116 | pkg->eflag = PKG_EFLAG_OK; | |
117 | pkg->want = PKG_WANT_UNKNOWN; | |
118 | pkg->priority = PKG_PRIO_UNKNOWN; | |
119 | pkg->otherpriority = NULL; | |
120 | pkg->section = NULL; | |
121 | dpkg_version_blank(&pkg->configversion); | |
122 | pkg->files = NULL; | |
123 | pkg->clientdata = NULL; | |
124 | pkg->trigaw.head = NULL; | |
125 | pkg->trigaw.tail = NULL; | |
126 | pkg->othertrigaw_head = NULL; | |
127 | pkg->trigpend_head = NULL; | |
128 | pkgbin_blank(&pkg->installed); | |
129 | pkgbin_blank(&pkg->available); | |
130 | ||
131 | /* The architectures are reset here (instead of in pkgbin_blank), | |
132 | * because they are part of the package specification, and needed | |
133 | * for selections. */ | |
134 | pkg->installed.arch = dpkg_arch_get(DPKG_ARCH_NONE); | |
135 | pkg->installed.multiarch = PKG_MULTIARCH_NO; | |
136 | pkg->available.arch = dpkg_arch_get(DPKG_ARCH_NONE); | |
137 | pkg->available.multiarch = PKG_MULTIARCH_NO; | |
138 | } | |
139 | ||
140 | void | |
141 | pkgset_blank(struct pkgset *set) | |
142 | { | |
143 | set->name = NULL; | |
144 | set->depended.available = NULL; | |
145 | set->depended.installed = NULL; | |
146 | pkg_blank(&set->pkg); | |
147 | set->installed_instances = 0; | |
148 | set->pkg.set = set; | |
149 | set->pkg.arch_next = NULL; | |
150 | } | |
151 | ||
152 | /** | |
153 | * Link a pkginfo instance into a package set. | |
154 | * | |
155 | * @param set The package set to use. | |
156 | * @param pkg The package to link into the set. | |
157 | */ | |
158 | void | |
159 | pkgset_link_pkg(struct pkgset *set, struct pkginfo *pkg) | |
160 | { | |
161 | pkg->set = set; | |
162 | pkg->arch_next = set->pkg.arch_next; | |
163 | set->pkg.arch_next = pkg; | |
164 | } | |
165 | ||
166 | /** | |
167 | * Get the number of installed package instances in a package set. | |
168 | * | |
169 | * @param set The package set to use. | |
170 | * | |
171 | * @return The count of installed packages. | |
172 | */ | |
173 | int | |
174 | pkgset_installed_instances(struct pkgset *set) | |
175 | { | |
176 | return set->installed_instances; | |
177 | } | |
178 | ||
179 | /** | |
180 | * Check if a pkg is informative. | |
181 | * | |
182 | * Used by dselect and dpkg query options as an aid to decide whether to | |
183 | * display things, and by dump to decide whether to write them out. | |
184 | */ | |
185 | bool | |
186 | pkg_is_informative(struct pkginfo *pkg, struct pkgbin *pkgbin) | |
187 | { | |
188 | /* We ignore Section and Priority, as these tend to hang around. */ | |
189 | if (pkgbin == &pkg->installed && | |
190 | (pkg->want != PKG_WANT_UNKNOWN || | |
191 | pkg->eflag != PKG_EFLAG_OK || | |
192 | pkg->status != PKG_STAT_NOTINSTALLED || | |
193 | dpkg_version_is_informative(&pkg->configversion))) | |
194 | return true; | |
195 | ||
196 | if (pkgbin->depends || | |
197 | str_is_set(pkgbin->description) || | |
198 | str_is_set(pkgbin->maintainer) || | |
199 | str_is_set(pkgbin->origin) || | |
200 | str_is_set(pkgbin->bugs) || | |
201 | str_is_set(pkgbin->installedsize) || | |
202 | str_is_set(pkgbin->source) || | |
203 | dpkg_version_is_informative(&pkgbin->version) || | |
204 | pkgbin->conffiles || | |
205 | pkgbin->arbs) | |
206 | return true; | |
207 | ||
208 | return false; | |
209 | } |