2 * dpkg - main program for package management
3 * archives.c - actions that process archive files, mainly unpack
5 * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2000 Wichert Akkerman <wakkerma@debian.org>
7 * Copyright © 2007-2015 Guillem Jover <guillem@debian.org>
8 * Copyright © 2011 Linaro Limited
9 * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
11 * This is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 #include <sys/types.h>
41 #define obstack_chunk_alloc m_malloc
42 #define obstack_chunk_free free
44 #include <dpkg/i18n.h>
45 #include <dpkg/dpkg.h>
46 #include <dpkg/dpkg-db.h>
48 #include <dpkg/path.h>
49 #include <dpkg/fdio.h>
50 #include <dpkg/buffer.h>
51 #include <dpkg/subproc.h>
52 #include <dpkg/command.h>
53 #include <dpkg/file.h>
54 #include <dpkg/treewalk.h>
55 #include <dpkg/tarfn.h>
56 #include <dpkg/options.h>
57 #include <dpkg/triglib.h>
58 #include <dpkg/db-ctrl.h>
59 #include <dpkg/db-fsys.h>
66 fd_writeback_init(int fd
)
68 /* Ignore the return code as it should be considered equivalent to an
69 * asynchronous hint for the kernel, we are doing an fsync() later on
71 #if defined(SYNC_FILE_RANGE_WRITE)
72 sync_file_range(fd
, 0, 0, SYNC_FILE_RANGE_WRITE
);
73 #elif defined(HAVE_POSIX_FADVISE)
74 posix_fadvise(fd
, 0, 0, POSIX_FADV_DONTNEED
);
78 static struct obstack tar_pool
;
79 static bool tar_pool_init
= false;
82 * Allocate memory from the tar memory pool.
85 tar_pool_alloc(size_t size
)
88 obstack_init(&tar_pool
);
92 /* cppcheck-suppress[nullPointerArithmetic]:
93 * False positive, imported module. */
94 return obstack_alloc(&tar_pool
, size
);
98 * Free memory from the tar memory pool.
101 tar_pool_free(void *ptr
)
103 obstack_free(&tar_pool
, ptr
);
107 * Release the tar memory pool.
110 tar_pool_release(void)
113 /* cppcheck-suppress[nullPointerArithmetic,pointerLessThanZero]:
114 * False positive, imported module. */
115 obstack_free(&tar_pool
, NULL
);
116 tar_pool_init
= false;
120 struct fsys_namenode_list
*
121 tar_fsys_namenode_queue_push(struct fsys_namenode_queue
*queue
,
122 struct fsys_namenode
*namenode
)
124 struct fsys_namenode_list
*node
;
126 node
= tar_pool_alloc(sizeof(*node
));
127 node
->namenode
= namenode
;
131 queue
->tail
= &node
->next
;
137 tar_fsys_namenode_queue_pop(struct fsys_namenode_queue
*queue
,
138 struct fsys_namenode_list
**tail_prev
,
139 struct fsys_namenode_list
*node
)
142 queue
->tail
= tail_prev
;
147 * Check if a file or directory will save a package from disappearance.
149 * A package can only be saved by a file or directory which is part
150 * only of itself - it must be neither part of the new package being
151 * installed nor part of any 3rd package (this is important so that
152 * shared directories don't stop packages from disappearing).
155 filesavespackage(struct fsys_namenode_list
*file
,
156 struct pkginfo
*pkgtobesaved
,
157 struct pkginfo
*pkgbeinginstalled
)
159 struct fsys_node_pkgs_iter
*iter
;
160 struct pkginfo
*thirdpkg
;
162 debug(dbg_eachfiledetail
, "filesavespackage file '%s' package %s",
163 file
->namenode
->name
, pkg_name(pkgtobesaved
, pnaw_always
));
165 /* If the file is a contended one and it's overridden by either
166 * the package we're considering disappearing or the package
167 * we're installing then they're not actually the same file, so
168 * we can't disappear the package - it is saved by this file. */
169 if (file
->namenode
->divert
&& file
->namenode
->divert
->useinstead
) {
170 struct pkgset
*divpkgset
;
172 divpkgset
= file
->namenode
->divert
->pkgset
;
173 if (divpkgset
== pkgtobesaved
->set
|| divpkgset
== pkgbeinginstalled
->set
) {
174 debug(dbg_eachfiledetail
,"filesavespackage ... diverted -- save!");
178 /* Is the file in the package being installed? If so then it can't save. */
179 if (file
->namenode
->flags
& FNNF_NEW_INARCHIVE
) {
180 debug(dbg_eachfiledetail
,"filesavespackage ... in new archive -- no save");
183 /* Look for a 3rd package which can take over the file (in case
184 * it's a directory which is shared by many packages. */
185 iter
= fsys_node_pkgs_iter_new(file
->namenode
);
186 while ((thirdpkg
= fsys_node_pkgs_iter_next(iter
))) {
187 debug(dbg_eachfiledetail
, "filesavespackage ... also in %s",
188 pkg_name(thirdpkg
, pnaw_always
));
190 /* Is this not the package being installed or the one being
191 * checked for disappearance? */
192 if (thirdpkg
== pkgbeinginstalled
|| thirdpkg
== pkgtobesaved
)
195 /* A Multi-Arch: same package can share files and their presence in a
196 * third package of the same set is not a sign that we can get rid of
198 if (pkgtobesaved
->installed
.multiarch
== PKG_MULTIARCH_SAME
&&
199 thirdpkg
->set
== pkgtobesaved
->set
)
202 debug(dbg_eachfiledetail
,"filesavespackage ... is 3rd package");
204 /* If !files_list_valid then we have already disappeared this one,
205 * so we should not try to make it take over this shared directory. */
206 if (!thirdpkg
->files_list_valid
) {
207 debug(dbg_eachfiledetail
, "process_archive ... already disappeared!");
211 /* We've found a package that can take this file. */
212 debug(dbg_eachfiledetail
, "filesavespackage ... taken -- no save");
213 fsys_node_pkgs_iter_free(iter
);
216 fsys_node_pkgs_iter_free(iter
);
218 debug(dbg_eachfiledetail
, "filesavespackage ... not taken -- save !");
223 md5hash_prev_conffile(struct pkginfo
*pkg
, char *oldhash
, const char *oldname
,
224 struct fsys_namenode
*namenode
)
226 struct pkginfo
*otherpkg
;
227 struct conffile
*conff
;
229 debug(dbg_conffdetail
, "tarobject looking for shared conffile %s",
232 for (otherpkg
= &pkg
->set
->pkg
; otherpkg
; otherpkg
= otherpkg
->arch_next
) {
235 /* If we are reinstalling, even if the other package is only unpacked,
236 * we can always make use of the Conffiles hash value from an initial
237 * installation, if that happened at all. */
238 if (otherpkg
->status
<= PKG_STAT_UNPACKED
&&
239 dpkg_version_compare(&otherpkg
->installed
.version
,
240 &otherpkg
->configversion
) != 0)
242 for (conff
= otherpkg
->installed
.conffiles
; conff
; conff
= conff
->next
) {
243 if (conff
->obsolete
|| conff
->remove_on_upgrade
)
245 if (strcmp(conff
->name
, namenode
->name
) == 0)
249 strcpy(oldhash
, conff
->hash
);
250 debug(dbg_conffdetail
,
251 "tarobject found shared conffile, from pkg %s (%s); digest=%s",
252 pkg_name(otherpkg
, pnaw_always
),
253 pkg_status_name(otherpkg
), oldhash
);
258 /* If no package was found with a valid Conffiles field, we make the
259 * risky assumption that the hash of the current .dpkg-new file is
260 * the one of the previously unpacked package. */
261 if (otherpkg
== NULL
) {
262 md5hash(pkg
, oldhash
, oldname
);
263 debug(dbg_conffdetail
,
264 "tarobject found shared conffile, from disk; digest=%s", oldhash
);
268 void cu_pathname(int argc
, void **argv
) {
269 path_remove_tree((char*)(argv
[0]));
273 tarfileread(struct tar_archive
*tar
, char *buf
, int len
)
275 struct tarcontext
*tc
= (struct tarcontext
*)tar
->ctx
;
278 n
= fd_read(tc
->backendpipe
, buf
, len
);
280 ohshite(_("error reading from dpkg-deb pipe"));
285 tarobject_skip_padding(struct tarcontext
*tc
, struct tar_entry
*te
)
287 struct dpkg_error err
;
290 remainder
= te
->size
% TARBLKSZ
;
294 if (fd_skip(tc
->backendpipe
, TARBLKSZ
- remainder
, &err
) < 0)
295 ohshit(_("cannot skip padding for file '%.255s': %s"), te
->name
, err
.str
);
299 tarobject_skip_entry(struct tarcontext
*tc
, struct tar_entry
*ti
)
301 /* We need to advance the tar file to the next object, so read the
302 * file data and set it to oblivion. */
303 if (ti
->type
== TAR_FILETYPE_FILE
) {
304 struct dpkg_error err
;
306 if (fd_skip(tc
->backendpipe
, ti
->size
, &err
) < 0)
307 ohshit(_("cannot skip file '%.255s' (replaced or excluded?) from pipe: %s"),
309 tarobject_skip_padding(tc
, ti
);
313 struct varbuf_state fname_state
;
314 struct varbuf_state fnametmp_state
;
315 struct varbuf_state fnamenew_state
;
316 struct varbuf fnamevb
;
317 struct varbuf fnametmpvb
;
318 struct varbuf fnamenewvb
;
319 struct pkg_deconf_list
*deconfigure
= NULL
;
321 static time_t currenttime
;
324 does_replace(struct pkginfo
*new_pkg
, struct pkgbin
*new_pkgbin
,
325 struct pkginfo
*old_pkg
, struct pkgbin
*old_pkgbin
)
327 struct dependency
*dep
;
329 debug(dbg_depcon
,"does_replace new=%s old=%s (%s)",
330 pkgbin_name(new_pkg
, new_pkgbin
, pnaw_always
),
331 pkgbin_name(old_pkg
, old_pkgbin
, pnaw_always
),
332 versiondescribe_c(&old_pkgbin
->version
, vdew_always
));
333 for (dep
= new_pkgbin
->depends
; dep
; dep
= dep
->next
) {
334 if (dep
->type
!= dep_replaces
|| dep
->list
->ed
!= old_pkg
->set
)
336 debug(dbg_depcondetail
,"does_replace ... found old, version %s",
337 versiondescribe_c(&dep
->list
->version
,vdew_always
));
338 if (!versionsatisfied(old_pkgbin
, dep
->list
))
340 /* The test below can only trigger if dep_replaces start having
341 * arch qualifiers different from “any”. */
342 if (!archsatisfied(old_pkgbin
, dep
->list
))
344 debug(dbg_depcon
,"does_replace ... yes");
347 debug(dbg_depcon
,"does_replace ... no");
352 tarobject_extract(struct tarcontext
*tc
, struct tar_entry
*te
,
353 const char *path
, struct file_stat
*st
,
354 struct fsys_namenode
*namenode
)
356 static struct varbuf hardlinkfn
;
359 struct dpkg_error err
;
360 struct fsys_namenode
*linknode
;
365 case TAR_FILETYPE_FILE
:
366 /* We create the file with mode 0 to make sure nobody can do anything with
367 * it until we apply the proper mode, which might be a statoverride. */
368 fd
= open(path
, O_CREAT
| O_EXCL
| O_WRONLY
, 0);
370 ohshite(_("unable to create '%.255s' (while processing '%.255s')"),
372 push_cleanup(cu_closefd
, ehflag_bombout
, 1, &fd
);
373 debug(dbg_eachfiledetail
, "tarobject file open size=%jd",
376 /* We try to tell the filesystem how much disk space we are going to
377 * need to let it reduce fragmentation and possibly improve performance,
378 * as we do know the size beforehand. */
379 fd_allocate_size(fd
, 0, te
->size
);
381 newhash
= nfmalloc(MD5HASHLEN
+ 1);
382 if (fd_fd_copy_and_md5(tc
->backendpipe
, fd
, newhash
, te
->size
, &err
) < 0)
383 ohshit(_("cannot copy extracted data for '%.255s' to '%.255s': %s"),
384 te
->name
, fnamenewvb
.buf
, err
.str
);
385 namenode
->newhash
= newhash
;
386 debug(dbg_eachfiledetail
, "tarobject file digest=%s", namenode
->newhash
);
388 tarobject_skip_padding(tc
, te
);
390 fd_writeback_init(fd
);
392 if (namenode
->statoverride
)
393 debug(dbg_eachfile
, "tarobject ... stat override, uid=%d, gid=%d, mode=%04o",
394 namenode
->statoverride
->uid
,
395 namenode
->statoverride
->gid
,
396 namenode
->statoverride
->mode
);
397 rc
= fchown(fd
, st
->uid
, st
->gid
);
398 if (forcible_nonroot_error(rc
))
399 ohshite(_("error setting ownership of '%.255s'"), te
->name
);
400 rc
= fchmod(fd
, st
->mode
& ~S_IFMT
);
401 if (forcible_nonroot_error(rc
))
402 ohshite(_("error setting permissions of '%.255s'"), te
->name
);
404 /* Postpone the fsync, to try to avoid massive I/O degradation. */
405 if (!in_force(FORCE_UNSAFE_IO
))
406 namenode
->flags
|= FNNF_DEFERRED_FSYNC
;
408 pop_cleanup(ehflag_normaltidy
); /* fd = open(path) */
410 ohshite(_("error closing/writing '%.255s'"), te
->name
);
412 case TAR_FILETYPE_FIFO
:
414 ohshite(_("error creating pipe '%.255s'"), te
->name
);
415 debug(dbg_eachfiledetail
, "tarobject fifo");
417 case TAR_FILETYPE_CHARDEV
:
418 if (mknod(path
, S_IFCHR
, te
->dev
))
419 ohshite(_("error creating device '%.255s'"), te
->name
);
420 debug(dbg_eachfiledetail
, "tarobject chardev");
422 case TAR_FILETYPE_BLOCKDEV
:
423 if (mknod(path
, S_IFBLK
, te
->dev
))
424 ohshite(_("error creating device '%.255s'"), te
->name
);
425 debug(dbg_eachfiledetail
, "tarobject blockdev");
427 case TAR_FILETYPE_HARDLINK
:
428 varbuf_set_str(&hardlinkfn
, dpkg_fsys_get_dir());
429 linknode
= fsys_hash_find_node(te
->linkname
, FHFF_NONE
);
430 varbuf_add_str(&hardlinkfn
,
431 namenodetouse(linknode
, tc
->pkg
, &tc
->pkg
->available
)->name
);
432 if (linknode
->flags
& (FNNF_DEFERRED_RENAME
| FNNF_NEW_CONFF
))
433 varbuf_add_str(&hardlinkfn
, DPKGNEWEXT
);
434 varbuf_end_str(&hardlinkfn
);
435 if (link(hardlinkfn
.buf
, path
))
436 ohshite(_("error creating hard link '%.255s'"), te
->name
);
437 namenode
->newhash
= linknode
->newhash
;
438 debug(dbg_eachfiledetail
, "tarobject hardlink digest=%s", namenode
->newhash
);
440 case TAR_FILETYPE_SYMLINK
:
441 /* We've already checked for an existing directory. */
442 if (symlink(te
->linkname
, path
))
443 ohshite(_("error creating symbolic link '%.255s'"), te
->name
);
444 debug(dbg_eachfiledetail
, "tarobject symlink creating");
446 case TAR_FILETYPE_DIR
:
447 /* We've already checked for an existing directory. */
449 ohshite(_("error creating directory '%.255s'"), te
->name
);
450 debug(dbg_eachfiledetail
, "tarobject directory creating");
453 internerr("unknown tar type '%d', but already checked", te
->type
);
458 tarobject_hash(struct tarcontext
*tc
, struct tar_entry
*te
,
459 struct fsys_namenode
*namenode
)
461 if (te
->type
== TAR_FILETYPE_FILE
) {
462 struct dpkg_error err
;
465 newhash
= nfmalloc(MD5HASHLEN
+ 1);
466 if (fd_md5(tc
->backendpipe
, newhash
, te
->size
, &err
) < 0)
467 ohshit(_("cannot compute MD5 digest for file '%.255s' in tar archive: %s"),
469 tarobject_skip_padding(tc
, te
);
471 namenode
->newhash
= newhash
;
472 debug(dbg_eachfiledetail
, "tarobject file digest=%s", namenode
->newhash
);
473 } else if (te
->type
== TAR_FILETYPE_HARDLINK
) {
474 struct fsys_namenode
*linknode
;
476 linknode
= fsys_hash_find_node(te
->linkname
, FHFF_NONE
);
477 namenode
->newhash
= linknode
->newhash
;
478 debug(dbg_eachfiledetail
, "tarobject hardlink digest=%s", namenode
->newhash
);
483 tarobject_set_mtime(struct tar_entry
*te
, const char *path
)
485 struct timeval tv
[2];
487 tv
[0].tv_sec
= currenttime
;
489 tv
[1].tv_sec
= te
->mtime
;
492 if (te
->type
== TAR_FILETYPE_SYMLINK
) {
494 if (lutimes(path
, tv
) && errno
!= ENOSYS
)
495 ohshite(_("error setting timestamps of '%.255s'"), path
);
498 if (utimes(path
, tv
))
499 ohshite(_("error setting timestamps of '%.255s'"), path
);
504 tarobject_set_perms(struct tar_entry
*te
, const char *path
, struct file_stat
*st
)
508 if (te
->type
== TAR_FILETYPE_FILE
)
509 return; /* Already handled using the file descriptor. */
511 if (te
->type
== TAR_FILETYPE_SYMLINK
) {
512 rc
= lchown(path
, st
->uid
, st
->gid
);
513 if (forcible_nonroot_error(rc
))
514 ohshite(_("error setting ownership of symlink '%.255s'"), path
);
516 rc
= chown(path
, st
->uid
, st
->gid
);
517 if (forcible_nonroot_error(rc
))
518 ohshite(_("error setting ownership of '%.255s'"), path
);
519 rc
= chmod(path
, st
->mode
& ~S_IFMT
);
520 if (forcible_nonroot_error(rc
))
521 ohshite(_("error setting permissions of '%.255s'"), path
);
526 tarobject_set_se_context(const char *matchpath
, const char *path
, mode_t mode
)
528 dpkg_selabel_set_context(matchpath
, path
, mode
);
532 tarobject_matches(struct tarcontext
*tc
,
533 const char *fn_old
, struct stat
*stab
, char *oldhash
,
534 const char *fn_new
, struct tar_entry
*te
,
535 struct fsys_namenode
*namenode
)
537 struct varbuf linkname
= VARBUF_INIT
;
541 debug(dbg_eachfiledetail
, "tarobject matches on-disk object?");
544 case TAR_FILETYPE_DIR
:
545 /* Nothing to check for a new directory. */
547 case TAR_FILETYPE_SYMLINK
:
548 /* Symlinks to existing dirs have already been dealt with, only
549 * remain real symlinks where we can compare the target. */
550 if (!S_ISLNK(stab
->st_mode
))
552 linksize
= file_readlink(fn_old
, &linkname
, stab
->st_size
);
554 ohshite(_("unable to read link '%.255s'"), fn_old
);
555 else if (linksize
> stab
->st_size
)
556 ohshit(_("symbolic link '%.250s' size has changed from %jd to %zd"),
557 fn_old
, (intmax_t)stab
->st_size
, linksize
);
558 else if (linksize
< stab
->st_size
)
559 warning(_("symbolic link '%.250s' size has changed from %jd to %zd"),
560 fn_old
, (intmax_t)stab
->st_size
, linksize
);
561 linkmatch
= strcmp(linkname
.buf
, te
->linkname
) == 0;
562 varbuf_destroy(&linkname
);
566 case TAR_FILETYPE_CHARDEV
:
567 if (S_ISCHR(stab
->st_mode
) && stab
->st_rdev
== te
->dev
)
570 case TAR_FILETYPE_BLOCKDEV
:
571 if (S_ISBLK(stab
->st_mode
) && stab
->st_rdev
== te
->dev
)
574 case TAR_FILETYPE_FIFO
:
575 if (S_ISFIFO(stab
->st_mode
))
578 case TAR_FILETYPE_HARDLINK
:
580 case TAR_FILETYPE_FILE
:
581 /* Only check metadata for non-conffiles. */
582 if (!(namenode
->flags
& FNNF_NEW_CONFF
) &&
583 !(S_ISREG(stab
->st_mode
) && te
->size
== stab
->st_size
))
585 if (strcmp(oldhash
, namenode
->newhash
) == 0)
589 internerr("unknown tar type '%d', but already checked", te
->type
);
592 forcibleerr(FORCE_OVERWRITE
,
593 _("trying to overwrite shared '%.250s', which is different "
594 "from other instances of package %.250s"),
595 namenode
->name
, pkg_name(tc
->pkg
, pnaw_nonambig
));
598 void setupfnamevbs(const char *filename
) {
599 varbuf_rollback(&fname_state
);
600 varbuf_add_str(&fnamevb
, filename
);
601 varbuf_end_str(&fnamevb
);
603 varbuf_rollback(&fnametmp_state
);
604 varbuf_add_str(&fnametmpvb
, filename
);
605 varbuf_add_str(&fnametmpvb
, DPKGTEMPEXT
);
606 varbuf_end_str(&fnametmpvb
);
608 varbuf_rollback(&fnamenew_state
);
609 varbuf_add_str(&fnamenewvb
, filename
);
610 varbuf_add_str(&fnamenewvb
, DPKGNEWEXT
);
611 varbuf_end_str(&fnamenewvb
);
613 debug(dbg_eachfiledetail
, "setupvnamevbs main='%s' tmp='%s' new='%s'",
614 fnamevb
.buf
, fnametmpvb
.buf
, fnamenewvb
.buf
);
618 linktosameexistingdir(const struct tar_entry
*ti
, const char *fname
,
619 struct varbuf
*symlinkfn
)
621 struct stat oldstab
, newstab
;
624 statr
= stat(fname
, &oldstab
);
626 if (!(errno
== ENOENT
|| errno
== ELOOP
|| errno
== ENOTDIR
))
627 ohshite(_("failed to stat (dereference) existing symlink '%.250s'"),
631 if (!S_ISDIR(oldstab
.st_mode
))
634 /* But is it to the same dir? */
635 if (ti
->linkname
[0] == '/') {
636 varbuf_set_str(symlinkfn
, dpkg_fsys_get_dir());
638 const char *lastslash
;
640 lastslash
= strrchr(fname
, '/');
641 if (lastslash
== NULL
)
642 internerr("tar entry filename '%s' does not contain '/'", fname
);
643 varbuf_set_buf(symlinkfn
, fname
, (lastslash
- fname
) + 1);
645 varbuf_add_str(symlinkfn
, ti
->linkname
);
646 varbuf_end_str(symlinkfn
);
648 statr
= stat(symlinkfn
->buf
, &newstab
);
650 if (!(errno
== ENOENT
|| errno
== ELOOP
|| errno
== ENOTDIR
))
651 ohshite(_("failed to stat (dereference) proposed new symlink target"
652 " '%.250s' for symlink '%.250s'"), symlinkfn
->buf
, fname
);
655 if (!S_ISDIR(newstab
.st_mode
))
657 if (newstab
.st_dev
!= oldstab
.st_dev
||
658 newstab
.st_ino
!= oldstab
.st_ino
)
664 tarobject(struct tar_archive
*tar
, struct tar_entry
*ti
)
666 static struct varbuf conffderefn
, symlinkfn
;
668 struct fsys_namenode
*namenode
, *usenode
;
670 struct conffile
*conff
;
671 struct tarcontext
*tc
= tar
->ctx
;
672 bool existingdir
, keepexisting
;
674 char oldhash
[MD5HASHLEN
+ 1];
676 struct stat stab
, stabtmp
;
677 struct file_stat nodestat
;
678 struct fsys_namenode_list
*nifd
, **oldnifd
;
679 struct pkgset
*divpkgset
;
680 struct pkginfo
*otherpkg
;
682 tar_entry_update_from_system(ti
);
684 /* Perform some sanity checks on the tar entry. */
685 if (strchr(ti
->name
, '\n'))
686 ohshit(_("newline not allowed in archive object name '%.255s'"), ti
->name
);
688 namenode
= fsys_hash_find_node(ti
->name
, FHFF_NONE
);
690 if (namenode
->flags
& FNNF_RM_CONFF_ON_UPGRADE
)
691 ohshit(_("conffile '%s' marked for removal on upgrade, shipped in package"),
694 /* Append to list of files.
695 * The trailing ‘/’ put on the end of names in tarfiles has already
696 * been stripped by tar_extractor(). */
697 oldnifd
= tc
->newfiles_queue
->tail
;
698 nifd
= tar_fsys_namenode_queue_push(tc
->newfiles_queue
, namenode
);
699 nifd
->namenode
->flags
|= FNNF_NEW_INARCHIVE
;
702 "tarobject ti->name='%s' mode=%lo owner=%u:%u type=%d(%c)"
703 " ti->linkname='%s' namenode='%s' flags=%o instead='%s'",
704 ti
->name
, (long)ti
->stat
.mode
,
705 (unsigned)ti
->stat
.uid
, (unsigned)ti
->stat
.gid
,
707 ti
->type
>= '0' && ti
->type
<= '6' ? "-hlcbdp"[ti
->type
- '0'] : '?',
709 nifd
->namenode
->name
, nifd
->namenode
->flags
,
710 nifd
->namenode
->divert
&& nifd
->namenode
->divert
->useinstead
711 ? nifd
->namenode
->divert
->useinstead
->name
: "<none>");
713 if (nifd
->namenode
->divert
&& nifd
->namenode
->divert
->camefrom
) {
714 divpkgset
= nifd
->namenode
->divert
->pkgset
;
717 forcibleerr(FORCE_OVERWRITE_DIVERTED
,
718 _("trying to overwrite '%.250s', which is the "
719 "diverted version of '%.250s' (package: %.100s)"),
720 nifd
->namenode
->name
, nifd
->namenode
->divert
->camefrom
->name
,
723 forcibleerr(FORCE_OVERWRITE_DIVERTED
,
724 _("trying to overwrite '%.250s', which is the "
725 "diverted version of '%.250s'"),
726 nifd
->namenode
->name
, nifd
->namenode
->divert
->camefrom
->name
);
730 if (nifd
->namenode
->statoverride
) {
731 nodestat
= *nifd
->namenode
->statoverride
;
732 nodestat
.mode
|= ti
->stat
.mode
& S_IFMT
;
737 usenode
= namenodetouse(nifd
->namenode
, tc
->pkg
, &tc
->pkg
->available
);
738 usename
= usenode
->name
;
740 trig_file_activate(usenode
, tc
->pkg
);
742 if (nifd
->namenode
->flags
& FNNF_NEW_CONFF
) {
743 /* If it's a conffile we have to extract it next to the installed
744 * version (i.e. we do the usual link-following). */
745 if (conffderef(tc
->pkg
, &conffderefn
, usename
))
746 usename
= conffderefn
.buf
;
747 debug(dbg_conff
, "tarobject FNNF_NEW_CONFF deref='%s'", usename
);
750 setupfnamevbs(usename
);
752 statr
= lstat(fnamevb
.buf
,&stab
);
754 /* The lstat failed. */
755 if (errno
!= ENOENT
&& errno
!= ENOTDIR
)
756 ohshite(_("unable to stat '%.255s' (which was about to be installed)"),
758 /* OK, so it doesn't exist.
759 * However, it's possible that we were in the middle of some other
760 * backup/restore operation and were rudely interrupted.
761 * So, we see if we have .dpkg-tmp, and if so we restore it. */
762 if (rename(fnametmpvb
.buf
,fnamevb
.buf
)) {
763 /* Trying to remove a directory or a file on a read-only filesystem,
764 * even if non-existent, always returns EROFS. */
765 if (errno
== EROFS
) {
766 /* If the file does not exist the access() function will remap the
767 * EROFS into an ENOENT, otherwise restore EROFS to fail with that. */
768 if (access(fnametmpvb
.buf
, F_OK
) == 0)
772 if (errno
!= ENOENT
&& errno
!= ENOTDIR
)
773 ohshite(_("unable to clean up mess surrounding '%.255s' before "
774 "installing another version"), ti
->name
);
775 debug(dbg_eachfiledetail
,"tarobject nonexistent");
777 debug(dbg_eachfiledetail
,"tarobject restored tmp to main");
778 statr
= lstat(fnamevb
.buf
,&stab
);
780 ohshite(_("unable to stat restored '%.255s' before installing"
781 " another version"), ti
->name
);
784 debug(dbg_eachfiledetail
,"tarobject already exists");
787 /* Check to see if it's a directory or link to one and we don't need to
788 * do anything. This has to be done now so that we don't die due to
789 * a file overwriting conflict. */
792 case TAR_FILETYPE_SYMLINK
:
793 /* If it's already an existing directory, do nothing. */
794 if (!statr
&& S_ISDIR(stab
.st_mode
)) {
795 debug(dbg_eachfiledetail
, "tarobject symlink exists as directory");
797 } else if (!statr
&& S_ISLNK(stab
.st_mode
)) {
798 if (linktosameexistingdir(ti
, fnamevb
.buf
, &symlinkfn
))
802 case TAR_FILETYPE_DIR
:
803 /* If it's already an existing directory, do nothing. */
804 if (!stat(fnamevb
.buf
,&stabtmp
) && S_ISDIR(stabtmp
.st_mode
)) {
805 debug(dbg_eachfiledetail
, "tarobject directory exists");
809 case TAR_FILETYPE_FILE
:
810 case TAR_FILETYPE_CHARDEV
:
811 case TAR_FILETYPE_BLOCKDEV
:
812 case TAR_FILETYPE_FIFO
:
813 case TAR_FILETYPE_HARDLINK
:
816 ohshit(_("archive contained object '%.255s' of unknown type 0x%x"),
820 keepexisting
= false;
823 struct fsys_node_pkgs_iter
*iter
;
825 iter
= fsys_node_pkgs_iter_new(nifd
->namenode
);
826 while ((otherpkg
= fsys_node_pkgs_iter_next(iter
))) {
827 if (otherpkg
== tc
->pkg
)
829 debug(dbg_eachfile
, "tarobject ... found in %s",
830 pkg_name(otherpkg
, pnaw_always
));
832 /* A pkgset can share files between its instances. Overwriting
833 * is allowed when they are not getting in sync, otherwise the
834 * file content must match the installed file. */
835 if (otherpkg
->set
== tc
->pkg
->set
&&
836 otherpkg
->installed
.multiarch
== PKG_MULTIARCH_SAME
&&
837 tc
->pkg
->available
.multiarch
== PKG_MULTIARCH_SAME
) {
838 if (statr
== 0 && tc
->pkgset_getting_in_sync
)
840 debug(dbg_eachfiledetail
, "tarobject ... shared with %s %s (syncing=%d)",
841 pkg_name(otherpkg
, pnaw_always
),
842 versiondescribe_c(&otherpkg
->installed
.version
, vdew_nonambig
),
843 tc
->pkgset_getting_in_sync
);
847 if (nifd
->namenode
->divert
&& nifd
->namenode
->divert
->useinstead
) {
848 /* Right, so we may be diverting this file. This makes the conflict
849 * OK iff one of us is the diverting package (we don't need to
850 * check for both being the diverting package, obviously). */
851 divpkgset
= nifd
->namenode
->divert
->pkgset
;
852 debug(dbg_eachfile
, "tarobject ... diverted, divpkgset=%s",
853 divpkgset
? divpkgset
->name
: "<none>");
854 if (otherpkg
->set
== divpkgset
|| tc
->pkg
->set
== divpkgset
)
858 /* If the new object is a directory and the previous object does
859 * not exist assume it's also a directory and skip further checks.
860 * XXX: Ideally with more information about the installed files we
861 * could perform more clever checks. */
862 if (statr
!= 0 && ti
->type
== TAR_FILETYPE_DIR
) {
863 debug(dbg_eachfile
, "tarobject ... assuming shared directory");
867 ensure_package_clientdata(otherpkg
);
869 /* Nope? Hmm, file conflict, perhaps. Check Replaces. */
870 switch (otherpkg
->clientdata
->replacingfilesandsaid
) {
878 /* Is the package with the conflicting file in the “config files only”
879 * state? If so it must be a config file and we can silently take it
881 if (otherpkg
->status
== PKG_STAT_CONFIGFILES
)
884 /* Perhaps we're removing a conflicting package? */
885 if (otherpkg
->clientdata
->istobe
== PKG_ISTOBE_REMOVE
)
888 /* Is the file an obsolete conffile in the other package
889 * and a conffile in the new package? */
890 if ((nifd
->namenode
->flags
& FNNF_NEW_CONFF
) &&
891 !statr
&& S_ISREG(stab
.st_mode
)) {
892 for (conff
= otherpkg
->installed
.conffiles
;
894 conff
= conff
->next
) {
895 if (!conff
->obsolete
)
897 if (strcmp(conff
->name
, nifd
->namenode
->name
) == 0)
901 debug(dbg_eachfiledetail
, "tarobject other's obsolete conffile");
902 /* process_archive() will have copied its hash already. */
907 if (does_replace(tc
->pkg
, &tc
->pkg
->available
,
908 otherpkg
, &otherpkg
->installed
)) {
909 printf(_("Replacing files in old package %s (%s) ...\n"),
910 pkg_name(otherpkg
, pnaw_nonambig
),
911 versiondescribe(&otherpkg
->installed
.version
, vdew_nonambig
));
912 otherpkg
->clientdata
->replacingfilesandsaid
= 1;
913 } else if (does_replace(otherpkg
, &otherpkg
->installed
,
914 tc
->pkg
, &tc
->pkg
->available
)) {
915 printf(_("Replaced by files in installed package %s (%s) ...\n"),
916 pkg_name(otherpkg
, pnaw_nonambig
),
917 versiondescribe(&otherpkg
->installed
.version
, vdew_nonambig
));
918 otherpkg
->clientdata
->replacingfilesandsaid
= 2;
919 nifd
->namenode
->flags
&= ~FNNF_NEW_INARCHIVE
;
922 /* At this point we are replacing something without a Replaces. */
923 if (!statr
&& S_ISDIR(stab
.st_mode
)) {
924 forcibleerr(FORCE_OVERWRITE_DIR
,
925 _("trying to overwrite directory '%.250s' "
926 "in package %.250s %.250s with nondirectory"),
927 nifd
->namenode
->name
, pkg_name(otherpkg
, pnaw_nonambig
),
928 versiondescribe(&otherpkg
->installed
.version
,
931 forcibleerr(FORCE_OVERWRITE
,
932 _("trying to overwrite '%.250s', "
933 "which is also in package %.250s %.250s"),
934 nifd
->namenode
->name
, pkg_name(otherpkg
, pnaw_nonambig
),
935 versiondescribe(&otherpkg
->installed
.version
,
940 fsys_node_pkgs_iter_free(iter
);
944 if (nifd
->namenode
->flags
& FNNF_NEW_CONFF
)
945 nifd
->namenode
->flags
|= FNNF_OBS_CONFF
;
946 tar_fsys_namenode_queue_pop(tc
->newfiles_queue
, oldnifd
, nifd
);
947 tarobject_skip_entry(tc
, ti
);
951 if (filter_should_skip(ti
)) {
952 nifd
->namenode
->flags
&= ~FNNF_NEW_INARCHIVE
;
953 nifd
->namenode
->flags
|= FNNF_FILTERED
;
954 tarobject_skip_entry(tc
, ti
);
962 /* Compute the hash of the previous object, before we might replace it
963 * with the new version on forced overwrites. */
965 debug(dbg_eachfiledetail
, "tarobject computing on-disk file '%s' digest, refcounting",
967 if (nifd
->namenode
->flags
& FNNF_NEW_CONFF
) {
968 md5hash_prev_conffile(tc
->pkg
, oldhash
, fnamenewvb
.buf
, nifd
->namenode
);
969 } else if (S_ISREG(stab
.st_mode
)) {
970 md5hash(tc
->pkg
, oldhash
, fnamevb
.buf
);
972 strcpy(oldhash
, EMPTYHASHFLAG
);
976 if (refcounting
&& !in_force(FORCE_OVERWRITE
)) {
977 /* If we are not forced to overwrite the path and are refcounting,
978 * just compute the hash w/o extracting the object. */
979 tarobject_hash(tc
, ti
, nifd
->namenode
);
981 /* Now, at this stage we want to make sure neither of .dpkg-new and
982 * .dpkg-tmp are hanging around. */
983 path_remove_tree(fnamenewvb
.buf
);
984 path_remove_tree(fnametmpvb
.buf
);
986 /* Now we start to do things that we need to be able to undo
987 * if something goes wrong. Watch out for the CLEANUP comments to
988 * keep an eye on what's installed on the disk at each point. */
989 push_cleanup(cu_installnew
, ~ehflag_normaltidy
, 1, nifd
->namenode
);
992 * CLEANUP: Now we either have the old file on the disk, or not, in
993 * its original filename.
996 /* Extract whatever it is as .dpkg-new ... */
997 tarobject_extract(tc
, ti
, fnamenewvb
.buf
, &nodestat
, nifd
->namenode
);
1000 /* For shared files, check now if the object matches. */
1002 tarobject_matches(tc
, fnamevb
.buf
, &stab
, oldhash
,
1003 fnamenewvb
.buf
, ti
, nifd
->namenode
);
1005 /* If we didn't extract anything, there's nothing else to do. */
1006 if (refcounting
&& !in_force(FORCE_OVERWRITE
))
1009 tarobject_set_perms(ti
, fnamenewvb
.buf
, &nodestat
);
1010 tarobject_set_mtime(ti
, fnamenewvb
.buf
);
1011 tarobject_set_se_context(fnamevb
.buf
, fnamenewvb
.buf
, nodestat
.mode
);
1014 * CLEANUP: Now we have extracted the new object in .dpkg-new (or,
1015 * if the file already exists as a directory and we were trying to
1016 * extract a directory or symlink, we returned earlier, so we don't
1017 * need to worry about that here).
1019 * The old file is still in the original filename,
1022 /* First, check to see if it's a conffile. If so we don't install
1023 * it now - we leave it in .dpkg-new for --configure to take care of. */
1024 if (nifd
->namenode
->flags
& FNNF_NEW_CONFF
) {
1025 debug(dbg_conffdetail
,"tarobject conffile extracted");
1026 nifd
->namenode
->flags
|= FNNF_ELIDE_OTHER_LISTS
;
1030 /* Now we move the old file out of the way, the backup file will
1031 * be deleted later. */
1033 /* Don't try to back it up if it didn't exist. */
1034 debug(dbg_eachfiledetail
,"tarobject new - no backup");
1036 if (ti
->type
== TAR_FILETYPE_DIR
|| S_ISDIR(stab
.st_mode
)) {
1037 /* One of the two is a directory - can't do atomic install. */
1038 debug(dbg_eachfiledetail
,"tarobject directory, nonatomic");
1039 nifd
->namenode
->flags
|= FNNF_NO_ATOMIC_OVERWRITE
;
1040 if (rename(fnamevb
.buf
,fnametmpvb
.buf
))
1041 ohshite(_("unable to move aside '%.255s' to install new version"),
1043 } else if (S_ISLNK(stab
.st_mode
)) {
1047 /* We can't make a symlink with two hardlinks, so we'll have to
1048 * copy it. (Pretend that making a copy of a symlink is the same
1049 * as linking to it.) */
1050 linksize
= file_readlink(fnamevb
.buf
, &symlinkfn
, stab
.st_size
);
1052 ohshite(_("unable to read link '%.255s'"), ti
->name
);
1053 else if (linksize
> stab
.st_size
)
1054 ohshit(_("symbolic link '%.250s' size has changed from %jd to %zd"),
1055 fnamevb
.buf
, (intmax_t)stab
.st_size
, linksize
);
1056 else if (linksize
< stab
.st_size
)
1057 warning(_("symbolic link '%.250s' size has changed from %jd to %zd"),
1058 fnamevb
.buf
, (intmax_t)stab
.st_size
, linksize
);
1059 if (symlink(symlinkfn
.buf
,fnametmpvb
.buf
))
1060 ohshite(_("unable to make backup symlink for '%.255s'"), ti
->name
);
1061 rc
= lchown(fnametmpvb
.buf
, stab
.st_uid
, stab
.st_gid
);
1062 if (forcible_nonroot_error(rc
))
1063 ohshite(_("unable to chown backup symlink for '%.255s'"), ti
->name
);
1064 tarobject_set_se_context(fnamevb
.buf
, fnametmpvb
.buf
, stab
.st_mode
);
1066 debug(dbg_eachfiledetail
, "tarobject nondirectory, 'link' backup");
1067 if (link(fnamevb
.buf
,fnametmpvb
.buf
))
1068 ohshite(_("unable to make backup link of '%.255s' before installing new version"),
1074 * CLEANUP: Now the old file is in .dpkg-tmp, and the new file is still
1078 if (ti
->type
== TAR_FILETYPE_FILE
|| ti
->type
== TAR_FILETYPE_HARDLINK
||
1079 ti
->type
== TAR_FILETYPE_SYMLINK
) {
1080 nifd
->namenode
->flags
|= FNNF_DEFERRED_RENAME
;
1082 debug(dbg_eachfiledetail
, "tarobject done and installation deferred");
1084 if (rename(fnamenewvb
.buf
, fnamevb
.buf
))
1085 ohshite(_("unable to install new version of '%.255s'"), ti
->name
);
1088 * CLEANUP: Now the new file is in the destination file, and the
1089 * old file is in .dpkg-tmp to be cleaned up later. We now need
1090 * to take a different attitude to cleanup, because we need to
1091 * remove the new file.
1094 nifd
->namenode
->flags
|= FNNF_PLACED_ON_DISK
;
1095 nifd
->namenode
->flags
|= FNNF_ELIDE_OTHER_LISTS
;
1097 debug(dbg_eachfiledetail
, "tarobject done and installed");
1103 #if defined(SYNC_FILE_RANGE_WAIT_BEFORE)
1105 tar_writeback_barrier(struct fsys_namenode_list
*files
, struct pkginfo
*pkg
)
1107 struct fsys_namenode_list
*cfile
;
1109 for (cfile
= files
; cfile
; cfile
= cfile
->next
) {
1110 struct fsys_namenode
*usenode
;
1113 if (!(cfile
->namenode
->flags
& FNNF_DEFERRED_FSYNC
))
1116 usenode
= namenodetouse(cfile
->namenode
, pkg
, &pkg
->available
);
1118 setupfnamevbs(usenode
->name
);
1120 fd
= open(fnamenewvb
.buf
, O_WRONLY
);
1122 ohshite(_("unable to open '%.255s'"), fnamenewvb
.buf
);
1123 /* Ignore the return code as it should be considered equivalent to an
1124 * asynchronous hint for the kernel, we are doing an fsync() later on
1126 sync_file_range(fd
, 0, 0, SYNC_FILE_RANGE_WAIT_BEFORE
);
1128 ohshite(_("error closing/writing '%.255s'"), fnamenewvb
.buf
);
1133 tar_writeback_barrier(struct fsys_namenode_list
*files
, struct pkginfo
*pkg
)
1139 tar_deferred_extract(struct fsys_namenode_list
*files
, struct pkginfo
*pkg
)
1141 struct fsys_namenode_list
*cfile
;
1142 struct fsys_namenode
*usenode
;
1144 tar_writeback_barrier(files
, pkg
);
1146 for (cfile
= files
; cfile
; cfile
= cfile
->next
) {
1147 debug(dbg_eachfile
, "deferred extract of '%.255s'", cfile
->namenode
->name
);
1149 if (!(cfile
->namenode
->flags
& FNNF_DEFERRED_RENAME
))
1152 usenode
= namenodetouse(cfile
->namenode
, pkg
, &pkg
->available
);
1154 setupfnamevbs(usenode
->name
);
1156 if (cfile
->namenode
->flags
& FNNF_DEFERRED_FSYNC
) {
1159 debug(dbg_eachfiledetail
, "deferred extract needs fsync");
1161 fd
= open(fnamenewvb
.buf
, O_WRONLY
);
1163 ohshite(_("unable to open '%.255s'"), fnamenewvb
.buf
);
1165 ohshite(_("unable to sync file '%.255s'"), fnamenewvb
.buf
);
1167 ohshite(_("error closing/writing '%.255s'"), fnamenewvb
.buf
);
1169 cfile
->namenode
->flags
&= ~FNNF_DEFERRED_FSYNC
;
1172 debug(dbg_eachfiledetail
, "deferred extract needs rename");
1174 if (rename(fnamenewvb
.buf
, fnamevb
.buf
))
1175 ohshite(_("unable to install new version of '%.255s'"),
1176 cfile
->namenode
->name
);
1178 cfile
->namenode
->flags
&= ~FNNF_DEFERRED_RENAME
;
1181 * CLEANUP: Now the new file is in the destination file, and the
1182 * old file is in .dpkg-tmp to be cleaned up later. We now need
1183 * to take a different attitude to cleanup, because we need to
1184 * remove the new file.
1187 cfile
->namenode
->flags
|= FNNF_PLACED_ON_DISK
;
1188 cfile
->namenode
->flags
|= FNNF_ELIDE_OTHER_LISTS
;
1190 debug(dbg_eachfiledetail
, "deferred extract done and installed");
1195 enqueue_deconfigure(struct pkginfo
*pkg
, struct pkginfo
*pkg_removal
,
1196 enum pkgwant reason
)
1198 struct pkg_deconf_list
*newdeconf
;
1200 ensure_package_clientdata(pkg
);
1201 pkg
->clientdata
->istobe
= PKG_ISTOBE_DECONFIGURE
;
1202 newdeconf
= m_malloc(sizeof(*newdeconf
));
1203 newdeconf
->next
= deconfigure
;
1204 newdeconf
->pkg
= pkg
;
1205 newdeconf
->pkg_removal
= pkg_removal
;
1206 newdeconf
->reason
= reason
;
1207 deconfigure
= newdeconf
;
1211 clear_deconfigure_queue(void)
1213 struct pkg_deconf_list
*deconf
, *deconf_next
;
1215 for (deconf
= deconfigure
; deconf
; deconf
= deconf_next
) {
1216 deconf_next
= deconf
->next
;
1223 * Try if we can deconfigure the package for installation and queue it if so.
1225 * This function gets called in the Breaks context, when trying to install
1226 * a package that might require another to be deconfigured to be able to
1229 * First checks whether the pdep is forced.
1231 * @retval 0 Not possible (why is printed).
1232 * @retval 1 Deconfiguration queued ok (no message printed).
1233 * @retval 2 Forced (no deconfiguration needed, why is printed).
1236 try_deconfigure_can(struct pkginfo
*pkg
, struct deppossi
*pdep
,
1237 struct pkginfo
*pkg_install
, const char *why
)
1239 if (force_breaks(pdep
)) {
1240 warning(_("ignoring dependency problem with installation of %s:\n%s"),
1241 pkgbin_name(pkg_install
, &pkg
->available
, pnaw_nonambig
), why
);
1243 } else if (f_autodeconf
) {
1244 enqueue_deconfigure(pkg
, NULL
, PKG_WANT_INSTALL
);
1247 notice(_("no, cannot proceed with installation of %s (--auto-deconfigure will help):\n%s"),
1248 pkgbin_name(pkg_install
, &pkg
->available
, pnaw_nonambig
), why
);
1254 * Try if we can deconfigure the package for removal and queue it if so.
1256 * This function gets called in the Conflicts+Depends context, when trying
1257 * to install a package that might require another to be fully removed to
1258 * be able to proceed.
1260 * First checks whether the pdep is forced, then if auto-configure is enabled
1261 * we make sure Essential and Protected are not allowed to be removed unless
1264 * @retval 0 Not possible (why is printed).
1265 * @retval 1 Deconfiguration queued ok (no message printed).
1266 * @retval 2 Forced (no deconfiguration needed, why is printed).
1269 try_remove_can(struct deppossi
*pdep
,
1270 struct pkginfo
*pkg_removal
, const char *why
)
1272 struct pkginfo
*pkg
= pdep
->up
->up
;
1274 if (force_depends(pdep
)) {
1275 warning(_("ignoring dependency problem with removal of %s:\n%s"),
1276 pkg_name(pkg_removal
, pnaw_nonambig
), why
);
1278 } else if (f_autodeconf
) {
1279 if (pkg
->installed
.essential
) {
1280 if (in_force(FORCE_REMOVE_ESSENTIAL
)) {
1281 warning(_("considering deconfiguration of essential\n"
1282 " package %s, to enable removal of %s"),
1283 pkg_name(pkg
, pnaw_nonambig
), pkg_name(pkg_removal
, pnaw_nonambig
));
1285 notice(_("no, %s is essential, will not deconfigure\n"
1286 " it in order to enable removal of %s"),
1287 pkg_name(pkg
, pnaw_nonambig
), pkg_name(pkg_removal
, pnaw_nonambig
));
1291 if (pkg
->installed
.is_protected
) {
1292 if (in_force(FORCE_REMOVE_PROTECTED
)) {
1293 warning(_("considering deconfiguration of protected\n"
1294 " package %s, to enable removal of %s"),
1295 pkg_name(pkg
, pnaw_nonambig
), pkg_name(pkg_removal
, pnaw_nonambig
));
1297 notice(_("no, %s is protected, will not deconfigure\n"
1298 " it in order to enable removal of %s"),
1299 pkg_name(pkg
, pnaw_nonambig
), pkg_name(pkg_removal
, pnaw_nonambig
));
1304 enqueue_deconfigure(pkg
, pkg_removal
, PKG_WANT_DEINSTALL
);
1307 notice(_("no, cannot proceed with removal of %s (--auto-deconfigure will help):\n%s"),
1308 pkg_name(pkg_removal
, pnaw_nonambig
), why
);
1313 void check_breaks(struct dependency
*dep
, struct pkginfo
*pkg
,
1314 const char *pfilename
) {
1315 struct pkginfo
*fixbydeconf
;
1316 struct varbuf why
= VARBUF_INIT
;
1320 if (depisok(dep
, &why
, &fixbydeconf
, NULL
, false)) {
1321 varbuf_destroy(&why
);
1325 varbuf_end_str(&why
);
1327 if (fixbydeconf
&& f_autodeconf
) {
1328 ensure_package_clientdata(fixbydeconf
);
1330 if (fixbydeconf
->clientdata
->istobe
!= PKG_ISTOBE_NORMAL
)
1331 internerr("package %s being fixed by deconf is not to be normal, "
1333 pkg_name(pkg
, pnaw_always
), fixbydeconf
->clientdata
->istobe
);
1335 notice(_("considering deconfiguration of %s, which would be broken by installation of %s ..."),
1336 pkg_name(fixbydeconf
, pnaw_nonambig
),
1337 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1339 ok
= try_deconfigure_can(fixbydeconf
, dep
->list
, pkg
, why
.buf
);
1341 notice(_("yes, will deconfigure %s (broken by %s)"),
1342 pkg_name(fixbydeconf
, pnaw_nonambig
),
1343 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1346 notice(_("regarding %s containing %s:\n%s"), pfilename
,
1347 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
), why
.buf
);
1350 varbuf_destroy(&why
);
1353 if (force_breaks(dep
->list
)) {
1354 warning(_("ignoring breakage, may proceed anyway!"));
1358 if (fixbydeconf
&& !f_autodeconf
) {
1359 ohshit(_("installing %.250s would break %.250s, and\n"
1360 " deconfiguration is not permitted (--auto-deconfigure might help)"),
1361 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
),
1362 pkg_name(fixbydeconf
, pnaw_nonambig
));
1364 ohshit(_("installing %.250s would break existing software"),
1365 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1369 void check_conflict(struct dependency
*dep
, struct pkginfo
*pkg
,
1370 const char *pfilename
) {
1371 struct pkginfo
*fixbyrm
;
1372 struct deppossi
*pdep
, flagdeppossi
= { 0 };
1373 struct varbuf conflictwhy
= VARBUF_INIT
, removalwhy
= VARBUF_INIT
;
1374 struct dependency
*providecheck
;
1377 if (depisok(dep
, &conflictwhy
, &fixbyrm
, NULL
, false)) {
1378 varbuf_destroy(&conflictwhy
);
1379 varbuf_destroy(&removalwhy
);
1383 ensure_package_clientdata(fixbyrm
);
1384 if (fixbyrm
->clientdata
->istobe
== PKG_ISTOBE_INSTALLNEW
) {
1386 ensure_package_clientdata(fixbyrm
);
1388 if (((pkg
->available
.essential
|| pkg
->available
.is_protected
) &&
1389 (fixbyrm
->installed
.essential
|| fixbyrm
->installed
.is_protected
)) ||
1390 (((fixbyrm
->want
!= PKG_WANT_INSTALL
&&
1391 fixbyrm
->want
!= PKG_WANT_HOLD
) ||
1392 does_replace(pkg
, &pkg
->available
, fixbyrm
, &fixbyrm
->installed
)) &&
1393 ((!fixbyrm
->installed
.essential
|| in_force(FORCE_REMOVE_ESSENTIAL
)) ||
1394 (!fixbyrm
->installed
.is_protected
|| in_force(FORCE_REMOVE_PROTECTED
))))) {
1395 if (fixbyrm
->clientdata
->istobe
!= PKG_ISTOBE_NORMAL
&&
1396 fixbyrm
->clientdata
->istobe
!= PKG_ISTOBE_DECONFIGURE
)
1397 internerr("package %s to be fixed by removal is not to be normal "
1398 "nor deconfigure, is to be %d",
1399 pkg_name(pkg
, pnaw_always
), fixbyrm
->clientdata
->istobe
);
1400 fixbyrm
->clientdata
->istobe
= PKG_ISTOBE_REMOVE
;
1401 notice(_("considering removing %s in favour of %s ..."),
1402 pkg_name(fixbyrm
, pnaw_nonambig
),
1403 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1404 if (!(fixbyrm
->status
== PKG_STAT_INSTALLED
||
1405 fixbyrm
->status
== PKG_STAT_TRIGGERSPENDING
||
1406 fixbyrm
->status
== PKG_STAT_TRIGGERSAWAITED
)) {
1407 notice(_("%s is not properly installed; ignoring any dependencies on it"),
1408 pkg_name(fixbyrm
, pnaw_nonambig
));
1411 for (pdep
= fixbyrm
->set
->depended
.installed
;
1413 pdep
= pdep
->rev_next
) {
1414 if (pdep
->up
->type
!= dep_depends
&& pdep
->up
->type
!= dep_predepends
)
1416 if (depisok(pdep
->up
, &removalwhy
, NULL
, NULL
, false))
1418 varbuf_end_str(&removalwhy
);
1419 if (!try_remove_can(pdep
,fixbyrm
,removalwhy
.buf
))
1423 /* If we haven't found a reason not to yet, let's look some more. */
1424 for (providecheck
= fixbyrm
->installed
.depends
;
1426 providecheck
= providecheck
->next
) {
1427 if (providecheck
->type
!= dep_provides
) continue;
1428 for (pdep
= providecheck
->list
->ed
->depended
.installed
;
1430 pdep
= pdep
->rev_next
) {
1431 if (pdep
->up
->type
!= dep_depends
&& pdep
->up
->type
!= dep_predepends
)
1433 if (depisok(pdep
->up
, &removalwhy
, NULL
, NULL
, false))
1435 varbuf_end_str(&removalwhy
);
1436 notice(_("may have trouble removing %s, as it provides %s ..."),
1437 pkg_name(fixbyrm
, pnaw_nonambig
),
1438 providecheck
->list
->ed
->name
);
1439 if (!try_remove_can(pdep
,fixbyrm
,removalwhy
.buf
))
1440 goto break_from_both_loops_at_once
;
1443 break_from_both_loops_at_once
:;
1446 if (!pdep
&& skip_due_to_hold(fixbyrm
)) {
1447 pdep
= &flagdeppossi
;
1449 if (!pdep
&& (fixbyrm
->eflag
& PKG_EFLAG_REINSTREQ
)) {
1450 if (in_force(FORCE_REMOVE_REINSTREQ
)) {
1451 notice(_("package %s requires reinstallation, but will "
1452 "remove anyway as you requested"),
1453 pkg_name(fixbyrm
, pnaw_nonambig
));
1455 notice(_("package %s requires reinstallation, will not remove"),
1456 pkg_name(fixbyrm
, pnaw_nonambig
));
1457 pdep
= &flagdeppossi
;
1461 /* This conflict is OK - we'll remove the conflictor. */
1462 enqueue_conflictor(fixbyrm
);
1463 varbuf_destroy(&conflictwhy
); varbuf_destroy(&removalwhy
);
1464 notice(_("yes, will remove %s in favour of %s"),
1465 pkg_name(fixbyrm
, pnaw_nonambig
),
1466 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1470 fixbyrm
->clientdata
->istobe
= PKG_ISTOBE_NORMAL
;
1473 varbuf_end_str(&conflictwhy
);
1474 notice(_("regarding %s containing %s:\n%s"), pfilename
,
1475 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
), conflictwhy
.buf
);
1476 if (!force_conflicts(dep
->list
))
1477 ohshit(_("conflicting packages - not installing %.250s"),
1478 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1479 warning(_("ignoring conflict, may proceed anyway!"));
1480 varbuf_destroy(&conflictwhy
);
1485 void cu_cidir(int argc
, void **argv
) {
1486 char *cidir
= (char*)argv
[0];
1487 char *cidirrest
= (char*)argv
[1];
1488 cidirrest
[-1] = '\0';
1489 path_remove_tree(cidir
);
1493 void cu_fileslist(int argc
, void **argv
) {
1498 archivefiles(const char *const *argv
)
1500 const char *const *volatile argp
;
1501 char **volatile arglist
= NULL
;
1504 enum modstatdb_rw msdbflags
;
1506 trigproc_install_hooks();
1509 msdbflags
= msdbrw_readonly
;
1510 else if (cipaction
->arg_int
== act_avail
)
1511 msdbflags
= msdbrw_readonly
| msdbrw_available_write
;
1512 else if (in_force(FORCE_NON_ROOT
))
1513 msdbflags
= msdbrw_write
;
1515 msdbflags
= msdbrw_needsuperuser
;
1517 modstatdb_open(msdbflags
);
1520 pkg_infodb_upgrade();
1522 log_message("startup archives %s", cipaction
->olong
);
1525 const char *const *ap
;
1529 badusage(_("--%s --recursive needs at least one path argument"),cipaction
->olong
);
1531 for (ap
= argv
; *ap
; ap
++) {
1532 struct treeroot
*tree
;
1533 struct treenode
*node
;
1535 tree
= treewalk_open((const char *)*ap
, TREEWALK_FOLLOW_LINKS
, NULL
);
1537 while ((node
= treewalk_next(tree
))) {
1538 const char *nodename
;
1540 if (!S_ISREG(treenode_get_mode(node
)))
1543 /* Check if it looks like a .deb file. */
1544 nodename
= treenode_get_pathname(node
);
1545 if (strcmp(nodename
+ strlen(nodename
) - 4, DEBEXT
) != 0)
1548 arglist
= m_realloc(arglist
, sizeof(char *) * (nfiles
+ 2));
1549 arglist
[nfiles
++] = m_strdup(nodename
);
1552 treewalk_close(tree
);
1556 ohshit(_("searched, but found no packages (files matching *.deb)"));
1558 arglist
[nfiles
] = NULL
;
1559 argp
= (const char **volatile)arglist
;
1561 if (!*argv
) badusage(_("--%s needs at least one package archive file argument"),
1566 /* Perform some sanity checks on the passed archives. */
1567 for (i
= 0; argp
[i
]; i
++) {
1570 /* We need the filename to exist. */
1571 if (stat(argp
[i
], &st
) < 0)
1572 ohshite(_("cannot access archive '%s'"), argp
[i
]);
1574 /* We cannot work with anything that is not a regular file. */
1575 if (!S_ISREG(st
.st_mode
))
1576 ohshit(_("archive '%s' is not a regular file"), argp
[i
]);
1579 currenttime
= time(NULL
);
1581 /* Initialize fname variables contents. */
1583 varbuf_reset(&fnamevb
);
1584 varbuf_reset(&fnametmpvb
);
1585 varbuf_reset(&fnamenewvb
);
1587 varbuf_add_str(&fnamevb
, dpkg_fsys_get_dir());
1588 varbuf_add_str(&fnametmpvb
, dpkg_fsys_get_dir());
1589 varbuf_add_str(&fnamenewvb
, dpkg_fsys_get_dir());
1591 varbuf_snapshot(&fnamevb
, &fname_state
);
1592 varbuf_snapshot(&fnametmpvb
, &fnametmp_state
);
1593 varbuf_snapshot(&fnamenewvb
, &fnamenew_state
);
1595 ensure_diversions();
1596 ensure_statoverrides(STATDB_PARSE_NORMAL
);
1598 for (i
= 0; argp
[i
]; i
++) {
1599 if (setjmp(ejbuf
)) {
1600 pop_error_context(ehflag_bombout
);
1601 if (abort_processing
)
1605 push_error_context_jump(&ejbuf
, print_error_perarchive
, argp
[i
]);
1607 dpkg_selabel_load();
1609 process_archive(argp
[i
]);
1611 m_output(stdout
, _("<standard output>"));
1612 m_output(stderr
, _("<standard error>"));
1615 pop_error_context(ehflag_normaltidy
);
1618 dpkg_selabel_close();
1621 for (i
= 0; arglist
[i
]; i
++)
1626 switch (cipaction
->arg_int
) {
1637 internerr("unknown action '%d'", cipaction
->arg_int
);
1640 trigproc_run_deferred();
1641 modstatdb_shutdown();
1647 * Decide whether we want to install a new version of the package.
1649 * @param pkg The package with the version we might want to install
1651 * @retval true If the package should be skipped.
1652 * @retval false If the package should be installed.
1655 wanttoinstall(struct pkginfo
*pkg
)
1659 if (pkg
->want
!= PKG_WANT_INSTALL
&& pkg
->want
!= PKG_WANT_HOLD
) {
1661 printf(_("Selecting previously unselected package %s.\n"),
1662 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1665 printf(_("Skipping unselected package %s.\n"),
1666 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1671 if (pkg
->eflag
& PKG_EFLAG_REINSTREQ
)
1673 if (pkg
->status
< PKG_STAT_UNPACKED
)
1676 rc
= dpkg_version_compare(&pkg
->available
.version
, &pkg
->installed
.version
);
1679 } else if (rc
== 0) {
1680 /* Same version fully installed. */
1681 if (f_skipsame
&& pkg
->available
.arch
== pkg
->installed
.arch
) {
1682 notice(_("version %.250s of %.250s already installed, skipping"),
1683 versiondescribe(&pkg
->installed
.version
, vdew_nonambig
),
1684 pkg_name(pkg
, pnaw_nonambig
));
1690 if (in_force(FORCE_DOWNGRADE
)) {
1691 warning(_("downgrading %.250s from %.250s to %.250s"),
1692 pkg_name(pkg
, pnaw_nonambig
),
1693 versiondescribe(&pkg
->installed
.version
, vdew_nonambig
),
1694 versiondescribe(&pkg
->available
.version
, vdew_nonambig
));
1697 notice(_("will not downgrade %.250s from %.250s to %.250s, skipping"),
1698 pkg_name(pkg
, pnaw_nonambig
),
1699 versiondescribe(&pkg
->installed
.version
, vdew_nonambig
),
1700 versiondescribe(&pkg
->available
.version
, vdew_nonambig
));