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