doebuild: use EbuildBuildDir for locking
authorZac Medico <zmedico@gentoo.org>
Sat, 7 May 2011 21:59:54 +0000 (14:59 -0700)
committerZac Medico <zmedico@gentoo.org>
Sat, 7 May 2011 21:59:54 +0000 (14:59 -0700)
EbuildBuildDir also performs safe removal of the category when it is
empty, so ebuild.sh/dyn_clean doesn't need to do it anymore. This
fixes a race condition if one process is trying to remove the category
directory while another one is trying to create it for
PORTAGE_BUILDDIR.

bin/ebuild.sh
pym/portage/package/ebuild/doebuild.py

index f3349aec9f038cc802b4b60e4525b8a4d250df3d..c3cf18164cf16db254152829dcf6aa96b6f53a23 100755 (executable)
@@ -812,7 +812,7 @@ dyn_clean() {
        # Some kernels, such as Solaris, return EINVAL when an attempt
        # is made to remove the current working directory.
        cd "$PORTAGE_BUILDDIR"/../..
-       rmdir "$PORTAGE_BUILDDIR" "${PORTAGE_BUILDDIR%/*}" 2>/dev/null
+       rmdir "$PORTAGE_BUILDDIR" 2>/dev/null
 
        true
 }
index 1c0482224936826cd2ba818ce25121cc9861c4ce..f83a1e327e05eade80bb32280b46dca436b739b8 100644 (file)
@@ -566,8 +566,19 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0,
                        use_cache, mydbapi)
 
                if mydo in clean_phases:
-                       return _spawn_phase(mydo, mysettings,
-                               fd_pipes=fd_pipes, returnpid=returnpid)
+                       builddir_lock = None
+                       if not returnpid and \
+                               'PORTAGE_BUILDIR_LOCKED' not in mysettings:
+                               builddir_lock = EbuildBuildDir(
+                                       scheduler=PollScheduler().sched_iface,
+                                       settings=mysettings)
+                               builddir_lock.lock()
+                       try:
+                               return _spawn_phase(mydo, mysettings,
+                                       fd_pipes=fd_pipes, returnpid=returnpid)
+                       finally:
+                               if builddir_lock is not None:
+                                       builddir_lock.unlock()
 
                restrict = set(mysettings.get('PORTAGE_RESTRICT', '').split())
                # get possible slot information from the deps file