Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 147446

Summary: portage-2.1.1 refuses to remove a dir in ${ROOT} in pkg_preinst()
Product: Portage Development Reporter: Jakub Moc (RETIRED) <jakub>
Component: Core - Interface (emerge)Assignee: Portage team <dev-portage>
Status: RESOLVED CANTFIX    
Severity: normal CC: lisa, radek
Priority: High    
Version: 2.1   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Jakub Moc (RETIRED) gentoo-dev 2006-09-13 06:00:52 UTC
<snip>
pkg_config() {
        # remove stale wrappers from previous broken versions
        [[ -d "${ROOT}/usr/lib/ccache/bin" ]] && rm -rf "${ROOT}/usr/lib/ccache/bin"
}
</snip>

# emerge -uavl portage

...
existing file /usr/lib/ccache/bin/c++ is not owned by this package
existing file /usr/lib/ccache/bin/g++ is not owned by this package
existing file /usr/lib/ccache/bin/gcc is not owned by this package
existing file /usr/lib/ccache/bin/i686-pc-linux-gnu-c++ is not owned by this package
existing file /usr/lib/ccache/bin/i686-pc-linux-gnu-g++ is not owned by this package
existing file /usr/lib/ccache/bin/i686-pc-linux-gnu-gcc is not owned by this package
* spent 0.00635409355164 seconds checking for file collisions
* This package is blocked because it wants to overwrite
* files belonging to other packages (see messages above).
* If you have no clue what this is all about report it 
* as a bug for this package on http://bugs.gentoo.org
 
package dev-util/ccache-2.4-r3 NOT merged

# ls -ld /usr/lib/portage/bin
# drwxr-xr-x 2 root root 328 2006-09-13 14:50 /usr/lib/ccache/bin

Now, for something a bit different:

<snip>
pkg_setup() {
        # remove stale wrappers from previous broken versions
        [[ -d "${ROOT}/usr/lib/ccache/bin" ]] && rm -rf "${ROOT}/usr/lib/ccache/bin"
}
<snip>

>>> dev-util/ccache-2.4-r3 merged.

WTH???
Comment 1 Jakub Moc (RETIRED) gentoo-dev 2006-09-13 06:01:13 UTC
Portage 2.1.1 (default-linux/x86/2006.1/desktop, gcc-4.1.1, glibc-2.4-r3, 2.6.17-gentoo-r7 i686)
=================================================================
System uname: 2.6.17-gentoo-r7 i686 AMD Athlon(tm) XP 1600+
Gentoo Base System version 1.12.4
Last Sync: Wed, 13 Sep 2006 12:00:07 +0000
ccache version 2.4 [enabled]
app-admin/eselect-compiler: [Not Present]
dev-lang/python:     2.4.3-r3
dev-python/pycrypto: 2.0.1-r5
dev-util/ccache:     2.4-r3
dev-util/confcache:  [Not Present]
sys-apps/sandbox:    1.2.18.1
sys-devel/autoconf:  2.13, 2.60
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2
sys-devel/binutils:  2.16.93, 2.17, 2.17.50.0.3
sys-devel/gcc-config: 1.3.13-r3
sys-devel/libtool:   1.5.22
virtual/os-headers:  2.6.17
ACCEPT_KEYWORDS="x86 ~x86"
AUTOCLEAN="yes"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-march=athlon-xp -O2 -pipe -fomit-frame-pointer -fforce-addr -ftree-vectorize"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/X11/xkb /usr/share/config"
CONFIG_PROTECT_MASK="/etc/env.d /etc/env.d/java/ /etc/gconf /etc/java-config/vms/ /etc/revdep-rebuild /etc/splash /etc/terminfo"
CXXFLAGS="-march=athlon-xp -O2 -pipe -fomit-frame-pointer -fforce-addr -ftree-vectorize"
DISTDIR="/usr/portage/distfiles"
EMERGE_DEFAULT_OPTS="--alphabetical"
FEATURES="autoconfig ccache collision-protect distlocks metadata-transfer parallel-fetch sandbox sfperms splitdebug strict userfetch userpriv usersandbox"
GENTOO_MIRRORS="ftp://ftp.sh.cvut.cz/MIRRORS/gentoo/gentoo ftp://ftp.fi.muni.cz/pub/linux/gentoo/"
LANG="en_US.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--sort-common"
LINGUAS="cs en"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_EXTRA_OPTS="--progress"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --delete-after --stats --timeout=180 --exclude='/distfiles' --exclude='/local' --exclude='/packages'"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="x86 3dnow 3dnowext 7zip X X509 a52 aac acl acpi alsa amr asf audiofile bash-completion berkdb bluetooth bzip2 cairo caps cddb cdparanoia cdr chroot cli crypt cscope css cups curl curlwrappers dbx dga dlloader dri dts dv dvd dvdr dvdread elibc_glibc encode ethereal exif expat fam fbcon ffmpeg fftw firefox flac flash flatfile foomaticdb gd gdbm gif glibc-omitfp glut gmp gpm gstreamer iconv icq idn imagemagick imap imlib inifile input_devices_joystick input_devices_keyboard input_devices_mouse input_devices_vmmouse ipv6 irda jack javascript jbig joystick jpeg jpeg2k kdeenablefinal kdehiddenvisibility kernel_linux lcms libcaca libg++ libsamplerate linguas_cs linguas_en lirc lirc_devices_cph06x lm_sensors logrotate mad maildir matroska mikmod mime mmap mmx mng mp3 mpeg musepack musicbrainz ncurses nls nodrm nptl nptlonly nsplugin nvidia offensive ogg openal opengl pam pcre pdf perl png ppds python qt3 quicktime readline real reflection samba sdl session sftplogging skey sndfile speex spell spl sse ssl svg symlink tcpd theora threads tiff truetype udev unicode urandom usb userland_GNU v4l v4l2 vcd video_cards_fbdev video_cards_nv video_cards_nvidia video_cards_v4l video_cards_vesa video_cards_vmware vorbis win32codecs wmf x264 xine xinerama xinetd xml xml2 xmlrpc xorg xosd xpm xv xvid xvmc zlib"
Unset:  CTARGET, INSTALL_MASK, LC_ALL

Comment 2 Jakub Moc (RETIRED) gentoo-dev 2006-09-13 06:13:00 UTC
Sigh, the above non-working example should obviously be:

<snip>
pkg_preinst() {
        # remove stale wrappers from previous broken versions
        [[ -d "${ROOT}/usr/lib/ccache/bin" ]] && rm -rf
"${ROOT}/usr/lib/ccache/bin"
}
</snip>

Well, anyway, to reproduce this:

1. emerge =ccache-2.4-r2
2. check that you have orphaned symlinks in /usr/lib/ccache/bin/
3. emerge =ccache-2.4-r4
4. watch the collision
5. move the stuff to pkg_setup() -> directory nuked, no collision


Comment 3 Alec Warner (RETIRED) archtester gentoo-dev Security 2006-09-13 07:39:46 UTC
Only thing I can think of is userpriv, but looking at the code preinst isn't userpriv'd ;)
Comment 4 Zac Medico gentoo-dev 2006-09-13 11:24:33 UTC
The problem is that pkg_preinst runs *after* the collision-protect check.  That makes sense, because the preinst phase should not be executed if the merge has been aborted due to collisions.  An alternative, for the ccache ebuild, would be to create the symlinks in pkg_postinst.
Comment 5 Jakub Moc (RETIRED) gentoo-dev 2006-09-13 11:32:16 UTC
(In reply to comment #4)
> That makes sense, because the preinst phase should not be executed if the >merge has been aborted due to collisions.

Uhm, I don't understand, I'm afraid. There would be no merge collisions if portage did check for them when relevant, not before any merge is actually done.

> An alternative, for the ccache ebuild, would be to create the symlinks in >pkg_postinst.

No, that's exactly what has caused this bug in the first place. :=) We need to nuke the orphaned symlinks, and it fails in pkg_preinst. The only workaround is to move it to pkg_setup.
Comment 6 Zac Medico gentoo-dev 2006-09-13 12:02:41 UTC
pkg_setup isn't proper because the system will be left in an inconsistent state if the build fails or if something like --buildpkgonly is enabled.

There's really no proper solution that doesn't require user intervention (doesn't affect users that don't have collision-protect enabled).
Comment 7 Jakub Moc (RETIRED) gentoo-dev 2006-09-13 12:10:15 UTC
(In reply to comment #6)
> pkg_setup isn't proper because the system will be left in an inconsistent state
> if the build fails or if something like --buildpkgonly is enabled.

We need a way to nuke files on live FS somehow. See Bug 145167 for reason why this is needed (And that's definitely not the only case in the current tree.)

> There's really no proper solution that doesn't require user intervention
> (doesn't affect users that don't have collision-protect enabled).

collision-protect doesn't matter here, we simply need a way to kill orphaned files that just break users and that plain shouldn't be there. Even with collision-protect disabled, users will still be broken if there's no way to do so.

So, what's your proper solution to this? Die in ebuilds? That plain sucks.
Comment 8 Zac Medico gentoo-dev 2006-09-13 12:18:28 UTC
(In reply to comment #7)
> collision-protect doesn't matter here, we simply need a way to kill orphaned
> files that just break users and that plain shouldn't be there. Even with
> collision-protect disabled, users will still be broken if there's no way to do
> so.
> 
> So, what's your proper solution to this? Die in ebuilds? That plain sucks.
> 

pkg_preinst is the most proper solution.  However, it doesn't work in the case of collisions.
Comment 9 Jakub Moc (RETIRED) gentoo-dev 2006-09-13 12:41:23 UTC
Shrug... I still can't see why checking for collision takes place at the point when no collisions whatsoever can occur. Just moving this check would fix this issue.
Comment 10 Zac Medico gentoo-dev 2006-09-13 12:49:33 UTC
If we move the check inside portage, then portage itself is actively putting the system into a potentially inconsistent state, which is something that we should try to avoid.
Comment 11 Marius Mauch (RETIRED) gentoo-dev 2006-09-19 05:53:04 UTC
(In reply to comment #9)
> Shrug... I still can't see why checking for collision takes place at the point
> when no collisions whatsoever can occur. Just moving this check would fix this
> issue.

NFC what you mean with "when no collisions can occur" (they obviously can).
preinst runs after the collision protect check as it's a potentially destructive operation and therefore should run as late as possible.