Branch data Line data Source code
1 : : /*
2 : : * dpkg - main program for package management
3 : : * unpack.c - .deb archive unpacking
4 : : *
5 : : * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 : : * Copyright © 2006-2015 Guillem Jover <guillem@debian.org>
7 : : * Copyright © 2011 Linaro Limited
8 : : * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
9 : : *
10 : : * This is free software; you can redistribute it and/or modify
11 : : * it under the terms of the GNU General Public License as published by
12 : : * the Free Software Foundation; either version 2 of the License, or
13 : : * (at your option) any later version.
14 : : *
15 : : * This is distributed in the hope that it will be useful,
16 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : : * GNU General Public License for more details.
19 : : *
20 : : * You should have received a copy of the GNU General Public License
21 : : * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 : : */
23 : :
24 : : #include <config.h>
25 : : #include <compat.h>
26 : :
27 : : #include <sys/types.h>
28 : : #include <sys/stat.h>
29 : : #include <sys/wait.h>
30 : :
31 : : #include <errno.h>
32 : : #include <string.h>
33 : : #include <time.h>
34 : : #include <utime.h>
35 : : #include <fcntl.h>
36 : : #include <dirent.h>
37 : : #include <unistd.h>
38 : : #include <stdint.h>
39 : : #include <stdlib.h>
40 : : #include <stdio.h>
41 : :
42 : : #include <dpkg/i18n.h>
43 : : #include <dpkg/c-ctype.h>
44 : : #include <dpkg/dpkg.h>
45 : : #include <dpkg/dpkg-db.h>
46 : : #include <dpkg/pkg.h>
47 : : #include <dpkg/pkg-queue.h>
48 : : #include <dpkg/path.h>
49 : : #include <dpkg/command.h>
50 : : #include <dpkg/buffer.h>
51 : : #include <dpkg/subproc.h>
52 : : #include <dpkg/dir.h>
53 : : #include <dpkg/tarfn.h>
54 : : #include <dpkg/options.h>
55 : : #include <dpkg/db-ctrl.h>
56 : : #include <dpkg/db-fsys.h>
57 : : #include <dpkg/triglib.h>
58 : :
59 : : #include "file-match.h"
60 : : #include "main.h"
61 : : #include "archives.h"
62 : :
63 : : static const char *
64 : 0 : summarize_filename(const char *filename)
65 : : {
66 : : const char *pfilename;
67 : : char *pfilenamebuf;
68 : :
69 : 0 : for (pfilename = filename;
70 [ # # # # : 0 : pfilename && strlen(pfilename) > 30 && strchr(pfilename, '/') != NULL;
# # ]
71 : 0 : pfilename++)
72 : 0 : pfilename = strchr(pfilename, '/');
73 : :
74 [ # # # # ]: 0 : if (pfilename && pfilename != filename) {
75 : 0 : pfilenamebuf = nfmalloc(strlen(pfilename) + 5);
76 : 0 : sprintf(pfilenamebuf, _(".../%s"), pfilename);
77 : 0 : pfilename = pfilenamebuf;
78 : : } else {
79 : 0 : pfilename = filename;
80 : : }
81 : :
82 : 0 : return pfilename;
83 : : }
84 : :
85 : : static bool
86 : 0 : deb_reassemble(const char **filename, const char **pfilename)
87 : : {
88 : : static char *reasmbuf = NULL;
89 : : struct stat stab;
90 : : int status;
91 : : pid_t pid;
92 : :
93 [ # # ]: 0 : if (!reasmbuf)
94 : 0 : reasmbuf = dpkg_db_get_path(REASSEMBLETMP);
95 [ # # # # ]: 0 : if (unlink(reasmbuf) && errno != ENOENT)
96 : 0 : ohshite(_("error ensuring '%.250s' doesn't exist"), reasmbuf);
97 : :
98 : 0 : push_cleanup(cu_pathname, ~0, 1, (void *)reasmbuf);
99 : :
100 : 0 : pid = subproc_fork();
101 [ # # ]: 0 : if (!pid) {
102 : 0 : execlp(SPLITTER, SPLITTER, "-Qao", reasmbuf, *filename, NULL);
103 : 0 : ohshite(_("unable to execute %s (%s)"),
104 : : _("split package reassembly"), SPLITTER);
105 : : }
106 : 0 : status = subproc_reap(pid, SPLITTER, SUBPROC_RETERROR);
107 [ # # # ]: 0 : switch (status) {
108 : 0 : case 0:
109 : : /* It was a part - is it complete? */
110 [ # # ]: 0 : if (!stat(reasmbuf, &stab)) {
111 : : /* Yes. */
112 : 0 : *filename = reasmbuf;
113 : 0 : *pfilename = _("reassembled package file");
114 : 0 : break;
115 [ # # ]: 0 : } else if (errno == ENOENT) {
116 : : /* No. That's it, we skip it. */
117 : 0 : return false;
118 : : }
119 : : case 1:
120 : : /* No, it wasn't a part. */
121 : 0 : break;
122 : 0 : default:
123 : 0 : ohshit(_("subprocess %s returned error exit status %d"), SPLITTER, status);
124 : : }
125 : :
126 : 0 : return true;
127 : : }
128 : :
129 : : static void
130 : 0 : deb_verify(const char *filename)
131 : : {
132 : : pid_t pid;
133 : :
134 : : /* We have to check on every unpack, in case the debsig-verify package
135 : : * gets installed or removed. */
136 [ # # ]: 0 : if (!command_in_path(DEBSIGVERIFY))
137 : 0 : return;
138 : :
139 : 0 : printf(_("Authenticating %s ...\n"), filename);
140 : 0 : fflush(stdout);
141 : 0 : pid = subproc_fork();
142 [ # # ]: 0 : if (!pid) {
143 : 0 : execlp(DEBSIGVERIFY, DEBSIGVERIFY, "-q", filename, NULL);
144 : 0 : ohshite(_("unable to execute %s (%s)"),
145 : : _("package signature verification"), DEBSIGVERIFY);
146 : : } else {
147 : : int status;
148 : :
149 : 0 : status = subproc_reap(pid, "debsig-verify", SUBPROC_NOCHECK);
150 [ # # # # ]: 0 : if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) {
151 [ # # ]: 0 : if (!in_force(FORCE_BAD_VERIFY))
152 : 0 : ohshit(_("verification on package %s failed!"), filename);
153 : : else
154 : 0 : notice(_("verification on package %s failed; "
155 : : "but installing anyway as you requested"), filename);
156 : : } else {
157 : 0 : printf(_("passed\n"));
158 : : }
159 : : }
160 : : }
161 : :
162 : : static char *
163 : 0 : get_control_dir(char *cidir)
164 : : {
165 [ # # ]: 0 : if (f_noact) {
166 : : char *tmpdir;
167 : :
168 : 0 : tmpdir = mkdtemp(path_make_temp_template("dpkg"));
169 [ # # ]: 0 : if (tmpdir == NULL)
170 : 0 : ohshite(_("unable to create temporary directory"));
171 : :
172 : 0 : cidir = m_realloc(cidir, strlen(tmpdir) + MAXCONTROLFILENAME + 10);
173 : :
174 : 0 : strcpy(cidir, tmpdir);
175 : :
176 : 0 : free(tmpdir);
177 : : } else {
178 : : const char *admindir;
179 : :
180 : 0 : admindir = dpkg_db_get_dir();
181 : :
182 : : /* The admindir length is always constant on a dpkg execution run. */
183 [ # # ]: 0 : if (cidir == NULL)
184 : 0 : cidir = m_malloc(strlen(admindir) + sizeof(CONTROLDIRTMP) +
185 : : MAXCONTROLFILENAME + 10);
186 : :
187 : : /* We want it to be on the same filesystem so that we can
188 : : * use rename(2) to install the postinst &c. */
189 : 0 : strcpy(cidir, admindir);
190 : 0 : strcat(cidir, "/" CONTROLDIRTMP);
191 : :
192 : : /* Make sure the control information directory is empty. */
193 : 0 : path_remove_tree(cidir);
194 : : }
195 : :
196 : 0 : strcat(cidir, "/");
197 : :
198 : 0 : return cidir;
199 : : }
200 : :
201 : : static void
202 : 0 : pkg_check_depcon(struct pkginfo *pkg, const char *pfilename)
203 : : {
204 : : struct dependency *dsearch;
205 : : struct deppossi *psearch;
206 : : struct pkginfo *fixbytrigaw;
207 : : static struct varbuf depprobwhy;
208 : :
209 : : /* Check if anything is installed that we conflict with, or not installed
210 : : * that we need. */
211 : 0 : ensure_package_clientdata(pkg);
212 : 0 : pkg->clientdata->istobe = PKG_ISTOBE_INSTALLNEW;
213 : :
214 [ # # ]: 0 : for (dsearch = pkg->available.depends; dsearch; dsearch = dsearch->next) {
215 [ # # # # : 0 : switch (dsearch->type) {
# # ]
216 : 0 : case dep_conflicts:
217 : : /* Look for things we conflict with. */
218 : 0 : check_conflict(dsearch, pkg, pfilename);
219 : 0 : break;
220 : 0 : case dep_breaks:
221 : : /* Look for things we break. */
222 : 0 : check_breaks(dsearch, pkg, pfilename);
223 : 0 : break;
224 : 0 : case dep_provides:
225 : : /* Look for things that conflict with what we provide. */
226 : 0 : for (psearch = dsearch->list->ed->depended.installed;
227 [ # # ]: 0 : psearch;
228 : 0 : psearch = psearch->rev_next) {
229 [ # # ]: 0 : if (psearch->up->type != dep_conflicts)
230 : 0 : continue;
231 : 0 : check_conflict(psearch->up, pkg, pfilename);
232 : : }
233 : 0 : break;
234 : 0 : case dep_suggests:
235 : : case dep_recommends:
236 : : case dep_depends:
237 : : case dep_replaces:
238 : : case dep_enhances:
239 : : /* Ignore these here. */
240 : 0 : break;
241 : 0 : case dep_predepends:
242 [ # # ]: 0 : if (!depisok(dsearch, &depprobwhy, NULL, &fixbytrigaw, true)) {
243 [ # # ]: 0 : if (fixbytrigaw) {
244 [ # # ]: 0 : while (fixbytrigaw->trigaw.head)
245 : 0 : trigproc(fixbytrigaw->trigaw.head->pend, TRIGPROC_REQUIRED);
246 : : } else {
247 : 0 : notice(_("regarding %s containing %s, pre-dependency problem:\n%s"),
248 : : pfilename, pkgbin_name(pkg, &pkg->available, pnaw_nonambig),
249 : : varbuf_str(&depprobwhy));
250 [ # # ]: 0 : if (!force_depends(dsearch->list))
251 : 0 : ohshit(_("pre-dependency problem - not installing %.250s"),
252 : : pkgbin_name(pkg, &pkg->available, pnaw_nonambig));
253 : 0 : warning(_("ignoring pre-dependency problem!"));
254 : : }
255 : : }
256 : : }
257 : : }
258 : :
259 : : /* Look for things that conflict with us. */
260 [ # # ]: 0 : for (psearch = pkg->set->depended.installed; psearch; psearch = psearch->rev_next) {
261 [ # # ]: 0 : if (psearch->up->type != dep_conflicts)
262 : 0 : continue;
263 : :
264 : 0 : check_conflict(psearch->up, pkg, pfilename);
265 : : }
266 : 0 : }
267 : :
268 : : static void
269 : 0 : pkg_deconfigure_others(struct pkginfo *pkg)
270 : : {
271 : : struct pkg_deconf_list *deconpil;
272 : :
273 [ # # ]: 0 : for (deconpil = deconfigure; deconpil; deconpil = deconpil->next) {
274 : 0 : struct pkginfo *removing = deconpil->pkg_removal;
275 : :
276 [ # # ]: 0 : if (deconpil->reason == PKG_WANT_DEINSTALL) {
277 : 0 : printf(_("De-configuring %s (%s), to allow removal of %s (%s) ...\n"),
278 : : pkg_name(deconpil->pkg, pnaw_nonambig),
279 : 0 : versiondescribe(&deconpil->pkg->installed.version, vdew_nonambig),
280 : : pkg_name(removing, pnaw_nonambig),
281 : 0 : versiondescribe(&removing->installed.version, vdew_nonambig));
282 [ # # ]: 0 : } else if (deconpil->reason == PKG_WANT_INSTALL) {
283 : 0 : printf(_("De-configuring %s (%s), to allow installation of %s (%s) ...\n"),
284 : : pkg_name(deconpil->pkg, pnaw_nonambig),
285 : 0 : versiondescribe(&deconpil->pkg->installed.version, vdew_nonambig),
286 : : pkg_name(pkg, pnaw_nonambig),
287 : 0 : versiondescribe(&pkg->available.version, vdew_nonambig));
288 : : } else {
289 : 0 : printf(_("De-configuring %s (%s), to allow configuration of %s (%s) ...\n"),
290 : : pkg_name(deconpil->pkg, pnaw_nonambig),
291 : 0 : versiondescribe(&deconpil->pkg->installed.version, vdew_nonambig),
292 : : pkg_name(pkg, pnaw_nonambig),
293 : 0 : versiondescribe(&pkg->available.version, vdew_nonambig));
294 : : }
295 : :
296 : 0 : trig_activate_packageprocessing(deconpil->pkg);
297 : 0 : pkg_set_status(deconpil->pkg, PKG_STAT_HALFCONFIGURED);
298 : 0 : modstatdb_note(deconpil->pkg);
299 : :
300 : : /* This means that we *either* go and run postinst abort-deconfigure,
301 : : * *or* queue the package for later configure processing, depending
302 : : * on which error cleanup route gets taken. */
303 : 0 : push_cleanup_fallback(cu_prermdeconfigure, ~ehflag_normaltidy,
304 : : ok_prermdeconfigure, ehflag_normaltidy,
305 : 0 : 3, (void *)deconpil->pkg, (void *)removing, (void *)pkg);
306 : :
307 [ # # ]: 0 : if (removing) {
308 : 0 : maintscript_installed(deconpil->pkg, PRERMFILE, "pre-removal",
309 : : "deconfigure", "in-favour",
310 : : pkgbin_name(pkg, &pkg->available, pnaw_nonambig),
311 : 0 : versiondescribe(&pkg->available.version,
312 : : vdew_nonambig),
313 : : "removing",
314 : : pkg_name(removing, pnaw_nonambig),
315 : 0 : versiondescribe(&removing->installed.version,
316 : : vdew_nonambig),
317 : : NULL);
318 : : } else {
319 : 0 : maintscript_installed(deconpil->pkg, PRERMFILE, "pre-removal",
320 : : "deconfigure", "in-favour",
321 : : pkgbin_name(pkg, &pkg->available, pnaw_nonambig),
322 : 0 : versiondescribe(&pkg->available.version,
323 : : vdew_nonambig),
324 : : NULL);
325 : : }
326 : : }
327 : 0 : }
328 : :
329 : : /**
330 : : * Read the conffiles, and copy the hashes across.
331 : : */
332 : : static void
333 : 0 : deb_parse_conffiles(const struct pkginfo *pkg, const char *control_conffiles,
334 : : struct fsys_namenode_queue *newconffiles)
335 : : {
336 : : FILE *conff;
337 : : char conffilenamebuf[MAXCONFFILENAME];
338 : :
339 : 0 : conff = fopen(control_conffiles, "r");
340 [ # # ]: 0 : if (conff == NULL) {
341 [ # # ]: 0 : if (errno == ENOENT)
342 : 0 : return;
343 : 0 : ohshite(_("error trying to open %.250s"), control_conffiles);
344 : : }
345 : :
346 : 0 : push_cleanup(cu_closestream, ehflag_bombout, 1, conff);
347 : :
348 [ # # ]: 0 : while (fgets(conffilenamebuf, MAXCONFFILENAME - 2, conff)) {
349 : : struct pkginfo *otherpkg;
350 : : struct fsys_node_pkgs_iter *iter;
351 : : struct fsys_namenode *namenode;
352 : : struct fsys_namenode_list *newconff;
353 : : struct conffile *searchconff;
354 : 0 : char *conffilename = conffilenamebuf;
355 : : char *p;
356 : 0 : enum fsys_namenode_flags confflags = FNNF_NEW_CONFF;
357 : :
358 : 0 : p = conffilename + strlen(conffilename);
359 [ # # ]: 0 : if (p == conffilename)
360 : 0 : ohshit(_("conffile file contains an empty line"));
361 [ # # ]: 0 : if (p[-1] != '\n')
362 : 0 : ohshit(_("conffile name '%s' is too long, or missing final newline"),
363 : : conffilename);
364 : 0 : p = str_rtrim_spaces(conffilename, p);
365 [ # # ]: 0 : if (p == conffilename)
366 : 0 : continue;
367 : :
368 : : /* Check for conffile flags. */
369 [ # # ]: 0 : if (conffilename[0] != '/') {
370 : 0 : char *flag = conffilename;
371 : 0 : char *flag_end = strchr(flag, ' ');
372 : :
373 [ # # ]: 0 : if (flag_end)
374 : 0 : conffilename = flag_end + 1;
375 : :
376 : : /* If no flag separator is found, assume a missing leading slash. */
377 [ # # # # : 0 : if (flag_end == NULL || (conffilename[0] && conffilename[0] != '/'))
# # ]
378 : 0 : ohshit(_("conffile name '%s' is not an absolute pathname"), conffilename);
379 : :
380 : 0 : flag_end[0] = '\0';
381 : :
382 : : /* Otherwise assume a missing filename after the flag separator. */
383 [ # # ]: 0 : if (conffilename[0] == '\0')
384 : 0 : ohshit(_("conffile name missing after flag '%s'"), flag);
385 : :
386 [ # # ]: 0 : if (strcmp(flag, "remove-on-upgrade") == 0) {
387 : 0 : confflags |= FNNF_RM_CONFF_ON_UPGRADE;
388 : 0 : confflags &= ~FNNF_NEW_CONFF;
389 : : } else {
390 [ # # ]: 0 : if (c_isspace(flag[0]))
391 : 0 : warning(_("line with conffile filename '%s' has leading white spaces"),
392 : : conffilename);
393 : 0 : ohshit(_("unknown flag '%s' for conffile '%s'"), flag, conffilename);
394 : : }
395 : : }
396 : :
397 : 0 : namenode = fsys_hash_find_node(conffilename, FHFF_NONE);
398 : 0 : namenode->oldhash = NEWCONFFILEFLAG;
399 : 0 : newconff = tar_fsys_namenode_queue_push(newconffiles, namenode);
400 : :
401 : : /*
402 : : * Let's see if any packages have this file.
403 : : *
404 : : * If they do we check to see if they listed it as a conffile,
405 : : * and if they did we copy the hash across. Since (for plain
406 : : * file conffiles, which is the only kind we are supposed to
407 : : * have) there will only be one package which ‘has’ the file,
408 : : * this will usually mean we only look in the package which
409 : : * we are installing now.
410 : : *
411 : : * The ‘conffiles’ data in the status file is ignored when a
412 : : * package is not also listed in the file ownership database as
413 : : * having that file. If several packages are listed as owning
414 : : * the file we pick one at random.
415 : : */
416 : 0 : searchconff = NULL;
417 : :
418 : 0 : iter = fsys_node_pkgs_iter_new(newconff->namenode);
419 [ # # ]: 0 : while ((otherpkg = fsys_node_pkgs_iter_next(iter))) {
420 : 0 : debug(dbg_conffdetail,
421 : : "process_archive conffile '%s' in package %s - conff ?",
422 : 0 : newconff->namenode->name, pkg_name(otherpkg, pnaw_always));
423 : 0 : for (searchconff = otherpkg->installed.conffiles;
424 [ # # # # ]: 0 : searchconff && strcmp(newconff->namenode->name, searchconff->name);
425 : 0 : searchconff = searchconff->next)
426 : 0 : debug(dbg_conffdetail,
427 : : "process_archive conffile '%s' in package %s - conff ? not '%s'",
428 : 0 : newconff->namenode->name, pkg_name(otherpkg, pnaw_always),
429 : : searchconff->name);
430 [ # # ]: 0 : if (searchconff) {
431 [ # # ]: 0 : debug(dbg_conff,
432 : : "process_archive conffile '%s' package=%s %s hash=%s",
433 : 0 : newconff->namenode->name, pkg_name(otherpkg, pnaw_always),
434 : : otherpkg == pkg ? "same" : "different!",
435 : : searchconff->hash);
436 [ # # ]: 0 : if (otherpkg == pkg)
437 : 0 : break;
438 : : }
439 : : }
440 : 0 : fsys_node_pkgs_iter_free(iter);
441 : :
442 [ # # ]: 0 : if (searchconff) {
443 : : /* We don't copy ‘obsolete’; it's not obsolete in the new package. */
444 : 0 : newconff->namenode->oldhash = searchconff->hash;
445 : : } else {
446 : 0 : debug(dbg_conff, "process_archive conffile '%s' no package, no hash",
447 : 0 : newconff->namenode->name);
448 : : }
449 : 0 : newconff->namenode->flags |= confflags;
450 : : }
451 : :
452 [ # # ]: 0 : if (ferror(conff))
453 : 0 : ohshite(_("read error in %.250s"), control_conffiles);
454 : 0 : pop_cleanup(ehflag_normaltidy); /* conff = fopen() */
455 [ # # ]: 0 : if (fclose(conff))
456 : 0 : ohshite(_("error closing %.250s"), control_conffiles);
457 : : }
458 : :
459 : : static struct pkg_queue conflictors = PKG_QUEUE_INIT;
460 : :
461 : : void
462 : 0 : enqueue_conflictor(struct pkginfo *pkg)
463 : : {
464 : 0 : pkg_queue_push(&conflictors, pkg);
465 : 0 : }
466 : :
467 : : static void
468 : 0 : pkg_infodb_remove_file(const char *filename, const char *filetype)
469 : : {
470 [ # # ]: 0 : if (unlink(filename))
471 : 0 : ohshite(_("unable to delete control info file '%.250s'"), filename);
472 : :
473 : 0 : debug(dbg_scripts, "removal_bulk info unlinked %s", filename);
474 : 0 : }
475 : :
476 : : static struct match_node *match_head = NULL;
477 : :
478 : : static void
479 : 0 : pkg_infodb_update_file(const char *filename, const char *filetype)
480 : : {
481 [ # # ]: 0 : if (strlen(filetype) > MAXCONTROLFILENAME)
482 : 0 : ohshit(_("old version of package has overly-long info file name starting '%.250s'"),
483 : : filename);
484 : :
485 : : /* We do the list separately. */
486 [ # # ]: 0 : if (strcmp(filetype, LISTFILE) == 0)
487 : 0 : return;
488 : :
489 : : /* We keep files to rename in a list as doing the rename immediately
490 : : * might influence the current readdir(), the just renamed file might
491 : : * be returned a second time as it's actually a new file from the
492 : : * point of view of the filesystem. */
493 : 0 : match_head = match_node_new(filename, filetype, match_head);
494 : : }
495 : :
496 : : static void
497 : 0 : pkg_infodb_update(struct pkginfo *pkg, char *cidir, char *cidirrest)
498 : : {
499 : : struct match_node *match_node;
500 : : DIR *dsd;
501 : : struct dirent *de;
502 : :
503 : : /* Deallocate the match list in case we aborted previously. */
504 [ # # ]: 0 : while ((match_node = match_head)) {
505 : 0 : match_head = match_node->next;
506 : 0 : match_node_free(match_node);
507 : : }
508 : :
509 : 0 : pkg_infodb_foreach(pkg, &pkg->available, pkg_infodb_update_file);
510 : :
511 [ # # ]: 0 : while ((match_node = match_head)) {
512 : 0 : strcpy(cidirrest, match_node->filetype);
513 : :
514 [ # # ]: 0 : if (!rename(cidir, match_node->filename)) {
515 : 0 : debug(dbg_scripts, "process_archive info installed %s as %s",
516 : : cidir, match_node->filename);
517 [ # # ]: 0 : } else if (errno == ENOENT) {
518 : : /* Right, no new version. */
519 [ # # ]: 0 : if (unlink(match_node->filename))
520 : 0 : ohshite(_("unable to remove obsolete info file '%.250s'"),
521 : : match_node->filename);
522 : 0 : debug(dbg_scripts, "process_archive info unlinked %s",
523 : : match_node->filename);
524 : : } else {
525 : 0 : ohshite(_("unable to install (supposed) new info file '%.250s'"), cidir);
526 : : }
527 : 0 : match_head = match_node->next;
528 : 0 : match_node_free(match_node);
529 : : }
530 : :
531 : : /* The control directory itself. */
532 : 0 : cidirrest[0] = '\0';
533 : 0 : dsd = opendir(cidir);
534 [ # # ]: 0 : if (!dsd)
535 : 0 : ohshite(_("unable to open temp control directory"));
536 : 0 : push_cleanup(cu_closedir, ~0, 1, (void *)dsd);
537 [ # # ]: 0 : while ((de = readdir(dsd))) {
538 : : const char *newinfofilename;
539 : :
540 [ # # ]: 0 : if (strchr(de->d_name, '.')) {
541 : 0 : debug(dbg_scripts, "process_archive tmp.ci script/file '%s' contains dot",
542 : 0 : de->d_name);
543 : 0 : continue;
544 : : }
545 [ # # ]: 0 : if (strlen(de->d_name) > MAXCONTROLFILENAME)
546 : 0 : ohshit(_("package contains overly-long control info file name (starting '%.50s')"),
547 : 0 : de->d_name);
548 : :
549 : 0 : strcpy(cidirrest, de->d_name);
550 : :
551 : : /* First we check it's not a directory. */
552 [ # # ]: 0 : if (rmdir(cidir) == 0)
553 : 0 : ohshit(_("package control info contained directory '%.250s'"), cidir);
554 [ # # ]: 0 : else if (errno != ENOTDIR)
555 : 0 : ohshite(_("package control info rmdir of '%.250s' didn't say not a dir"),
556 : 0 : de->d_name);
557 : :
558 : : /* Ignore the control file. */
559 [ # # ]: 0 : if (strcmp(de->d_name, CONTROLFILE) == 0) {
560 : 0 : debug(dbg_scripts, "process_archive tmp.ci script/file '%s' is control",
561 : : cidir);
562 : 0 : continue;
563 : : }
564 [ # # ]: 0 : if (strcmp(de->d_name, LISTFILE) == 0) {
565 : 0 : warning(_("package %s contained list as info file"),
566 : : pkgbin_name(pkg, &pkg->available, pnaw_nonambig));
567 : 0 : continue;
568 : : }
569 : :
570 : : /* Right, install it */
571 : 0 : newinfofilename = pkg_infodb_get_file(pkg, &pkg->available, de->d_name);
572 [ # # ]: 0 : if (rename(cidir, newinfofilename))
573 : 0 : ohshite(_("unable to install new info file '%.250s' as '%.250s'"),
574 : : cidir, newinfofilename);
575 : :
576 : 0 : debug(dbg_scripts,
577 : : "process_archive tmp.ci script/file '%s' installed as '%s'",
578 : : cidir, newinfofilename);
579 : : }
580 : 0 : pop_cleanup(ehflag_normaltidy); /* closedir */
581 : :
582 : : /* If the old and new versions use a different infodb layout, get rid
583 : : * of the files using the old layout. */
584 [ # # ]: 0 : if (pkg->installed.multiarch != pkg->available.multiarch &&
585 [ # # ]: 0 : (pkg->installed.multiarch == PKG_MULTIARCH_SAME ||
586 [ # # ]: 0 : pkg->available.multiarch == PKG_MULTIARCH_SAME)) {
587 : 0 : debug(dbg_scripts,
588 : : "process_archive remove old info files after db layout switch");
589 : 0 : pkg_infodb_foreach(pkg, &pkg->installed, pkg_infodb_remove_file);
590 : : }
591 : :
592 : 0 : dir_sync_path(pkg_infodb_get_dir());
593 : 0 : }
594 : :
595 : : static void
596 : 0 : pkg_remove_conffile_on_upgrade(struct pkginfo *pkg, struct fsys_namenode *namenode)
597 : : {
598 : : struct pkginfo *otherpkg;
599 : : struct fsys_namenode *usenode;
600 : : struct fsys_node_pkgs_iter *iter;
601 : 0 : struct varbuf cdr = VARBUF_INIT;
602 : 0 : struct varbuf cdrext = VARBUF_INIT;
603 : : struct varbuf_state cdrext_state;
604 : : char currenthash[MD5HASHLEN + 1];
605 : : int rc;
606 : :
607 : 0 : usenode = namenodetouse(namenode, pkg, &pkg->installed);
608 : :
609 : 0 : rc = conffderef(pkg, &cdr, usenode->name);
610 [ # # ]: 0 : if (rc < 0) {
611 : 0 : debug(dbg_conffdetail, "%s: '%s' conffile dereference error: %s", __func__,
612 : 0 : namenode->name, strerror(errno));
613 : 0 : namenode->oldhash = EMPTYHASHFLAG;
614 : 0 : return;
615 : : }
616 : :
617 : 0 : varbuf_set_varbuf(&cdrext, &cdr);
618 : 0 : varbuf_snapshot(&cdrext, &cdrext_state);
619 : :
620 : 0 : iter = fsys_node_pkgs_iter_new(namenode);
621 [ # # ]: 0 : while ((otherpkg = fsys_node_pkgs_iter_next(iter))) {
622 : 0 : debug(dbg_conffdetail, "%s: namenode '%s' owned by other %s?",
623 : : __func__, namenode->name, pkg_name(otherpkg, pnaw_always));
624 : :
625 [ # # ]: 0 : if (otherpkg == pkg)
626 : 0 : continue;
627 : :
628 : 0 : debug(dbg_conff, "%s: namenode '%s' owned by other %s, remove-on-upgrade ignored",
629 : : __func__, namenode->name, pkg_name(otherpkg, pnaw_always));
630 : 0 : fsys_node_pkgs_iter_free(iter);
631 : 0 : return;
632 : : }
633 : 0 : fsys_node_pkgs_iter_free(iter);
634 : :
635 : : /* Remove DPKGDISTEXT variant if still present. */
636 : 0 : varbuf_rollback(&cdrext_state);
637 : 0 : varbuf_add_str(&cdrext, DPKGDISTEXT);
638 : :
639 [ # # # # ]: 0 : if (unlink(cdrext.buf) < 0 && errno != ENOENT)
640 : 0 : warning(_("%s: failed to remove '%.250s': %s"),
641 : : pkg_name(pkg, pnaw_nonambig), cdrext.buf,
642 : 0 : strerror(errno));
643 : :
644 : 0 : md5hash(pkg, currenthash, cdr.buf);
645 : :
646 : : /* Has it been already removed (e.g. by local admin)? */
647 [ # # ]: 0 : if (strcmp(currenthash, NONEXISTENTFLAG) == 0)
648 : 0 : return;
649 : :
650 : : /* For unmodified conffiles, we just remove them. */
651 [ # # ]: 0 : if (strcmp(currenthash, namenode->oldhash) == 0) {
652 : 0 : printf(_("Removing obsolete conffile %s ...\n"), cdr.buf);
653 [ # # # # ]: 0 : if (unlink(cdr.buf) < 0 && errno != ENOENT)
654 : 0 : warning(_("%s: failed to remove '%.250s': %s"),
655 : 0 : pkg_name(pkg, pnaw_nonambig), cdr.buf, strerror(errno));
656 : 0 : return;
657 : : }
658 : :
659 : : /* Otherwise, preserve the modified conffile. */
660 : 0 : varbuf_rollback(&cdrext_state);
661 : 0 : varbuf_add_str(&cdrext, DPKGOLDEXT);
662 : :
663 : 0 : printf(_("Obsolete conffile '%s' has been modified by you.\n"), cdr.buf);
664 : 0 : printf(_("Saving as %s ...\n"), cdrext.buf);
665 [ # # ]: 0 : if (rename(cdr.buf, cdrext.buf) < 0)
666 : 0 : warning(_("%s: cannot rename obsolete conffile '%s' to '%s': %s"),
667 : : pkg_name(pkg, pnaw_nonambig),
668 : 0 : cdr.buf, cdrext.buf, strerror(errno));
669 : : }
670 : :
671 : : static void
672 : 0 : pkg_remove_old_files(struct pkginfo *pkg,
673 : : struct fsys_namenode_queue *newfiles_queue,
674 : : struct fsys_namenode_queue *newconffiles)
675 : : {
676 : : struct fsys_hash_rev_iter rev_iter;
677 : : struct fsys_namenode_list *cfile;
678 : : struct fsys_namenode *namenode;
679 : : struct stat stab, oldfs;
680 : :
681 : : /* Before removing any old files, we try to remove obsolete conffiles that
682 : : * have been requested to be removed during upgrade. These conffiles are
683 : : * not tracked as part of the package file lists, so removing them here
684 : : * means we will get their parent directories removed if not present in the
685 : : * new package without needing to do anything special ourselves. */
686 [ # # ]: 0 : for (cfile = newconffiles->head; cfile; cfile = cfile->next) {
687 : 0 : debug(dbg_conffdetail, "%s: removing conffile '%s' for %s?", __func__,
688 : 0 : cfile->namenode->name, pkg_name(pkg, pnaw_always));
689 : :
690 [ # # ]: 0 : if (!(cfile->namenode->flags & FNNF_RM_CONFF_ON_UPGRADE))
691 : 0 : continue;
692 : :
693 : 0 : pkg_remove_conffile_on_upgrade(pkg, cfile->namenode);
694 : : }
695 : :
696 : 0 : fsys_hash_rev_iter_init(&rev_iter, pkg->files);
697 : :
698 [ # # ]: 0 : while ((namenode = fsys_hash_rev_iter_next(&rev_iter))) {
699 : : struct fsys_namenode *usenode;
700 : :
701 [ # # ]: 0 : if ((namenode->flags & FNNF_NEW_CONFF) ||
702 [ # # ]: 0 : (namenode->flags & FNNF_RM_CONFF_ON_UPGRADE) ||
703 [ # # ]: 0 : (namenode->flags & FNNF_NEW_INARCHIVE))
704 : 0 : continue;
705 : :
706 : 0 : usenode = namenodetouse(namenode, pkg, &pkg->installed);
707 : :
708 : 0 : varbuf_rollback(&fname_state);
709 : 0 : varbuf_add_str(&fnamevb, usenode->name);
710 : :
711 [ # # # # ]: 0 : if (!stat(fnamevb.buf, &stab) && S_ISDIR(stab.st_mode)) {
712 : 0 : debug(dbg_eachfiledetail, "process_archive: %s is a directory",
713 : : fnamevb.buf);
714 [ # # ]: 0 : if (dir_is_used_by_others(namenode, pkg))
715 : 0 : continue;
716 : : }
717 : :
718 [ # # ]: 0 : if (lstat(varbuf_str(&fnamevb), &oldfs)) {
719 [ # # # # : 0 : if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR))
# # ]
720 : 0 : warning(_("could not stat old file '%.250s' so not deleting it: %s"),
721 : 0 : varbuf_str(&fnamevb), strerror(errno));
722 : 0 : continue;
723 : : }
724 [ # # ]: 0 : if (S_ISDIR(oldfs.st_mode)) {
725 : 0 : trig_path_activate(usenode, pkg);
726 : :
727 : : /* Do not try to remove the root directory. */
728 [ # # ]: 0 : if (strcmp(usenode->name, "/.") == 0)
729 : 0 : continue;
730 : :
731 [ # # ]: 0 : if (rmdir(varbuf_str(&fnamevb))) {
732 : 0 : warning(_("unable to delete old directory '%.250s': %s"),
733 : 0 : namenode->name, strerror(errno));
734 [ # # ]: 0 : } else if ((namenode->flags & FNNF_OLD_CONFF)) {
735 : 0 : warning(_("old conffile '%.250s' was an empty directory "
736 : : "(and has now been deleted)"), namenode->name);
737 : : }
738 : : } else {
739 : 0 : struct fsys_namenode_list *sameas = NULL;
740 : : static struct file_ondisk_id empty_ondisk_id;
741 : 0 : struct varbuf cfilename = VARBUF_INIT;
742 : :
743 : : /*
744 : : * Ok, it's an old file, but is it really not in the new package?
745 : : * It might be known by a different name because of symlinks.
746 : : *
747 : : * We need to check to make sure, so we stat the file, then compare
748 : : * it to the new list. If we find a dev/inode match, we assume they
749 : : * are the same file, and leave it alone. NOTE: we don't check in
750 : : * other packages for sanity reasons (we don't want to stat _all_
751 : : * the files on the system).
752 : : *
753 : : * We run down the list of _new_ files in this package. This keeps
754 : : * the process a little leaner. We are only worried about new ones
755 : : * since ones that stayed the same don't really apply here.
756 : : */
757 : :
758 : : /* If we can't stat the old or new file, or it's a directory,
759 : : * we leave it up to the normal code. */
760 : 0 : debug(dbg_eachfile, "process_archive: checking %s for same files on "
761 : : "upgrade/downgrade", varbuf_str(&fnamevb));
762 : :
763 [ # # ]: 0 : for (cfile = newfiles_queue->head; cfile; cfile = cfile->next) {
764 : : /* If the file has been filtered then treat it as if it didn't exist
765 : : * on the file system. */
766 [ # # ]: 0 : if (cfile->namenode->flags & FNNF_FILTERED)
767 : 0 : continue;
768 : :
769 [ # # ]: 0 : if (cfile->namenode->file_ondisk_id == NULL) {
770 : : struct stat tmp_stat;
771 : :
772 : 0 : varbuf_set_str(&cfilename, dpkg_fsys_get_dir());
773 : 0 : varbuf_add_str(&cfilename, cfile->namenode->name);
774 : :
775 [ # # ]: 0 : if (lstat(varbuf_str(&cfilename), &tmp_stat) == 0) {
776 : : struct file_ondisk_id *file_ondisk_id;
777 : :
778 : 0 : file_ondisk_id = nfmalloc(sizeof(*file_ondisk_id));
779 : 0 : file_ondisk_id->id_dev = tmp_stat.st_dev;
780 : 0 : file_ondisk_id->id_ino = tmp_stat.st_ino;
781 : 0 : cfile->namenode->file_ondisk_id = file_ondisk_id;
782 : : } else {
783 [ # # # # : 0 : if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR))
# # ]
784 : 0 : ohshite(_("unable to stat other new file '%.250s'"),
785 : 0 : cfile->namenode->name);
786 : 0 : cfile->namenode->file_ondisk_id = &empty_ondisk_id;
787 : 0 : continue;
788 : : }
789 : : }
790 : :
791 [ # # ]: 0 : if (cfile->namenode->file_ondisk_id == &empty_ondisk_id)
792 : 0 : continue;
793 : :
794 [ # # ]: 0 : if (oldfs.st_dev == cfile->namenode->file_ondisk_id->id_dev &&
795 [ # # ]: 0 : oldfs.st_ino == cfile->namenode->file_ondisk_id->id_ino) {
796 [ # # ]: 0 : if (sameas)
797 : 0 : warning(_("old file '%.250s' is the same as several new files! "
798 : : "(both '%.250s' and '%.250s')"), varbuf_str(&fnamevb),
799 : 0 : sameas->namenode->name, cfile->namenode->name);
800 : 0 : sameas = cfile;
801 : 0 : debug(dbg_eachfile, "process_archive: not removing %s, "
802 : 0 : "since it matches %s", varbuf_str(&fnamevb), cfile->namenode->name);
803 : : }
804 : : }
805 : :
806 : 0 : varbuf_destroy(&cfilename);
807 : :
808 [ # # ]: 0 : if ((namenode->flags & FNNF_OLD_CONFF)) {
809 [ # # ]: 0 : if (sameas) {
810 [ # # ]: 0 : if (sameas->namenode->flags & FNNF_NEW_CONFF) {
811 [ # # ]: 0 : if (strcmp(sameas->namenode->oldhash, NEWCONFFILEFLAG) == 0) {
812 : 0 : sameas->namenode->oldhash = namenode->oldhash;
813 : 0 : debug(dbg_eachfile, "process_archive: old conff %s "
814 : : "is same as new conff %s, copying hash",
815 : 0 : namenode->name, sameas->namenode->name);
816 : : } else {
817 : 0 : debug(dbg_eachfile, "process_archive: old conff %s "
818 : : "is same as new conff %s but latter already has hash",
819 : 0 : namenode->name, sameas->namenode->name);
820 : : }
821 : : }
822 : : } else {
823 : 0 : debug(dbg_eachfile, "process_archive: old conff %s "
824 : : "is disappearing", namenode->name);
825 : 0 : namenode->flags |= FNNF_OBS_CONFF;
826 : 0 : tar_fsys_namenode_queue_push(newconffiles, namenode);
827 : 0 : tar_fsys_namenode_queue_push(newfiles_queue, namenode);
828 : : }
829 : 0 : continue;
830 : : }
831 : :
832 [ # # ]: 0 : if (sameas)
833 : 0 : continue;
834 : :
835 : 0 : trig_path_activate(usenode, pkg);
836 : :
837 [ # # ]: 0 : if (secure_unlink_statted(varbuf_str(&fnamevb), &oldfs)) {
838 : 0 : warning(_("unable to securely remove old file '%.250s': %s"),
839 : 0 : namenode->name, strerror(errno));
840 : : }
841 : : } /* !S_ISDIR */
842 : : }
843 : 0 : }
844 : :
845 : : static void
846 : 0 : pkg_update_fields(struct pkginfo *pkg, struct fsys_namenode_queue *newconffiles)
847 : : {
848 : : struct dependency *newdeplist, **newdeplistlastp;
849 : : struct dependency *dep;
850 : : struct conffile **iconffileslastp, *newiconff;
851 : : struct fsys_namenode_list *cfile;
852 : :
853 : : /* The dependencies are the most difficult. We have to build
854 : : * a whole new forward dependency tree. At least the reverse
855 : : * links (linking our deppossi's into the reverse chains)
856 : : * can be done by copy_dependency_links. */
857 : 0 : newdeplist = NULL;
858 : 0 : newdeplistlastp = &newdeplist;
859 [ # # ]: 0 : for (dep = pkg->available.depends; dep; dep = dep->next) {
860 : : struct deppossi **newpossilastp, *possi;
861 : : struct dependency *newdep;
862 : :
863 : 0 : newdep = nfmalloc(sizeof(*newdep));
864 : 0 : newdep->up = pkg;
865 : 0 : newdep->next = NULL;
866 : 0 : newdep->list = NULL;
867 : 0 : newpossilastp = &newdep->list;
868 : :
869 [ # # ]: 0 : for (possi = dep->list; possi; possi = possi->next) {
870 : : struct deppossi *newpossi;
871 : :
872 : 0 : newpossi = nfmalloc(sizeof(*newpossi));
873 : 0 : newpossi->up = newdep;
874 : 0 : newpossi->ed = possi->ed;
875 : 0 : newpossi->next = NULL;
876 : 0 : newpossi->rev_next = newpossi->rev_prev = NULL;
877 : 0 : newpossi->arch_is_implicit = possi->arch_is_implicit;
878 : 0 : newpossi->arch = possi->arch;
879 : 0 : newpossi->verrel = possi->verrel;
880 [ # # ]: 0 : if (possi->verrel != DPKG_RELATION_NONE)
881 : 0 : newpossi->version = possi->version;
882 : : else
883 : 0 : dpkg_version_blank(&newpossi->version);
884 : 0 : newpossi->cyclebreak = false;
885 : 0 : *newpossilastp = newpossi;
886 : 0 : newpossilastp = &newpossi->next;
887 : : }
888 : 0 : newdep->type = dep->type;
889 : 0 : *newdeplistlastp = newdep;
890 : 0 : newdeplistlastp = &newdep->next;
891 : : }
892 : :
893 : : /* Right, now we've replicated the forward tree, we
894 : : * get copy_dependency_links to remove all the old dependency
895 : : * structures from the reverse links and add the new dependency
896 : : * structures in instead. It also copies the new dependency
897 : : * structure pointer for this package into the right field. */
898 : 0 : copy_dependency_links(pkg, &pkg->installed.depends, newdeplist, 0);
899 : :
900 : : /* We copy the text fields. */
901 : 0 : pkg->installed.essential = pkg->available.essential;
902 : 0 : pkg->installed.is_protected = pkg->available.is_protected;
903 : 0 : pkg->installed.multiarch = pkg->available.multiarch;
904 : 0 : pkg->installed.description = pkg->available.description;
905 : 0 : pkg->installed.maintainer = pkg->available.maintainer;
906 : 0 : pkg->installed.source = pkg->available.source;
907 : 0 : pkg->installed.arch = pkg->available.arch;
908 : 0 : pkg->installed.pkgname_archqual = pkg->available.pkgname_archqual;
909 : 0 : pkg->installed.installedsize = pkg->available.installedsize;
910 : 0 : pkg->installed.version = pkg->available.version;
911 : 0 : pkg->installed.origin = pkg->available.origin;
912 : 0 : pkg->installed.bugs = pkg->available.bugs;
913 : :
914 : : /* We have to generate our own conffiles structure. */
915 : 0 : pkg->installed.conffiles = NULL;
916 : 0 : iconffileslastp = &pkg->installed.conffiles;
917 [ # # ]: 0 : for (cfile = newconffiles->head; cfile; cfile = cfile->next) {
918 : 0 : newiconff = nfmalloc(sizeof(*newiconff));
919 : 0 : newiconff->next = NULL;
920 : 0 : newiconff->name = nfstrsave(cfile->namenode->name);
921 : 0 : newiconff->hash = nfstrsave(cfile->namenode->oldhash);
922 : 0 : newiconff->flags = CONFFILE_NONE;
923 [ # # ]: 0 : if (cfile->namenode->flags & FNNF_OBS_CONFF)
924 : 0 : newiconff->flags |= CONFFILE_OBSOLETE;
925 [ # # ]: 0 : if (cfile->namenode->flags & FNNF_RM_CONFF_ON_UPGRADE)
926 : 0 : newiconff->flags |= CONFFILE_REMOVE_ON_UPGRADE;
927 : 0 : *iconffileslastp = newiconff;
928 : 0 : iconffileslastp = &newiconff->next;
929 : : }
930 : :
931 : : /* We can just copy the arbitrary fields list, because it is
932 : : * never even rearranged. Phew! */
933 : 0 : pkg->installed.arbs = pkg->available.arbs;
934 : 0 : }
935 : :
936 : : static void
937 : 0 : pkg_disappear(struct pkginfo *pkg, struct pkginfo *infavour)
938 : : {
939 : 0 : printf(_("(Noting disappearance of %s, which has been completely replaced.)\n"),
940 : : pkg_name(pkg, pnaw_nonambig));
941 : 0 : log_action("disappear", pkg, &pkg->installed);
942 : 0 : debug(dbg_general, "pkg_disappear disappearing %s",
943 : : pkg_name(pkg, pnaw_always));
944 : :
945 : 0 : trig_activate_packageprocessing(pkg);
946 : 0 : maintscript_installed(pkg, POSTRMFILE,
947 : : "post-removal script (for disappearance)",
948 : : "disappear",
949 : : pkgbin_name(infavour, &infavour->available,
950 : : pnaw_nonambig),
951 : 0 : versiondescribe(&infavour->available.version,
952 : : vdew_nonambig),
953 : : NULL);
954 : :
955 : : /* OK, now we delete all the stuff in the ‘info’ directory ... */
956 : 0 : debug(dbg_general, "pkg_disappear cleaning info directory");
957 : 0 : pkg_infodb_foreach(pkg, &pkg->installed, pkg_infodb_remove_file);
958 : 0 : dir_sync_path(pkg_infodb_get_dir());
959 : :
960 : 0 : pkg_set_status(pkg, PKG_STAT_NOTINSTALLED);
961 : 0 : pkg_set_want(pkg, PKG_WANT_UNKNOWN);
962 : 0 : pkg_reset_eflags(pkg);
963 : :
964 : 0 : dpkg_version_blank(&pkg->configversion);
965 : 0 : pkgbin_blank(&pkg->installed);
966 : :
967 : 0 : pkg->files_list_valid = false;
968 : :
969 : 0 : modstatdb_note(pkg);
970 : 0 : }
971 : :
972 : : static void
973 : 0 : pkg_disappear_others(struct pkginfo *pkg)
974 : : {
975 : : struct pkg_hash_iter *iter;
976 : : struct pkginfo *otherpkg;
977 : : struct fsys_namenode_list *cfile;
978 : : struct deppossi *pdep;
979 : : struct dependency *providecheck;
980 : 0 : struct varbuf depprobwhy = VARBUF_INIT;
981 : :
982 : 0 : iter = pkg_hash_iter_new();
983 [ # # ]: 0 : while ((otherpkg = pkg_hash_iter_next_pkg(iter)) != NULL) {
984 : 0 : ensure_package_clientdata(otherpkg);
985 : :
986 [ # # ]: 0 : if (otherpkg == pkg ||
987 [ # # ]: 0 : otherpkg->status == PKG_STAT_NOTINSTALLED ||
988 [ # # ]: 0 : otherpkg->status == PKG_STAT_CONFIGFILES ||
989 [ # # ]: 0 : otherpkg->clientdata->istobe == PKG_ISTOBE_REMOVE ||
990 [ # # ]: 0 : !otherpkg->files)
991 : 0 : continue;
992 : :
993 : : /* Do not try to disappear other packages from the same set
994 : : * if they are Multi-Arch: same */
995 [ # # ]: 0 : if (pkg->installed.multiarch == PKG_MULTIARCH_SAME &&
996 [ # # ]: 0 : otherpkg->installed.multiarch == PKG_MULTIARCH_SAME &&
997 [ # # ]: 0 : otherpkg->set == pkg->set)
998 : 0 : continue;
999 : :
1000 : 0 : debug(dbg_veryverbose, "process_archive checking disappearance %s",
1001 : : pkg_name(otherpkg, pnaw_always));
1002 : :
1003 [ # # ]: 0 : if (otherpkg->clientdata->istobe != PKG_ISTOBE_NORMAL &&
1004 [ # # ]: 0 : otherpkg->clientdata->istobe != PKG_ISTOBE_DECONFIGURE)
1005 : 0 : internerr("disappearing package %s is not to be normal or deconfigure, "
1006 : : "is to be %d",
1007 : : pkg_name(otherpkg, pnaw_always), otherpkg->clientdata->istobe);
1008 : :
1009 : 0 : for (cfile = otherpkg->files;
1010 [ # # # # ]: 0 : cfile && strcmp(cfile->namenode->name, "/.") == 0;
1011 : 0 : cfile = cfile->next);
1012 [ # # ]: 0 : if (!cfile) {
1013 : 0 : debug(dbg_stupidlyverbose, "process_archive no non-root, no disappear");
1014 : 0 : continue;
1015 : : }
1016 : 0 : for (cfile = otherpkg->files;
1017 [ # # # # ]: 0 : cfile && !filesavespackage(cfile, otherpkg, pkg);
1018 : 0 : cfile = cfile->next);
1019 [ # # ]: 0 : if (cfile)
1020 : 0 : continue;
1021 : :
1022 : : /* So dependency things will give right answers ... */
1023 : 0 : otherpkg->clientdata->istobe = PKG_ISTOBE_REMOVE;
1024 : 0 : debug(dbg_veryverbose, "process_archive disappear checking dependencies");
1025 : 0 : for (pdep = otherpkg->set->depended.installed;
1026 [ # # ]: 0 : pdep;
1027 : 0 : pdep = pdep->rev_next) {
1028 [ # # ]: 0 : if (pdep->up->type != dep_depends &&
1029 [ # # ]: 0 : pdep->up->type != dep_predepends &&
1030 [ # # ]: 0 : pdep->up->type != dep_recommends)
1031 : 0 : continue;
1032 : :
1033 [ # # ]: 0 : if (depisok(pdep->up, &depprobwhy, NULL, NULL, false))
1034 : 0 : continue;
1035 : :
1036 : 0 : debug(dbg_veryverbose,"process_archive cannot disappear: %s",
1037 : : varbuf_str(&depprobwhy));
1038 : 0 : break;
1039 : : }
1040 [ # # ]: 0 : if (!pdep) {
1041 : : /* If we haven't found a reason not to yet, let's look some more. */
1042 : 0 : for (providecheck = otherpkg->installed.depends;
1043 [ # # ]: 0 : providecheck;
1044 : 0 : providecheck = providecheck->next) {
1045 [ # # ]: 0 : if (providecheck->type != dep_provides)
1046 : 0 : continue;
1047 : :
1048 : 0 : for (pdep = providecheck->list->ed->depended.installed;
1049 [ # # ]: 0 : pdep;
1050 : 0 : pdep = pdep->rev_next) {
1051 [ # # ]: 0 : if (pdep->up->type != dep_depends &&
1052 [ # # ]: 0 : pdep->up->type != dep_predepends &&
1053 [ # # ]: 0 : pdep->up->type != dep_recommends)
1054 : 0 : continue;
1055 : :
1056 [ # # ]: 0 : if (depisok(pdep->up, &depprobwhy, NULL, NULL, false))
1057 : 0 : continue;
1058 : :
1059 : 0 : debug(dbg_veryverbose,
1060 : : "process_archive cannot disappear (provides %s): %s",
1061 : 0 : providecheck->list->ed->name, varbuf_str(&depprobwhy));
1062 : 0 : goto break_from_both_loops_at_once;
1063 : : }
1064 : : }
1065 : 0 : break_from_both_loops_at_once:;
1066 : : }
1067 : 0 : otherpkg->clientdata->istobe = PKG_ISTOBE_NORMAL;
1068 [ # # ]: 0 : if (pdep)
1069 : 0 : continue;
1070 : :
1071 : : /* No, we're disappearing it. This is the wrong time to go and
1072 : : * run maintainer scripts and things, as we can't back out. But
1073 : : * what can we do ? It has to be run this late. */
1074 : 0 : pkg_disappear(otherpkg, pkg);
1075 : : } /* while (otherpkg= ... */
1076 : 0 : pkg_hash_iter_free(iter);
1077 : 0 : }
1078 : :
1079 : : /**
1080 : : * Check if all instances of a pkgset are getting in sync.
1081 : : *
1082 : : * If that's the case, the extraction is going to ensure consistency
1083 : : * of shared files.
1084 : : */
1085 : : static bool
1086 : 0 : pkgset_getting_in_sync(struct pkginfo *pkg)
1087 : : {
1088 : : struct pkginfo *otherpkg;
1089 : :
1090 [ # # ]: 0 : for (otherpkg = &pkg->set->pkg; otherpkg; otherpkg = otherpkg->arch_next) {
1091 [ # # ]: 0 : if (otherpkg == pkg)
1092 : 0 : continue;
1093 [ # # ]: 0 : if (otherpkg->status <= PKG_STAT_CONFIGFILES)
1094 : 0 : continue;
1095 [ # # ]: 0 : if (dpkg_version_compare(&pkg->available.version,
1096 : 0 : &otherpkg->installed.version)) {
1097 : 0 : return false;
1098 : : }
1099 : : }
1100 : :
1101 : 0 : return true;
1102 : : }
1103 : :
1104 : : static void
1105 : 0 : pkg_remove_files_from_others(struct pkginfo *pkg, struct fsys_namenode_list *newfileslist)
1106 : : {
1107 : : struct fsys_namenode_list *cfile;
1108 : : struct pkginfo *otherpkg;
1109 : :
1110 [ # # ]: 0 : for (cfile = newfileslist; cfile; cfile = cfile->next) {
1111 : : struct fsys_node_pkgs_iter *iter;
1112 : : struct pkgset *divpkgset;
1113 : :
1114 [ # # ]: 0 : if (!(cfile->namenode->flags & FNNF_ELIDE_OTHER_LISTS))
1115 : 0 : continue;
1116 : :
1117 [ # # # # ]: 0 : if (cfile->namenode->divert && cfile->namenode->divert->useinstead) {
1118 : 0 : divpkgset = cfile->namenode->divert->pkgset;
1119 [ # # ]: 0 : if (divpkgset == pkg->set) {
1120 : 0 : debug(dbg_eachfile,
1121 : : "process_archive not overwriting any '%s' (overriding, '%s')",
1122 : 0 : cfile->namenode->name, cfile->namenode->divert->useinstead->name);
1123 : 0 : continue;
1124 : : } else {
1125 [ # # ]: 0 : debug(dbg_eachfile,
1126 : : "process_archive looking for overwriting '%s' (overridden by %s)",
1127 : 0 : cfile->namenode->name, divpkgset ? divpkgset->name : "<local>");
1128 : : }
1129 : : } else {
1130 : 0 : divpkgset = NULL;
1131 : 0 : debug(dbg_eachfile, "process_archive looking for overwriting '%s'",
1132 : 0 : cfile->namenode->name);
1133 : : }
1134 : :
1135 : 0 : iter = fsys_node_pkgs_iter_new(cfile->namenode);
1136 [ # # ]: 0 : while ((otherpkg = fsys_node_pkgs_iter_next(iter))) {
1137 : 0 : debug(dbg_eachfiledetail, "process_archive ... found in %s",
1138 : : pkg_name(otherpkg, pnaw_always));
1139 : :
1140 : : /* A pkgset can share files between instances, so there's no point
1141 : : * in rewriting the file that's already in place. */
1142 [ # # ]: 0 : if (otherpkg->set == pkg->set)
1143 : 0 : continue;
1144 : :
1145 [ # # ]: 0 : if (otherpkg->set == divpkgset) {
1146 : 0 : debug(dbg_eachfiledetail, "process_archive ... diverted, skipping");
1147 : 0 : continue;
1148 : : }
1149 : :
1150 [ # # ]: 0 : if (cfile->namenode->flags & FNNF_NEW_CONFF)
1151 : 0 : conffile_mark_obsolete(otherpkg, cfile->namenode);
1152 : :
1153 : : /* If !files_list_valid then it's one of the disappeared packages above
1154 : : * or we have already updated the files list file, and we don't bother
1155 : : * with it here, clearly. */
1156 [ # # ]: 0 : if (!otherpkg->files_list_valid)
1157 : 0 : continue;
1158 : :
1159 : : /* Found one. We delete the list entry for this file,
1160 : : * (and any others in the same package) and then mark the package
1161 : : * as requiring a reread. */
1162 : 0 : write_filelist_except(otherpkg, &otherpkg->installed,
1163 : : otherpkg->files, FNNF_ELIDE_OTHER_LISTS);
1164 : 0 : debug(dbg_veryverbose, "process_archive overwrote from %s",
1165 : : pkg_name(otherpkg, pnaw_always));
1166 : : }
1167 : 0 : fsys_node_pkgs_iter_free(iter);
1168 : : }
1169 : 0 : }
1170 : :
1171 : : static void
1172 : 0 : pkg_remove_backup_files(struct pkginfo *pkg, struct fsys_namenode_list *newfileslist)
1173 : : {
1174 : : struct fsys_namenode_list *cfile;
1175 : :
1176 [ # # ]: 0 : for (cfile = newfileslist; cfile; cfile = cfile->next) {
1177 : : struct fsys_namenode *usenode;
1178 : :
1179 [ # # ]: 0 : if (cfile->namenode->flags & FNNF_NEW_CONFF)
1180 : 0 : continue;
1181 : :
1182 : 0 : usenode = namenodetouse(cfile->namenode, pkg, &pkg->installed);
1183 : :
1184 : : /* Do not try to remove backups for the root directory. */
1185 [ # # ]: 0 : if (strcmp(usenode->name, "/.") == 0)
1186 : 0 : continue;
1187 : :
1188 : 0 : varbuf_rollback(&fnametmp_state);
1189 : 0 : varbuf_add_str(&fnametmpvb, usenode->name);
1190 : 0 : varbuf_add_str(&fnametmpvb, DPKGTEMPEXT);
1191 : 0 : path_remove_tree(varbuf_str(&fnametmpvb));
1192 : : }
1193 : 0 : }
1194 : :
1195 : 0 : void process_archive(const char *filename) {
1196 : : static const struct tar_operations tf = {
1197 : : .read = tarfileread,
1198 : : .extract_file = tarobject,
1199 : : .link = tarobject,
1200 : : .symlink = tarobject,
1201 : : .mkdir = tarobject,
1202 : : .mknod = tarobject,
1203 : : };
1204 : :
1205 : : /* These need to be static so that we can pass their addresses to
1206 : : * push_cleanup as arguments to the cu_xxx routines; if an error occurs
1207 : : * we unwind the stack before processing the cleanup list, and these
1208 : : * variables had better still exist ... */
1209 : : static int p1[2];
1210 : : static enum pkgstatus oldversionstatus;
1211 : : static struct tarcontext tc;
1212 : :
1213 : : struct tar_archive tar;
1214 : : struct dpkg_error err;
1215 : : enum parsedbflags parsedb_flags;
1216 : : int rc;
1217 : : pid_t pid;
1218 : : struct pkginfo *pkg, *otherpkg;
1219 : : struct pkg_list *conflictor_iter;
1220 : 0 : char *cidir = NULL;
1221 : : char *cidirrest;
1222 : : char *psize;
1223 : : const char *pfilename;
1224 : : struct fsys_namenode_queue newconffiles, newfiles_queue;
1225 : : struct stat stab;
1226 : :
1227 : 0 : cleanup_pkg_failed= cleanup_conflictor_failed= 0;
1228 : :
1229 : 0 : pfilename = summarize_filename(filename);
1230 : :
1231 [ # # ]: 0 : if (stat(filename, &stab))
1232 : 0 : ohshite(_("cannot access archive '%s'"), filename);
1233 : :
1234 : : /* We can't ‘tentatively-reassemble’ packages. */
1235 [ # # ]: 0 : if (!f_noact) {
1236 [ # # ]: 0 : if (!deb_reassemble(&filename, &pfilename))
1237 : 0 : return;
1238 : : }
1239 : :
1240 : : /* Verify the package. */
1241 [ # # ]: 0 : if (!f_nodebsig)
1242 : 0 : deb_verify(filename);
1243 : :
1244 : : /* Get the control information directory. */
1245 : 0 : cidir = get_control_dir(cidir);
1246 : 0 : cidirrest = cidir + strlen(cidir);
1247 : 0 : push_cleanup(cu_cidir, ~0, 2, (void *)cidir, (void *)cidirrest);
1248 : :
1249 : 0 : pid = subproc_fork();
1250 [ # # ]: 0 : if (pid == 0) {
1251 : 0 : cidirrest[-1] = '\0';
1252 : 0 : execlp(BACKEND, BACKEND, "--control", filename, cidir, NULL);
1253 : 0 : ohshite(_("unable to execute %s (%s)"),
1254 : : _("package control information extraction"), BACKEND);
1255 : : }
1256 : 0 : subproc_reap(pid, BACKEND " --control", 0);
1257 : :
1258 : : /* We want to guarantee the extracted files are on the disk, so that the
1259 : : * subsequent renames to the info database do not end up with old or zero
1260 : : * length files in case of a system crash. As neither dpkg-deb nor tar do
1261 : : * explicit fsync()s, we have to do them here.
1262 : : * XXX: This could be avoided by switching to an internal tar extractor. */
1263 : 0 : dir_sync_contents(cidir);
1264 : :
1265 : 0 : strcpy(cidirrest,CONTROLFILE);
1266 : :
1267 [ # # ]: 0 : if (cipaction->arg_int == act_avail)
1268 : 0 : parsedb_flags = pdb_parse_available;
1269 : : else
1270 : 0 : parsedb_flags = pdb_parse_binary;
1271 : 0 : parsedb_flags |= pdb_ignore_archives;
1272 [ # # ]: 0 : if (in_force(FORCE_BAD_VERSION))
1273 : 0 : parsedb_flags |= pdb_lax_version_parser;
1274 : :
1275 : 0 : parsedb(cidir, parsedb_flags, &pkg);
1276 : :
1277 [ # # ]: 0 : if (!pkg->archives) {
1278 : 0 : pkg->archives = nfmalloc(sizeof(*pkg->archives));
1279 : 0 : pkg->archives->next = NULL;
1280 : 0 : pkg->archives->name = NULL;
1281 : 0 : pkg->archives->msdosname = NULL;
1282 : 0 : pkg->archives->md5sum = NULL;
1283 : : }
1284 : : /* Always nfmalloc. Otherwise, we may overwrite some other field (like
1285 : : * md5sum). */
1286 : 0 : psize = nfmalloc(30);
1287 : 0 : sprintf(psize, "%jd", (intmax_t)stab.st_size);
1288 : 0 : pkg->archives->size = psize;
1289 : :
1290 [ # # ]: 0 : if (cipaction->arg_int == act_avail) {
1291 : 0 : printf(_("Recorded info about %s from %s.\n"),
1292 : 0 : pkgbin_name(pkg, &pkg->available, pnaw_nonambig), pfilename);
1293 : 0 : pop_cleanup(ehflag_normaltidy);
1294 : 0 : return;
1295 : : }
1296 : :
1297 [ # # ]: 0 : if (pkg->available.arch->type != DPKG_ARCH_ALL &&
1298 [ # # ]: 0 : pkg->available.arch->type != DPKG_ARCH_NATIVE &&
1299 [ # # ]: 0 : pkg->available.arch->type != DPKG_ARCH_FOREIGN)
1300 : 0 : forcibleerr(FORCE_ARCHITECTURE,
1301 : 0 : _("package architecture (%s) does not match system (%s)"),
1302 : 0 : pkg->available.arch->name,
1303 : 0 : dpkg_arch_get(DPKG_ARCH_NATIVE)->name);
1304 : :
1305 : 0 : clear_deconfigure_queue();
1306 : 0 : clear_istobes();
1307 : :
1308 [ # # ]: 0 : if (wanttoinstall(pkg)) {
1309 : 0 : pkg_set_want(pkg, PKG_WANT_INSTALL);
1310 : : } else {
1311 : 0 : pop_cleanup(ehflag_normaltidy);
1312 : 0 : return;
1313 : : }
1314 : :
1315 : : /* Deconfigure other instances from a pkgset if they are not in sync. */
1316 [ # # ]: 0 : for (otherpkg = &pkg->set->pkg; otherpkg; otherpkg = otherpkg->arch_next) {
1317 [ # # ]: 0 : if (otherpkg == pkg)
1318 : 0 : continue;
1319 [ # # ]: 0 : if (otherpkg->status <= PKG_STAT_HALFCONFIGURED)
1320 : 0 : continue;
1321 : :
1322 [ # # ]: 0 : if (dpkg_version_compare(&pkg->available.version,
1323 : 0 : &otherpkg->installed.version))
1324 : 0 : enqueue_deconfigure(otherpkg, NULL, PKG_WANT_UNKNOWN);
1325 : : }
1326 : :
1327 : 0 : pkg_check_depcon(pkg, pfilename);
1328 : :
1329 : 0 : ensure_allinstfiles_available();
1330 : 0 : fsys_hash_init();
1331 : 0 : trig_file_interests_ensure();
1332 : :
1333 : 0 : printf(_("Preparing to unpack %s ...\n"), pfilename);
1334 : :
1335 [ # # ]: 0 : if (pkg->status != PKG_STAT_NOTINSTALLED &&
1336 [ # # ]: 0 : pkg->status != PKG_STAT_CONFIGFILES) {
1337 : 0 : log_action("upgrade", pkg, &pkg->installed);
1338 : : } else {
1339 : 0 : log_action("install", pkg, &pkg->available);
1340 : : }
1341 : :
1342 [ # # ]: 0 : if (f_noact) {
1343 : 0 : pop_cleanup(ehflag_normaltidy);
1344 : 0 : return;
1345 : : }
1346 : :
1347 : : /*
1348 : : * OK, we're going ahead.
1349 : : */
1350 : :
1351 : 0 : trig_activate_packageprocessing(pkg);
1352 : 0 : strcpy(cidirrest, TRIGGERSCIFILE);
1353 : 0 : trig_parse_ci(cidir, NULL, trig_cicb_statuschange_activate, pkg, &pkg->available);
1354 : :
1355 : : /* Read the conffiles, and copy the hashes across. */
1356 : 0 : newconffiles.head = NULL;
1357 : 0 : newconffiles.tail = &newconffiles.head;
1358 : 0 : push_cleanup(cu_fileslist, ~0, 0);
1359 : 0 : strcpy(cidirrest,CONFFILESFILE);
1360 : 0 : deb_parse_conffiles(pkg, cidir, &newconffiles);
1361 : :
1362 : : /* All the old conffiles are marked with a flag, so that we don't delete
1363 : : * them if they seem to disappear completely. */
1364 : 0 : pkg_conffiles_mark_old(pkg);
1365 : 0 : for (conflictor_iter = conflictors.head;
1366 [ # # ]: 0 : conflictor_iter;
1367 : 0 : conflictor_iter = conflictor_iter->next)
1368 : 0 : pkg_conffiles_mark_old(conflictor_iter->pkg);
1369 : :
1370 : 0 : oldversionstatus= pkg->status;
1371 : :
1372 [ # # ]: 0 : if (oldversionstatus > PKG_STAT_INSTALLED)
1373 : 0 : internerr("package %s state %d is out-of-bounds",
1374 : : pkg_name(pkg, pnaw_always), oldversionstatus);
1375 : :
1376 : 0 : debug(dbg_general,"process_archive oldversionstatus=%s",
1377 : 0 : statusstrings[oldversionstatus]);
1378 : :
1379 [ # # ]: 0 : if (oldversionstatus == PKG_STAT_HALFCONFIGURED ||
1380 [ # # ]: 0 : oldversionstatus == PKG_STAT_TRIGGERSAWAITED ||
1381 [ # # ]: 0 : oldversionstatus == PKG_STAT_TRIGGERSPENDING ||
1382 [ # # ]: 0 : oldversionstatus == PKG_STAT_INSTALLED) {
1383 : 0 : pkg_set_eflags(pkg, PKG_EFLAG_REINSTREQ);
1384 : 0 : pkg_set_status(pkg, PKG_STAT_HALFCONFIGURED);
1385 : 0 : modstatdb_note(pkg);
1386 : 0 : push_cleanup(cu_prermupgrade, ~ehflag_normaltidy, 1, (void *)pkg);
1387 : 0 : maintscript_fallback(pkg, PRERMFILE, "pre-removal", cidir, cidirrest,
1388 : : "upgrade", "failed-upgrade");
1389 : 0 : pkg_set_status(pkg, PKG_STAT_UNPACKED);
1390 : 0 : oldversionstatus = PKG_STAT_UNPACKED;
1391 : 0 : modstatdb_note(pkg);
1392 : : }
1393 : :
1394 : 0 : pkg_deconfigure_others(pkg);
1395 : :
1396 : 0 : for (conflictor_iter = conflictors.head;
1397 [ # # ]: 0 : conflictor_iter;
1398 : 0 : conflictor_iter = conflictor_iter->next) {
1399 : 0 : struct pkginfo *conflictor = conflictor_iter->pkg;
1400 : :
1401 [ # # ]: 0 : if (!(conflictor->status == PKG_STAT_HALFCONFIGURED ||
1402 [ # # ]: 0 : conflictor->status == PKG_STAT_TRIGGERSAWAITED ||
1403 [ # # ]: 0 : conflictor->status == PKG_STAT_TRIGGERSPENDING ||
1404 [ # # ]: 0 : conflictor->status == PKG_STAT_INSTALLED))
1405 : 0 : continue;
1406 : :
1407 : 0 : trig_activate_packageprocessing(conflictor);
1408 : 0 : pkg_set_status(conflictor, PKG_STAT_HALFCONFIGURED);
1409 : 0 : modstatdb_note(conflictor);
1410 : 0 : push_cleanup(cu_prerminfavour, ~ehflag_normaltidy,
1411 : : 2, conflictor, pkg);
1412 : 0 : maintscript_installed(conflictor, PRERMFILE, "pre-removal",
1413 : : "remove", "in-favour",
1414 : 0 : pkgbin_name(pkg, &pkg->available, pnaw_nonambig),
1415 : 0 : versiondescribe(&pkg->available.version,
1416 : : vdew_nonambig),
1417 : : NULL);
1418 : 0 : pkg_set_status(conflictor, PKG_STAT_HALFINSTALLED);
1419 : 0 : modstatdb_note(conflictor);
1420 : : }
1421 : :
1422 : 0 : pkg_set_eflags(pkg, PKG_EFLAG_REINSTREQ);
1423 [ # # ]: 0 : if (pkg->status == PKG_STAT_NOTINSTALLED) {
1424 : 0 : pkg->installed.version= pkg->available.version;
1425 : 0 : pkg->installed.multiarch = pkg->available.multiarch;
1426 : : }
1427 : 0 : pkg_set_status(pkg, PKG_STAT_HALFINSTALLED);
1428 : 0 : modstatdb_note(pkg);
1429 [ # # ]: 0 : if (oldversionstatus == PKG_STAT_NOTINSTALLED) {
1430 : 0 : push_cleanup(cu_preinstverynew, ~ehflag_normaltidy,
1431 : : 3,(void*)pkg,(void*)cidir,(void*)cidirrest);
1432 : 0 : maintscript_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest,
1433 : : "install", NULL);
1434 [ # # ]: 0 : } else if (oldversionstatus == PKG_STAT_CONFIGFILES) {
1435 : 0 : push_cleanup(cu_preinstnew, ~ehflag_normaltidy,
1436 : : 3,(void*)pkg,(void*)cidir,(void*)cidirrest);
1437 : 0 : maintscript_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest,
1438 : : "install",
1439 : 0 : versiondescribe(&pkg->installed.version, vdew_nonambig),
1440 : 0 : versiondescribe(&pkg->available.version, vdew_nonambig),
1441 : : NULL);
1442 : : } else {
1443 : 0 : push_cleanup(cu_preinstupgrade, ~ehflag_normaltidy,
1444 : : 4,(void*)pkg,(void*)cidir,(void*)cidirrest,(void*)&oldversionstatus);
1445 : 0 : maintscript_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest,
1446 : : "upgrade",
1447 : 0 : versiondescribe(&pkg->installed.version, vdew_nonambig),
1448 : 0 : versiondescribe(&pkg->available.version, vdew_nonambig),
1449 : : NULL);
1450 : : }
1451 : :
1452 [ # # ]: 0 : if (oldversionstatus == PKG_STAT_NOTINSTALLED ||
1453 [ # # ]: 0 : oldversionstatus == PKG_STAT_CONFIGFILES) {
1454 : 0 : printf(_("Unpacking %s (%s) ...\n"),
1455 : 0 : pkgbin_name(pkg, &pkg->available, pnaw_nonambig),
1456 : 0 : versiondescribe(&pkg->available.version, vdew_nonambig));
1457 : : } else {
1458 : 0 : printf(_("Unpacking %s (%s) over (%s) ...\n"),
1459 : 0 : pkgbin_name(pkg, &pkg->available, pnaw_nonambig),
1460 : 0 : versiondescribe(&pkg->available.version, vdew_nonambig),
1461 : 0 : versiondescribe(&pkg->installed.version, vdew_nonambig));
1462 : : }
1463 : :
1464 : : /*
1465 : : * Now we unpack the archive, backing things up as we go.
1466 : : * For each file, we check to see if it already exists.
1467 : : * There are several possibilities:
1468 : : *
1469 : : * + We are trying to install a non-directory ...
1470 : : * - It doesn't exist. In this case we simply extract it.
1471 : : * - It is a plain file, device, symlink, &c. We do an ‘atomic
1472 : : * overwrite’ using link() and rename(), but leave a backup copy.
1473 : : * Later, when we delete the backup, we remove it from any other
1474 : : * packages' lists.
1475 : : * - It is a directory. In this case it depends on whether we're
1476 : : * trying to install a symlink or something else.
1477 : : * = If we're not trying to install a symlink we move the directory
1478 : : * aside and extract the node. Later, when we recursively remove
1479 : : * the backed-up directory, we remove it from any other packages'
1480 : : * lists.
1481 : : * = If we are trying to install a symlink we do nothing - ie,
1482 : : * dpkg will never replace a directory tree with a symlink. This
1483 : : * is to avoid embarrassing effects such as replacing a directory
1484 : : * tree with a link to a link to the original directory tree.
1485 : : * + We are trying to install a directory ...
1486 : : * - It doesn't exist. We create it with the appropriate modes.
1487 : : * - It exists as a directory or a symlink to one. We do nothing.
1488 : : * - It is a plain file or a symlink (other than to a directory).
1489 : : * We move it aside and create the directory. Later, when we
1490 : : * delete the backup, we remove it from any other packages' lists.
1491 : : *
1492 : : * Install non-dir Install symlink Install dir
1493 : : * Exists not X X X
1494 : : * File/node/symlink LXR LXR BXR
1495 : : * Directory BXR - -
1496 : : *
1497 : : * X: extract file/node/link/directory
1498 : : * LX: atomic overwrite leaving backup
1499 : : * B: ordinary backup
1500 : : * R: later remove from other packages' lists
1501 : : * -: do nothing
1502 : : *
1503 : : * After we've done this we go through the remaining things in the
1504 : : * lists of packages we're trying to remove (including the old
1505 : : * version of the current package). This happens in reverse order,
1506 : : * so that we process files before the directories (or symlinks-to-
1507 : : * directories) containing them.
1508 : : *
1509 : : * + If the thing is a conffile then we leave it alone for the purge
1510 : : * operation.
1511 : : * + Otherwise, there are several possibilities too:
1512 : : * - The listed thing does not exist. We ignore it.
1513 : : * - The listed thing is a directory or a symlink to a directory.
1514 : : * We delete it only if it isn't listed in any other package.
1515 : : * - The listed thing is not a directory, but was part of the package
1516 : : * that was upgraded, we check to make sure the files aren't the
1517 : : * same ones from the old package by checking dev/inode
1518 : : * - The listed thing is not a directory or a symlink to one (ie,
1519 : : * it's a plain file, device, pipe, &c, or a symlink to one, or a
1520 : : * dangling symlink). We delete it.
1521 : : *
1522 : : * The removed packages' list becomes empty (of course, the new
1523 : : * version of the package we're installing will have a new list,
1524 : : * which replaces the old version's list).
1525 : : *
1526 : : * If at any stage we remove a file from a package's list, and the
1527 : : * package isn't one we're already processing, and the package's
1528 : : * list becomes empty as a result, we ‘vanish’ the package. This
1529 : : * means that we run its postrm with the ‘disappear’ argument, and
1530 : : * put the package in the ‘not-installed’ state. If it had any
1531 : : * conffiles, their hashes and ownership will have been transferred
1532 : : * already, so we just ignore those and forget about them from the
1533 : : * point of view of the disappearing package.
1534 : : *
1535 : : * NOTE THAT THE OLD POSTRM IS RUN AFTER THE NEW PREINST, since the
1536 : : * files get replaced ‘as we go’.
1537 : : */
1538 : :
1539 : 0 : m_pipe(p1);
1540 : 0 : push_cleanup(cu_closepipe, ehflag_bombout, 1, (void *)&p1[0]);
1541 : 0 : pid = subproc_fork();
1542 [ # # ]: 0 : if (pid == 0) {
1543 : 0 : m_dup2(p1[1],1); close(p1[0]); close(p1[1]);
1544 : 0 : execlp(BACKEND, BACKEND, "--fsys-tarfile", filename, NULL);
1545 : 0 : ohshite(_("unable to execute %s (%s)"),
1546 : : _("package filesystem archive extraction"), BACKEND);
1547 : : }
1548 : 0 : close(p1[1]);
1549 : 0 : p1[1] = -1;
1550 : :
1551 : 0 : newfiles_queue.head = NULL;
1552 : 0 : newfiles_queue.tail = &newfiles_queue.head;
1553 : 0 : tc.newfiles_queue = &newfiles_queue;
1554 : 0 : push_cleanup(cu_fileslist, ~0, 0);
1555 : 0 : tc.pkg= pkg;
1556 : 0 : tc.backendpipe= p1[0];
1557 : 0 : tc.pkgset_getting_in_sync = pkgset_getting_in_sync(pkg);
1558 : :
1559 : : /* Setup the tar archive. */
1560 : 0 : tar.err = DPKG_ERROR_OBJECT;
1561 : 0 : tar.ctx = &tc;
1562 : 0 : tar.ops = &tf;
1563 : :
1564 : 0 : rc = tar_extractor(&tar);
1565 [ # # ]: 0 : if (rc)
1566 : 0 : dpkg_error_print(&tar.err,
1567 : 0 : _("corrupted filesystem tarfile in package archive"));
1568 [ # # ]: 0 : if (fd_skip(p1[0], -1, &err) < 0)
1569 : 0 : ohshit(_("cannot zap possible trailing zeros from dpkg-deb: %s"), err.str);
1570 : 0 : close(p1[0]);
1571 : 0 : p1[0] = -1;
1572 : 0 : subproc_reap(pid, BACKEND " --fsys-tarfile", SUBPROC_NOPIPE);
1573 : :
1574 : 0 : tar_deferred_extract(newfiles_queue.head, pkg);
1575 : :
1576 [ # # ]: 0 : if (oldversionstatus == PKG_STAT_HALFINSTALLED ||
1577 [ # # ]: 0 : oldversionstatus == PKG_STAT_UNPACKED) {
1578 : : /* Packages that were in ‘installed’ and ‘postinstfailed’ have been
1579 : : * reduced to ‘unpacked’ by now, by the running of the prerm script. */
1580 : 0 : pkg_set_status(pkg, PKG_STAT_HALFINSTALLED);
1581 : 0 : modstatdb_note(pkg);
1582 : 0 : push_cleanup(cu_postrmupgrade, ~ehflag_normaltidy, 1, (void *)pkg);
1583 : 0 : maintscript_fallback(pkg, POSTRMFILE, "post-removal", cidir, cidirrest,
1584 : : "upgrade", "failed-upgrade");
1585 : : }
1586 : :
1587 : : /* If anything goes wrong while tidying up it's a bit late to do
1588 : : * anything about it. However, we don't install the new status
1589 : : * info yet, so that a future dpkg installation will put everything
1590 : : * right (we hope).
1591 : : *
1592 : : * If something does go wrong later the ‘conflictor’ package will be
1593 : : * left in the ‘removal_failed’ state. Removing or installing it
1594 : : * will be impossible if it was required because of the conflict with
1595 : : * the package we're installing now and (presumably) the dependency
1596 : : * by other packages. This means that the files it contains in
1597 : : * common with this package will hang around until we successfully
1598 : : * get this package installed, after which point we can trust the
1599 : : * conflicting package's file list, which will have been updated to
1600 : : * remove any files in this package. */
1601 : 0 : push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
1602 : :
1603 : : /* Now we delete all the files that were in the old version of
1604 : : * the package only, except (old or new) conffiles, which we leave
1605 : : * alone. */
1606 : 0 : pkg_remove_old_files(pkg, &newfiles_queue, &newconffiles);
1607 : :
1608 : : /* OK, now we can write the updated files-in-this package list,
1609 : : * since we've done away (hopefully) with all the old junk. */
1610 : 0 : write_filelist_except(pkg, &pkg->available, newfiles_queue.head, 0);
1611 : :
1612 : : /* Trigger interests may have changed.
1613 : : * Firstly we go through the old list of interests deleting them.
1614 : : * Then we go through the new list adding them. */
1615 : 0 : strcpy(cidirrest, TRIGGERSCIFILE);
1616 : 0 : trig_parse_ci(pkg_infodb_get_file(pkg, &pkg->installed, TRIGGERSCIFILE),
1617 : 0 : trig_cicb_interest_delete, NULL, pkg, &pkg->installed);
1618 : 0 : trig_parse_ci(cidir, trig_cicb_interest_add, NULL, pkg, &pkg->available);
1619 : 0 : trig_file_interests_save();
1620 : :
1621 : : /* We also install the new maintainer scripts, and any other
1622 : : * cruft that may have come along with the package. First
1623 : : * we go through the existing scripts replacing or removing
1624 : : * them as appropriate; then we go through the new scripts
1625 : : * (any that are left) and install them. */
1626 : 0 : debug(dbg_general, "process_archive updating info directory");
1627 : 0 : pkg_infodb_update(pkg, cidir, cidirrest);
1628 : :
1629 : : /* We store now the checksums dynamically computed while unpacking. */
1630 : 0 : write_filehash_except(pkg, &pkg->available, newfiles_queue.head, 0);
1631 : :
1632 : : /*
1633 : : * Update the status database.
1634 : : *
1635 : : * This involves copying each field across from the ‘available’
1636 : : * to the ‘installed’ half of the pkg structure.
1637 : : * For some of the fields we have to do a complicated construction
1638 : : * operation; for others we can just copy the value.
1639 : : * We tackle the fields in the order they appear, so that
1640 : : * we don't miss any out :-).
1641 : : * At least we don't have to copy any strings that are referred
1642 : : * to, because these are never modified and never freed.
1643 : : */
1644 : 0 : pkg_update_fields(pkg, &newconffiles);
1645 : :
1646 : : /* In case this was an architecture cross-grade, the in-core pkgset might
1647 : : * be in an inconsistent state, with two pkginfo entries having the same
1648 : : * architecture, so let's fix that. Note that this does not lose data,
1649 : : * as the pkg.available member parsed from the binary should replace the
1650 : : * to be cleared duplicate in the other instance. */
1651 [ # # ]: 0 : for (otherpkg = &pkg->set->pkg; otherpkg; otherpkg = otherpkg->arch_next) {
1652 [ # # ]: 0 : if (otherpkg == pkg)
1653 : 0 : continue;
1654 [ # # ]: 0 : if (otherpkg->installed.arch != pkg->installed.arch)
1655 : 0 : continue;
1656 : :
1657 [ # # ]: 0 : if (otherpkg->status != PKG_STAT_NOTINSTALLED)
1658 : 0 : internerr("other package %s instance in state %s instead of not-installed",
1659 : : pkg_name(otherpkg, pnaw_always), pkg_status_name(otherpkg));
1660 : :
1661 : 0 : pkg_blank(otherpkg);
1662 : : }
1663 : :
1664 : : /* Check for disappearing packages:
1665 : : * We go through all the packages on the system looking for ones
1666 : : * whose files are entirely part of the one we've just unpacked
1667 : : * (and which actually *have* some files!).
1668 : : *
1669 : : * Any that we find are removed - we run the postrm with ‘disappear’
1670 : : * as an argument, and remove their info/... files and status info.
1671 : : * Conffiles are ignored (the new package had better do something
1672 : : * with them!). */
1673 : 0 : pkg_disappear_others(pkg);
1674 : :
1675 : : /* Delete files from any other packages' lists.
1676 : : * We have to do this before we claim this package is in any
1677 : : * sane kind of state, as otherwise we might delete by mistake
1678 : : * a file that we overwrote, when we remove the package which
1679 : : * had the version we overwrote. To prevent this we make
1680 : : * sure that we don't claim this package is OK until we
1681 : : * have claimed ‘ownership’ of all its files. */
1682 : 0 : pkg_remove_files_from_others(pkg, newfiles_queue.head);
1683 : :
1684 : : /* Right, the package we've unpacked is now in a reasonable state.
1685 : : * The only thing that we have left to do with it is remove
1686 : : * backup files, and we can leave the user to fix that if and when
1687 : : * it happens (we leave the reinstall required flag, of course). */
1688 : 0 : pkg_set_status(pkg, PKG_STAT_UNPACKED);
1689 : 0 : modstatdb_note(pkg);
1690 : :
1691 : : /* Now we delete all the backup files that we made when
1692 : : * extracting the archive - except for files listed as conffiles
1693 : : * in the new package.
1694 : : * This time we count it as an error if something goes wrong.
1695 : : *
1696 : : * Note that we don't ever delete things that were in the old
1697 : : * package as a conffile and don't appear at all in the new.
1698 : : * They stay recorded as obsolete conffiles and will eventually
1699 : : * (if not taken over by another package) be forgotten. */
1700 : 0 : pkg_remove_backup_files(pkg, newfiles_queue.head);
1701 : :
1702 : : /* OK, we're now fully done with the main package.
1703 : : * This is quite a nice state, so we don't unwind past here. */
1704 : 0 : pkg_reset_eflags(pkg);
1705 : 0 : modstatdb_note(pkg);
1706 : 0 : push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
1707 : :
1708 : : /* Only the removal of the conflictor left to do.
1709 : : * The files list for the conflictor is still a little inconsistent in-core,
1710 : : * as we have not yet updated the filename->packages mappings; however,
1711 : : * the package->filenames mapping is. */
1712 [ # # ]: 0 : while (!pkg_queue_is_empty(&conflictors)) {
1713 : 0 : struct pkginfo *conflictor = pkg_queue_pop(&conflictors);
1714 : :
1715 : : /* We need to have the most up-to-date info about which files are
1716 : : * what ... */
1717 : 0 : ensure_allinstfiles_available();
1718 : 0 : printf(_("Removing %s (%s), to allow configuration of %s (%s) ...\n"),
1719 : : pkg_name(conflictor, pnaw_nonambig),
1720 : 0 : versiondescribe(&conflictor->installed.version, vdew_nonambig),
1721 : : pkg_name(pkg, pnaw_nonambig),
1722 : 0 : versiondescribe(&pkg->installed.version, vdew_nonambig));
1723 : 0 : removal_bulk(conflictor);
1724 : : }
1725 : :
1726 [ # # ]: 0 : if (cipaction->arg_int == act_install)
1727 : 0 : enqueue_package_mark_seen(pkg);
1728 : : }
|