2 * dpkg - main program for package management
3 * unpack.c - .deb archive unpacking
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>
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.
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.
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/>.
27 #include <sys/types.h>
43 #include <dpkg/i18n.h>
44 #include <dpkg/c-ctype.h>
45 #include <dpkg/dpkg.h>
46 #include <dpkg/dpkg-db.h>
48 #include <dpkg/pkg-queue.h>
49 #include <dpkg/path.h>
50 #include <dpkg/buffer.h>
51 #include <dpkg/subproc.h>
53 #include <dpkg/tarfn.h>
54 #include <dpkg/options.h>
55 #include <dpkg/triglib.h>
58 #include "file-match.h"
64 summarize_filename(const char *filename
)
66 const char *pfilename
;
69 for (pfilename
= filename
;
70 pfilename
&& strlen(pfilename
) > 30 && strchr(pfilename
, '/') != NULL
;
72 pfilename
= strchr(pfilename
, '/');
74 if (pfilename
&& pfilename
!= filename
) {
75 pfilenamebuf
= nfmalloc(strlen(pfilename
) + 5);
76 sprintf(pfilenamebuf
, _(".../%s"), pfilename
);
77 pfilename
= pfilenamebuf
;
86 deb_reassemble(const char **filename
, const char **pfilename
)
88 static char *reasmbuf
= NULL
;
94 reasmbuf
= dpkg_db_get_path(REASSEMBLETMP
);
95 if (unlink(reasmbuf
) && errno
!= ENOENT
)
96 ohshite(_("error ensuring '%.250s' doesn't exist"), reasmbuf
);
98 push_cleanup(cu_pathname
, ~0, NULL
, 0, 1, (void *)reasmbuf
);
100 pid
= subproc_fork();
102 execlp(SPLITTER
, SPLITTER
, "-Qao", reasmbuf
, *filename
, NULL
);
103 ohshite(_("unable to execute %s (%s)"),
104 _("split package reassembly"), SPLITTER
);
106 status
= subproc_reap(pid
, SPLITTER
, SUBPROC_RETERROR
);
109 /* It was a part - is it complete? */
110 if (!stat(reasmbuf
, &stab
)) {
112 *filename
= reasmbuf
;
113 *pfilename
= _("reassembled package file");
115 } else if (errno
== ENOENT
) {
116 /* No. That's it, we skip it. */
120 /* No, it wasn't a part. */
123 ohshit(_("subprocess %s returned error exit status %d"), SPLITTER
, status
);
130 deb_verify(const char *filename
)
134 /* We have to check on every unpack, in case the debsig-verify package
135 * gets installed or removed. */
136 if (!find_command(DEBSIGVERIFY
))
139 printf(_("Authenticating %s ...\n"), filename
);
141 pid
= subproc_fork();
143 execlp(DEBSIGVERIFY
, DEBSIGVERIFY
, "-q", filename
, NULL
);
144 ohshite(_("unable to execute %s (%s)"),
145 _("package signature verification"), DEBSIGVERIFY
);
149 status
= subproc_reap(pid
, "debsig-verify", SUBPROC_NOCHECK
);
150 if (!(WIFEXITED(status
) && WEXITSTATUS(status
) == 0)) {
152 ohshit(_("verification on package %s failed!"), filename
);
154 notice(_("verification on package %s failed; "
155 "but installing anyway as you requested"), filename
);
157 printf(_("passed\n"));
163 get_control_dir(char *cidir
)
168 tmpdir
= mkdtemp(path_make_temp_template("dpkg"));
170 ohshite(_("unable to create temporary directory"));
172 cidir
= m_realloc(cidir
, strlen(tmpdir
) + MAXCONTROLFILENAME
+ 10);
174 strcpy(cidir
, tmpdir
);
178 const char *admindir
;
180 admindir
= dpkg_db_get_dir();
182 /* The admindir length is always constant on a dpkg execution run. */
184 cidir
= m_malloc(strlen(admindir
) + sizeof(CONTROLDIRTMP
) +
185 MAXCONTROLFILENAME
+ 10);
187 /* We want it to be on the same filesystem so that we can
188 * use rename(2) to install the postinst &c. */
189 strcpy(cidir
, admindir
);
190 strcat(cidir
, "/" CONTROLDIRTMP
);
192 /* Make sure the control information directory is empty. */
193 path_remove_tree(cidir
);
202 pkg_check_depcon(struct pkginfo
*pkg
, const char *pfilename
)
204 struct dependency
*dsearch
;
205 struct deppossi
*psearch
;
206 struct pkginfo
*fixbytrigaw
;
207 static struct varbuf depprobwhy
;
209 /* Check if anything is installed that we conflict with, or not installed
211 pkg
->clientdata
->istobe
= PKG_ISTOBE_INSTALLNEW
;
213 for (dsearch
= pkg
->available
.depends
; dsearch
; dsearch
= dsearch
->next
) {
214 switch (dsearch
->type
) {
216 /* Look for things we conflict with. */
217 check_conflict(dsearch
, pkg
, pfilename
);
220 /* Look for things we break. */
221 check_breaks(dsearch
, pkg
, pfilename
);
224 /* Look for things that conflict with what we provide. */
225 for (psearch
= dsearch
->list
->ed
->depended
.installed
;
227 psearch
= psearch
->rev_next
) {
228 if (psearch
->up
->type
!= dep_conflicts
)
230 check_conflict(psearch
->up
, pkg
, pfilename
);
238 /* Ignore these here. */
241 if (!depisok(dsearch
, &depprobwhy
, NULL
, &fixbytrigaw
, true)) {
243 while (fixbytrigaw
->trigaw
.head
)
244 trigproc(fixbytrigaw
->trigaw
.head
->pend
, TRIGPROC_REQUIRED
);
246 varbuf_end_str(&depprobwhy
);
247 notice(_("regarding %s containing %s, pre-dependency problem:\n%s"),
248 pfilename
, pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
),
250 if (!force_depends(dsearch
->list
))
251 ohshit(_("pre-dependency problem - not installing %.250s"),
252 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
253 warning(_("ignoring pre-dependency problem!"));
259 /* Look for things that conflict with us. */
260 for (psearch
= pkg
->set
->depended
.installed
; psearch
; psearch
= psearch
->rev_next
) {
261 if (psearch
->up
->type
!= dep_conflicts
)
264 check_conflict(psearch
->up
, pkg
, pfilename
);
269 pkg_deconfigure_others(struct pkginfo
*pkg
)
271 struct pkg_deconf_list
*deconpil
;
273 for (deconpil
= deconfigure
; deconpil
; deconpil
= deconpil
->next
) {
274 struct pkginfo
*removing
= deconpil
->pkg_removal
;
277 printf(_("De-configuring %s (%s), to allow removal of %s (%s) ...\n"),
278 pkg_name(deconpil
->pkg
, pnaw_nonambig
),
279 versiondescribe(&deconpil
->pkg
->installed
.version
, vdew_nonambig
),
280 pkg_name(removing
, pnaw_nonambig
),
281 versiondescribe(&removing
->installed
.version
, vdew_nonambig
));
283 printf(_("De-configuring %s (%s) ...\n"),
284 pkg_name(deconpil
->pkg
, pnaw_nonambig
),
285 versiondescribe(&deconpil
->pkg
->installed
.version
, vdew_nonambig
));
287 trig_activate_packageprocessing(deconpil
->pkg
);
288 pkg_set_status(deconpil
->pkg
, PKG_STAT_HALFCONFIGURED
);
289 modstatdb_note(deconpil
->pkg
);
291 /* This means that we *either* go and run postinst abort-deconfigure,
292 * *or* queue the package for later configure processing, depending
293 * on which error cleanup route gets taken. */
294 push_cleanup(cu_prermdeconfigure
, ~ehflag_normaltidy
,
295 ok_prermdeconfigure
, ehflag_normaltidy
,
296 3, (void *)deconpil
->pkg
, (void *)removing
, (void *)pkg
);
299 maintscript_installed(deconpil
->pkg
, PRERMFILE
, "pre-removal",
300 "deconfigure", "in-favour",
301 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
),
302 versiondescribe(&pkg
->available
.version
,
305 pkg_name(removing
, pnaw_nonambig
),
306 versiondescribe(&removing
->installed
.version
,
310 maintscript_installed(deconpil
->pkg
, PRERMFILE
, "pre-removal",
311 "deconfigure", "in-favour",
312 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
),
313 versiondescribe(&pkg
->available
.version
,
321 * Read the conffiles, and copy the hashes across.
324 deb_parse_conffiles(struct pkginfo
*pkg
, const char *control_conffiles
,
325 struct filenamenode_queue
*newconffiles
)
328 char conffilenamebuf
[MAXCONFFILENAME
];
330 conff
= fopen(control_conffiles
, "r");
334 ohshite(_("error trying to open %.250s"), control_conffiles
);
337 push_cleanup(cu_closestream
, ehflag_bombout
, NULL
, 0, 1, conff
);
339 while (fgets(conffilenamebuf
, MAXCONFFILENAME
- 2, conff
)) {
340 struct pkginfo
*otherpkg
;
341 struct filepackages_iterator
*iter
;
342 struct filenamenode
*namenode
;
343 struct fileinlist
*newconff
;
344 struct conffile
*searchconff
;
347 p
= conffilenamebuf
+ strlen(conffilenamebuf
);
348 assert(p
!= conffilenamebuf
);
350 ohshit(_("conffile name '%s' is too long, or missing final newline"),
352 while (p
> conffilenamebuf
&& c_isspace(p
[-1]))
354 if (p
== conffilenamebuf
)
358 namenode
= findnamenode(conffilenamebuf
, 0);
359 namenode
->oldhash
= NEWCONFFILEFLAG
;
360 newconff
= tar_filenamenode_queue_push(newconffiles
, namenode
);
363 * Let's see if any packages have this file.
365 * If they do we check to see if they listed it as a conffile,
366 * and if they did we copy the hash across. Since (for plain
367 * file conffiles, which is the only kind we are supposed to
368 * have) there will only be one package which ‘has’ the file,
369 * this will usually mean we only look in the package which
370 * we are installing now.
372 * The ‘conffiles’ data in the status file is ignored when a
373 * package is not also listed in the file ownership database as
374 * having that file. If several packages are listed as owning
375 * the file we pick one at random.
379 iter
= filepackages_iter_new(newconff
->namenode
);
380 while ((otherpkg
= filepackages_iter_next(iter
))) {
381 debug(dbg_conffdetail
,
382 "process_archive conffile '%s' in package %s - conff ?",
383 newconff
->namenode
->name
, pkg_name(otherpkg
, pnaw_always
));
384 for (searchconff
= otherpkg
->installed
.conffiles
;
385 searchconff
&& strcmp(newconff
->namenode
->name
, searchconff
->name
);
386 searchconff
= searchconff
->next
)
387 debug(dbg_conffdetail
,
388 "process_archive conffile '%s' in package %s - conff ? not '%s'",
389 newconff
->namenode
->name
, pkg_name(otherpkg
, pnaw_always
),
393 "process_archive conffile '%s' package=%s %s hash=%s",
394 newconff
->namenode
->name
, pkg_name(otherpkg
, pnaw_always
),
395 otherpkg
== pkg ?
"same" : "different!",
401 filepackages_iter_free(iter
);
404 /* We don't copy ‘obsolete’; it's not obsolete in the new package. */
405 newconff
->namenode
->oldhash
= searchconff
->hash
;
407 debug(dbg_conff
, "process_archive conffile '%s' no package, no hash",
408 newconff
->namenode
->name
);
410 newconff
->namenode
->flags
|= fnnf_new_conff
;
414 ohshite(_("read error in %.250s"), control_conffiles
);
415 pop_cleanup(ehflag_normaltidy
); /* conff = fopen() */
417 ohshite(_("error closing %.250s"), control_conffiles
);
420 static struct pkg_queue conflictors
= PKG_QUEUE_INIT
;
423 enqueue_conflictor(struct pkginfo
*pkg
)
425 pkg_queue_push(&conflictors
, pkg
);
429 pkg_infodb_remove_file(const char *filename
, const char *filetype
)
431 if (unlink(filename
))
432 ohshite(_("unable to delete control info file '%.250s'"), filename
);
434 debug(dbg_scripts
, "removal_bulk info unlinked %s", filename
);
437 static struct match_node
*match_head
= NULL
;
440 pkg_infodb_update_file(const char *filename
, const char *filetype
)
442 if (strlen(filetype
) > MAXCONTROLFILENAME
)
443 ohshit(_("old version of package has overly-long info file name starting '%.250s'"),
446 /* We do the list separately. */
447 if (strcmp(filetype
, LISTFILE
) == 0)
450 /* We keep files to rename in a list as doing the rename immediately
451 * might influence the current readdir(), the just renamed file might
452 * be returned a second time as it's actually a new file from the
453 * point of view of the filesystem. */
454 match_head
= match_node_new(filename
, filetype
, match_head
);
458 pkg_infodb_update(struct pkginfo
*pkg
, char *cidir
, char *cidirrest
)
460 struct match_node
*match_node
;
464 /* Deallocate the match list in case we aborted previously. */
465 while ((match_node
= match_head
)) {
466 match_head
= match_node
->next
;
467 match_node_free(match_node
);
470 pkg_infodb_foreach(pkg
, &pkg
->available
, pkg_infodb_update_file
);
472 while ((match_node
= match_head
)) {
473 strcpy(cidirrest
, match_node
->filetype
);
475 if (!rename(cidir
, match_node
->filename
)) {
476 debug(dbg_scripts
, "process_archive info installed %s as %s",
477 cidir
, match_node
->filename
);
478 } else if (errno
== ENOENT
) {
479 /* Right, no new version. */
480 if (unlink(match_node
->filename
))
481 ohshite(_("unable to remove obsolete info file '%.250s'"),
482 match_node
->filename
);
483 debug(dbg_scripts
, "process_archive info unlinked %s",
484 match_node
->filename
);
486 ohshite(_("unable to install (supposed) new info file '%.250s'"), cidir
);
488 match_head
= match_node
->next
;
489 match_node_free(match_node
);
492 /* The control directory itself. */
494 dsd
= opendir(cidir
);
496 ohshite(_("unable to open temp control directory"));
497 push_cleanup(cu_closedir
, ~0, NULL
, 0, 1, (void *)dsd
);
498 while ((de
= readdir(dsd
))) {
499 const char *newinfofilename
;
501 if (strchr(de
->d_name
, '.')) {
502 debug(dbg_scripts
, "process_archive tmp.ci script/file '%s' contains dot",
506 if (strlen(de
->d_name
) > MAXCONTROLFILENAME
)
507 ohshit(_("package contains overly-long control info file name (starting '%.50s')"),
510 strcpy(cidirrest
, de
->d_name
);
512 /* First we check it's not a directory. */
513 if (rmdir(cidir
) == 0)
514 ohshit(_("package control info contained directory '%.250s'"), cidir
);
515 else if (errno
!= ENOTDIR
)
516 ohshite(_("package control info rmdir of '%.250s' didn't say not a dir"),
519 /* Ignore the control file. */
520 if (strcmp(de
->d_name
, CONTROLFILE
) == 0) {
521 debug(dbg_scripts
, "process_archive tmp.ci script/file '%s' is control",
525 if (strcmp(de
->d_name
, LISTFILE
) == 0) {
526 warning(_("package %s contained list as info file"),
527 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
531 /* Right, install it */
532 newinfofilename
= pkg_infodb_get_file(pkg
, &pkg
->available
, de
->d_name
);
533 if (rename(cidir
, newinfofilename
))
534 ohshite(_("unable to install new info file '%.250s' as '%.250s'"),
535 cidir
, newinfofilename
);
538 "process_archive tmp.ci script/file '%s' installed as '%s'",
539 cidir
, newinfofilename
);
541 pop_cleanup(ehflag_normaltidy
); /* closedir */
543 /* If the old and new versions use a different infodb layout, get rid
544 * of the files using the old layout. */
545 if (pkg
->installed
.multiarch
!= pkg
->available
.multiarch
&&
546 (pkg
->installed
.multiarch
== PKG_MULTIARCH_SAME
||
547 pkg
->available
.multiarch
== PKG_MULTIARCH_SAME
)) {
549 "process_archive remove old info files after db layout switch");
550 pkg_infodb_foreach(pkg
, &pkg
->installed
, pkg_infodb_remove_file
);
553 dir_sync_path(pkg_infodb_get_dir());
557 pkg_remove_old_files(struct pkginfo
*pkg
,
558 struct filenamenode_queue
*newfiles_queue
,
559 struct filenamenode_queue
*newconffiles
)
561 struct reversefilelistiter rev_iter
;
562 struct filenamenode
*namenode
;
563 struct stat stab
, oldfs
;
565 reversefilelist_init(&rev_iter
, pkg
->clientdata
->files
);
567 while ((namenode
= reversefilelist_next(&rev_iter
))) {
568 struct filenamenode
*usenode
;
570 if ((namenode
->flags
& fnnf_new_conff
) ||
571 (namenode
->flags
& fnnf_new_inarchive
))
574 usenode
= namenodetouse(namenode
, pkg
, &pkg
->installed
);
576 varbuf_rollback(&fnamevb
, &fname_state
);
577 varbuf_add_str(&fnamevb
, usenode
->name
);
578 varbuf_end_str(&fnamevb
);
580 if (!stat(namenode
->name
, &stab
) && S_ISDIR(stab
.st_mode
)) {
581 debug(dbg_eachfiledetail
, "process_archive: %s is a directory",
583 if (dir_is_used_by_others(namenode
, pkg
))
587 if (lstat(fnamevb
.buf
, &oldfs
)) {
588 if (!(errno
== ENOENT
|| errno
== ELOOP
|| errno
== ENOTDIR
))
589 warning(_("could not stat old file '%.250s' so not deleting it: %s"),
590 fnamevb
.buf
, strerror(errno
));
593 if (S_ISDIR(oldfs
.st_mode
)) {
594 trig_path_activate(usenode
, pkg
);
596 /* Do not try to remove the root directory. */
597 if (strcmp(usenode
->name
, "/.") == 0)
600 if (rmdir(fnamevb
.buf
)) {
601 warning(_("unable to delete old directory '%.250s': %s"),
602 namenode
->name
, strerror(errno
));
603 } else if ((namenode
->flags
& fnnf_old_conff
)) {
604 warning(_("old conffile '%.250s' was an empty directory "
605 "(and has now been deleted)"), namenode
->name
);
608 struct fileinlist
*sameas
= NULL
;
609 struct fileinlist
*cfile
;
610 static struct stat empty_stat
;
611 struct varbuf cfilename
= VARBUF_INIT
;
614 * Ok, it's an old file, but is it really not in the new package?
615 * It might be known by a different name because of symlinks.
617 * We need to check to make sure, so we stat the file, then compare
618 * it to the new list. If we find a dev/inode match, we assume they
619 * are the same file, and leave it alone. NOTE: we don't check in
620 * other packages for sanity reasons (we don't want to stat _all_
621 * the files on the system).
623 * We run down the list of _new_ files in this package. This keeps
624 * the process a little leaner. We are only worried about new ones
625 * since ones that stayed the same don't really apply here.
628 /* If we can't stat the old or new file, or it's a directory,
629 * we leave it up to the normal code. */
630 debug(dbg_eachfile
, "process_archive: checking %s for same files on "
631 "upgrade/downgrade", fnamevb
.buf
);
633 for (cfile
= newfiles_queue
->head
; cfile
; cfile
= cfile
->next
) {
634 /* If the file has been filtered then treat it as if it didn't exist
635 * on the file system. */
636 if (cfile
->namenode
->flags
& fnnf_filtered
)
639 if (!cfile
->namenode
->filestat
) {
640 struct stat tmp_stat
;
642 varbuf_reset(&cfilename
);
643 varbuf_add_str(&cfilename
, instdir
);
644 varbuf_add_str(&cfilename
, cfile
->namenode
->name
);
645 varbuf_end_str(&cfilename
);
647 if (lstat(cfilename
.buf
, &tmp_stat
) == 0) {
648 cfile
->namenode
->filestat
= nfmalloc(sizeof(struct stat
));
649 memcpy(cfile
->namenode
->filestat
, &tmp_stat
, sizeof(struct stat
));
651 if (!(errno
== ENOENT
|| errno
== ELOOP
|| errno
== ENOTDIR
))
652 ohshite(_("unable to stat other new file '%.250s'"),
653 cfile
->namenode
->name
);
654 cfile
->namenode
->filestat
= &empty_stat
;
659 if (cfile
->namenode
->filestat
== &empty_stat
)
662 if (oldfs
.st_dev
== cfile
->namenode
->filestat
->st_dev
&&
663 oldfs
.st_ino
== cfile
->namenode
->filestat
->st_ino
) {
665 warning(_("old file '%.250s' is the same as several new files! "
666 "(both '%.250s' and '%.250s')"), fnamevb
.buf
,
667 sameas
->namenode
->name
, cfile
->namenode
->name
);
669 debug(dbg_eachfile
, "process_archive: not removing %s, "
670 "since it matches %s", fnamevb
.buf
, cfile
->namenode
->name
);
674 varbuf_destroy(&cfilename
);
676 if ((namenode
->flags
& fnnf_old_conff
)) {
678 if (sameas
->namenode
->flags
& fnnf_new_conff
) {
679 if (strcmp(sameas
->namenode
->oldhash
, NEWCONFFILEFLAG
) == 0) {
680 sameas
->namenode
->oldhash
= namenode
->oldhash
;
681 debug(dbg_eachfile
, "process_archive: old conff %s "
682 "is same as new conff %s, copying hash",
683 namenode
->name
, sameas
->namenode
->name
);
685 debug(dbg_eachfile
, "process_archive: old conff %s "
686 "is same as new conff %s but latter already has hash",
687 namenode
->name
, sameas
->namenode
->name
);
691 debug(dbg_eachfile
, "process_archive: old conff %s "
692 "is disappearing", namenode
->name
);
693 namenode
->flags
|= fnnf_obs_conff
;
694 tar_filenamenode_queue_push(newconffiles
, namenode
);
695 tar_filenamenode_queue_push(newfiles_queue
, namenode
);
703 trig_path_activate(usenode
, pkg
);
705 if (secure_unlink_statted(fnamevb
.buf
, &oldfs
)) {
706 warning(_("unable to securely remove old file '%.250s': %s"),
707 namenode
->name
, strerror(errno
));
714 pkg_update_fields(struct pkginfo
*pkg
, struct filenamenode_queue
*newconffiles
)
716 struct dependency
*newdeplist
, **newdeplistlastp
;
717 struct dependency
*newdep
, *dep
;
718 struct deppossi
**newpossilastp
, *possi
, *newpossi
;
719 struct conffile
**iconffileslastp
, *newiconff
;
720 struct fileinlist
*cfile
;
722 /* The dependencies are the most difficult. We have to build
723 * a whole new forward dependency tree. At least the reverse
724 * links (linking our deppossi's into the reverse chains)
725 * can be done by copy_dependency_links. */
727 newdeplistlastp
= &newdeplist
;
728 for (dep
= pkg
->available
.depends
; dep
; dep
= dep
->next
) {
729 newdep
= nfmalloc(sizeof(struct dependency
));
733 newpossilastp
= &newdep
->list
;
735 for (possi
= dep
->list
; possi
; possi
= possi
->next
) {
736 newpossi
= nfmalloc(sizeof(struct deppossi
));
737 newpossi
->up
= newdep
;
738 newpossi
->ed
= possi
->ed
;
739 newpossi
->next
= NULL
;
740 newpossi
->rev_next
= newpossi
->rev_prev
= NULL
;
741 newpossi
->arch_is_implicit
= possi
->arch_is_implicit
;
742 newpossi
->arch
= possi
->arch
;
743 newpossi
->verrel
= possi
->verrel
;
744 if (possi
->verrel
!= DPKG_RELATION_NONE
)
745 newpossi
->version
= possi
->version
;
747 dpkg_version_blank(&newpossi
->version
);
748 newpossi
->cyclebreak
= false;
749 *newpossilastp
= newpossi
;
750 newpossilastp
= &newpossi
->next
;
752 newdep
->type
= dep
->type
;
753 *newdeplistlastp
= newdep
;
754 newdeplistlastp
= &newdep
->next
;
757 /* Right, now we've replicated the forward tree, we
758 * get copy_dependency_links to remove all the old dependency
759 * structures from the reverse links and add the new dependency
760 * structures in instead. It also copies the new dependency
761 * structure pointer for this package into the right field. */
762 copy_dependency_links(pkg
, &pkg
->installed
.depends
, newdeplist
, 0);
764 /* We copy the text fields. */
765 pkg
->installed
.essential
= pkg
->available
.essential
;
766 pkg
->installed
.multiarch
= pkg
->available
.multiarch
;
767 pkg
->installed
.description
= pkg
->available
.description
;
768 pkg
->installed
.maintainer
= pkg
->available
.maintainer
;
769 pkg
->installed
.source
= pkg
->available
.source
;
770 pkg
->installed
.arch
= pkg
->available
.arch
;
771 pkg
->installed
.pkgname_archqual
= pkg
->available
.pkgname_archqual
;
772 pkg
->installed
.installedsize
= pkg
->available
.installedsize
;
773 pkg
->installed
.version
= pkg
->available
.version
;
774 pkg
->installed
.origin
= pkg
->available
.origin
;
775 pkg
->installed
.bugs
= pkg
->available
.bugs
;
777 /* We have to generate our own conffiles structure. */
778 pkg
->installed
.conffiles
= NULL
;
779 iconffileslastp
= &pkg
->installed
.conffiles
;
780 for (cfile
= newconffiles
->head
; cfile
; cfile
= cfile
->next
) {
781 newiconff
= nfmalloc(sizeof(struct conffile
));
782 newiconff
->next
= NULL
;
783 newiconff
->name
= nfstrsave(cfile
->namenode
->name
);
784 newiconff
->hash
= nfstrsave(cfile
->namenode
->oldhash
);
785 newiconff
->obsolete
= !!(cfile
->namenode
->flags
& fnnf_obs_conff
);
786 *iconffileslastp
= newiconff
;
787 iconffileslastp
= &newiconff
->next
;
790 /* We can just copy the arbitrary fields list, because it is
791 * never even rearranged. Phew! */
792 pkg
->installed
.arbs
= pkg
->available
.arbs
;
796 pkg_disappear(struct pkginfo
*pkg
, struct pkginfo
*infavour
)
798 printf(_("(Noting disappearance of %s, which has been completely replaced.)\n"),
799 pkg_name(pkg
, pnaw_nonambig
));
800 log_action("disappear", pkg
, &pkg
->installed
);
801 debug(dbg_general
, "pkg_disappear disappearing %s",
802 pkg_name(pkg
, pnaw_always
));
804 trig_activate_packageprocessing(pkg
);
805 maintscript_installed(pkg
, POSTRMFILE
,
806 "post-removal script (for disappearance)",
808 pkgbin_name(infavour
, &infavour
->available
,
810 versiondescribe(&infavour
->available
.version
,
814 /* OK, now we delete all the stuff in the ‘info’ directory ... */
815 debug(dbg_general
, "pkg_disappear cleaning info directory");
816 pkg_infodb_foreach(pkg
, &pkg
->installed
, pkg_infodb_remove_file
);
817 dir_sync_path(pkg_infodb_get_dir());
819 pkg_set_status(pkg
, PKG_STAT_NOTINSTALLED
);
820 pkg_set_want(pkg
, PKG_WANT_UNKNOWN
);
821 pkg_reset_eflags(pkg
);
823 dpkg_version_blank(&pkg
->configversion
);
824 pkgbin_blank(&pkg
->installed
);
826 pkg
->clientdata
->fileslistvalid
= false;
832 pkg_disappear_others(struct pkginfo
*pkg
)
834 struct pkgiterator
*iter
;
835 struct pkginfo
*otherpkg
;
836 struct fileinlist
*cfile
;
837 struct deppossi
*pdep
;
838 struct dependency
*providecheck
;
839 struct varbuf depprobwhy
= VARBUF_INIT
;
841 iter
= pkg_db_iter_new();
842 while ((otherpkg
= pkg_db_iter_next_pkg(iter
)) != NULL
) {
843 ensure_package_clientdata(otherpkg
);
845 if (otherpkg
== pkg
||
846 otherpkg
->status
== PKG_STAT_NOTINSTALLED
||
847 otherpkg
->status
== PKG_STAT_CONFIGFILES
||
848 otherpkg
->clientdata
->istobe
== PKG_ISTOBE_REMOVE
||
849 !otherpkg
->clientdata
->files
)
852 /* Do not try to disappear other packages from the same set
853 * if they are Multi-Arch: same */
854 if (pkg
->installed
.multiarch
== PKG_MULTIARCH_SAME
&&
855 otherpkg
->installed
.multiarch
== PKG_MULTIARCH_SAME
&&
856 otherpkg
->set
== pkg
->set
)
859 debug(dbg_veryverbose
, "process_archive checking disappearance %s",
860 pkg_name(otherpkg
, pnaw_always
));
861 assert(otherpkg
->clientdata
->istobe
== PKG_ISTOBE_NORMAL
||
862 otherpkg
->clientdata
->istobe
== PKG_ISTOBE_DECONFIGURE
);
864 for (cfile
= otherpkg
->clientdata
->files
;
865 cfile
&& strcmp(cfile
->namenode
->name
, "/.") == 0;
866 cfile
= cfile
->next
);
868 debug(dbg_stupidlyverbose
, "process_archive no non-root, no disappear");
871 for (cfile
= otherpkg
->clientdata
->files
;
872 cfile
&& !filesavespackage(cfile
, otherpkg
, pkg
);
873 cfile
= cfile
->next
);
877 /* So dependency things will give right answers ... */
878 otherpkg
->clientdata
->istobe
= PKG_ISTOBE_REMOVE
;
879 debug(dbg_veryverbose
, "process_archive disappear checking dependencies");
880 for (pdep
= otherpkg
->set
->depended
.installed
;
882 pdep
= pdep
->rev_next
) {
883 if (pdep
->up
->type
!= dep_depends
&&
884 pdep
->up
->type
!= dep_predepends
&&
885 pdep
->up
->type
!= dep_recommends
)
888 if (depisok(pdep
->up
, &depprobwhy
, NULL
, NULL
, false))
891 varbuf_end_str(&depprobwhy
);
892 debug(dbg_veryverbose
,"process_archive cannot disappear: %s",
897 /* If we haven't found a reason not to yet, let's look some more. */
898 for (providecheck
= otherpkg
->installed
.depends
;
900 providecheck
= providecheck
->next
) {
901 if (providecheck
->type
!= dep_provides
)
904 for (pdep
= providecheck
->list
->ed
->depended
.installed
;
906 pdep
= pdep
->rev_next
) {
907 if (pdep
->up
->type
!= dep_depends
&&
908 pdep
->up
->type
!= dep_predepends
&&
909 pdep
->up
->type
!= dep_recommends
)
912 if (depisok(pdep
->up
, &depprobwhy
, NULL
, NULL
, false))
915 varbuf_end_str(&depprobwhy
);
916 debug(dbg_veryverbose
,
917 "process_archive cannot disappear (provides %s): %s",
918 providecheck
->list
->ed
->name
, depprobwhy
.buf
);
919 goto break_from_both_loops_at_once
;
922 break_from_both_loops_at_once
:;
924 otherpkg
->clientdata
->istobe
= PKG_ISTOBE_NORMAL
;
928 /* No, we're disappearing it. This is the wrong time to go and
929 * run maintainer scripts and things, as we can't back out. But
930 * what can we do ? It has to be run this late. */
931 pkg_disappear(otherpkg
, pkg
);
932 } /* while (otherpkg= ... */
933 pkg_db_iter_free(iter
);
937 * Check if all instances of a pkgset are getting in sync.
939 * If that's the case, the extraction is going to ensure consistency
943 pkgset_getting_in_sync(struct pkginfo
*pkg
)
945 struct pkginfo
*otherpkg
;
947 for (otherpkg
= &pkg
->set
->pkg
; otherpkg
; otherpkg
= otherpkg
->arch_next
) {
950 if (otherpkg
->status
<= PKG_STAT_CONFIGFILES
)
952 if (dpkg_version_compare(&pkg
->available
.version
,
953 &otherpkg
->installed
.version
)) {
962 pkg_remove_files_from_others(struct pkginfo
*pkg
, struct fileinlist
*newfileslist
)
964 struct fileinlist
*cfile
;
965 struct pkginfo
*otherpkg
;
967 for (cfile
= newfileslist
; cfile
; cfile
= cfile
->next
) {
968 struct filepackages_iterator
*iter
;
969 struct pkgset
*divpkgset
;
971 if (!(cfile
->namenode
->flags
& fnnf_elide_other_lists
))
974 if (cfile
->namenode
->divert
&& cfile
->namenode
->divert
->useinstead
) {
975 divpkgset
= cfile
->namenode
->divert
->pkgset
;
976 if (divpkgset
== pkg
->set
) {
978 "process_archive not overwriting any '%s' (overriding, '%s')",
979 cfile
->namenode
->name
, cfile
->namenode
->divert
->useinstead
->name
);
983 "process_archive looking for overwriting '%s' (overridden by %s)",
984 cfile
->namenode
->name
, divpkgset ? divpkgset
->name
: "<local>");
988 debug(dbg_eachfile
, "process_archive looking for overwriting '%s'",
989 cfile
->namenode
->name
);
992 iter
= filepackages_iter_new(cfile
->namenode
);
993 while ((otherpkg
= filepackages_iter_next(iter
))) {
994 debug(dbg_eachfiledetail
, "process_archive ... found in %s",
995 pkg_name(otherpkg
, pnaw_always
));
997 /* A pkgset can share files between instances, so there's no point
998 * in rewriting the file that's already in place. */
999 if (otherpkg
->set
== pkg
->set
)
1002 if (otherpkg
->set
== divpkgset
) {
1003 debug(dbg_eachfiledetail
, "process_archive ... diverted, skipping");
1007 if (cfile
->namenode
->flags
& fnnf_new_conff
)
1008 conffile_mark_obsolete(otherpkg
, cfile
->namenode
);
1010 /* If !fileslistvalid then it's one of the disappeared packages above
1011 * or we have already updated the files list file, and we don't bother
1012 * with it here, clearly. */
1013 if (!otherpkg
->clientdata
->fileslistvalid
)
1016 /* Found one. We delete the list entry for this file,
1017 * (and any others in the same package) and then mark the package
1018 * as requiring a reread. */
1019 write_filelist_except(otherpkg
, &otherpkg
->installed
,
1020 otherpkg
->clientdata
->files
, fnnf_elide_other_lists
);
1021 ensure_package_clientdata(otherpkg
);
1022 debug(dbg_veryverbose
, "process_archive overwrote from %s",
1023 pkg_name(otherpkg
, pnaw_always
));
1025 filepackages_iter_free(iter
);
1030 pkg_remove_backup_files(struct pkginfo
*pkg
, struct fileinlist
*newfileslist
)
1032 struct fileinlist
*cfile
;
1034 for (cfile
= newfileslist
; cfile
; cfile
= cfile
->next
) {
1035 struct filenamenode
*usenode
;
1037 if (cfile
->namenode
->flags
& fnnf_new_conff
)
1040 usenode
= namenodetouse(cfile
->namenode
, pkg
, &pkg
->installed
);
1042 /* Do not try to remove backups for the root directory. */
1043 if (strcmp(usenode
->name
, "/.") == 0)
1046 varbuf_rollback(&fnametmpvb
, &fname_state
);
1047 varbuf_add_str(&fnametmpvb
, usenode
->name
);
1048 varbuf_add_str(&fnametmpvb
, DPKGTEMPEXT
);
1049 varbuf_end_str(&fnametmpvb
);
1050 path_remove_tree(fnametmpvb
.buf
);
1054 void process_archive(const char *filename
) {
1055 static const struct tar_operations tf
= {
1056 .read
= tarfileread
,
1057 .extract_file
= tarobject
,
1059 .symlink
= tarobject
,
1064 /* These need to be static so that we can pass their addresses to
1065 * push_cleanup as arguments to the cu_xxx routines; if an error occurs
1066 * we unwind the stack before processing the cleanup list, and these
1067 * variables had better still exist ... */
1069 static enum pkgstatus oldversionstatus
;
1070 static struct tarcontext tc
;
1072 struct dpkg_error err
;
1073 enum parsedbflags parsedb_flags
;
1076 struct pkginfo
*pkg
, *otherpkg
;
1077 struct pkg_list
*conflictor_iter
;
1081 const char *pfilename
;
1082 struct filenamenode_queue newconffiles
, newfiles_queue
;
1085 cleanup_pkg_failed
= cleanup_conflictor_failed
= 0;
1087 pfilename
= summarize_filename(filename
);
1089 if (stat(filename
, &stab
))
1090 ohshite(_("cannot access archive '%s'"), filename
);
1092 /* We can't ‘tentatively-reassemble’ packages. */
1094 if (!deb_reassemble(&filename
, &pfilename
))
1098 /* Verify the package. */
1100 deb_verify(filename
);
1102 /* Get the control information directory. */
1103 cidir
= get_control_dir(cidir
);
1104 cidirrest
= cidir
+ strlen(cidir
);
1105 push_cleanup(cu_cidir
, ~0, NULL
, 0, 2, (void *)cidir
, (void *)cidirrest
);
1107 pid
= subproc_fork();
1109 cidirrest
[-1] = '\0';
1110 execlp(BACKEND
, BACKEND
, "--control", filename
, cidir
, NULL
);
1111 ohshite(_("unable to execute %s (%s)"),
1112 _("package control information extraction"), BACKEND
);
1114 subproc_reap(pid
, BACKEND
" --control", 0);
1116 /* We want to guarantee the extracted files are on the disk, so that the
1117 * subsequent renames to the info database do not end up with old or zero
1118 * length files in case of a system crash. As neither dpkg-deb nor tar do
1119 * explicit fsync()s, we have to do them here.
1120 * XXX: This could be avoided by switching to an internal tar extractor. */
1121 dir_sync_contents(cidir
);
1123 strcpy(cidirrest
,CONTROLFILE
);
1125 if (cipaction
->arg_int
== act_avail
)
1126 parsedb_flags
= pdb_parse_available
;
1128 parsedb_flags
= pdb_parse_binary
;
1129 parsedb_flags
|= pdb_ignorefiles
;
1131 parsedb_flags
|= pdb_lax_version_parser
;
1133 parsedb(cidir
, parsedb_flags
, &pkg
);
1136 pkg
->files
= nfmalloc(sizeof(struct filedetails
));
1137 pkg
->files
->next
= NULL
;
1138 pkg
->files
->name
= pkg
->files
->msdosname
= pkg
->files
->md5sum
= NULL
;
1140 /* Always nfmalloc. Otherwise, we may overwrite some other field (like
1142 psize
= nfmalloc(30);
1143 sprintf(psize
, "%jd", (intmax_t)stab
.st_size
);
1144 pkg
->files
->size
= psize
;
1146 if (cipaction
->arg_int
== act_avail
) {
1147 printf(_("Recorded info about %s from %s.\n"),
1148 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
), pfilename
);
1149 pop_cleanup(ehflag_normaltidy
);
1153 if (pkg
->available
.arch
->type
!= DPKG_ARCH_ALL
&&
1154 pkg
->available
.arch
->type
!= DPKG_ARCH_NATIVE
&&
1155 pkg
->available
.arch
->type
!= DPKG_ARCH_FOREIGN
)
1156 forcibleerr(fc_architecture
,
1157 _("package architecture (%s) does not match system (%s)"),
1158 pkg
->available
.arch
->name
,
1159 dpkg_arch_get(DPKG_ARCH_NATIVE
)->name
);
1161 clear_deconfigure_queue();
1164 if (wanttoinstall(pkg
)) {
1165 pkg_set_want(pkg
, PKG_WANT_INSTALL
);
1167 pop_cleanup(ehflag_normaltidy
);
1171 /* Deconfigure other instances from a pkgset if they are not in sync. */
1172 for (otherpkg
= &pkg
->set
->pkg
; otherpkg
; otherpkg
= otherpkg
->arch_next
) {
1173 if (otherpkg
== pkg
)
1175 if (otherpkg
->status
<= PKG_STAT_HALFCONFIGURED
)
1178 if (dpkg_version_compare(&pkg
->available
.version
,
1179 &otherpkg
->installed
.version
))
1180 enqueue_deconfigure(otherpkg
, NULL
);
1183 pkg_check_depcon(pkg
, pfilename
);
1185 ensure_allinstfiles_available();
1187 trig_file_interests_ensure();
1189 printf(_("Preparing to unpack %s ...\n"), pfilename
);
1191 if (pkg
->status
!= PKG_STAT_NOTINSTALLED
&&
1192 pkg
->status
!= PKG_STAT_CONFIGFILES
) {
1193 log_action("upgrade", pkg
, &pkg
->installed
);
1195 log_action("install", pkg
, &pkg
->available
);
1199 pop_cleanup(ehflag_normaltidy
);
1204 * OK, we're going ahead.
1207 trig_activate_packageprocessing(pkg
);
1208 strcpy(cidirrest
, TRIGGERSCIFILE
);
1209 trig_parse_ci(cidir
, NULL
, trig_cicb_statuschange_activate
, pkg
, &pkg
->available
);
1211 /* Read the conffiles, and copy the hashes across. */
1212 newconffiles
.head
= NULL
;
1213 newconffiles
.tail
= &newconffiles
.head
;
1214 push_cleanup(cu_fileslist
, ~0, NULL
, 0, 0);
1215 strcpy(cidirrest
,CONFFILESFILE
);
1216 deb_parse_conffiles(pkg
, cidir
, &newconffiles
);
1218 /* All the old conffiles are marked with a flag, so that we don't delete
1219 * them if they seem to disappear completely. */
1220 pkg_conffiles_mark_old(pkg
);
1221 for (conflictor_iter
= conflictors
.head
;
1223 conflictor_iter
= conflictor_iter
->next
)
1224 pkg_conffiles_mark_old(conflictor_iter
->pkg
);
1226 oldversionstatus
= pkg
->status
;
1228 assert(oldversionstatus
<= PKG_STAT_INSTALLED
);
1229 debug(dbg_general
,"process_archive oldversionstatus=%s",
1230 statusstrings
[oldversionstatus
]);
1232 if (oldversionstatus
== PKG_STAT_HALFCONFIGURED
||
1233 oldversionstatus
== PKG_STAT_TRIGGERSAWAITED
||
1234 oldversionstatus
== PKG_STAT_TRIGGERSPENDING
||
1235 oldversionstatus
== PKG_STAT_INSTALLED
) {
1236 pkg_set_eflags(pkg
, PKG_EFLAG_REINSTREQ
);
1237 pkg_set_status(pkg
, PKG_STAT_HALFCONFIGURED
);
1238 modstatdb_note(pkg
);
1239 push_cleanup(cu_prermupgrade
, ~ehflag_normaltidy
, NULL
, 0, 1, (void *)pkg
);
1240 if (dpkg_version_compare(&pkg
->available
.version
,
1241 &pkg
->installed
.version
) >= 0)
1242 /* Upgrade or reinstall. */
1243 maintscript_fallback(pkg
, PRERMFILE
, "pre-removal", cidir
, cidirrest
,
1244 "upgrade", "failed-upgrade");
1245 else /* Downgrade => no fallback */
1246 maintscript_installed(pkg
, PRERMFILE
, "pre-removal",
1248 versiondescribe(&pkg
->available
.version
,
1251 pkg_set_status(pkg
, PKG_STAT_UNPACKED
);
1252 oldversionstatus
= PKG_STAT_UNPACKED
;
1253 modstatdb_note(pkg
);
1256 pkg_deconfigure_others(pkg
);
1258 for (conflictor_iter
= conflictors
.head
;
1260 conflictor_iter
= conflictor_iter
->next
) {
1261 struct pkginfo
*conflictor
= conflictor_iter
->pkg
;
1263 if (!(conflictor
->status
== PKG_STAT_HALFCONFIGURED
||
1264 conflictor
->status
== PKG_STAT_TRIGGERSAWAITED
||
1265 conflictor
->status
== PKG_STAT_TRIGGERSPENDING
||
1266 conflictor
->status
== PKG_STAT_INSTALLED
))
1269 trig_activate_packageprocessing(conflictor
);
1270 pkg_set_status(conflictor
, PKG_STAT_HALFCONFIGURED
);
1271 modstatdb_note(conflictor
);
1272 push_cleanup(cu_prerminfavour
, ~ehflag_normaltidy
, NULL
, 0,
1273 2, conflictor
, pkg
);
1274 maintscript_installed(conflictor
, PRERMFILE
, "pre-removal",
1275 "remove", "in-favour",
1276 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
),
1277 versiondescribe(&pkg
->available
.version
,
1280 pkg_set_status(conflictor
, PKG_STAT_HALFINSTALLED
);
1281 modstatdb_note(conflictor
);
1284 pkg_set_eflags(pkg
, PKG_EFLAG_REINSTREQ
);
1285 if (pkg
->status
== PKG_STAT_NOTINSTALLED
) {
1286 pkg
->installed
.version
= pkg
->available
.version
;
1287 pkg
->installed
.multiarch
= pkg
->available
.multiarch
;
1289 pkg_set_status(pkg
, PKG_STAT_HALFINSTALLED
);
1290 modstatdb_note(pkg
);
1291 if (oldversionstatus
== PKG_STAT_NOTINSTALLED
) {
1292 push_cleanup(cu_preinstverynew
, ~ehflag_normaltidy
, NULL
, 0,
1293 3,(void*)pkg
,(void*)cidir
,(void*)cidirrest
);
1294 maintscript_new(pkg
, PREINSTFILE
, "pre-installation", cidir
, cidirrest
,
1296 } else if (oldversionstatus
== PKG_STAT_CONFIGFILES
) {
1297 push_cleanup(cu_preinstnew
, ~ehflag_normaltidy
, NULL
, 0,
1298 3,(void*)pkg
,(void*)cidir
,(void*)cidirrest
);
1299 maintscript_new(pkg
, PREINSTFILE
, "pre-installation", cidir
, cidirrest
,
1301 versiondescribe(&pkg
->installed
.version
, vdew_nonambig
),
1302 versiondescribe(&pkg
->available
.version
, vdew_nonambig
),
1305 push_cleanup(cu_preinstupgrade
, ~ehflag_normaltidy
, NULL
, 0,
1306 4,(void*)pkg
,(void*)cidir
,(void*)cidirrest
,(void*)&oldversionstatus
);
1307 maintscript_new(pkg
, PREINSTFILE
, "pre-installation", cidir
, cidirrest
,
1309 versiondescribe(&pkg
->installed
.version
, vdew_nonambig
),
1310 versiondescribe(&pkg
->available
.version
, vdew_nonambig
),
1314 if (oldversionstatus
== PKG_STAT_NOTINSTALLED
||
1315 oldversionstatus
== PKG_STAT_CONFIGFILES
) {
1316 printf(_("Unpacking %s (%s) ...\n"),
1317 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
),
1318 versiondescribe(&pkg
->available
.version
, vdew_nonambig
));
1320 printf(_("Unpacking %s (%s) over (%s) ...\n"),
1321 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
),
1322 versiondescribe(&pkg
->available
.version
, vdew_nonambig
),
1323 versiondescribe(&pkg
->installed
.version
, vdew_nonambig
));
1327 * Now we unpack the archive, backing things up as we go.
1328 * For each file, we check to see if it already exists.
1329 * There are several possibilities:
1331 * + We are trying to install a non-directory ...
1332 * - It doesn't exist. In this case we simply extract it.
1333 * - It is a plain file, device, symlink, &c. We do an ‘atomic
1334 * overwrite’ using link() and rename(), but leave a backup copy.
1335 * Later, when we delete the backup, we remove it from any other
1337 * - It is a directory. In this case it depends on whether we're
1338 * trying to install a symlink or something else.
1339 * = If we're not trying to install a symlink we move the directory
1340 * aside and extract the node. Later, when we recursively remove
1341 * the backed-up directory, we remove it from any other packages'
1343 * = If we are trying to install a symlink we do nothing - ie,
1344 * dpkg will never replace a directory tree with a symlink. This
1345 * is to avoid embarrassing effects such as replacing a directory
1346 * tree with a link to a link to the original directory tree.
1347 * + We are trying to install a directory ...
1348 * - It doesn't exist. We create it with the appropriate modes.
1349 * - It exists as a directory or a symlink to one. We do nothing.
1350 * - It is a plain file or a symlink (other than to a directory).
1351 * We move it aside and create the directory. Later, when we
1352 * delete the backup, we remove it from any other packages' lists.
1354 * Install non-dir Install symlink Install dir
1356 * File/node/symlink LXR LXR BXR
1359 * X: extract file/node/link/directory
1360 * LX: atomic overwrite leaving backup
1361 * B: ordinary backup
1362 * R: later remove from other packages' lists
1365 * After we've done this we go through the remaining things in the
1366 * lists of packages we're trying to remove (including the old
1367 * version of the current package). This happens in reverse order,
1368 * so that we process files before the directories (or symlinks-to-
1369 * directories) containing them.
1371 * + If the thing is a conffile then we leave it alone for the purge
1373 * + Otherwise, there are several possibilities too:
1374 * - The listed thing does not exist. We ignore it.
1375 * - The listed thing is a directory or a symlink to a directory.
1376 * We delete it only if it isn't listed in any other package.
1377 * - The listed thing is not a directory, but was part of the package
1378 * that was upgraded, we check to make sure the files aren't the
1379 * same ones from the old package by checking dev/inode
1380 * - The listed thing is not a directory or a symlink to one (ie,
1381 * it's a plain file, device, pipe, &c, or a symlink to one, or a
1382 * dangling symlink). We delete it.
1384 * The removed packages' list becomes empty (of course, the new
1385 * version of the package we're installing will have a new list,
1386 * which replaces the old version's list).
1388 * If at any stage we remove a file from a package's list, and the
1389 * package isn't one we're already processing, and the package's
1390 * list becomes empty as a result, we ‘vanish’ the package. This
1391 * means that we run its postrm with the ‘disappear’ argument, and
1392 * put the package in the ‘not-installed’ state. If it had any
1393 * conffiles, their hashes and ownership will have been transferred
1394 * already, so we just ignore those and forget about them from the
1395 * point of view of the disappearing package.
1397 * NOTE THAT THE OLD POSTRM IS RUN AFTER THE NEW PREINST, since the
1398 * files get replaced ‘as we go’.
1402 push_cleanup(cu_closepipe
, ehflag_bombout
, NULL
, 0, 1, (void *)&p1
[0]);
1403 pid
= subproc_fork();
1405 m_dup2(p1
[1],1); close(p1
[0]); close(p1
[1]);
1406 execlp(BACKEND
, BACKEND
, "--fsys-tarfile", filename
, NULL
);
1407 ohshite(_("unable to execute %s (%s)"),
1408 _("package filesystem archive extraction"), BACKEND
);
1413 newfiles_queue
.head
= NULL
;
1414 newfiles_queue
.tail
= &newfiles_queue
.head
;
1415 tc
.newfiles_queue
= &newfiles_queue
;
1416 push_cleanup(cu_fileslist
, ~0, NULL
, 0, 0);
1418 tc
.backendpipe
= p1
[0];
1419 tc
.pkgset_getting_in_sync
= pkgset_getting_in_sync(pkg
);
1421 rc
= tar_extractor(&tc
, &tf
);
1424 ohshite(_("error reading dpkg-deb tar output"));
1426 ohshit(_("corrupted filesystem tarfile - corrupted package archive"));
1429 if (fd_skip(p1
[0], -1, &err
) < 0)
1430 ohshit(_("cannot zap possible trailing zeros from dpkg-deb: %s"), err
.str
);
1433 subproc_reap(pid
, BACKEND
" --fsys-tarfile", SUBPROC_NOPIPE
);
1435 tar_deferred_extract(newfiles_queue
.head
, pkg
);
1437 if (oldversionstatus
== PKG_STAT_HALFINSTALLED
||
1438 oldversionstatus
== PKG_STAT_UNPACKED
) {
1439 /* Packages that were in ‘installed’ and ‘postinstfailed’ have been
1440 * reduced to ‘unpacked’ by now, by the running of the prerm script. */
1441 pkg_set_status(pkg
, PKG_STAT_HALFINSTALLED
);
1442 modstatdb_note(pkg
);
1443 push_cleanup(cu_postrmupgrade
, ~ehflag_normaltidy
, NULL
, 0, 1, (void *)pkg
);
1444 maintscript_fallback(pkg
, POSTRMFILE
, "post-removal", cidir
, cidirrest
,
1445 "upgrade", "failed-upgrade");
1448 /* If anything goes wrong while tidying up it's a bit late to do
1449 * anything about it. However, we don't install the new status
1450 * info yet, so that a future dpkg installation will put everything
1453 * If something does go wrong later the ‘conflictor’ package will be
1454 * left in the ‘removal_failed’ state. Removing or installing it
1455 * will be impossible if it was required because of the conflict with
1456 * the package we're installing now and (presumably) the dependency
1457 * by other packages. This means that the files it contains in
1458 * common with this package will hang around until we successfully
1459 * get this package installed, after which point we can trust the
1460 * conflicting package's file list, which will have been updated to
1461 * remove any files in this package. */
1462 push_checkpoint(~ehflag_bombout
, ehflag_normaltidy
);
1464 /* Now we delete all the files that were in the old version of
1465 * the package only, except (old or new) conffiles, which we leave
1467 pkg_remove_old_files(pkg
, &newfiles_queue
, &newconffiles
);
1469 /* OK, now we can write the updated files-in-this package list,
1470 * since we've done away (hopefully) with all the old junk. */
1471 write_filelist_except(pkg
, &pkg
->available
, newfiles_queue
.head
, 0);
1473 /* Trigger interests may have changed.
1474 * Firstly we go through the old list of interests deleting them.
1475 * Then we go through the new list adding them. */
1476 strcpy(cidirrest
, TRIGGERSCIFILE
);
1477 trig_parse_ci(pkg_infodb_get_file(pkg
, &pkg
->installed
, TRIGGERSCIFILE
),
1478 trig_cicb_interest_delete
, NULL
, pkg
, &pkg
->installed
);
1479 trig_parse_ci(cidir
, trig_cicb_interest_add
, NULL
, pkg
, &pkg
->available
);
1480 trig_file_interests_save();
1482 /* We also install the new maintainer scripts, and any other
1483 * cruft that may have come along with the package. First
1484 * we go through the existing scripts replacing or removing
1485 * them as appropriate; then we go through the new scripts
1486 * (any that are left) and install them. */
1487 debug(dbg_general
, "process_archive updating info directory");
1488 pkg_infodb_update(pkg
, cidir
, cidirrest
);
1490 /* We store now the checksums dynamically computed while unpacking. */
1491 write_filehash_except(pkg
, &pkg
->available
, newfiles_queue
.head
, 0);
1494 * Update the status database.
1496 * This involves copying each field across from the ‘available’
1497 * to the ‘installed’ half of the pkg structure.
1498 * For some of the fields we have to do a complicated construction
1499 * operation; for others we can just copy the value.
1500 * We tackle the fields in the order they appear, so that
1501 * we don't miss any out :-).
1502 * At least we don't have to copy any strings that are referred
1503 * to, because these are never modified and never freed.
1505 pkg_update_fields(pkg
, &newconffiles
);
1507 /* In case this was an architecture cross-grade, the in-core pkgset might
1508 * be in an inconsistent state, with two pkginfo entries having the same
1509 * architecture, so let's fix that. Note that this does not lose data,
1510 * as the pkg.available member parsed from the binary should replace the
1511 * to be cleared duplicate in the other instance. */
1512 for (otherpkg
= &pkg
->set
->pkg
; otherpkg
; otherpkg
= otherpkg
->arch_next
) {
1513 if (otherpkg
== pkg
)
1515 if (otherpkg
->installed
.arch
!= pkg
->installed
.arch
)
1518 assert(otherpkg
->status
== PKG_STAT_NOTINSTALLED
);
1520 pkg_blank(otherpkg
);
1523 /* Check for disappearing packages:
1524 * We go through all the packages on the system looking for ones
1525 * whose files are entirely part of the one we've just unpacked
1526 * (and which actually *have* some files!).
1528 * Any that we find are removed - we run the postrm with ‘disappear’
1529 * as an argument, and remove their info/... files and status info.
1530 * Conffiles are ignored (the new package had better do something
1532 pkg_disappear_others(pkg
);
1534 /* Delete files from any other packages' lists.
1535 * We have to do this before we claim this package is in any
1536 * sane kind of state, as otherwise we might delete by mistake
1537 * a file that we overwrote, when we remove the package which
1538 * had the version we overwrote. To prevent this we make
1539 * sure that we don't claim this package is OK until we
1540 * have claimed ‘ownership’ of all its files. */
1541 pkg_remove_files_from_others(pkg
, newfiles_queue
.head
);
1543 /* Right, the package we've unpacked is now in a reasonable state.
1544 * The only thing that we have left to do with it is remove
1545 * backup files, and we can leave the user to fix that if and when
1546 * it happens (we leave the reinstall required flag, of course). */
1547 pkg_set_status(pkg
, PKG_STAT_UNPACKED
);
1548 modstatdb_note(pkg
);
1550 /* Now we delete all the backup files that we made when
1551 * extracting the archive - except for files listed as conffiles
1552 * in the new package.
1553 * This time we count it as an error if something goes wrong.
1555 * Note that we don't ever delete things that were in the old
1556 * package as a conffile and don't appear at all in the new.
1557 * They stay recorded as obsolete conffiles and will eventually
1558 * (if not taken over by another package) be forgotten. */
1559 pkg_remove_backup_files(pkg
, newfiles_queue
.head
);
1561 /* OK, we're now fully done with the main package.
1562 * This is quite a nice state, so we don't unwind past here. */
1563 pkg_reset_eflags(pkg
);
1564 modstatdb_note(pkg
);
1565 push_checkpoint(~ehflag_bombout
, ehflag_normaltidy
);
1567 /* Only the removal of the conflictor left to do.
1568 * The files list for the conflictor is still a little inconsistent in-core,
1569 * as we have not yet updated the filename->packages mappings; however,
1570 * the package->filenames mapping is. */
1571 while (!pkg_queue_is_empty(&conflictors
)) {
1572 struct pkginfo
*conflictor
= pkg_queue_pop(&conflictors
);
1574 /* We need to have the most up-to-date info about which files are
1576 ensure_allinstfiles_available();
1577 removal_bulk(conflictor
);
1580 if (cipaction
->arg_int
== act_install
)
1581 enqueue_package_mark_seen(pkg
);