aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2020-04-07 22:02:13 -0700
committerZac Medico <zmedico@gentoo.org>2020-04-07 22:29:48 -0700
commit5f0f1daa25e4eef751660909610ab247aff50f39 (patch)
tree486098ac1845f44db3c9657f9ee2454d1526d095 /lib/_emerge
parentRevert "ForkExecutor: use async_start method" (diff)
downloadportage-5f0f1daa25e4eef751660909610ab247aff50f39.tar.gz
portage-5f0f1daa25e4eef751660909610ab247aff50f39.tar.bz2
portage-5f0f1daa25e4eef751660909610ab247aff50f39.zip
Revert "EbuildBuildDir: use async_start method"
This reverts commit 2c596f49bab63c6c81dd4d68789823d45341264d. Bug: https://bugs.gentoo.org/716636 Signed-off-by: Zac Medico <zmedico@gentoo.org>
Diffstat (limited to 'lib/_emerge')
-rw-r--r--lib/_emerge/EbuildBuildDir.py122
1 files changed, 78 insertions, 44 deletions
diff --git a/lib/_emerge/EbuildBuildDir.py b/lib/_emerge/EbuildBuildDir.py
index 77dbff1fb..477113db8 100644
--- a/lib/_emerge/EbuildBuildDir.py
+++ b/lib/_emerge/EbuildBuildDir.py
@@ -1,12 +1,13 @@
-# Copyright 1999-2020 Gentoo Authors
+# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
+import functools
+
from _emerge.AsynchronousLock import AsynchronousLock
import portage
from portage import os
from portage.exception import PortageException
-from portage.util.futures.compat_coroutine import coroutine
from portage.util.SlotObject import SlotObject
class EbuildBuildDir(SlotObject):
@@ -38,7 +39,6 @@ class EbuildBuildDir(SlotObject):
except OSError:
pass
- @coroutine
def async_lock(self):
"""
Acquire the lock asynchronously. Notification is available
@@ -59,45 +59,60 @@ class EbuildBuildDir(SlotObject):
raise AssertionError('PORTAGE_BUILDDIR is unset')
catdir = os.path.dirname(dir_path)
self._catdir = catdir
-
- try:
- portage.util.ensure_dirs(os.path.dirname(catdir),
- gid=portage.portage_gid,
- mode=0o70, mask=0)
- except PortageException:
- if not os.path.isdir(os.path.dirname(catdir)):
- raise
-
catdir_lock = AsynchronousLock(path=catdir, scheduler=self.scheduler)
- yield catdir_lock.async_start()
- yield catdir_lock.async_wait()
+ builddir_lock = AsynchronousLock(path=dir_path, scheduler=self.scheduler)
+ result = self.scheduler.create_future()
- self._assert_lock(catdir_lock)
+ def catdir_locked(catdir_lock):
+ try:
+ self._assert_lock(catdir_lock)
+ except AssertionError as e:
+ result.set_exception(e)
+ return
+
+ try:
+ portage.util.ensure_dirs(catdir,
+ gid=portage.portage_gid,
+ mode=0o70, mask=0)
+ except PortageException as e:
+ if not os.path.isdir(catdir):
+ result.set_exception(e)
+ return
+
+ builddir_lock.addExitListener(builddir_locked)
+ builddir_lock.start()
+
+ def builddir_locked(builddir_lock):
+ try:
+ self._assert_lock(builddir_lock)
+ except AssertionError as e:
+ catdir_lock.async_unlock.add_done_callback(
+ functools.partial(catdir_unlocked, exception=e))
+ return
+
+ self._lock_obj = builddir_lock
+ self.locked = True
+ self.settings['PORTAGE_BUILDDIR_LOCKED'] = '1'
+ catdir_lock.async_unlock().add_done_callback(catdir_unlocked)
+
+ def catdir_unlocked(future, exception=None):
+ if not (exception is None and future.exception() is None):
+ result.set_exception(exception or future.exception())
+ else:
+ result.set_result(None)
try:
- portage.util.ensure_dirs(catdir,
+ portage.util.ensure_dirs(os.path.dirname(catdir),
gid=portage.portage_gid,
mode=0o70, mask=0)
except PortageException:
- if not os.path.isdir(catdir):
+ if not os.path.isdir(os.path.dirname(catdir)):
raise
- builddir_lock = AsynchronousLock(path=dir_path, scheduler=self.scheduler)
- yield builddir_lock.async_start()
- yield builddir_lock.async_wait()
-
- try:
- self._assert_lock(builddir_lock)
- except AssertionError:
- yield catdir_lock.async_unlock()
- raise
+ catdir_lock.addExitListener(catdir_locked)
+ catdir_lock.start()
+ return result
- self._lock_obj = builddir_lock
- self.locked = True
- self.settings['PORTAGE_BUILDDIR_LOCKED'] = '1'
- yield catdir_lock.async_unlock()
-
- @coroutine
def async_unlock(self):
"""
Release the lock asynchronously. Release notification is available
@@ -105,22 +120,41 @@ class EbuildBuildDir(SlotObject):
@returns: Future, result is None
"""
- if self._lock_obj is not None:
- yield self._lock_obj.async_unlock()
-
- self._lock_obj = None
- self.locked = False
- self.settings.pop('PORTAGE_BUILDDIR_LOCKED', None)
- catdir_lock = AsynchronousLock(
- path=self._catdir, scheduler=self.scheduler)
- yield catdir_lock.async_start()
- yield catdir_lock.async_wait()
- if catdir_lock.returncode == os.EX_OK:
+ result = self.scheduler.create_future()
+
+ def builddir_unlocked(future):
+ if future.exception() is not None:
+ result.set_exception(future.exception())
+ else:
+ self._lock_obj = None
+ self.locked = False
+ self.settings.pop('PORTAGE_BUILDDIR_LOCKED', None)
+ catdir_lock = AsynchronousLock(
+ path=self._catdir, scheduler=self.scheduler)
+ catdir_lock.addExitListener(catdir_locked)
+ catdir_lock.start()
+
+ def catdir_locked(catdir_lock):
+ if catdir_lock.wait() != os.EX_OK:
+ result.set_result(None)
+ else:
try:
os.rmdir(self._catdir)
except OSError:
pass
- yield catdir_lock.async_unlock()
+ catdir_lock.async_unlock().add_done_callback(catdir_unlocked)
+
+ def catdir_unlocked(future):
+ if future.exception() is None:
+ result.set_result(None)
+ else:
+ result.set_exception(future.exception())
+
+ if self._lock_obj is None:
+ self.scheduler.call_soon(result.set_result, None)
+ else:
+ self._lock_obj.async_unlock().add_done_callback(builddir_unlocked)
+ return result
class AlreadyLocked(portage.exception.PortageException):
pass