From 16f19c3555bc7d9192d17934df569c07e34a03e1 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Sat, 28 Oct 2006 15:59:07 +0000 Subject: [PATCH] Merged from trunk 4857:4863 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Avoid a TypeError with emerge -kN when there's no matching ebuild. Use mtree to save/restore bsd file flags before/after prepall and installation. Thanks to Diego Pettenò for this patch (related to bug #153109). svn path=/main/branches/prefix/; revision=4865 --- bin/emerge | 5 +++- bin/misc-functions.sh | 18 +++++++++++++++ bin/prepall | 12 ++++++++++ pym/portage.py | 53 ++++++++++++++++++++----------------------- 4 files changed, 58 insertions(+), 30 deletions(-) diff --git a/bin/emerge b/bin/emerge index 69ef549a4..15a2fb887 100755 --- a/bin/emerge +++ b/bin/emerge @@ -1270,7 +1270,10 @@ class depgraph: mydb = None if "--usepkgonly" not in self.myopts and myeb: mydb = portdb - pkgsettings.setcpv(myeb, mydb=mydb) + if myeb: + pkgsettings.setcpv(myeb, mydb=mydb) + else: + pkgsettings.setcpv(myeb_pkg, mydb=mydb) now_use = pkgsettings["USE"].split() forced_flags = set() forced_flags.update(pkgsettings.useforce) diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh index dd15ebb00..d673b37e2 100644 --- a/bin/misc-functions.sh +++ b/bin/misc-functions.sh @@ -267,6 +267,24 @@ install_mask() { set -${shopts} } +preinst_bsdflags() { + type -p chflags &>/dev/null || return 0 + type -p mtree &>/dev/null || return 1 + # Save all the file flags for restoration after installation. + mtree -c -p "${D}" -k flags > "${T}/bsdflags.mtree" + # Remove all the file flags so that the merge phase can do anything + # necessary. + chflags -R noschg,nouchg,nosappnd,nouappnd "${D}" + chflags -R nosunlnk,nouunlnk "${D}" 2>/dev/null +} + +postinst_bsdflags() { + type -p chflags &>/dev/null || return 0 + type -p mtree &>/dev/null || return 1 + # Restore all the file flags that were saved before installation. + mtree -e -p "${ROOT}" -U -k flags < "${T}/bsdflags.mtree" &> /dev/null +} + preinst_mask() { if [ -z "$IMAGE" ]; then eerror "${FUNCNAME}: IMAGE is unset" diff --git a/bin/prepall b/bin/prepall index 4ff190dd0..32ea7ef9e 100755 --- a/bin/prepall +++ b/bin/prepall @@ -3,6 +3,14 @@ # Distributed under the terms of the GNU General Public License v2 # $Id: prepall 2230 2005-11-01 01:35:59Z vapier $ +if type -p chflags &>/dev/null && type -p mtree &>/dev/null; then + # Save all the file flags for restoration at the end of prepall. + mtree -c -p "${ED}" -k flags > "${T}/bsdflags.mtree" + # Remove all the file flags so that prepall can do anything necessary. + chflags -R noschg,nouchg,nosappnd,nouappnd "${ED}" + chflags -R nosunlnk,nouunlnk "${ED}" 2>/dev/null +fi + prepallman prepallinfo prepallstrip @@ -87,3 +95,7 @@ done fi +if type -p chflags &>/dev/null && type -p mtree &>/dev/null; then + # Restore all the file flags that were saved at the beginning of prepall. + mtree -U -e -p "${ED}" -k flags < "${T}/bsdflags.mtree" &> /dev/null +fi diff --git a/pym/portage.py b/pym/portage.py index e5d91bccd..50e42cc3b 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -3015,8 +3015,9 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, if phase_retval == os.EX_OK: # Post phase logic and tasks that have been factored out of # ebuild.sh. - myargs = [MISC_SH_BINARY, "preinst_mask", "preinst_sfperms", - "preinst_selinux_labels", "preinst_suid_scan"] + myargs = [MISC_SH_BINARY, "preinst_bsdflags", "preinst_mask", + "preinst_sfperms", "preinst_selinux_labels", + "preinst_suid_scan"] phase_retval = spawn(" ".join(myargs), mysettings, debug=debug, free=1, logfile=logfile) if phase_retval != os.EX_OK: @@ -3024,7 +3025,21 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, noiselevel=-1) del mysettings["IMAGE"] return phase_retval - elif mydo in ["prerm","postrm","postinst","config"]: + elif mydo == "postinst": + mysettings.load_infodir(mysettings["O"]) + phase_retval = spawn(" ".join((EBUILD_SH_BINARY, mydo)), + mysettings, debug=debug, free=1, logfile=logfile) + if phase_retval == os.EX_OK: + # Post phase logic and tasks that have been factored out of + # ebuild.sh. + myargs = [MISC_SH_BINARY, "postinst_bsdflags"] + phase_retval = spawn(" ".join(myargs), + mysettings, debug=debug, free=1, logfile=logfile) + if phase_retval != os.EX_OK: + writemsg("!!! post postinst failed; exiting.\n", + noiselevel=-1) + return phase_retval + elif mydo in ["prerm","postrm","config"]: mysettings.load_infodir(mysettings["O"]) return spawn(EBUILD_SH_BINARY + " " + mydo, mysettings, debug=debug, free=1, logfile=logfile) @@ -3243,13 +3258,6 @@ def movefile(src,dest,newmtime=None,sstat=None,mysettings=None): try: if not sstat: sstat=os.lstat(src) - if bsd_chflags: - sflags=bsd_chflags.lgetflags(src) - if sflags < 0: - # Problem getting flags... - writemsg("!!! Couldn't get flags for "+dest+"\n", - noiselevel=-1) - return None except SystemExit, e: raise @@ -3270,7 +3278,7 @@ def movefile(src,dest,newmtime=None,sstat=None,mysettings=None): if bsd_chflags: # Check that we can actually unset schg etc flags... # Clear the flags on source and destination; we'll reinstate them after merging - if destexists and sflags != 0: + if destexists and dstat.st_flags != 0: if bsd_chflags.lchflags(dest, 0) < 0: writemsg("!!! Couldn't clear flags on file being merged: \n ", noiselevel=-1) @@ -3279,10 +3287,8 @@ def movefile(src,dest,newmtime=None,sstat=None,mysettings=None): if pflags != 0: bsd_chflags.lchflags(os.path.dirname(dest), 0) - # Don't bother checking the return value here; if it fails then the next line will catch it. - bsd_chflags.lchflags(src, 0) - - if bsd_chflags.lhasproblems(src)>0 or (destexists and bsd_chflags.lhasproblems(dest)>0) or bsd_chflags.lhasproblems(os.path.dirname(dest))>0: + if (destexists and bsd_chflags.lhasproblems(dest) > 0) or \ + bsd_chflags.lhasproblems(os.path.dirname(dest)) > 0: # This is bad: we can't merge the file with these flags set. writemsg("!!! Can't merge file "+dest+" because of flags set\n", noiselevel=-1) @@ -3312,14 +3318,6 @@ def movefile(src,dest,newmtime=None,sstat=None,mysettings=None): else: os.symlink(target,dest) lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID]) - if bsd_chflags: - # Restore the flags we saved before moving - if (sflags != 0 and bsd_chflags.lchflags(dest, sflags) < 0) or \ - (pflags and bsd_chflags.lchflags(os.path.dirname(dest), pflags) < 0): - writemsg("!!! Couldn't restore flags ("+str(flags)+") on " + dest+":\n", - noiselevel=-1) - writemsg("!!! %s\n" % str(e), noiselevel=-1) - return None return os.lstat(dest)[stat.ST_MTIME] except SystemExit, e: raise @@ -3398,10 +3396,9 @@ def movefile(src,dest,newmtime=None,sstat=None,mysettings=None): if bsd_chflags: # Restore the flags we saved before moving - if (sflags != 0 and bsd_chflags.lchflags(dest, sflags) < 0) or \ - (pflags and bsd_chflags.lchflags(os.path.dirname(dest), pflags) < 0): - writemsg("!!! Couldn't restore flags ("+str(sflags)+") on " + dest+":\n", - noiselevel=-1) + if pflags and bsd_chflags.lchflags(os.path.dirname(dest), pflags) < 0: + writemsg("!!! Couldn't restore flags (%s) on '%s'\n" % \ + (str(pflags), os.path.dirname(dest)), noiselevel=-1) return None return newmtime @@ -6734,8 +6731,6 @@ class dblink: else: os.mkdir(mydest) os.chmod(mydest,mystat[0]) - if bsd_chflags: - bsd_chflags.lchflags(mydest, bsd_chflags.lgetflags(mysrc)) os.chown(mydest,mystat[4],mystat[5]) writemsg_stdout(">>> %s/\n" % mydest) outfile.write("dir "+myrealdest+"\n") -- 2.26.2