From 8601ea2b80208491b471f37710b35813fd341c28 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 7 May 2011 14:59:54 -0700 Subject: doebuild: use EbuildBuildDir for locking 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 | 2 +- pym/portage/package/ebuild/doebuild.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bin/ebuild.sh b/bin/ebuild.sh index f3349aec9..c3cf18164 100755 --- a/bin/ebuild.sh +++ b/bin/ebuild.sh @@ -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 } diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py index 1c0482224..f83a1e327 100644 --- a/pym/portage/package/ebuild/doebuild.py +++ b/pym/portage/package/ebuild/doebuild.py @@ -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 -- cgit v1.2.3-1-g7c22