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>
42 #define obstack_chunk_alloc m_malloc
43 #define obstack_chunk_free free
45 #include <dpkg/i18n.h>
46 #include <dpkg/dpkg.h>
47 #include <dpkg/dpkg-db.h>
49 #include <dpkg/path.h>
50 #include <dpkg/fdio.h>
51 #include <dpkg/buffer.h>
52 #include <dpkg/subproc.h>
53 #include <dpkg/command.h>
54 #include <dpkg/file.h>
55 #include <dpkg/treewalk.h>
56 #include <dpkg/tarfn.h>
57 #include <dpkg/options.h>
58 #include <dpkg/triglib.h>
67 fd_writeback_init(int fd
)
69 /* Ignore the return code as it should be considered equivalent to an
70 * asynchronous hint for the kernel, we are doing an fsync() later on
72 #if defined(SYNC_FILE_RANGE_WRITE)
73 sync_file_range(fd
, 0, 0, SYNC_FILE_RANGE_WRITE
);
74 #elif defined(HAVE_POSIX_FADVISE)
75 posix_fadvise(fd
, 0, 0, POSIX_FADV_DONTNEED
);
79 static struct obstack tar_pool
;
80 static bool tar_pool_init
= false;
83 * Allocate memory from the tar memory pool.
86 tar_pool_alloc(size_t size
)
89 obstack_init(&tar_pool
);
93 return obstack_alloc(&tar_pool
, size
);
97 * Free memory from the tar memory pool.
100 tar_pool_free(void *ptr
)
102 obstack_free(&tar_pool
, ptr
);
106 * Release the tar memory pool.
109 tar_pool_release(void)
112 obstack_free(&tar_pool
, NULL
);
113 tar_pool_init
= false;
118 tar_filenamenode_queue_push(struct filenamenode_queue
*queue
,
119 struct filenamenode
*namenode
)
121 struct fileinlist
*node
;
123 node
= tar_pool_alloc(sizeof(*node
));
124 node
->namenode
= namenode
;
128 queue
->tail
= &node
->next
;
134 tar_filenamenode_queue_pop(struct filenamenode_queue
*queue
,
135 struct fileinlist
**tail_prev
,
136 struct fileinlist
*node
)
139 queue
->tail
= tail_prev
;
144 * Check if a file or directory will save a package from disappearance.
146 * A package can only be saved by a file or directory which is part
147 * only of itself - it must be neither part of the new package being
148 * installed nor part of any 3rd package (this is important so that
149 * shared directories don't stop packages from disappearing).
152 filesavespackage(struct fileinlist
*file
,
153 struct pkginfo
*pkgtobesaved
,
154 struct pkginfo
*pkgbeinginstalled
)
156 struct filepackages_iterator
*iter
;
157 struct pkgset
*divpkgset
;
158 struct pkginfo
*thirdpkg
;
160 debug(dbg_eachfiledetail
, "filesavespackage file '%s' package %s",
161 file
->namenode
->name
, pkg_name(pkgtobesaved
, pnaw_always
));
163 /* If the file is a contended one and it's overridden by either
164 * the package we're considering disappearing or the package
165 * we're installing then they're not actually the same file, so
166 * we can't disappear the package - it is saved by this file. */
167 if (file
->namenode
->divert
&& file
->namenode
->divert
->useinstead
) {
168 divpkgset
= file
->namenode
->divert
->pkgset
;
169 if (divpkgset
== pkgtobesaved
->set
|| divpkgset
== pkgbeinginstalled
->set
) {
170 debug(dbg_eachfiledetail
,"filesavespackage ... diverted -- save!");
174 /* Is the file in the package being installed? If so then it can't save. */
175 if (file
->namenode
->flags
& fnnf_new_inarchive
) {
176 debug(dbg_eachfiledetail
,"filesavespackage ... in new archive -- no save");
179 /* Look for a 3rd package which can take over the file (in case
180 * it's a directory which is shared by many packages. */
181 iter
= filepackages_iter_new(file
->namenode
);
182 while ((thirdpkg
= filepackages_iter_next(iter
))) {
183 debug(dbg_eachfiledetail
, "filesavespackage ... also in %s",
184 pkg_name(thirdpkg
, pnaw_always
));
186 /* Is this not the package being installed or the one being
187 * checked for disappearance? */
188 if (thirdpkg
== pkgbeinginstalled
|| thirdpkg
== pkgtobesaved
)
191 /* A Multi-Arch: same package can share files and their presence in a
192 * third package of the same set is not a sign that we can get rid of
194 if (pkgtobesaved
->installed
.multiarch
== PKG_MULTIARCH_SAME
&&
195 thirdpkg
->set
== pkgtobesaved
->set
)
198 /* If !fileslistvalid then we've already disappeared this one, so
199 * we shouldn't try to make it take over this shared directory. */
200 debug(dbg_eachfiledetail
,"filesavespackage ... is 3rd package");
202 if (!thirdpkg
->clientdata
->fileslistvalid
) {
203 debug(dbg_eachfiledetail
, "process_archive ... already disappeared!");
207 /* We've found a package that can take this file. */
208 debug(dbg_eachfiledetail
, "filesavespackage ... taken -- no save");
209 filepackages_iter_free(iter
);
212 filepackages_iter_free(iter
);
214 debug(dbg_eachfiledetail
, "filesavespackage ... not taken -- save !");
219 md5hash_prev_conffile(struct pkginfo
*pkg
, char *oldhash
, const char *oldname
,
220 struct filenamenode
*namenode
)
222 struct pkginfo
*otherpkg
;
223 struct conffile
*conff
;
225 debug(dbg_conffdetail
, "tarobject looking for shared conffile %s",
228 for (otherpkg
= &pkg
->set
->pkg
; otherpkg
; otherpkg
= otherpkg
->arch_next
) {
231 /* If we are reinstalling, even if the other package is only unpacked,
232 * we can always make use of the Conffiles hash value from an initial
233 * installation, if that happened at all. */
234 if (otherpkg
->status
<= PKG_STAT_UNPACKED
&&
235 dpkg_version_compare(&otherpkg
->installed
.version
,
236 &otherpkg
->configversion
) != 0)
238 for (conff
= otherpkg
->installed
.conffiles
; conff
; conff
= conff
->next
) {
241 if (strcmp(conff
->name
, namenode
->name
) == 0)
245 strcpy(oldhash
, conff
->hash
);
246 debug(dbg_conffdetail
,
247 "tarobject found shared conffile, from pkg %s (%s); hash=%s",
248 pkg_name(otherpkg
, pnaw_always
),
249 pkg_status_name(otherpkg
), oldhash
);
254 /* If no package was found with a valid Conffiles field, we make the
255 * risky assumption that the hash of the current .dpkg-new file is
256 * the one of the previously unpacked package. */
257 if (otherpkg
== NULL
) {
258 md5hash(pkg
, oldhash
, oldname
);
259 debug(dbg_conffdetail
,
260 "tarobject found shared conffile, from disk; hash=%s", oldhash
);
264 void cu_pathname(int argc
, void **argv
) {
265 path_remove_tree((char*)(argv
[0]));
268 int tarfileread(void *ud
, char *buf
, int len
) {
269 struct tarcontext
*tc
= (struct tarcontext
*)ud
;
272 r
= fd_read(tc
->backendpipe
, buf
, len
);
274 ohshite(_("error reading from dpkg-deb pipe"));
279 tarobject_skip_padding(struct tarcontext
*tc
, struct tar_entry
*te
)
281 struct dpkg_error err
;
284 r
= te
->size
% TARBLKSZ
;
288 if (fd_skip(tc
->backendpipe
, TARBLKSZ
- r
, &err
) < 0)
289 ohshit(_("cannot skip padding for file '%.255s': %s"), te
->name
, err
.str
);
293 tarobject_skip_entry(struct tarcontext
*tc
, struct tar_entry
*ti
)
295 /* We need to advance the tar file to the next object, so read the
296 * file data and set it to oblivion. */
297 if (ti
->type
== TAR_FILETYPE_FILE
) {
298 struct dpkg_error err
;
301 if (fd_skip(tc
->backendpipe
, ti
->size
, &err
) < 0)
302 ohshit(_("cannot skip file '%.255s' (replaced or excluded?) from pipe: %s"),
303 path_quote_filename(fnamebuf
, ti
->name
, 256), err
.str
);
304 tarobject_skip_padding(tc
, ti
);
308 struct varbuf_state fname_state
;
309 struct varbuf fnamevb
;
310 struct varbuf fnametmpvb
;
311 struct varbuf fnamenewvb
;
312 struct pkg_deconf_list
*deconfigure
= NULL
;
314 static time_t currenttime
;
317 does_replace(struct pkginfo
*new_pkg
, struct pkgbin
*new_pkgbin
,
318 struct pkginfo
*old_pkg
, struct pkgbin
*old_pkgbin
)
320 struct dependency
*dep
;
322 debug(dbg_depcon
,"does_replace new=%s old=%s (%s)",
323 pkgbin_name(new_pkg
, new_pkgbin
, pnaw_always
),
324 pkgbin_name(old_pkg
, old_pkgbin
, pnaw_always
),
325 versiondescribe(&old_pkgbin
->version
, vdew_always
));
326 for (dep
= new_pkgbin
->depends
; dep
; dep
= dep
->next
) {
327 if (dep
->type
!= dep_replaces
|| dep
->list
->ed
!= old_pkg
->set
)
329 debug(dbg_depcondetail
,"does_replace ... found old, version %s",
330 versiondescribe(&dep
->list
->version
,vdew_always
));
331 if (!versionsatisfied(old_pkgbin
, dep
->list
))
333 /* The test below can only trigger if dep_replaces start having
334 * arch qualifiers different from “any”. */
335 if (!archsatisfied(old_pkgbin
, dep
->list
))
337 debug(dbg_depcon
,"does_replace ... yes");
340 debug(dbg_depcon
,"does_replace ... no");
345 tarobject_extract(struct tarcontext
*tc
, struct tar_entry
*te
,
346 const char *path
, struct file_stat
*st
,
347 struct filenamenode
*namenode
)
349 static struct varbuf hardlinkfn
;
352 struct dpkg_error err
;
353 struct filenamenode
*linknode
;
355 char fnamenewbuf
[256];
359 case TAR_FILETYPE_FILE
:
360 /* We create the file with mode 0 to make sure nobody can do anything with
361 * it until we apply the proper mode, which might be a statoverride. */
362 fd
= open(path
, O_CREAT
| O_EXCL
| O_WRONLY
, 0);
364 ohshite(_("unable to create '%.255s' (while processing '%.255s')"),
366 push_cleanup(cu_closefd
, ehflag_bombout
, NULL
, 0, 1, &fd
);
367 debug(dbg_eachfiledetail
, "tarobject file open size=%jd",
370 /* We try to tell the filesystem how much disk space we are going to
371 * need to let it reduce fragmentation and possibly improve performance,
372 * as we do know the size beforehand. */
373 fd_allocate_size(fd
, 0, te
->size
);
375 newhash
= nfmalloc(MD5HASHLEN
+ 1);
376 if (fd_fd_copy_and_md5(tc
->backendpipe
, fd
, newhash
, te
->size
, &err
) < 0)
377 ohshit(_("cannot copy extracted data for '%.255s' to '%.255s': %s"),
378 path_quote_filename(fnamebuf
, te
->name
, 256),
379 path_quote_filename(fnamenewbuf
, fnamenewvb
.buf
, 256), err
.str
);
380 namenode
->newhash
= newhash
;
381 debug(dbg_eachfiledetail
, "tarobject file hash=%s", namenode
->newhash
);
383 tarobject_skip_padding(tc
, te
);
385 fd_writeback_init(fd
);
387 if (namenode
->statoverride
)
388 debug(dbg_eachfile
, "tarobject ... stat override, uid=%d, gid=%d, mode=%04o",
389 namenode
->statoverride
->uid
,
390 namenode
->statoverride
->gid
,
391 namenode
->statoverride
->mode
);
392 if (fchown(fd
, st
->uid
, st
->gid
))
393 ohshite(_("error setting ownership of '%.255s'"), te
->name
);
394 if (fchmod(fd
, st
->mode
& ~S_IFMT
))
395 ohshite(_("error setting permissions of '%.255s'"), te
->name
);
397 /* Postpone the fsync, to try to avoid massive I/O degradation. */
399 namenode
->flags
|= fnnf_deferred_fsync
;
401 pop_cleanup(ehflag_normaltidy
); /* fd = open(path) */
403 ohshite(_("error closing/writing '%.255s'"), te
->name
);
405 case TAR_FILETYPE_FIFO
:
407 ohshite(_("error creating pipe '%.255s'"), te
->name
);
408 debug(dbg_eachfiledetail
, "tarobject fifo");
410 case TAR_FILETYPE_CHARDEV
:
411 if (mknod(path
, S_IFCHR
, te
->dev
))
412 ohshite(_("error creating device '%.255s'"), te
->name
);
413 debug(dbg_eachfiledetail
, "tarobject chardev");
415 case TAR_FILETYPE_BLOCKDEV
:
416 if (mknod(path
, S_IFBLK
, te
->dev
))
417 ohshite(_("error creating device '%.255s'"), te
->name
);
418 debug(dbg_eachfiledetail
, "tarobject blockdev");
420 case TAR_FILETYPE_HARDLINK
:
421 varbuf_reset(&hardlinkfn
);
422 varbuf_add_str(&hardlinkfn
, instdir
);
423 linknode
= findnamenode(te
->linkname
, 0);
424 varbuf_add_str(&hardlinkfn
,
425 namenodetouse(linknode
, tc
->pkg
, &tc
->pkg
->available
)->name
);
426 if (linknode
->flags
& (fnnf_deferred_rename
| fnnf_new_conff
))
427 varbuf_add_str(&hardlinkfn
, DPKGNEWEXT
);
428 varbuf_end_str(&hardlinkfn
);
429 if (link(hardlinkfn
.buf
, path
))
430 ohshite(_("error creating hard link '%.255s'"), te
->name
);
431 namenode
->newhash
= linknode
->newhash
;
432 debug(dbg_eachfiledetail
, "tarobject hardlink hash=%s", namenode
->newhash
);
434 case TAR_FILETYPE_SYMLINK
:
435 /* We've already checked for an existing directory. */
436 if (symlink(te
->linkname
, path
))
437 ohshite(_("error creating symbolic link '%.255s'"), te
->name
);
438 debug(dbg_eachfiledetail
, "tarobject symlink creating");
440 case TAR_FILETYPE_DIR
:
441 /* We've already checked for an existing directory. */
443 ohshite(_("error creating directory '%.255s'"), te
->name
);
444 debug(dbg_eachfiledetail
, "tarobject directory creating");
447 internerr("unknown tar type '%d', but already checked", te
->type
);
452 tarobject_hash(struct tarcontext
*tc
, struct tar_entry
*te
,
453 struct filenamenode
*namenode
)
455 if (te
->type
== TAR_FILETYPE_FILE
) {
456 struct dpkg_error err
;
460 newhash
= nfmalloc(MD5HASHLEN
+ 1);
461 if (fd_md5(tc
->backendpipe
, newhash
, te
->size
, &err
) < 0)
462 ohshit(_("cannot compute MD5 hash for tar file '%.255s': %s"),
463 path_quote_filename(fnamebuf
, te
->name
, 256), err
.str
);
464 tarobject_skip_padding(tc
, te
);
466 namenode
->newhash
= newhash
;
467 debug(dbg_eachfiledetail
, "tarobject file hash=%s", namenode
->newhash
);
468 } else if (te
->type
== TAR_FILETYPE_HARDLINK
) {
469 struct filenamenode
*linknode
;
471 linknode
= findnamenode(te
->linkname
, 0);
472 namenode
->newhash
= linknode
->newhash
;
473 debug(dbg_eachfiledetail
, "tarobject hardlink hash=%s", namenode
->newhash
);
478 tarobject_set_mtime(struct tar_entry
*te
, const char *path
)
480 struct timeval tv
[2];
482 tv
[0].tv_sec
= currenttime
;
484 tv
[1].tv_sec
= te
->mtime
;
487 if (te
->type
== TAR_FILETYPE_SYMLINK
) {
489 if (lutimes(path
, tv
) && errno
!= ENOSYS
)
490 ohshite(_("error setting timestamps of '%.255s'"), path
);
493 if (utimes(path
, tv
))
494 ohshite(_("error setting timestamps of '%.255s'"), path
);
499 tarobject_set_perms(struct tar_entry
*te
, const char *path
, struct file_stat
*st
)
501 if (te
->type
== TAR_FILETYPE_FILE
)
502 return; /* Already handled using the file descriptor. */
504 if (te
->type
== TAR_FILETYPE_SYMLINK
) {
505 if (lchown(path
, st
->uid
, st
->gid
))
506 ohshite(_("error setting ownership of symlink '%.255s'"), path
);
508 if (chown(path
, st
->uid
, st
->gid
))
509 ohshite(_("error setting ownership of '%.255s'"), path
);
510 if (chmod(path
, st
->mode
& ~S_IFMT
))
511 ohshite(_("error setting permissions of '%.255s'"), path
);
516 tarobject_set_se_context(const char *matchpath
, const char *path
, mode_t mode
)
518 dpkg_selabel_set_context(matchpath
, path
, mode
);
522 tarobject_matches(struct tarcontext
*tc
,
523 const char *fn_old
, struct stat
*stab
, char *oldhash
,
524 const char *fn_new
, struct tar_entry
*te
,
525 struct filenamenode
*namenode
)
530 debug(dbg_eachfiledetail
, "tarobject matches on-disk object?");
533 case TAR_FILETYPE_DIR
:
534 /* Nothing to check for a new directory. */
536 case TAR_FILETYPE_SYMLINK
:
537 /* Symlinks to existing dirs have already been dealt with, only
538 * remain real symlinks where we can compare the target. */
539 if (!S_ISLNK(stab
->st_mode
))
541 linkname
= m_malloc(stab
->st_size
+ 1);
542 linksize
= readlink(fn_old
, linkname
, stab
->st_size
+ 1);
544 ohshite(_("unable to read link '%.255s'"), fn_old
);
545 else if (linksize
> stab
->st_size
)
546 ohshit(_("symbolic link '%.250s' size has changed from %jd to %zd"),
547 fn_old
, (intmax_t)stab
->st_size
, linksize
);
548 else if (linksize
< stab
->st_size
)
549 warning(_("symbolic link '%.250s' size has changed from %jd to %zd"),
550 fn_old
, (intmax_t)stab
->st_size
, linksize
);
551 linkname
[linksize
] = '\0';
552 if (strcmp(linkname
, te
->linkname
) == 0) {
559 case TAR_FILETYPE_CHARDEV
:
560 if (S_ISCHR(stab
->st_mode
) && stab
->st_rdev
== te
->dev
)
563 case TAR_FILETYPE_BLOCKDEV
:
564 if (S_ISBLK(stab
->st_mode
) && stab
->st_rdev
== te
->dev
)
567 case TAR_FILETYPE_FIFO
:
568 if (S_ISFIFO(stab
->st_mode
))
571 case TAR_FILETYPE_HARDLINK
:
573 case TAR_FILETYPE_FILE
:
574 /* Only check metadata for non-conffiles. */
575 if (!(namenode
->flags
& fnnf_new_conff
) &&
576 !(S_ISREG(stab
->st_mode
) && te
->size
== stab
->st_size
))
578 if (strcmp(oldhash
, namenode
->newhash
) == 0)
582 internerr("unknown tar type '%d', but already checked", te
->type
);
585 forcibleerr(fc_overwrite
,
586 _("trying to overwrite shared '%.250s', which is different "
587 "from other instances of package %.250s"),
588 namenode
->name
, pkg_name(tc
->pkg
, pnaw_nonambig
));
591 void setupfnamevbs(const char *filename
) {
592 varbuf_rollback(&fnamevb
, &fname_state
);
593 varbuf_add_str(&fnamevb
, filename
);
594 varbuf_end_str(&fnamevb
);
596 varbuf_rollback(&fnametmpvb
, &fname_state
);
597 varbuf_add_str(&fnametmpvb
, filename
);
598 varbuf_add_str(&fnametmpvb
, DPKGTEMPEXT
);
599 varbuf_end_str(&fnametmpvb
);
601 varbuf_rollback(&fnamenewvb
, &fname_state
);
602 varbuf_add_str(&fnamenewvb
, filename
);
603 varbuf_add_str(&fnamenewvb
, DPKGNEWEXT
);
604 varbuf_end_str(&fnamenewvb
);
606 debug(dbg_eachfiledetail
, "setupvnamevbs main='%s' tmp='%s' new='%s'",
607 fnamevb
.buf
, fnametmpvb
.buf
, fnamenewvb
.buf
);
611 linktosameexistingdir(const struct tar_entry
*ti
, const char *fname
,
612 struct varbuf
*symlinkfn
)
614 struct stat oldstab
, newstab
;
616 const char *lastslash
;
618 statr
= stat(fname
, &oldstab
);
620 if (!(errno
== ENOENT
|| errno
== ELOOP
|| errno
== ENOTDIR
))
621 ohshite(_("failed to stat (dereference) existing symlink '%.250s'"),
625 if (!S_ISDIR(oldstab
.st_mode
))
628 /* But is it to the same dir? */
629 varbuf_reset(symlinkfn
);
630 if (ti
->linkname
[0] == '/') {
631 varbuf_add_str(symlinkfn
, instdir
);
633 lastslash
= strrchr(fname
, '/');
635 varbuf_add_buf(symlinkfn
, fname
, (lastslash
- fname
) + 1);
637 varbuf_add_str(symlinkfn
, ti
->linkname
);
638 varbuf_end_str(symlinkfn
);
640 statr
= stat(symlinkfn
->buf
, &newstab
);
642 if (!(errno
== ENOENT
|| errno
== ELOOP
|| errno
== ENOTDIR
))
643 ohshite(_("failed to stat (dereference) proposed new symlink target"
644 " '%.250s' for symlink '%.250s'"), symlinkfn
->buf
, fname
);
647 if (!S_ISDIR(newstab
.st_mode
))
649 if (newstab
.st_dev
!= oldstab
.st_dev
||
650 newstab
.st_ino
!= oldstab
.st_ino
)
656 tarobject(void *ctx
, struct tar_entry
*ti
)
658 static struct varbuf conffderefn
, symlinkfn
;
660 struct filenamenode
*usenode
;
662 struct conffile
*conff
;
663 struct tarcontext
*tc
= ctx
;
664 bool existingdir
, keepexisting
;
666 char oldhash
[MD5HASHLEN
+ 1];
669 struct stat stab
, stabtmp
;
670 struct file_stat nodestat
;
671 struct fileinlist
*nifd
, **oldnifd
;
672 struct pkgset
*divpkgset
;
673 struct pkginfo
*otherpkg
;
675 tar_entry_update_from_system(ti
);
677 /* Perform some sanity checks on the tar entry. */
678 if (strchr(ti
->name
, '\n'))
679 ohshit(_("newline not allowed in archive object name '%.255s'"), ti
->name
);
681 /* Append to list of files.
682 * The trailing ‘/’ put on the end of names in tarfiles has already
683 * been stripped by tar_extractor(). */
684 oldnifd
= tc
->newfiles_queue
->tail
;
685 nifd
= tar_filenamenode_queue_push(tc
->newfiles_queue
,
686 findnamenode(ti
->name
, 0));
687 nifd
->namenode
->flags
|= fnnf_new_inarchive
;
690 "tarobject ti->name='%s' mode=%lo owner=%u:%u type=%d(%c)"
691 " ti->linkname='%s' namenode='%s' flags=%o instead='%s'",
692 ti
->name
, (long)ti
->stat
.mode
,
693 (unsigned)ti
->stat
.uid
, (unsigned)ti
->stat
.gid
,
695 ti
->type
>= '0' && ti
->type
<= '6' ?
"-hlcbdp"[ti
->type
- '0'] : '?',
697 nifd
->namenode
->name
, nifd
->namenode
->flags
,
698 nifd
->namenode
->divert
&& nifd
->namenode
->divert
->useinstead
699 ? nifd
->namenode
->divert
->useinstead
->name
: "<none>");
701 if (nifd
->namenode
->divert
&& nifd
->namenode
->divert
->camefrom
) {
702 divpkgset
= nifd
->namenode
->divert
->pkgset
;
705 forcibleerr(fc_overwritediverted
,
706 _("trying to overwrite '%.250s', which is the "
707 "diverted version of '%.250s' (package: %.100s)"),
708 nifd
->namenode
->name
, nifd
->namenode
->divert
->camefrom
->name
,
711 forcibleerr(fc_overwritediverted
,
712 _("trying to overwrite '%.250s', which is the "
713 "diverted version of '%.250s'"),
714 nifd
->namenode
->name
, nifd
->namenode
->divert
->camefrom
->name
);
718 if (nifd
->namenode
->statoverride
) {
719 nodestat
= *nifd
->namenode
->statoverride
;
720 nodestat
.mode
|= ti
->stat
.mode
& S_IFMT
;
725 usenode
= namenodetouse(nifd
->namenode
, tc
->pkg
, &tc
->pkg
->available
);
726 usename
= usenode
->name
;
728 trig_file_activate(usenode
, tc
->pkg
);
730 if (nifd
->namenode
->flags
& fnnf_new_conff
) {
731 /* If it's a conffile we have to extract it next to the installed
732 * version (i.e. we do the usual link-following). */
733 if (conffderef(tc
->pkg
, &conffderefn
, usename
))
734 usename
= conffderefn
.buf
;
735 debug(dbg_conff
, "tarobject fnnf_new_conff deref='%s'", usename
);
738 setupfnamevbs(usename
);
740 statr
= lstat(fnamevb
.buf
,&stab
);
742 /* The lstat failed. */
743 if (errno
!= ENOENT
&& errno
!= ENOTDIR
)
744 ohshite(_("unable to stat '%.255s' (which I was about to install)"),
746 /* OK, so it doesn't exist.
747 * However, it's possible that we were in the middle of some other
748 * backup/restore operation and were rudely interrupted.
749 * So, we see if we have .dpkg-tmp, and if so we restore it. */
750 if (rename(fnametmpvb
.buf
,fnamevb
.buf
)) {
751 if (errno
!= ENOENT
&& errno
!= ENOTDIR
)
752 ohshite(_("unable to clean up mess surrounding '%.255s' before "
753 "installing another version"), ti
->name
);
754 debug(dbg_eachfiledetail
,"tarobject nonexistent");
756 debug(dbg_eachfiledetail
,"tarobject restored tmp to main");
757 statr
= lstat(fnamevb
.buf
,&stab
);
759 ohshite(_("unable to stat restored '%.255s' before installing"
760 " another version"), ti
->name
);
763 debug(dbg_eachfiledetail
,"tarobject already exists");
766 /* Check to see if it's a directory or link to one and we don't need to
767 * do anything. This has to be done now so that we don't die due to
768 * a file overwriting conflict. */
771 case TAR_FILETYPE_SYMLINK
:
772 /* If it's already an existing directory, do nothing. */
773 if (!statr
&& S_ISDIR(stab
.st_mode
)) {
774 debug(dbg_eachfiledetail
, "tarobject symlink exists as directory");
776 } else if (!statr
&& S_ISLNK(stab
.st_mode
)) {
777 if (linktosameexistingdir(ti
, fnamevb
.buf
, &symlinkfn
))
781 case TAR_FILETYPE_DIR
:
782 /* If it's already an existing directory, do nothing. */
783 if (!stat(fnamevb
.buf
,&stabtmp
) && S_ISDIR(stabtmp
.st_mode
)) {
784 debug(dbg_eachfiledetail
, "tarobject directory exists");
788 case TAR_FILETYPE_FILE
:
789 case TAR_FILETYPE_CHARDEV
:
790 case TAR_FILETYPE_BLOCKDEV
:
791 case TAR_FILETYPE_FIFO
:
792 case TAR_FILETYPE_HARDLINK
:
795 ohshit(_("archive contained object '%.255s' of unknown type 0x%x"),
799 keepexisting
= false;
802 struct filepackages_iterator
*iter
;
804 iter
= filepackages_iter_new(nifd
->namenode
);
805 while ((otherpkg
= filepackages_iter_next(iter
))) {
806 if (otherpkg
== tc
->pkg
)
808 debug(dbg_eachfile
, "tarobject ... found in %s",
809 pkg_name(otherpkg
, pnaw_always
));
811 /* A pkgset can share files between its instances. Overwriting
812 * is allowed when they are not getting in sync, otherwise the
813 * file content must match the installed file. */
814 if (otherpkg
->set
== tc
->pkg
->set
&&
815 otherpkg
->installed
.multiarch
== PKG_MULTIARCH_SAME
&&
816 tc
->pkg
->available
.multiarch
== PKG_MULTIARCH_SAME
) {
817 if (statr
== 0 && tc
->pkgset_getting_in_sync
)
819 debug(dbg_eachfiledetail
, "tarobject ... shared with %s %s (syncing=%d)",
820 pkg_name(otherpkg
, pnaw_always
),
821 versiondescribe(&otherpkg
->installed
.version
, vdew_nonambig
),
822 tc
->pkgset_getting_in_sync
);
826 if (nifd
->namenode
->divert
&& nifd
->namenode
->divert
->useinstead
) {
827 /* Right, so we may be diverting this file. This makes the conflict
828 * OK iff one of us is the diverting package (we don't need to
829 * check for both being the diverting package, obviously). */
830 divpkgset
= nifd
->namenode
->divert
->pkgset
;
831 debug(dbg_eachfile
, "tarobject ... diverted, divpkgset=%s",
832 divpkgset ? divpkgset
->name
: "<none>");
833 if (otherpkg
->set
== divpkgset
|| tc
->pkg
->set
== divpkgset
)
837 /* If the new object is a directory and the previous object does
838 * not exist assume it's also a directory and skip further checks.
839 * XXX: Ideally with more information about the installed files we
840 * could perform more clever checks. */
841 if (statr
!= 0 && ti
->type
== TAR_FILETYPE_DIR
) {
842 debug(dbg_eachfile
, "tarobject ... assuming shared directory");
846 /* Nope? Hmm, file conflict, perhaps. Check Replaces. */
847 switch (otherpkg
->clientdata
->replacingfilesandsaid
) {
855 /* Is the package with the conflicting file in the “config files only”
856 * state? If so it must be a config file and we can silently take it
858 if (otherpkg
->status
== PKG_STAT_CONFIGFILES
)
861 /* Perhaps we're removing a conflicting package? */
862 if (otherpkg
->clientdata
->istobe
== PKG_ISTOBE_REMOVE
)
865 /* Is the file an obsolete conffile in the other package
866 * and a conffile in the new package? */
867 if ((nifd
->namenode
->flags
& fnnf_new_conff
) &&
868 !statr
&& S_ISREG(stab
.st_mode
)) {
869 for (conff
= otherpkg
->installed
.conffiles
;
871 conff
= conff
->next
) {
872 if (!conff
->obsolete
)
874 if (strcmp(conff
->name
, nifd
->namenode
->name
) == 0)
878 debug(dbg_eachfiledetail
, "tarobject other's obsolete conffile");
879 /* process_archive() will have copied its hash already. */
884 if (does_replace(tc
->pkg
, &tc
->pkg
->available
,
885 otherpkg
, &otherpkg
->installed
)) {
886 printf(_("Replacing files in old package %s (%s) ...\n"),
887 pkg_name(otherpkg
, pnaw_nonambig
),
888 versiondescribe(&otherpkg
->installed
.version
, vdew_nonambig
));
889 otherpkg
->clientdata
->replacingfilesandsaid
= 1;
890 } else if (does_replace(otherpkg
, &otherpkg
->installed
,
891 tc
->pkg
, &tc
->pkg
->available
)) {
892 printf(_("Replaced by files in installed package %s (%s) ...\n"),
893 pkg_name(otherpkg
, pnaw_nonambig
),
894 versiondescribe(&otherpkg
->installed
.version
, vdew_nonambig
));
895 otherpkg
->clientdata
->replacingfilesandsaid
= 2;
896 nifd
->namenode
->flags
&= ~fnnf_new_inarchive
;
899 /* At this point we are replacing something without a Replaces. */
900 if (!statr
&& S_ISDIR(stab
.st_mode
)) {
901 forcibleerr(fc_overwritedir
,
902 _("trying to overwrite directory '%.250s' "
903 "in package %.250s %.250s with nondirectory"),
904 nifd
->namenode
->name
, pkg_name(otherpkg
, pnaw_nonambig
),
905 versiondescribe(&otherpkg
->installed
.version
,
908 forcibleerr(fc_overwrite
,
909 _("trying to overwrite '%.250s', "
910 "which is also in package %.250s %.250s"),
911 nifd
->namenode
->name
, pkg_name(otherpkg
, pnaw_nonambig
),
912 versiondescribe(&otherpkg
->installed
.version
,
917 filepackages_iter_free(iter
);
921 if (nifd
->namenode
->flags
& fnnf_new_conff
)
922 nifd
->namenode
->flags
|= fnnf_obs_conff
;
923 tar_filenamenode_queue_pop(tc
->newfiles_queue
, oldnifd
, nifd
);
924 tarobject_skip_entry(tc
, ti
);
928 if (filter_should_skip(ti
)) {
929 nifd
->namenode
->flags
&= ~fnnf_new_inarchive
;
930 nifd
->namenode
->flags
|= fnnf_filtered
;
931 tarobject_skip_entry(tc
, ti
);
939 /* Compute the hash of the previous object, before we might replace it
940 * with the new version on forced overwrites. */
942 debug(dbg_eachfiledetail
, "tarobject hashing on-disk file '%s', refcounting",
944 if (nifd
->namenode
->flags
& fnnf_new_conff
) {
945 md5hash_prev_conffile(tc
->pkg
, oldhash
, fnamenewvb
.buf
, nifd
->namenode
);
946 } else if (S_ISREG(stab
.st_mode
)) {
947 md5hash(tc
->pkg
, oldhash
, fnamevb
.buf
);
949 strcpy(oldhash
, EMPTYHASHFLAG
);
953 if (refcounting
&& !fc_overwrite
) {
954 /* If we are not forced to overwrite the path and are refcounting,
955 * just compute the hash w/o extracting the object. */
956 tarobject_hash(tc
, ti
, nifd
->namenode
);
958 /* Now, at this stage we want to make sure neither of .dpkg-new and
959 * .dpkg-tmp are hanging around. */
960 path_remove_tree(fnamenewvb
.buf
);
961 path_remove_tree(fnametmpvb
.buf
);
963 /* Now we start to do things that we need to be able to undo
964 * if something goes wrong. Watch out for the CLEANUP comments to
965 * keep an eye on what's installed on the disk at each point. */
966 push_cleanup(cu_installnew
, ~ehflag_normaltidy
, NULL
, 0, 1, nifd
->namenode
);
969 * CLEANUP: Now we either have the old file on the disk, or not, in
970 * its original filename.
973 /* Extract whatever it is as .dpkg-new ... */
974 tarobject_extract(tc
, ti
, fnamenewvb
.buf
, &nodestat
, nifd
->namenode
);
977 /* For shared files, check now if the object matches. */
979 tarobject_matches(tc
, fnamevb
.buf
, &stab
, oldhash
,
980 fnamenewvb
.buf
, ti
, nifd
->namenode
);
982 /* If we didn't extract anything, there's nothing else to do. */
983 if (refcounting
&& !fc_overwrite
)
986 tarobject_set_perms(ti
, fnamenewvb
.buf
, &nodestat
);
987 tarobject_set_mtime(ti
, fnamenewvb
.buf
);
988 tarobject_set_se_context(fnamevb
.buf
, fnamenewvb
.buf
, nodestat
.mode
);
991 * CLEANUP: Now we have extracted the new object in .dpkg-new (or,
992 * if the file already exists as a directory and we were trying to
993 * extract a directory or symlink, we returned earlier, so we don't
994 * need to worry about that here).
996 * The old file is still in the original filename,
999 /* First, check to see if it's a conffile. If so we don't install
1000 * it now - we leave it in .dpkg-new for --configure to take care of. */
1001 if (nifd
->namenode
->flags
& fnnf_new_conff
) {
1002 debug(dbg_conffdetail
,"tarobject conffile extracted");
1003 nifd
->namenode
->flags
|= fnnf_elide_other_lists
;
1007 /* Now we move the old file out of the way, the backup file will
1008 * be deleted later. */
1010 /* Don't try to back it up if it didn't exist. */
1011 debug(dbg_eachfiledetail
,"tarobject new - no backup");
1013 if (ti
->type
== TAR_FILETYPE_DIR
|| S_ISDIR(stab
.st_mode
)) {
1014 /* One of the two is a directory - can't do atomic install. */
1015 debug(dbg_eachfiledetail
,"tarobject directory, nonatomic");
1016 nifd
->namenode
->flags
|= fnnf_no_atomic_overwrite
;
1017 if (rename(fnamevb
.buf
,fnametmpvb
.buf
))
1018 ohshite(_("unable to move aside '%.255s' to install new version"),
1020 } else if (S_ISLNK(stab
.st_mode
)) {
1021 /* We can't make a symlink with two hardlinks, so we'll have to
1022 * copy it. (Pretend that making a copy of a symlink is the same
1023 * as linking to it.) */
1024 varbuf_reset(&symlinkfn
);
1025 varbuf_grow(&symlinkfn
, stab
.st_size
+ 1);
1026 r
= readlink(fnamevb
.buf
, symlinkfn
.buf
, symlinkfn
.size
);
1028 ohshite(_("unable to read link '%.255s'"), ti
->name
);
1029 else if (r
> stab
.st_size
)
1030 ohshit(_("symbolic link '%.250s' size has changed from %jd to %zd"),
1031 fnamevb
.buf
, (intmax_t)stab
.st_size
, r
);
1032 else if (r
< stab
.st_size
)
1033 warning(_("symbolic link '%.250s' size has changed from %jd to %zd"),
1034 fnamevb
.buf
, (intmax_t)stab
.st_size
, r
);
1035 varbuf_trunc(&symlinkfn
, r
);
1036 varbuf_end_str(&symlinkfn
);
1037 if (symlink(symlinkfn
.buf
,fnametmpvb
.buf
))
1038 ohshite(_("unable to make backup symlink for '%.255s'"), ti
->name
);
1039 if (lchown(fnametmpvb
.buf
,stab
.st_uid
,stab
.st_gid
))
1040 ohshite(_("unable to chown backup symlink for '%.255s'"), ti
->name
);
1041 tarobject_set_se_context(fnamevb
.buf
, fnametmpvb
.buf
, stab
.st_mode
);
1043 debug(dbg_eachfiledetail
, "tarobject nondirectory, 'link' backup");
1044 if (link(fnamevb
.buf
,fnametmpvb
.buf
))
1045 ohshite(_("unable to make backup link of '%.255s' before installing new version"),
1051 * CLEANUP: Now the old file is in .dpkg-tmp, and the new file is still
1055 if (ti
->type
== TAR_FILETYPE_FILE
|| ti
->type
== TAR_FILETYPE_HARDLINK
||
1056 ti
->type
== TAR_FILETYPE_SYMLINK
) {
1057 nifd
->namenode
->flags
|= fnnf_deferred_rename
;
1059 debug(dbg_eachfiledetail
, "tarobject done and installation deferred");
1061 if (rename(fnamenewvb
.buf
, fnamevb
.buf
))
1062 ohshite(_("unable to install new version of '%.255s'"), ti
->name
);
1065 * CLEANUP: Now the new file is in the destination file, and the
1066 * old file is in .dpkg-tmp to be cleaned up later. We now need
1067 * to take a different attitude to cleanup, because we need to
1068 * remove the new file.
1071 nifd
->namenode
->flags
|= fnnf_placed_on_disk
;
1072 nifd
->namenode
->flags
|= fnnf_elide_other_lists
;
1074 debug(dbg_eachfiledetail
, "tarobject done and installed");
1080 #if defined(SYNC_FILE_RANGE_WAIT_BEFORE)
1082 tar_writeback_barrier(struct fileinlist
*files
, struct pkginfo
*pkg
)
1084 struct fileinlist
*cfile
;
1086 for (cfile
= files
; cfile
; cfile
= cfile
->next
) {
1087 struct filenamenode
*usenode
;
1090 if (!(cfile
->namenode
->flags
& fnnf_deferred_fsync
))
1093 usenode
= namenodetouse(cfile
->namenode
, pkg
, &pkg
->available
);
1095 setupfnamevbs(usenode
->name
);
1097 fd
= open(fnamenewvb
.buf
, O_WRONLY
);
1099 ohshite(_("unable to open '%.255s'"), fnamenewvb
.buf
);
1100 /* Ignore the return code as it should be considered equivalent to an
1101 * asynchronous hint for the kernel, we are doing an fsync() later on
1103 sync_file_range(fd
, 0, 0, SYNC_FILE_RANGE_WAIT_BEFORE
);
1105 ohshite(_("error closing/writing '%.255s'"), fnamenewvb
.buf
);
1110 tar_writeback_barrier(struct fileinlist
*files
, struct pkginfo
*pkg
)
1116 tar_deferred_extract(struct fileinlist
*files
, struct pkginfo
*pkg
)
1118 struct fileinlist
*cfile
;
1119 struct filenamenode
*usenode
;
1121 tar_writeback_barrier(files
, pkg
);
1123 for (cfile
= files
; cfile
; cfile
= cfile
->next
) {
1124 debug(dbg_eachfile
, "deferred extract of '%.255s'", cfile
->namenode
->name
);
1126 if (!(cfile
->namenode
->flags
& fnnf_deferred_rename
))
1129 usenode
= namenodetouse(cfile
->namenode
, pkg
, &pkg
->available
);
1131 setupfnamevbs(usenode
->name
);
1133 if (cfile
->namenode
->flags
& fnnf_deferred_fsync
) {
1136 debug(dbg_eachfiledetail
, "deferred extract needs fsync");
1138 fd
= open(fnamenewvb
.buf
, O_WRONLY
);
1140 ohshite(_("unable to open '%.255s'"), fnamenewvb
.buf
);
1142 ohshite(_("unable to sync file '%.255s'"), fnamenewvb
.buf
);
1144 ohshite(_("error closing/writing '%.255s'"), fnamenewvb
.buf
);
1146 cfile
->namenode
->flags
&= ~fnnf_deferred_fsync
;
1149 debug(dbg_eachfiledetail
, "deferred extract needs rename");
1151 if (rename(fnamenewvb
.buf
, fnamevb
.buf
))
1152 ohshite(_("unable to install new version of '%.255s'"),
1153 cfile
->namenode
->name
);
1155 cfile
->namenode
->flags
&= ~fnnf_deferred_rename
;
1158 * CLEANUP: Now the new file is in the destination file, and the
1159 * old file is in .dpkg-tmp to be cleaned up later. We now need
1160 * to take a different attitude to cleanup, because we need to
1161 * remove the new file.
1164 cfile
->namenode
->flags
|= fnnf_placed_on_disk
;
1165 cfile
->namenode
->flags
|= fnnf_elide_other_lists
;
1167 debug(dbg_eachfiledetail
, "deferred extract done and installed");
1172 enqueue_deconfigure(struct pkginfo
*pkg
, struct pkginfo
*pkg_removal
)
1174 struct pkg_deconf_list
*newdeconf
;
1176 ensure_package_clientdata(pkg
);
1177 pkg
->clientdata
->istobe
= PKG_ISTOBE_DECONFIGURE
;
1178 newdeconf
= m_malloc(sizeof(struct pkg_deconf_list
));
1179 newdeconf
->next
= deconfigure
;
1180 newdeconf
->pkg
= pkg
;
1181 newdeconf
->pkg_removal
= pkg_removal
;
1182 deconfigure
= newdeconf
;
1186 clear_deconfigure_queue(void)
1188 struct pkg_deconf_list
*deconf
, *deconf_next
;
1190 for (deconf
= deconfigure
; deconf
; deconf
= deconf_next
) {
1191 deconf_next
= deconf
->next
;
1198 * Try if we can deconfigure the package and queue it if so.
1200 * Also checks whether the pdep is forced, first, according to force_p.
1201 * force_p may be NULL in which case nothing is considered forced.
1203 * Action is a string describing the action which causes the
1206 * "removal of <package>" (due to Conflicts+Depends; removal != NULL)
1207 * "installation of <package>" (due to Breaks; removal == NULL)
1209 * @retval 0 Not possible (why is printed).
1210 * @retval 1 Deconfiguration queued ok (no message printed).
1211 * @retval 2 Forced (no deconfiguration needed, why is printed).
1214 try_deconfigure_can(bool (*force_p
)(struct deppossi
*), struct pkginfo
*pkg
,
1215 struct deppossi
*pdep
, const char *action
,
1216 struct pkginfo
*removal
, const char *why
)
1218 if (force_p
&& force_p(pdep
)) {
1219 warning(_("ignoring dependency problem with %s:\n%s"), action
, why
);
1221 } else if (f_autodeconf
) {
1222 if (pkg
->installed
.essential
) {
1223 if (fc_removeessential
) {
1224 warning(_("considering deconfiguration of essential\n"
1225 " package %s, to enable %s"),
1226 pkg_name(pkg
, pnaw_nonambig
), action
);
1228 notice(_("no, %s is essential, will not deconfigure\n"
1229 " it in order to enable %s"),
1230 pkg_name(pkg
, pnaw_nonambig
), action
);
1234 enqueue_deconfigure(pkg
, removal
);
1237 notice(_("no, cannot proceed with %s (--auto-deconfigure will help):\n%s"),
1243 static int try_remove_can(struct deppossi
*pdep
,
1244 struct pkginfo
*fixbyrm
,
1247 sprintf(action
, _("removal of %.250s"), pkg_name(fixbyrm
, pnaw_nonambig
));
1248 return try_deconfigure_can(force_depends
, pdep
->up
->up
, pdep
,
1249 action
, fixbyrm
, why
);
1252 void check_breaks(struct dependency
*dep
, struct pkginfo
*pkg
,
1253 const char *pfilename
) {
1254 struct pkginfo
*fixbydeconf
;
1255 struct varbuf why
= VARBUF_INIT
;
1259 if (depisok(dep
, &why
, &fixbydeconf
, NULL
, false)) {
1260 varbuf_destroy(&why
);
1264 varbuf_end_str(&why
);
1266 if (fixbydeconf
&& f_autodeconf
) {
1269 ensure_package_clientdata(fixbydeconf
);
1270 assert(fixbydeconf
->clientdata
->istobe
== PKG_ISTOBE_NORMAL
);
1272 sprintf(action
, _("installation of %.250s"),
1273 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1274 notice(_("considering deconfiguration of %s, which would be broken by %s ..."),
1275 pkg_name(fixbydeconf
, pnaw_nonambig
), action
);
1277 ok
= try_deconfigure_can(force_breaks
, fixbydeconf
, dep
->list
,
1278 action
, NULL
, why
.buf
);
1280 notice(_("yes, will deconfigure %s (broken by %s)"),
1281 pkg_name(fixbydeconf
, pnaw_nonambig
),
1282 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1285 notice(_("regarding %s containing %s:\n%s"), pfilename
,
1286 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
), why
.buf
);
1289 varbuf_destroy(&why
);
1292 if (force_breaks(dep
->list
)) {
1293 warning(_("ignoring breakage, may proceed anyway!"));
1297 if (fixbydeconf
&& !f_autodeconf
) {
1298 ohshit(_("installing %.250s would break %.250s, and\n"
1299 " deconfiguration is not permitted (--auto-deconfigure might help)"),
1300 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
),
1301 pkg_name(fixbydeconf
, pnaw_nonambig
));
1303 ohshit(_("installing %.250s would break existing software"),
1304 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1308 void check_conflict(struct dependency
*dep
, struct pkginfo
*pkg
,
1309 const char *pfilename
) {
1310 struct pkginfo
*fixbyrm
;
1311 struct deppossi
*pdep
, flagdeppossi
;
1312 struct varbuf conflictwhy
= VARBUF_INIT
, removalwhy
= VARBUF_INIT
;
1313 struct dependency
*providecheck
;
1316 if (depisok(dep
, &conflictwhy
, &fixbyrm
, NULL
, false)) {
1317 varbuf_destroy(&conflictwhy
);
1318 varbuf_destroy(&removalwhy
);
1322 ensure_package_clientdata(fixbyrm
);
1323 if (fixbyrm
->clientdata
->istobe
== PKG_ISTOBE_INSTALLNEW
) {
1325 ensure_package_clientdata(fixbyrm
);
1327 if (((pkg
->available
.essential
&& fixbyrm
->installed
.essential
) ||
1328 (((fixbyrm
->want
!= PKG_WANT_INSTALL
&&
1329 fixbyrm
->want
!= PKG_WANT_HOLD
) ||
1330 does_replace(pkg
, &pkg
->available
, fixbyrm
, &fixbyrm
->installed
)) &&
1331 (!fixbyrm
->installed
.essential
|| fc_removeessential
)))) {
1332 assert(fixbyrm
->clientdata
->istobe
== PKG_ISTOBE_NORMAL
||
1333 fixbyrm
->clientdata
->istobe
== PKG_ISTOBE_DECONFIGURE
);
1334 fixbyrm
->clientdata
->istobe
= PKG_ISTOBE_REMOVE
;
1335 notice(_("considering removing %s in favour of %s ..."),
1336 pkg_name(fixbyrm
, pnaw_nonambig
),
1337 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1338 if (!(fixbyrm
->status
== PKG_STAT_INSTALLED
||
1339 fixbyrm
->status
== PKG_STAT_TRIGGERSPENDING
||
1340 fixbyrm
->status
== PKG_STAT_TRIGGERSAWAITED
)) {
1341 notice(_("%s is not properly installed; ignoring any dependencies on it"),
1342 pkg_name(fixbyrm
, pnaw_nonambig
));
1345 for (pdep
= fixbyrm
->set
->depended
.installed
;
1347 pdep
= pdep
->rev_next
) {
1348 if (pdep
->up
->type
!= dep_depends
&& pdep
->up
->type
!= dep_predepends
)
1350 if (depisok(pdep
->up
, &removalwhy
, NULL
, NULL
, false))
1352 varbuf_end_str(&removalwhy
);
1353 if (!try_remove_can(pdep
,fixbyrm
,removalwhy
.buf
))
1357 /* If we haven't found a reason not to yet, let's look some more. */
1358 for (providecheck
= fixbyrm
->installed
.depends
;
1360 providecheck
= providecheck
->next
) {
1361 if (providecheck
->type
!= dep_provides
) continue;
1362 for (pdep
= providecheck
->list
->ed
->depended
.installed
;
1364 pdep
= pdep
->rev_next
) {
1365 if (pdep
->up
->type
!= dep_depends
&& pdep
->up
->type
!= dep_predepends
)
1367 if (depisok(pdep
->up
, &removalwhy
, NULL
, NULL
, false))
1369 varbuf_end_str(&removalwhy
);
1370 notice(_("may have trouble removing %s, as it provides %s ..."),
1371 pkg_name(fixbyrm
, pnaw_nonambig
),
1372 providecheck
->list
->ed
->name
);
1373 if (!try_remove_can(pdep
,fixbyrm
,removalwhy
.buf
))
1374 goto break_from_both_loops_at_once
;
1377 break_from_both_loops_at_once
:;
1380 if (!pdep
&& skip_due_to_hold(fixbyrm
)) {
1381 pdep
= &flagdeppossi
;
1383 if (!pdep
&& (fixbyrm
->eflag
& PKG_EFLAG_REINSTREQ
)) {
1384 if (fc_removereinstreq
) {
1385 notice(_("package %s requires reinstallation, but will "
1386 "remove anyway as you requested"),
1387 pkg_name(fixbyrm
, pnaw_nonambig
));
1389 notice(_("package %s requires reinstallation, will not remove"),
1390 pkg_name(fixbyrm
, pnaw_nonambig
));
1391 pdep
= &flagdeppossi
;
1395 /* This conflict is OK - we'll remove the conflictor. */
1396 enqueue_conflictor(fixbyrm
);
1397 varbuf_destroy(&conflictwhy
); varbuf_destroy(&removalwhy
);
1398 notice(_("yes, will remove %s in favour of %s"),
1399 pkg_name(fixbyrm
, pnaw_nonambig
),
1400 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1404 fixbyrm
->clientdata
->istobe
= PKG_ISTOBE_NORMAL
;
1407 varbuf_end_str(&conflictwhy
);
1408 notice(_("regarding %s containing %s:\n%s"), pfilename
,
1409 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
), conflictwhy
.buf
);
1410 if (!force_conflicts(dep
->list
))
1411 ohshit(_("conflicting packages - not installing %.250s"),
1412 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1413 warning(_("ignoring conflict, may proceed anyway!"));
1414 varbuf_destroy(&conflictwhy
);
1419 void cu_cidir(int argc
, void **argv
) {
1420 char *cidir
= (char*)argv
[0];
1421 char *cidirrest
= (char*)argv
[1];
1422 cidirrest
[-1] = '\0';
1423 path_remove_tree(cidir
);
1426 void cu_fileslist(int argc
, void **argv
) {
1431 archivefiles(const char *const *argv
)
1433 const char *const *volatile argp
;
1434 const char **volatile arglist
= NULL
;
1437 enum modstatdb_rw msdbflags
;
1439 trigproc_install_hooks();
1442 msdbflags
= msdbrw_readonly
;
1443 else if (cipaction
->arg_int
== act_avail
)
1444 msdbflags
= msdbrw_readonly
| msdbrw_available_write
;
1445 else if (fc_nonroot
)
1446 msdbflags
= msdbrw_write
;
1448 msdbflags
= msdbrw_needsuperuser
;
1450 modstatdb_open(msdbflags
);
1453 pkg_infodb_upgrade();
1455 log_message("startup archives %s", cipaction
->olong
);
1458 const char *const *ap
;
1462 badusage(_("--%s --recursive needs at least one path argument"),cipaction
->olong
);
1464 for (ap
= argv
; *ap
; ap
++) {
1465 struct treeroot
*tree
;
1466 struct treenode
*node
;
1468 tree
= treewalk_open((const char *)*ap
, TREEWALK_FOLLOW_LINKS
, NULL
);
1470 while ((node
= treewalk_next(tree
))) {
1471 const char *nodename
;
1473 if (!S_ISREG(treenode_get_mode(node
)))
1476 /* Check if it looks like a .deb file. */
1477 nodename
= treenode_get_pathname(node
);
1478 if (strcmp(nodename
+ strlen(nodename
) - 4, ".deb") != 0)
1481 arglist
= m_realloc(arglist
, sizeof(char *) * (nfiles
+ 2));
1482 arglist
[nfiles
++] = m_strdup(nodename
);
1485 treewalk_close(tree
);
1489 ohshit(_("searched, but found no packages (files matching *.deb)"));
1491 arglist
[nfiles
] = NULL
;
1494 if (!*argv
) badusage(_("--%s needs at least one package archive file argument"),
1499 /* Perform some sanity checks on the passed archives. */
1500 for (i
= 0; argp
[i
]; i
++) {
1503 /* We need the filename to exist. */
1504 if (stat(argp
[i
], &st
) < 0)
1505 ohshite(_("cannot access archive '%s'"), argp
[i
]);
1507 /* We cannot work with anything that is not a regular file. */
1508 if (!S_ISREG(st
.st_mode
))
1509 ohshit(_("archive '%s' is not a regular file"), argp
[i
]);
1512 currenttime
= time(NULL
);
1514 /* Initialize fname variables contents. */
1516 varbuf_reset(&fnamevb
);
1517 varbuf_reset(&fnametmpvb
);
1518 varbuf_reset(&fnamenewvb
);
1520 varbuf_add_str(&fnamevb
, instdir
);
1521 varbuf_add_str(&fnametmpvb
, instdir
);
1522 varbuf_add_str(&fnamenewvb
, instdir
);
1524 varbuf_snapshot(&fnamevb
, &fname_state
);
1526 ensure_diversions();
1527 ensure_statoverrides(STATDB_PARSE_NORMAL
);
1529 for (i
= 0; argp
[i
]; i
++) {
1530 if (setjmp(ejbuf
)) {
1531 pop_error_context(ehflag_bombout
);
1532 if (abort_processing
)
1536 push_error_context_jump(&ejbuf
, print_error_perarchive
, argp
[i
]);
1538 dpkg_selabel_load();
1540 process_archive(argp
[i
]);
1542 m_output(stdout
, _("<standard output>"));
1543 m_output(stderr
, _("<standard error>"));
1546 pop_error_context(ehflag_normaltidy
);
1549 dpkg_selabel_close();
1553 switch (cipaction
->arg_int
) {
1564 internerr("unknown action '%d'", cipaction
->arg_int
);
1567 trigproc_run_deferred();
1568 modstatdb_shutdown();
1574 * Decide whether we want to install a new version of the package.
1576 * @param pkg The package with the version we might want to install
1578 * @retval true If the package should be skipped.
1579 * @retval false If the package should be installed.
1582 wanttoinstall(struct pkginfo
*pkg
)
1586 if (pkg
->want
!= PKG_WANT_INSTALL
&& pkg
->want
!= PKG_WANT_HOLD
) {
1588 printf(_("Selecting previously unselected package %s.\n"),
1589 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1592 printf(_("Skipping unselected package %s.\n"),
1593 pkgbin_name(pkg
, &pkg
->available
, pnaw_nonambig
));
1598 if (pkg
->eflag
& PKG_EFLAG_REINSTREQ
)
1600 if (pkg
->status
< PKG_STAT_UNPACKED
)
1603 rc
= dpkg_version_compare(&pkg
->available
.version
, &pkg
->installed
.version
);
1606 } else if (rc
== 0) {
1607 /* Same version fully installed. */
1609 notice(_("version %.250s of %.250s already installed, skipping"),
1610 versiondescribe(&pkg
->installed
.version
, vdew_nonambig
),
1611 pkg_name(pkg
, pnaw_nonambig
));
1618 warning(_("downgrading %.250s from %.250s to %.250s"),
1619 pkg_name(pkg
, pnaw_nonambig
),
1620 versiondescribe(&pkg
->installed
.version
, vdew_nonambig
),
1621 versiondescribe(&pkg
->available
.version
, vdew_nonambig
));
1624 notice(_("will not downgrade %.250s from %.250s to %.250s, skipping"),
1625 pkg_name(pkg
, pnaw_nonambig
),
1626 versiondescribe(&pkg
->installed
.version
, vdew_nonambig
),
1627 versiondescribe(&pkg
->available
.version
, vdew_nonambig
));