Move PORTAGE_BUILDDIR in to a category subdirectory and clean up the category directo...
authorZac Medico <zmedico@gentoo.org>
Wed, 11 Oct 2006 05:54:12 +0000 (05:54 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 11 Oct 2006 05:54:12 +0000 (05:54 -0000)
svn path=/main/trunk/; revision=4654

bin/emerge
pym/portage.py

index f82448a4a302bc5ae1c90b575e77b6b9e60cb27a..ee53b647ea9c2ad08529610ef26f983f1716d381 100755 (executable)
@@ -2118,14 +2118,23 @@ class MergeTask(object):
 
                                portage.doebuild_environment(y, "setup", myroot,
                                        pkgsettings, self.edebug, 1, portdb)
-                               portage_util.ensure_dirs(
-                                       os.path.dirname(pkgsettings["PORTAGE_BUILDDIR"]),
+                               catdir = os.path.dirname(pkgsettings["PORTAGE_BUILDDIR"])
+                               portage_util.ensure_dirs(os.path.dirname(catdir),
                                        uid=portage.portage_uid, gid=portage.portage_gid,
                                        mode=070, mask=0)
                                builddir_lock = None
+                               catdir_lock = None
                                try:
+                                       catdir_lock = portage_locks.lockdir(catdir)
+                                       portage_util.ensure_dirs(catdir,
+                                               uid=portage.portage_uid, gid=portage.portage_gid,
+                                               mode=070, mask=0)
                                        builddir_lock = portage_locks.lockdir(
                                                pkgsettings["PORTAGE_BUILDDIR"])
+                                       try:
+                                               portage_locks.unlockdir(catdir_lock)
+                                       finally:
+                                               catdir_lock = None
                                        msg = " === (%s of %s) Cleaning (%s::%s)" % \
                                                (mergecount, len(mymergelist), pkg_key, y)
                                        short_msg = "emerge: (%s of %s) %s Clean" % \
@@ -2187,6 +2196,19 @@ class MergeTask(object):
                                finally:
                                        if builddir_lock:
                                                portage_locks.unlockdir(builddir_lock)
+                                       try:
+                                               if not catdir_lock:
+                                                       # Lock catdir for removal if empty.
+                                                       catdir_lock = portage_locks.lockdir(catdir)
+                                       finally:
+                                               if catdir_lock:
+                                                       try:
+                                                               os.rmdir(catdir)
+                                                       except OSError, e:
+                                                               if e.errno != errno.ENOTEMPTY:
+                                                                       raise
+                                                               del e
+                                                       portage_locks.unlockdir(catdir_lock)
 
                        elif x[0]=="binary":
                                #merge the tbz2
index 99e65b1013c0c94f4919ae4b480aaceed50502f4..b28aca245c190b298ab936350781c7f46411fdfd 100644 (file)
@@ -2570,9 +2570,13 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, m
        # Package {pre,post}inst and {pre,post}rm may overlap, so they must have separate
        # locations in order to prevent interference.
        if mydo in ("unmerge", "prerm", "postrm", "cleanrm"):
-               mysettings["PORTAGE_BUILDDIR"] = os.path.join(mysettings["PKG_TMPDIR"], mysettings["PF"])
+               mysettings["PORTAGE_BUILDDIR"] = os.path.join(
+                       mysettings["PKG_TMPDIR"],
+                       mysettings["CATEGORY"], mysettings["PF"])
        else:
-               mysettings["PORTAGE_BUILDDIR"] = os.path.join(mysettings["BUILD_PREFIX"], mysettings["PF"])
+               mysettings["PORTAGE_BUILDDIR"] = os.path.join(
+                       mysettings["BUILD_PREFIX"],
+                       mysettings["CATEGORY"], mysettings["PF"])
 
        mysettings["HOME"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "homedir")
        mysettings["WORKDIR"] = os.path.join(mysettings["PORTAGE_BUILDDIR"], "work")
@@ -2639,10 +2643,14 @@ def prepare_build_dirs(myroot, mysettings, cleanup):
 
        mysettings["PKG_LOGDIR"] = os.path.join(mysettings["T"], "logging")
 
+       mydirs = [os.path.dirname(mysettings["PORTAGE_BUILDDIR"])]
+       mydirs.append(os.path.dirname(mydirs[-1]))
+
        try:
-               portage_util.ensure_dirs(mysettings["BUILD_PREFIX"])
-               portage_util.apply_secpass_permissions(mysettings["BUILD_PREFIX"],
-                       gid=portage_gid, uid=portage_uid, mode=070, mask=0)
+               for mydir in mydirs:
+                       portage_util.ensure_dirs(mydir)
+                       portage_util.apply_secpass_permissions(mydir,
+                               gid=portage_gid, uid=portage_uid, mode=070, mask=0)
                for dir_key in ("PORTAGE_BUILDDIR", "HOME", "PKG_LOGDIR", "T"):
                        """These directories don't necessarily need to be group writable.
                        However, the setup phase is commonly run as a privileged user prior
@@ -5773,15 +5781,23 @@ class dblink:
                if myebuildpath:
                        doebuild_environment(myebuildpath, "prerm", self.myroot,
                                self.settings, 0, 0, self.vartree.dbapi)
-                       portage_util.ensure_dirs(
-                               os.path.dirname(self.settings["PORTAGE_BUILDDIR"]),
+                       catdir = os.path.dirname(self.settings["PORTAGE_BUILDDIR"])
+                       portage_util.ensure_dirs(os.path.dirname(catdir),
                                uid=portage_uid, gid=portage_gid, mode=070, mask=0)
                builddir_lock = None
+               catdir_lock = None
                try:
                        if myebuildpath:
+                               catdir_lock = portage_locks.lockdir(catdir)
+                               portage_util.ensure_dirs(catdir,
+                                       uid=portage_uid, gid=portage_gid,
+                                       mode=070, mask=0)
                                builddir_lock = portage_locks.lockdir(
                                        self.settings["PORTAGE_BUILDDIR"])
-
+                               try:
+                                       portage_locks.unlockdir(catdir_lock)
+                               finally:
+                                       catdir_lock = None
                                # Eventually, we'd like to pass in the saved ebuild env here...
                                retval = doebuild(myebuildpath, "prerm", self.myroot,
                                        self.settings, cleanup=cleanup, use_cache=0,
@@ -5813,7 +5829,19 @@ class dblink:
                finally:
                        if builddir_lock:
                                portage_locks.unlockdir(builddir_lock)
-
+                       try:
+                               if myebuildpath and not catdir_lock:
+                                       # Lock catdir for removal if empty.
+                                       catdir_lock = portage_locks.lockdir(catdir)
+                       finally:
+                               if catdir_lock:
+                                       try:
+                                               os.rmdir(catdir)
+                                       except OSError, e:
+                                               if e.errno != errno.ENOTEMPTY:
+                                                       raise
+                                               del e
+                                       portage_locks.unlockdir(catdir_lock)
                env_update(target_root=self.myroot, prev_mtimes=ldpath_mtimes)
 
        def _unmerge_pkgfiles(self, pkgfiles):
@@ -6603,6 +6631,7 @@ def pkgmerge(mytbz2, myroot, mysettings, mydbapi=None, vartree=None, prev_mtimes
 
        tbz2_lock = None
        builddir_lock = None
+       catdir_lock = None
        try:
                """ Don't lock the tbz2 file because the filesytem could be readonly or
                shared by a cluster."""
@@ -6618,14 +6647,23 @@ def pkgmerge(mytbz2, myroot, mysettings, mydbapi=None, vartree=None, prev_mtimes
                mycat = mycat.strip()
 
                # These are the same directories that would be used at build time.
-               builddir = os.path.join(mysettings["PORTAGE_TMPDIR"], "portage", mypkg)
+               builddir = os.path.join(
+                       mysettings["PORTAGE_TMPDIR"], "portage", mycat, mypkg)
+               catdir = os.path.dirname(builddir)
                pkgloc = os.path.join(builddir, "image")
                infloc = os.path.join(builddir, "build-info")
                myebuild = os.path.join(
                        infloc, os.path.basename(mytbz2)[:-4] + "ebuild")
-               portage_util.ensure_dirs(os.path.dirname(builddir),
+               portage_util.ensure_dirs(os.path.dirname(catdir),
+                       uid=portage_uid, gid=portage_gid, mode=070, mask=0)
+               catdir_lock = portage_locks.lockdir(catdir)
+               portage_util.ensure_dirs(catdir,
                        uid=portage_uid, gid=portage_gid, mode=070, mask=0)
                builddir_lock = portage_locks.lockdir(builddir)
+               try:
+                       portage_locks.unlockdir(catdir_lock)
+               finally:
+                       catdir_lock = None
                try:
                        shutil.rmtree(builddir)
                except (IOError, OSError), e:
@@ -6686,6 +6724,19 @@ def pkgmerge(mytbz2, myroot, mysettings, mydbapi=None, vartree=None, prev_mtimes
                                        raise
                                del e
                        portage_locks.unlockdir(builddir_lock)
+                       try:
+                               if not catdir_lock:
+                                       # Lock catdir for removal if empty.
+                                       catdir_lock = portage_locks.lockdir(catdir)
+                       finally:
+                               if catdir_lock:
+                                       try:
+                                               os.rmdir(catdir)
+                                       except OSError, e:
+                                               if e.errno != errno.ENOTEMPTY:
+                                                       raise
+                                               del e
+                                       portage_locks.unlockdir(catdir_lock)
 
 def deprecated_profile_check():
        if not os.access(DEPRECATED_PROFILE_FILE, os.R_OK):