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/fdio.h>
51 #include <dpkg/buffer.h>
52 #include <dpkg/subproc.h>
54 #include <dpkg/tarfn.h>
55 #include <dpkg/options.h>
56 #include <dpkg/triglib.h>
59 #include "file-match.h"
65 summarize_filename(const char *filename
)
67 const char *pfilename
;
70 for (pfilename
= filename
;
71 pfilename
&& strlen(pfilename
) > 30 && strchr(pfilename
, '/') != NULL
;
73 pfilename
= strchr(pfilename
, '/');
75 if (pfilename
&& pfilename
!= filename
) {
76 pfilenamebuf
= nfmalloc(strlen(pfilename
) + 5);
77 sprintf(pfilenamebuf
, _(".../%s"), pfilename
);
78 pfilename
= pfilenamebuf
;
87 deb_reassemble(const char **filename
, const char **pfilename
)
89 static char *reasmbuf
= NULL
;
95 reasmbuf
= dpkg_db_get_path(REASSEMBLETMP
);
96 if (unlink(reasmbuf
) && errno
!= ENOENT
)
97 ohshite(_("error ensuring '%.250s' doesn't exist"), reasmbuf
);
99 push_cleanup(cu_pathname
, ~0, NULL
, 0, 1, (void *)reasmbuf
);
101 pid
= subproc_fork();
103 execlp(SPLITTER
, SPLITTER
, "-Qao", reasmbuf
, *filename
, NULL
);
104 ohshite(_("unable to execute %s (%s)"),
105 _("split package reassembly"), SPLITTER
);
107 status
= subproc_reap(pid
, SPLITTER
, SUBPROC_RETERROR
);
110 /* It was a part - is it complete? */
111 if (!stat(reasmbuf
, &stab
)) {
113 *filename
= reasmbuf
;
114 *pfilename
= _("reassembled package file");
116 } else if (errno
== ENOENT
) {
117 /* No. That's it, we skip it. */
121 /* No, it wasn't a part. */
124 ohshit(_("subprocess %s returned error exit status %d"), SPLITTER
, status
);
131 deb_verify(const char *filename
)
135 /* We have to check on every unpack, in case the debsig-verify package
136 * gets installed or removed. */
137 if (!find_command(DEBSIGVERIFY
))
140 printf(_("Authenticating %s ...\n"), filename
);
142 pid
= subproc_fork();
144 execlp(DEBSIGVERIFY
, DEBSIGVERIFY
, "-q", filename
, NULL
);
145 ohshite(_("unable to execute %s (%s)"),
146 _("package signature verification"), DEBSIGVERIFY
);
150 status
= subproc_reap(pid
, "debsig-verify", SUBPROC_NOCHECK
);
151 if (!(WIFEXITED(status
) && WEXITSTATUS(status
) == 0)) {
153 ohshit(_("verification on package %s failed!"), filename
);
155 notice(_("verification on package %s failed; "
156 "but installing anyway as you requested"), filename
);
158 printf(_("passed\n"));
164 get_control_dir(char *cidir
)
169 tmpdir
= mkdtemp(path_make_temp_template("dpkg"));
171 ohshite(_("unable to create temporary directory"));
173 cidir
= m_realloc(cidir
, strlen(tmpdir
) + MAXCONTROLFILENAME
+ 10);
175 strcpy(cidir
, tmpdir
);
179 const char *admindir
;
181 admindir
= dpkg_db_get_dir();
183 /* The admindir length is always constant on a dpkg execution run. */
185 cidir
= m_malloc(strlen(admindir
) + sizeof(CONTROLDIRTMP
) +
186 MAXCONTROLFILENAME
+ 10);
188 /* We want it to be on the same filesystem so that we can
189 * use rename(2) to install the postinst &c. */
190 strcpy(cidir
, admindir
);
191 strcat(cidir
, "/" CONTROLDIRTMP
);
193 /* Make sure the control information directory is empty. */
194 path_remove_tree(cidir
);
203 pkg_check_depcon(struct pkginfo
*pkg
, const char *pfilename
)
205 struct dependency
*dsearch
;
206 struct deppossi
*psearch
;
207 struct pkginfo
*fixbytrigaw
;
208 static struct varbuf depprobwhy
;
210 /* Check if anything is installed that we conflict with, or not installed
212 pkg
->clientdata
->istobe
= PKG_ISTOBE_INSTALLNEW
;
214 for (dsearch
= pkg
->available
.depends
; dsearch
; dsearch
= dsearch
->next
) {
215 switch (dsearch
->type
) {
217 /* Look for things we conflict with. */
218 check_conflict(dsearch
, pkg
, pfilename
);
221 /* Look for things we break. */
222 check_breaks(dsearch
, pkg
, pfilename
);
225 /* Look for things that conflict with what we provide. */
226 for (psearch
= dsearch
->list
->ed
->depended
.installed
;
228 psearch
= psearch
->rev_next
) {
229 if (psearch
->up
->type
!= dep_conflicts
)
231 check_conflict(psearch
->up
, pkg
, pfilename
);
239 /* Ignore these here. */
242 if (!depisok(dsearch
, &depprobwhy
, NULL
, &fixbytrigaw
, true)) {
244 while (fixbytrigaw
->trigaw
.head
)
245 trigproc(fixbytrigaw
->trigaw
.head
->pend
, TRIGPROC_REQUIRED
);
247 varbuf_end_str(&depprobwhy
);
248 notice(_("regarding %s containing %s, pre-dependency problem:\n%s"),
249 pfilename
, pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
),
251 if (!force_depends(dsearch
->list
))
252 ohshit(_("pre-dependency problem - not installing %.250s"),
253 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
254 warning(_("ignoring pre-dependency problem!"));
260 /* Look for things that conflict with us. */
261 for (psearch
= pkg
->set
->depended
.installed
; psearch
; psearch
= psearch
->rev_next
) {
262 if (psearch
->up
->type
!= dep_conflicts
)
265 check_conflict(psearch
->up
, pkg
, pfilename
);
270 pkg_deconfigure_others(struct pkginfo
*pkg
)
272 struct pkg_deconf_list
*deconpil
;
274 for (deconpil
= deconfigure
; deconpil
; deconpil
= deconpil
->next
) {
275 struct pkginfo
*removing
= deconpil
->pkg_removal
;
278 printf(_("De-configuring %s (%s), to allow removal of %s (%s) ...\n"),
279 pkg_name(deconpil
->pkg
, pnaw_nonambig
),
280 versiondescribe(&deconpil
->pkg
->installed
.version
, vdew_nonambig
),
281 pkg_name(removing
, pnaw_nonambig
),
282 versiondescribe(&removing
->installed
.version
, vdew_nonambig
));
284 printf(_("De-configuring %s (%s) ...\n"),
285 pkg_name(deconpil
->pkg
, pnaw_nonambig
),
286 versiondescribe(&deconpil
->pkg
->installed
.version
, vdew_nonambig
));
288 trig_activate_packageprocessing(deconpil
->pkg
);
289 pkg_set_status(deconpil
->pkg
, PKG_STAT_HALFCONFIGURED
);
290 modstatdb_note(deconpil
->pkg
);
292 /* This means that we *either* go and run postinst abort-deconfigure,
293 * *or* queue the package for later configure processing, depending
294 * on which error cleanup route gets taken. */
295 push_cleanup(cu_prermdeconfigure
, ~ehflag_normaltidy
,
296 ok_prermdeconfigure
, ehflag_normaltidy
,
297 3, (void *)deconpil
->pkg
, (void *)removing
, (void *)pkg
);
300 maintscript_installed(deconpil
->pkg
, PRERMFILE
, "pre-removal",
301 "deconfigure", "in-favour",
302 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
),
303 versiondescribe(&pkg
->available
.version
,
306 pkg_name(removing
, pnaw_nonambig
),
307 versiondescribe(&removing
->installed
.version
,
311 maintscript_installed(deconpil
->pkg
, PRERMFILE
, "pre-removal",
312 "deconfigure", "in-favour",
313 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
),
314 versiondescribe(&pkg
->available
.version
,
322 * Read the conffiles, and copy the hashes across.
325 deb_parse_conffiles(struct pkginfo
*pkg
, const char *control_conffiles
,
326 struct filenamenode_queue
*newconffiles
)
329 char conffilenamebuf
[MAXCONFFILENAME
];
331 conff
= fopen(control_conffiles
, "r");
335 ohshite(_("error trying to open %.250s"), control_conffiles
);
338 push_cleanup(cu_closestream
, ehflag_bombout
, NULL
, 0, 1, conff
);
340 while (fgets(conffilenamebuf
, MAXCONFFILENAME
- 2, conff
)) {
341 struct pkginfo
*otherpkg
;
342 struct filepackages_iterator
*iter
;
343 struct filenamenode
*namenode
;
344 struct fileinlist
*newconff
;
345 struct conffile
*searchconff
;
348 p
= conffilenamebuf
+ strlen(conffilenamebuf
);
349 assert(p
!= conffilenamebuf
);
351 ohshit(_("conffile name '%s' is too long, or missing final newline"),
353 while (p
> conffilenamebuf
&& c_isspace(p
[-1]))
355 if (p
== conffilenamebuf
)
359 namenode
= findnamenode(conffilenamebuf
, 0);
360 namenode
->oldhash
= NEWCONFFILEFLAG
;
361 newconff
= tar_filenamenode_queue_push(newconffiles
, namenode
);
364 * Let's see if any packages have this file.
366 * If they do we check to see if they listed it as a conffile,
367 * and if they did we copy the hash across. Since (for plain
368 * file conffiles, which is the only kind we are supposed to
369 * have) there will only be one package which ‘has’ the file,
370 * this will usually mean we only look in the package which
371 * we are installing now.
373 * The ‘conffiles’ data in the status file is ignored when a
374 * package is not also listed in the file ownership database as
375 * having that file. If several packages are listed as owning
376 * the file we pick one at random.
380 iter
= filepackages_iter_new(newconff
->namenode
);
381 while ((otherpkg
= filepackages_iter_next(iter
))) {
382 debug(dbg_conffdetail
,
383 "process_archive conffile '%s' in package %s - conff ?",
384 newconff
->namenode
->name
, pkg_name(otherpkg
, pnaw_always
));
385 for (searchconff
= otherpkg
->installed
.conffiles
;
386 searchconff
&& strcmp(newconff
->namenode
->name
, searchconff
->name
);
387 searchconff
= searchconff
->next
)
388 debug(dbg_conffdetail
,
389 "process_archive conffile '%s' in package %s - conff ? not '%s'",
390 newconff
->namenode
->name
, pkg_name(otherpkg
, pnaw_always
),
394 "process_archive conffile '%s' package=%s %s hash=%s",
395 newconff
->namenode
->name
, pkg_name(otherpkg
, pnaw_always
),
396 otherpkg
== pkg ?
"same" : "different!",
402 filepackages_iter_free(iter
);
405 /* We don't copy ‘obsolete’; it's not obsolete in the new package. */
406 newconff
->namenode
->oldhash
= searchconff
->hash
;
408 debug(dbg_conff
, "process_archive conffile '%s' no package, no hash",
409 newconff
->namenode
->name
);
411 newconff
->namenode
->flags
|= fnnf_new_conff
;
415 ohshite(_("read error in %.250s"), control_conffiles
);
416 pop_cleanup(ehflag_normaltidy
); /* conff = fopen() */
418 ohshite(_("error closing %.250s"), control_conffiles
);
421 static struct pkg_queue conflictors
= PKG_QUEUE_INIT
;
424 enqueue_conflictor(struct pkginfo
*pkg
)
426 pkg_queue_push(&conflictors
, pkg
);
430 pkg_infodb_remove_file(const char *filename
, const char *filetype
)
432 if (unlink(filename
))
433 ohshite(_("unable to delete control info file '%.250s'"), filename
);
435 debug(dbg_scripts
, "removal_bulk info unlinked %s", filename
);
438 static struct match_node
*match_head
= NULL
;
441 pkg_infodb_update_file(const char *filename
, const char *filetype
)
443 if (strlen(filetype
) > MAXCONTROLFILENAME
)
444 ohshit(_("old version of package has overly-long info file name starting '%.250s'"),
447 /* We do the list separately. */
448 if (strcmp(filetype
, LISTFILE
) == 0)
451 /* We keep files to rename in a list as doing the rename immediately
452 * might influence the current readdir(), the just renamed file might
453 * be returned a second time as it's actually a new file from the
454 * point of view of the filesystem. */
455 match_head
= match_node_new(filename
, filetype
, match_head
);
459 pkg_infodb_update(struct pkginfo
*pkg
, char *cidir
, char *cidirrest
)
461 struct match_node
*match_node
;
465 /* Deallocate the match list in case we aborted previously. */
466 while ((match_node
= match_head
)) {
467 match_head
= match_node
->next
;
468 match_node_free(match_node
);
471 pkg_infodb_foreach(pkg
, &pkg
->available
, pkg_infodb_update_file
);
473 while ((match_node
= match_head
)) {
474 strcpy(cidirrest
, match_node
->filetype
);
476 if (!rename(cidir
, match_node
->filename
)) {
477 debug(dbg_scripts
, "process_archive info installed %s as %s",
478 cidir
, match_node
->filename
);
479 } else if (errno
== ENOENT
) {
480 /* Right, no new version. */
481 if (unlink(match_node
->filename
))
482 ohshite(_("unable to remove obsolete info file '%.250s'"),
483 match_node
->filename
);
484 debug(dbg_scripts
, "process_archive info unlinked %s",
485 match_node
->filename
);
487 ohshite(_("unable to install (supposed) new info file '%.250s'"), cidir
);
489 match_head
= match_node
->next
;
490 match_node_free(match_node
);
493 /* The control directory itself. */
495 dsd
= opendir(cidir
);
497 ohshite(_("unable to open temp control directory"));
498 push_cleanup(cu_closedir
, ~0, NULL
, 0, 1, (void *)dsd
);
499 while ((de
= readdir(dsd
))) {
500 const char *newinfofilename
;
502 if (strchr(de
->d_name
, '.')) {
503 debug(dbg_scripts
, "process_archive tmp.ci script/file '%s' contains dot",
507 if (strlen(de
->d_name
) > MAXCONTROLFILENAME
)
508 ohshit(_("package contains overly-long control info file name (starting '%.50s')"),
511 strcpy(cidirrest
, de
->d_name
);
513 /* First we check it's not a directory. */
514 if (rmdir(cidir
) == 0)
515 ohshit(_("package control info contained directory '%.250s'"), cidir
);
516 else if (errno
!= ENOTDIR
)
517 ohshite(_("package control info rmdir of '%.250s' didn't say not a dir"),
520 /* Ignore the control file. */
521 if (strcmp(de
->d_name
, CONTROLFILE
) == 0) {
522 debug(dbg_scripts
, "process_archive tmp.ci script/file '%s' is control",
526 if (strcmp(de
->d_name
, LISTFILE
) == 0) {
527 warning(_("package %s contained list as info file"),
528 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
532 /* Right, install it */
533 newinfofilename
= pkg_infodb_get_file(pkg
, &pkg
->available
, de
->d_name
);
534 if (rename(cidir
, newinfofilename
))
535 ohshite(_("unable to install new info file '%.250s' as '%.250s'"),
536 cidir
, newinfofilename
);
539 "process_archive tmp.ci script/file '%s' installed as '%s'",
540 cidir
, newinfofilename
);
542 pop_cleanup(ehflag_normaltidy
); /* closedir */
544 /* If the old and new versions use a different infodb layout, get rid
545 * of the files using the old layout. */
546 if (pkg
->installed
.multiarch
!= pkg
->available
.multiarch
&&
547 (pkg
->installed
.multiarch
== PKG_MULTIARCH_SAME
||
548 pkg
->available
.multiarch
== PKG_MULTIARCH_SAME
)) {
550 "process_archive remove old info files after db layout switch");
551 pkg_infodb_foreach(pkg
, &pkg
->installed
, pkg_infodb_remove_file
);
554 dir_sync_path(pkg_infodb_get_dir());
558 pkg_remove_old_files(struct pkginfo
*pkg
,
559 struct filenamenode_queue
*newfiles_queue
,
560 struct filenamenode_queue
*newconffiles
)
562 struct reversefilelistiter rev_iter
;
563 struct filenamenode
*namenode
;
564 struct stat stab
, oldfs
;
566 reversefilelist_init(&rev_iter
, pkg
->clientdata
->files
);
568 while ((namenode
= reversefilelist_next(&rev_iter
))) {
569 struct filenamenode
*usenode
;
571 if ((namenode
->flags
& fnnf_new_conff
) ||
572 (namenode
->flags
& fnnf_new_inarchive
))
575 usenode
= namenodetouse(namenode
, pkg
, &pkg
->installed
);
577 varbuf_rollback(&fnamevb
, &fname_state
);
578 varbuf_add_str(&fnamevb
, usenode
->name
);
579 varbuf_end_str(&fnamevb
);
581 if (!stat(namenode
->name
, &stab
) && S_ISDIR(stab
.st_mode
)) {
582 debug(dbg_eachfiledetail
, "process_archive: %s is a directory",
584 if (dir_is_used_by_others(namenode
, pkg
))
588 if (lstat(fnamevb
.buf
, &oldfs
)) {
589 if (!(errno
== ENOENT
|| errno
== ELOOP
|| errno
== ENOTDIR
))
590 warning(_("could not stat old file '%.250s' so not deleting it: %s"),
591 fnamevb
.buf
, strerror(errno
));
594 if (S_ISDIR(oldfs
.st_mode
)) {
595 trig_path_activate(usenode
, pkg
);
597 /* Do not try to remove the root directory. */
598 if (strcmp(usenode
->name
, "/.") == 0)
601 if (rmdir(fnamevb
.buf
)) {
602 warning(_("unable to delete old directory '%.250s': %s"),
603 namenode
->name
, strerror(errno
));
604 } else if ((namenode
->flags
& fnnf_old_conff
)) {
605 warning(_("old conffile '%.250s' was an empty directory "
606 "(and has now been deleted)"), namenode
->name
);
609 struct fileinlist
*sameas
= NULL
;
610 struct fileinlist
*cfile
;
611 static struct stat empty_stat
;
612 struct varbuf cfilename
= VARBUF_INIT
;
615 * Ok, it's an old file, but is it really not in the new package?
616 * It might be known by a different name because of symlinks.
618 * We need to check to make sure, so we stat the file, then compare
619 * it to the new list. If we find a dev/inode match, we assume they
620 * are the same file, and leave it alone. NOTE: we don't check in
621 * other packages for sanity reasons (we don't want to stat _all_
622 * the files on the system).
624 * We run down the list of _new_ files in this package. This keeps
625 * the process a little leaner. We are only worried about new ones
626 * since ones that stayed the same don't really apply here.
629 /* If we can't stat the old or new file, or it's a directory,
630 * we leave it up to the normal code. */
631 debug(dbg_eachfile
, "process_archive: checking %s for same files on "
632 "upgrade/downgrade", fnamevb
.buf
);
634 for (cfile
= newfiles_queue
->head
; cfile
; cfile
= cfile
->next
) {
635 /* If the file has been filtered then treat it as if it didn't exist
636 * on the file system. */
637 if (cfile
->namenode
->flags
& fnnf_filtered
)
640 if (!cfile
->namenode
->filestat
) {
641 struct stat tmp_stat
;
643 varbuf_reset(&cfilename
);
644 varbuf_add_str(&cfilename
, instdir
);
645 varbuf_add_str(&cfilename
, cfile
->namenode
->name
);
646 varbuf_end_str(&cfilename
);
648 if (lstat(cfilename
.buf
, &tmp_stat
) == 0) {
649 cfile
->namenode
->filestat
= nfmalloc(sizeof(struct stat
));
650 memcpy(cfile
->namenode
->filestat
, &tmp_stat
, sizeof(struct stat
));
652 if (!(errno
== ENOENT
|| errno
== ELOOP
|| errno
== ENOTDIR
))
653 ohshite(_("unable to stat other new file '%.250s'"),
654 cfile
->namenode
->name
);
655 cfile
->namenode
->filestat
= &empty_stat
;
660 if (cfile
->namenode
->filestat
== &empty_stat
)
663 if (oldfs
.st_dev
== cfile
->namenode
->filestat
->st_dev
&&
664 oldfs
.st_ino
== cfile
->namenode
->filestat
->st_ino
) {
666 warning(_("old file '%.250s' is the same as several new files! "
667 "(both '%.250s' and '%.250s')"), fnamevb
.buf
,
668 sameas
->namenode
->name
, cfile
->namenode
->name
);
670 debug(dbg_eachfile
, "process_archive: not removing %s, "
671 "since it matches %s", fnamevb
.buf
, cfile
->namenode
->name
);
675 varbuf_destroy(&cfilename
);
677 if ((namenode
->flags
& fnnf_old_conff
)) {
679 if (sameas
->namenode
->flags
& fnnf_new_conff
) {
680 if (strcmp(sameas
->namenode
->oldhash
, NEWCONFFILEFLAG
) == 0) {
681 sameas
->namenode
->oldhash
= namenode
->oldhash
;
682 debug(dbg_eachfile
, "process_archive: old conff %s "
683 "is same as new conff %s, copying hash",
684 namenode
->name
, sameas
->namenode
->name
);
686 debug(dbg_eachfile
, "process_archive: old conff %s "
687 "is same as new conff %s but latter already has hash",
688 namenode
->name
, sameas
->namenode
->name
);
692 debug(dbg_eachfile
, "process_archive: old conff %s "
693 "is disappearing", namenode
->name
);
694 namenode
->flags
|= fnnf_obs_conff
;
695 tar_filenamenode_queue_push(newconffiles
, namenode
);
696 tar_filenamenode_queue_push(newfiles_queue
, namenode
);
704 trig_path_activate(usenode
, pkg
);
706 if (secure_unlink_statted(fnamevb
.buf
, &oldfs
)) {
707 warning(_("unable to securely remove old file '%.250s': %s"),
708 namenode
->name
, strerror(errno
));
715 pkg_update_fields(struct pkginfo
*pkg
, struct filenamenode_queue
*newconffiles
)
717 struct dependency
*newdeplist
, **newdeplistlastp
;
718 struct dependency
*newdep
, *dep
;
719 struct deppossi
**newpossilastp
, *possi
, *newpossi
;
720 struct conffile
**iconffileslastp
, *newiconff
;
721 struct fileinlist
*cfile
;
723 /* The dependencies are the most difficult. We have to build
724 * a whole new forward dependency tree. At least the reverse
725 * links (linking our deppossi's into the reverse chains)
726 * can be done by copy_dependency_links. */
728 newdeplistlastp
= &newdeplist
;
729 for (dep
= pkg
->available
.depends
; dep
; dep
= dep
->next
) {
730 newdep
= nfmalloc(sizeof(struct dependency
));
734 newpossilastp
= &newdep
->list
;
736 for (possi
= dep
->list
; possi
; possi
= possi
->next
) {
737 newpossi
= nfmalloc(sizeof(struct deppossi
));
738 newpossi
->up
= newdep
;
739 newpossi
->ed
= possi
->ed
;
740 newpossi
->next
= NULL
;
741 newpossi
->rev_next
= newpossi
->rev_prev
= NULL
;
742 newpossi
->arch_is_implicit
= possi
->arch_is_implicit
;
743 newpossi
->arch
= possi
->arch
;
744 newpossi
->verrel
= possi
->verrel
;
745 if (possi
->verrel
!= DPKG_RELATION_NONE
)
746 newpossi
->version
= possi
->version
;
748 dpkg_version_blank(&newpossi
->version
);
749 newpossi
->cyclebreak
= false;
750 *newpossilastp
= newpossi
;
751 newpossilastp
= &newpossi
->next
;
753 newdep
->type
= dep
->type
;
754 *newdeplistlastp
= newdep
;
755 newdeplistlastp
= &newdep
->next
;
758 /* Right, now we've replicated the forward tree, we
759 * get copy_dependency_links to remove all the old dependency
760 * structures from the reverse links and add the new dependency
761 * structures in instead. It also copies the new dependency
762 * structure pointer for this package into the right field. */
763 copy_dependency_links(pkg
, &pkg
->installed
.depends
, newdeplist
, 0);
765 /* We copy the text fields. */
766 pkg
->installed
.essential
= pkg
->available
.essential
;
767 pkg
->installed
.multiarch
= pkg
->available
.multiarch
;
768 pkg
->installed
.description
= pkg
->available
.description
;
769 pkg
->installed
.maintainer
= pkg
->available
.maintainer
;
770 pkg
->installed
.source
= pkg
->available
.source
;
771 pkg
->installed
.arch
= pkg
->available
.arch
;
772 pkg
->installed
.pkgname_archqual
= pkg
->available
.pkgname_archqual
;
773 pkg
->installed
.installedsize
= pkg
->available
.installedsize
;
774 pkg
->installed
.version
= pkg
->available
.version
;
775 pkg
->installed
.origin
= pkg
->available
.origin
;
776 pkg
->installed
.bugs
= pkg
->available
.bugs
;
778 /* We have to generate our own conffiles structure. */
779 pkg
->installed
.conffiles
= NULL
;
780 iconffileslastp
= &pkg
->installed
.conffiles
;
781 for (cfile
= newconffiles
->head
; cfile
; cfile
= cfile
->next
) {
782 newiconff
= nfmalloc(sizeof(struct conffile
));
783 newiconff
->next
= NULL
;
784 newiconff
->name
= nfstrsave(cfile
->namenode
->name
);
785 newiconff
->hash
= nfstrsave(cfile
->namenode
->oldhash
);
786 newiconff
->obsolete
= !!(cfile
->namenode
->flags
& fnnf_obs_conff
);
787 *iconffileslastp
= newiconff
;
788 iconffileslastp
= &newiconff
->next
;
791 /* We can just copy the arbitrary fields list, because it is
792 * never even rearranged. Phew! */
793 pkg
->installed
.arbs
= pkg
->available
.arbs
;
797 pkg_disappear(struct pkginfo
*pkg
, struct pkginfo
*infavour
)
799 printf(_("(Noting disappearance of %s, which has been completely replaced.)\n"),
800 pkg_name(pkg
, pnaw_nonambig
));
801 log_action("disappear", pkg
, &pkg
->installed
);
802 debug(dbg_general
, "pkg_disappear disappearing %s",
803 pkg_name(pkg
, pnaw_always
));
805 trig_activate_packageprocessing(pkg
);
806 maintscript_installed(pkg
, POSTRMFILE
,
807 "post-removal script (for disappearance)",
809 pkgbin_name(infavour
, &infavour
->available
,
811 versiondescribe(&infavour
->available
.version
,
815 /* OK, now we delete all the stuff in the ‘info’ directory ... */
816 debug(dbg_general
, "pkg_disappear cleaning info directory");
817 pkg_infodb_foreach(pkg
, &pkg
->installed
, pkg_infodb_remove_file
);
818 dir_sync_path(pkg_infodb_get_dir());
820 pkg_set_status(pkg
, PKG_STAT_NOTINSTALLED
);
821 pkg_set_want(pkg
, PKG_WANT_UNKNOWN
);
822 pkg_reset_eflags(pkg
);
824 dpkg_version_blank(&pkg
->configversion
);
825 pkgbin_blank(&pkg
->installed
);
827 pkg
->clientdata
->fileslistvalid
= false;
833 pkg_disappear_others(struct pkginfo
*pkg
)
835 struct pkgiterator
*iter
;
836 struct pkginfo
*otherpkg
;
837 struct fileinlist
*cfile
;
838 struct deppossi
*pdep
;
839 struct dependency
*providecheck
;
840 struct varbuf depprobwhy
= VARBUF_INIT
;
842 iter
= pkg_db_iter_new();
843 while ((otherpkg
= pkg_db_iter_next_pkg(iter
)) != NULL
) {
844 ensure_package_clientdata(otherpkg
);
846 if (otherpkg
== pkg
||
847 otherpkg
->status
== PKG_STAT_NOTINSTALLED
||
848 otherpkg
->status
== PKG_STAT_CONFIGFILES
||
849 otherpkg
->clientdata
->istobe
== PKG_ISTOBE_REMOVE
||
850 !otherpkg
->clientdata
->files
)
853 /* Do not try to disappear other packages from the same set
854 * if they are Multi-Arch: same */
855 if (pkg
->installed
.multiarch
== PKG_MULTIARCH_SAME
&&
856 otherpkg
->installed
.multiarch
== PKG_MULTIARCH_SAME
&&
857 otherpkg
->set
== pkg
->set
)
860 debug(dbg_veryverbose
, "process_archive checking disappearance %s",
861 pkg_name(otherpkg
, pnaw_always
));
862 assert(otherpkg
->clientdata
->istobe
== PKG_ISTOBE_NORMAL
||
863 otherpkg
->clientdata
->istobe
== PKG_ISTOBE_DECONFIGURE
);
865 for (cfile
= otherpkg
->clientdata
->files
;
866 cfile
&& strcmp(cfile
->namenode
->name
, "/.") == 0;
867 cfile
= cfile
->next
);
869 debug(dbg_stupidlyverbose
, "process_archive no non-root, no disappear");
872 for (cfile
= otherpkg
->clientdata
->files
;
873 cfile
&& !filesavespackage(cfile
, otherpkg
, pkg
);
874 cfile
= cfile
->next
);
878 /* So dependency things will give right answers ... */
879 otherpkg
->clientdata
->istobe
= PKG_ISTOBE_REMOVE
;
880 debug(dbg_veryverbose
, "process_archive disappear checking dependencies");
881 for (pdep
= otherpkg
->set
->depended
.installed
;
883 pdep
= pdep
->rev_next
) {
884 if (pdep
->up
->type
!= dep_depends
&&
885 pdep
->up
->type
!= dep_predepends
&&
886 pdep
->up
->type
!= dep_recommends
)
889 if (depisok(pdep
->up
, &depprobwhy
, NULL
, NULL
, false))
892 varbuf_end_str(&depprobwhy
);
893 debug(dbg_veryverbose
,"process_archive cannot disappear: %s",
898 /* If we haven't found a reason not to yet, let's look some more. */
899 for (providecheck
= otherpkg
->installed
.depends
;
901 providecheck
= providecheck
->next
) {
902 if (providecheck
->type
!= dep_provides
)
905 for (pdep
= providecheck
->list
->ed
->depended
.installed
;
907 pdep
= pdep
->rev_next
) {
908 if (pdep
->up
->type
!= dep_depends
&&
909 pdep
->up
->type
!= dep_predepends
&&
910 pdep
->up
->type
!= dep_recommends
)
913 if (depisok(pdep
->up
, &depprobwhy
, NULL
, NULL
, false))
916 varbuf_end_str(&depprobwhy
);
917 debug(dbg_veryverbose
,
918 "process_archive cannot disappear (provides %s): %s",
919 providecheck
->list
->ed
->name
, depprobwhy
.buf
);
920 goto break_from_both_loops_at_once
;
923 break_from_both_loops_at_once
:;
925 otherpkg
->clientdata
->istobe
= PKG_ISTOBE_NORMAL
;
929 /* No, we're disappearing it. This is the wrong time to go and
930 * run maintainer scripts and things, as we can't back out. But
931 * what can we do ? It has to be run this late. */
932 pkg_disappear(otherpkg
, pkg
);
933 } /* while (otherpkg= ... */
934 pkg_db_iter_free(iter
);
938 * Check if all instances of a pkgset are getting in sync.
940 * If that's the case, the extraction is going to ensure consistency
944 pkgset_getting_in_sync(struct pkginfo
*pkg
)
946 struct pkginfo
*otherpkg
;
948 for (otherpkg
= &pkg
->set
->pkg
; otherpkg
; otherpkg
= otherpkg
->arch_next
) {
951 if (otherpkg
->status
<= PKG_STAT_CONFIGFILES
)
953 if (dpkg_version_compare(&pkg
->available
.version
,
954 &otherpkg
->installed
.version
)) {
963 pkg_remove_files_from_others(struct pkginfo
*pkg
, struct fileinlist
*newfileslist
)
965 struct fileinlist
*cfile
;
966 struct pkginfo
*otherpkg
;
968 for (cfile
= newfileslist
; cfile
; cfile
= cfile
->next
) {
969 struct filepackages_iterator
*iter
;
970 struct pkgset
*divpkgset
;
972 if (!(cfile
->namenode
->flags
& fnnf_elide_other_lists
))
975 if (cfile
->namenode
->divert
&& cfile
->namenode
->divert
->useinstead
) {
976 divpkgset
= cfile
->namenode
->divert
->pkgset
;
977 if (divpkgset
== pkg
->set
) {
979 "process_archive not overwriting any '%s' (overriding, '%s')",
980 cfile
->namenode
->name
, cfile
->namenode
->divert
->useinstead
->name
);
984 "process_archive looking for overwriting '%s' (overridden by %s)",
985 cfile
->namenode
->name
, divpkgset ? divpkgset
->name
: "<local>");
989 debug(dbg_eachfile
, "process_archive looking for overwriting '%s'",
990 cfile
->namenode
->name
);
993 iter
= filepackages_iter_new(cfile
->namenode
);
994 while ((otherpkg
= filepackages_iter_next(iter
))) {
995 debug(dbg_eachfiledetail
, "process_archive ... found in %s",
996 pkg_name(otherpkg
, pnaw_always
));
998 /* A pkgset can share files between instances, so there's no point
999 * in rewriting the file that's already in place. */
1000 if (otherpkg
->set
== pkg
->set
)
1003 if (otherpkg
->set
== divpkgset
) {
1004 debug(dbg_eachfiledetail
, "process_archive ... diverted, skipping");
1008 if (cfile
->namenode
->flags
& fnnf_new_conff
)
1009 conffile_mark_obsolete(otherpkg
, cfile
->namenode
);
1011 /* If !fileslistvalid then it's one of the disappeared packages above
1012 * or we have already updated the files list file, and we don't bother
1013 * with it here, clearly. */
1014 if (!otherpkg
->clientdata
->fileslistvalid
)
1017 /* Found one. We delete the list entry for this file,
1018 * (and any others in the same package) and then mark the package
1019 * as requiring a reread. */
1020 write_filelist_except(otherpkg
, &otherpkg
->installed
,
1021 otherpkg
->clientdata
->files
, fnnf_elide_other_lists
);
1022 ensure_package_clientdata(otherpkg
);
1023 debug(dbg_veryverbose
, "process_archive overwrote from %s",
1024 pkg_name(otherpkg
, pnaw_always
));
1026 filepackages_iter_free(iter
);
1031 pkg_remove_backup_files(struct pkginfo
*pkg
, struct fileinlist
*newfileslist
)
1033 struct fileinlist
*cfile
;
1035 for (cfile
= newfileslist
; cfile
; cfile
= cfile
->next
) {
1036 struct filenamenode
*usenode
;
1038 if (cfile
->namenode
->flags
& fnnf_new_conff
)
1041 usenode
= namenodetouse(cfile
->namenode
, pkg
, &pkg
->installed
);
1043 /* Do not try to remove backups for the root directory. */
1044 if (strcmp(usenode
->name
, "/.") == 0)
1047 varbuf_rollback(&fnametmpvb
, &fname_state
);
1048 varbuf_add_str(&fnametmpvb
, usenode
->name
);
1049 varbuf_add_str(&fnametmpvb
, DPKGTEMPEXT
);
1050 varbuf_end_str(&fnametmpvb
);
1051 path_remove_tree(fnametmpvb
.buf
);
1055 void process_archive(const char *filename
) {
1056 static const struct tar_operations tf
= {
1057 .read
= tarfileread
,
1058 .extract_file
= tarobject
,
1060 .symlink
= tarobject
,
1065 /* These need to be static so that we can pass their addresses to
1066 * push_cleanup as arguments to the cu_xxx routines; if an error occurs
1067 * we unwind the stack before processing the cleanup list, and these
1068 * variables had better still exist ... */
1070 static enum pkgstatus oldversionstatus
;
1071 static struct tarcontext tc
;
1073 struct dpkg_error err
;
1074 enum parsedbflags parsedb_flags
;
1077 struct pkginfo
*pkg
, *otherpkg
;
1078 struct pkg_list
*conflictor_iter
;
1082 const char *pfilename
;
1083 struct filenamenode_queue newconffiles
, newfiles_queue
;
1086 cleanup_pkg_failed
= cleanup_conflictor_failed
= 0;
1088 pfilename
= summarize_filename(filename
);
1090 if (stat(filename
, &stab
))
1091 ohshite(_("cannot access archive '%s'"), filename
);
1093 /* We can't ‘tentatively-reassemble’ packages. */
1095 if (!deb_reassemble(&filename
, &pfilename
))
1099 /* Verify the package. */
1101 deb_verify(filename
);
1103 /* Get the control information directory. */
1104 cidir
= get_control_dir(cidir
);
1105 cidirrest
= cidir
+ strlen(cidir
);
1106 push_cleanup(cu_cidir
, ~0, NULL
, 0, 2, (void *)cidir
, (void *)cidirrest
);
1108 pid
= subproc_fork();
1110 cidirrest
[-1] = '\0';
1111 execlp(BACKEND
, BACKEND
, "--control", filename
, cidir
, NULL
);
1112 ohshite(_("unable to execute %s (%s)"),
1113 _("package control information extraction"), BACKEND
);
1115 subproc_reap(pid
, BACKEND
" --control", 0);
1117 /* We want to guarantee the extracted files are on the disk, so that the
1118 * subsequent renames to the info database do not end up with old or zero
1119 * length files in case of a system crash. As neither dpkg-deb nor tar do
1120 * explicit fsync()s, we have to do them here.
1121 * XXX: This could be avoided by switching to an internal tar extractor. */
1122 dir_sync_contents(cidir
);
1124 strcpy(cidirrest
,CONTROLFILE
);
1126 if (cipaction
->arg_int
== act_avail
)
1127 parsedb_flags
= pdb_parse_available
;
1129 parsedb_flags
= pdb_parse_binary
;
1130 parsedb_flags
|= pdb_ignorefiles
;
1132 parsedb_flags
|= pdb_lax_version_parser
;
1134 parsedb(cidir
, parsedb_flags
, &pkg
);
1137 pkg
->files
= nfmalloc(sizeof(struct filedetails
));
1138 pkg
->files
->next
= NULL
;
1139 pkg
->files
->name
= pkg
->files
->msdosname
= pkg
->files
->md5sum
= NULL
;
1141 /* Always nfmalloc. Otherwise, we may overwrite some other field (like
1143 psize
= nfmalloc(30);
1144 sprintf(psize
, "%jd", (intmax_t)stab
.st_size
);
1145 pkg
->files
->size
= psize
;
1147 if (cipaction
->arg_int
== act_avail
) {
1148 printf(_("Recorded info about %s from %s.\n"),
1149 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
), pfilename
);
1150 pop_cleanup(ehflag_normaltidy
);
1154 if (pkg
->available
.arch
->type
!= DPKG_ARCH_ALL
&&
1155 pkg
->available
.arch
->type
!= DPKG_ARCH_NATIVE
&&
1156 pkg
->available
.arch
->type
!= DPKG_ARCH_FOREIGN
)
1157 forcibleerr(fc_architecture
,
1158 _("package architecture (%s) does not match system (%s)"),
1159 pkg
->available
.arch
->name
,
1160 dpkg_arch_get(DPKG_ARCH_NATIVE
)->name
);
1162 clear_deconfigure_queue();
1165 if (wanttoinstall(pkg
)) {
1166 pkg_set_want(pkg
, PKG_WANT_INSTALL
);
1168 pop_cleanup(ehflag_normaltidy
);
1172 /* Deconfigure other instances from a pkgset if they are not in sync. */
1173 for (otherpkg
= &pkg
->set
->pkg
; otherpkg
; otherpkg
= otherpkg
->arch_next
) {
1174 if (otherpkg
== pkg
)
1176 if (otherpkg
->status
<= PKG_STAT_HALFCONFIGURED
)
1179 if (dpkg_version_compare(&pkg
->available
.version
,
1180 &otherpkg
->installed
.version
))
1181 enqueue_deconfigure(otherpkg
, NULL
);
1184 pkg_check_depcon(pkg
, pfilename
);
1186 ensure_allinstfiles_available();
1188 trig_file_interests_ensure();
1190 printf(_("Preparing to unpack %s ...\n"), pfilename
);
1192 if (pkg
->status
!= PKG_STAT_NOTINSTALLED
&&
1193 pkg
->status
!= PKG_STAT_CONFIGFILES
) {
1194 log_action("upgrade", pkg
, &pkg
->installed
);
1196 log_action("install", pkg
, &pkg
->available
);
1200 pop_cleanup(ehflag_normaltidy
);
1205 * OK, we're going ahead.
1208 trig_activate_packageprocessing(pkg
);
1209 strcpy(cidirrest
, TRIGGERSCIFILE
);
1210 trig_parse_ci(cidir
, NULL
, trig_cicb_statuschange_activate
, pkg
, &pkg
->available
);
1212 /* Read the conffiles, and copy the hashes across. */
1213 newconffiles
.head
= NULL
;
1214 newconffiles
.tail
= &newconffiles
.head
;
1215 push_cleanup(cu_fileslist
, ~0, NULL
, 0, 0);
1216 strcpy(cidirrest
,CONFFILESFILE
);
1217 deb_parse_conffiles(pkg
, cidir
, &newconffiles
);
1219 /* All the old conffiles are marked with a flag, so that we don't delete
1220 * them if they seem to disappear completely. */
1221 pkg_conffiles_mark_old(pkg
);
1222 for (conflictor_iter
= conflictors
.head
;
1224 conflictor_iter
= conflictor_iter
->next
)
1225 pkg_conffiles_mark_old(conflictor_iter
->pkg
);
1227 oldversionstatus
= pkg
->status
;
1229 assert(oldversionstatus
<= PKG_STAT_INSTALLED
);
1230 debug(dbg_general
,"process_archive oldversionstatus=%s",
1231 statusstrings
[oldversionstatus
]);
1233 if (oldversionstatus
== PKG_STAT_HALFCONFIGURED
||
1234 oldversionstatus
== PKG_STAT_TRIGGERSAWAITED
||
1235 oldversionstatus
== PKG_STAT_TRIGGERSPENDING
||
1236 oldversionstatus
== PKG_STAT_INSTALLED
) {
1237 pkg_set_eflags(pkg
, PKG_EFLAG_REINSTREQ
);
1238 pkg_set_status(pkg
, PKG_STAT_HALFCONFIGURED
);
1239 modstatdb_note(pkg
);
1240 push_cleanup(cu_prermupgrade
, ~ehflag_normaltidy
, NULL
, 0, 1, (void *)pkg
);
1241 if (dpkg_version_compare(&pkg
->available
.version
,
1242 &pkg
->installed
.version
) >= 0)
1243 /* Upgrade or reinstall. */
1244 maintscript_fallback(pkg
, PRERMFILE
, "pre-removal", cidir
, cidirrest
,
1245 "upgrade", "failed-upgrade");
1246 else /* Downgrade => no fallback */
1247 maintscript_installed(pkg
, PRERMFILE
, "pre-removal",
1249 versiondescribe(&pkg
->available
.version
,
1252 pkg_set_status(pkg
, PKG_STAT_UNPACKED
);
1253 oldversionstatus
= PKG_STAT_UNPACKED
;
1254 modstatdb_note(pkg
);
1257 pkg_deconfigure_others(pkg
);
1259 for (conflictor_iter
= conflictors
.head
;
1261 conflictor_iter
= conflictor_iter
->next
) {
1262 struct pkginfo
*conflictor
= conflictor_iter
->pkg
;
1264 if (!(conflictor
->status
== PKG_STAT_HALFCONFIGURED
||
1265 conflictor
->status
== PKG_STAT_TRIGGERSAWAITED
||
1266 conflictor
->status
== PKG_STAT_TRIGGERSPENDING
||
1267 conflictor
->status
== PKG_STAT_INSTALLED
))
1270 trig_activate_packageprocessing(conflictor
);
1271 pkg_set_status(conflictor
, PKG_STAT_HALFCONFIGURED
);
1272 modstatdb_note(conflictor
);
1273 push_cleanup(cu_prerminfavour
, ~ehflag_normaltidy
, NULL
, 0,
1274 2, conflictor
, pkg
);
1275 maintscript_installed(conflictor
, PRERMFILE
, "pre-removal",
1276 "remove", "in-favour",
1277 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
),
1278 versiondescribe(&pkg
->available
.version
,
1281 pkg_set_status(conflictor
, PKG_STAT_HALFINSTALLED
);
1282 modstatdb_note(conflictor
);
1285 pkg_set_eflags(pkg
, PKG_EFLAG_REINSTREQ
);
1286 if (pkg
->status
== PKG_STAT_NOTINSTALLED
) {
1287 pkg
->installed
.version
= pkg
->available
.version
;
1288 pkg
->installed
.multiarch
= pkg
->available
.multiarch
;
1290 pkg_set_status(pkg
, PKG_STAT_HALFINSTALLED
);
1291 modstatdb_note(pkg
);
1292 if (oldversionstatus
== PKG_STAT_NOTINSTALLED
) {
1293 push_cleanup(cu_preinstverynew
, ~ehflag_normaltidy
, NULL
, 0,
1294 3,(void*)pkg
,(void*)cidir
,(void*)cidirrest
);
1295 maintscript_new(pkg
, PREINSTFILE
, "pre-installation", cidir
, cidirrest
,
1297 } else if (oldversionstatus
== PKG_STAT_CONFIGFILES
) {
1298 push_cleanup(cu_preinstnew
, ~ehflag_normaltidy
, NULL
, 0,
1299 3,(void*)pkg
,(void*)cidir
,(void*)cidirrest
);
1300 maintscript_new(pkg
, PREINSTFILE
, "pre-installation", cidir
, cidirrest
,
1302 versiondescribe(&pkg
->installed
.version
, vdew_nonambig
),
1303 versiondescribe(&pkg
->available
.version
, vdew_nonambig
),
1306 push_cleanup(cu_preinstupgrade
, ~ehflag_normaltidy
, NULL
, 0,
1307 4,(void*)pkg
,(void*)cidir
,(void*)cidirrest
,(void*)&oldversionstatus
);
1308 maintscript_new(pkg
, PREINSTFILE
, "pre-installation", cidir
, cidirrest
,
1310 versiondescribe(&pkg
->installed
.version
, vdew_nonambig
),
1311 versiondescribe(&pkg
->available
.version
, vdew_nonambig
),
1315 if (oldversionstatus
== PKG_STAT_NOTINSTALLED
||
1316 oldversionstatus
== PKG_STAT_CONFIGFILES
) {
1317 printf(_("Unpacking %s (%s) ...\n"),
1318 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
),
1319 versiondescribe(&pkg
->available
.version
, vdew_nonambig
));
1321 printf(_("Unpacking %s (%s) over (%s) ...\n"),
1322 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
),
1323 versiondescribe(&pkg
->available
.version
, vdew_nonambig
),
1324 versiondescribe(&pkg
->installed
.version
, vdew_nonambig
));
1328 * Now we unpack the archive, backing things up as we go.
1329 * For each file, we check to see if it already exists.
1330 * There are several possibilities:
1332 * + We are trying to install a non-directory ...
1333 * - It doesn't exist. In this case we simply extract it.
1334 * - It is a plain file, device, symlink, &c. We do an ‘atomic
1335 * overwrite’ using link() and rename(), but leave a backup copy.
1336 * Later, when we delete the backup, we remove it from any other
1338 * - It is a directory. In this case it depends on whether we're
1339 * trying to install a symlink or something else.
1340 * = If we're not trying to install a symlink we move the directory
1341 * aside and extract the node. Later, when we recursively remove
1342 * the backed-up directory, we remove it from any other packages'
1344 * = If we are trying to install a symlink we do nothing - ie,
1345 * dpkg will never replace a directory tree with a symlink. This
1346 * is to avoid embarrassing effects such as replacing a directory
1347 * tree with a link to a link to the original directory tree.
1348 * + We are trying to install a directory ...
1349 * - It doesn't exist. We create it with the appropriate modes.
1350 * - It exists as a directory or a symlink to one. We do nothing.
1351 * - It is a plain file or a symlink (other than to a directory).
1352 * We move it aside and create the directory. Later, when we
1353 * delete the backup, we remove it from any other packages' lists.
1355 * Install non-dir Install symlink Install dir
1357 * File/node/symlink LXR LXR BXR
1360 * X: extract file/node/link/directory
1361 * LX: atomic overwrite leaving backup
1362 * B: ordinary backup
1363 * R: later remove from other packages' lists
1366 * After we've done this we go through the remaining things in the
1367 * lists of packages we're trying to remove (including the old
1368 * version of the current package). This happens in reverse order,
1369 * so that we process files before the directories (or symlinks-to-
1370 * directories) containing them.
1372 * + If the thing is a conffile then we leave it alone for the purge
1374 * + Otherwise, there are several possibilities too:
1375 * - The listed thing does not exist. We ignore it.
1376 * - The listed thing is a directory or a symlink to a directory.
1377 * We delete it only if it isn't listed in any other package.
1378 * - The listed thing is not a directory, but was part of the package
1379 * that was upgraded, we check to make sure the files aren't the
1380 * same ones from the old package by checking dev/inode
1381 * - The listed thing is not a directory or a symlink to one (ie,
1382 * it's a plain file, device, pipe, &c, or a symlink to one, or a
1383 * dangling symlink). We delete it.
1385 * The removed packages' list becomes empty (of course, the new
1386 * version of the package we're installing will have a new list,
1387 * which replaces the old version's list).
1389 * If at any stage we remove a file from a package's list, and the
1390 * package isn't one we're already processing, and the package's
1391 * list becomes empty as a result, we ‘vanish’ the package. This
1392 * means that we run its postrm with the ‘disappear’ argument, and
1393 * put the package in the ‘not-installed’ state. If it had any
1394 * conffiles, their hashes and ownership will have been transferred
1395 * already, so we just ignore those and forget about them from the
1396 * point of view of the disappearing package.
1398 * NOTE THAT THE OLD POSTRM IS RUN AFTER THE NEW PREINST, since the
1399 * files get replaced ‘as we go’.
1403 push_cleanup(cu_closepipe
, ehflag_bombout
, NULL
, 0, 1, (void *)&p1
[0]);
1404 pid
= subproc_fork();
1406 m_dup2(p1
[1],1); close(p1
[0]); close(p1
[1]);
1407 execlp(BACKEND
, BACKEND
, "--fsys-tarfile", filename
, NULL
);
1408 ohshite(_("unable to execute %s (%s)"),
1409 _("package filesystem archive extraction"), BACKEND
);
1413 open_shadow(p1
[0], "deb-extract-decompressed-in");
1415 newfiles_queue
.head
= NULL
;
1416 newfiles_queue
.tail
= &newfiles_queue
.head
;
1417 tc
.newfiles_queue
= &newfiles_queue
;
1418 push_cleanup(cu_fileslist
, ~0, NULL
, 0, 0);
1420 tc
.backendpipe
= p1
[0];
1421 tc
.pkgset_getting_in_sync
= pkgset_getting_in_sync(pkg
);
1423 rc
= tar_extractor(&tc
, &tf
);
1425 save_shadow("deb-extract-ar", "a");
1426 save_shadow("deb-extract-compressed-out", "tar.xz");
1427 save_shadow("deb-extract-compressed-in", "tar.xz");
1428 save_shadow("deb-extract-decompressed-out", "tar");
1429 save_shadow("deb-extract-decompressed-in", "tar");
1431 ohshite(_("error reading dpkg-deb tar output"));
1433 ohshit(_("corrupted filesystem tarfile - corrupted package archive"));
1436 if (fd_skip(p1
[0], -1, &err
) < 0)
1437 ohshit(_("cannot zap possible trailing zeros from dpkg-deb: %s"), err
.str
);
1438 close_shadow(p1
[0]);
1441 subproc_reap(pid
, BACKEND
" --fsys-tarfile", SUBPROC_NOPIPE
);
1443 tar_deferred_extract(newfiles_queue
.head
, pkg
);
1445 if (oldversionstatus
== PKG_STAT_HALFINSTALLED
||
1446 oldversionstatus
== PKG_STAT_UNPACKED
) {
1447 /* Packages that were in ‘installed’ and ‘postinstfailed’ have been
1448 * reduced to ‘unpacked’ by now, by the running of the prerm script. */
1449 pkg_set_status(pkg
, PKG_STAT_HALFINSTALLED
);
1450 modstatdb_note(pkg
);
1451 push_cleanup(cu_postrmupgrade
, ~ehflag_normaltidy
, NULL
, 0, 1, (void *)pkg
);
1452 maintscript_fallback(pkg
, POSTRMFILE
, "post-removal", cidir
, cidirrest
,
1453 "upgrade", "failed-upgrade");
1456 /* If anything goes wrong while tidying up it's a bit late to do
1457 * anything about it. However, we don't install the new status
1458 * info yet, so that a future dpkg installation will put everything
1461 * If something does go wrong later the ‘conflictor’ package will be
1462 * left in the ‘removal_failed’ state. Removing or installing it
1463 * will be impossible if it was required because of the conflict with
1464 * the package we're installing now and (presumably) the dependency
1465 * by other packages. This means that the files it contains in
1466 * common with this package will hang around until we successfully
1467 * get this package installed, after which point we can trust the
1468 * conflicting package's file list, which will have been updated to
1469 * remove any files in this package. */
1470 push_checkpoint(~ehflag_bombout
, ehflag_normaltidy
);
1472 /* Now we delete all the files that were in the old version of
1473 * the package only, except (old or new) conffiles, which we leave
1475 pkg_remove_old_files(pkg
, &newfiles_queue
, &newconffiles
);
1477 /* OK, now we can write the updated files-in-this package list,
1478 * since we've done away (hopefully) with all the old junk. */
1479 write_filelist_except(pkg
, &pkg
->available
, newfiles_queue
.head
, 0);
1481 /* Trigger interests may have changed.
1482 * Firstly we go through the old list of interests deleting them.
1483 * Then we go through the new list adding them. */
1484 strcpy(cidirrest
, TRIGGERSCIFILE
);
1485 trig_parse_ci(pkg_infodb_get_file(pkg
, &pkg
->installed
, TRIGGERSCIFILE
),
1486 trig_cicb_interest_delete
, NULL
, pkg
, &pkg
->installed
);
1487 trig_parse_ci(cidir
, trig_cicb_interest_add
, NULL
, pkg
, &pkg
->available
);
1488 trig_file_interests_save();
1490 /* We also install the new maintainer scripts, and any other
1491 * cruft that may have come along with the package. First
1492 * we go through the existing scripts replacing or removing
1493 * them as appropriate; then we go through the new scripts
1494 * (any that are left) and install them. */
1495 debug(dbg_general
, "process_archive updating info directory");
1496 pkg_infodb_update(pkg
, cidir
, cidirrest
);
1498 /* We store now the checksums dynamically computed while unpacking. */
1499 write_filehash_except(pkg
, &pkg
->available
, newfiles_queue
.head
, 0);
1502 * Update the status database.
1504 * This involves copying each field across from the ‘available’
1505 * to the ‘installed’ half of the pkg structure.
1506 * For some of the fields we have to do a complicated construction
1507 * operation; for others we can just copy the value.
1508 * We tackle the fields in the order they appear, so that
1509 * we don't miss any out :-).
1510 * At least we don't have to copy any strings that are referred
1511 * to, because these are never modified and never freed.
1513 pkg_update_fields(pkg
, &newconffiles
);
1515 /* In case this was an architecture cross-grade, the in-core pkgset might
1516 * be in an inconsistent state, with two pkginfo entries having the same
1517 * architecture, so let's fix that. Note that this does not lose data,
1518 * as the pkg.available member parsed from the binary should replace the
1519 * to be cleared duplicate in the other instance. */
1520 for (otherpkg
= &pkg
->set
->pkg
; otherpkg
; otherpkg
= otherpkg
->arch_next
) {
1521 if (otherpkg
== pkg
)
1523 if (otherpkg
->installed
.arch
!= pkg
->installed
.arch
)
1526 assert(otherpkg
->status
== PKG_STAT_NOTINSTALLED
);
1528 pkg_blank(otherpkg
);
1531 /* Check for disappearing packages:
1532 * We go through all the packages on the system looking for ones
1533 * whose files are entirely part of the one we've just unpacked
1534 * (and which actually *have* some files!).
1536 * Any that we find are removed - we run the postrm with ‘disappear’
1537 * as an argument, and remove their info/... files and status info.
1538 * Conffiles are ignored (the new package had better do something
1540 pkg_disappear_others(pkg
);
1542 /* Delete files from any other packages' lists.
1543 * We have to do this before we claim this package is in any
1544 * sane kind of state, as otherwise we might delete by mistake
1545 * a file that we overwrote, when we remove the package which
1546 * had the version we overwrote. To prevent this we make
1547 * sure that we don't claim this package is OK until we
1548 * have claimed ‘ownership’ of all its files. */
1549 pkg_remove_files_from_others(pkg
, newfiles_queue
.head
);
1551 /* Right, the package we've unpacked is now in a reasonable state.
1552 * The only thing that we have left to do with it is remove
1553 * backup files, and we can leave the user to fix that if and when
1554 * it happens (we leave the reinstall required flag, of course). */
1555 pkg_set_status(pkg
, PKG_STAT_UNPACKED
);
1556 modstatdb_note(pkg
);
1558 /* Now we delete all the backup files that we made when
1559 * extracting the archive - except for files listed as conffiles
1560 * in the new package.
1561 * This time we count it as an error if something goes wrong.
1563 * Note that we don't ever delete things that were in the old
1564 * package as a conffile and don't appear at all in the new.
1565 * They stay recorded as obsolete conffiles and will eventually
1566 * (if not taken over by another package) be forgotten. */
1567 pkg_remove_backup_files(pkg
, newfiles_queue
.head
);
1569 /* OK, we're now fully done with the main package.
1570 * This is quite a nice state, so we don't unwind past here. */
1571 pkg_reset_eflags(pkg
);
1572 modstatdb_note(pkg
);
1573 push_checkpoint(~ehflag_bombout
, ehflag_normaltidy
);
1575 /* Only the removal of the conflictor left to do.
1576 * The files list for the conflictor is still a little inconsistent in-core,
1577 * as we have not yet updated the filename->packages mappings; however,
1578 * the package->filenames mapping is. */
1579 while (!pkg_queue_is_empty(&conflictors
)) {
1580 struct pkginfo
*conflictor
= pkg_queue_pop(&conflictors
);
1582 /* We need to have the most up-to-date info about which files are
1584 ensure_allinstfiles_available();
1585 removal_bulk(conflictor
);
1588 if (cipaction
->arg_int
== act_install
)
1589 enqueue_package_mark_seen(pkg
);