From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 89C4C138351 for ; Wed, 8 Apr 2020 05:56:56 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C8728E0999; Wed, 8 Apr 2020 05:56:51 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 9D2C8E0999 for ; Wed, 8 Apr 2020 05:56:51 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5D6FD34F12A for ; Wed, 8 Apr 2020 05:56:50 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id AEDCA1DA for ; Wed, 8 Apr 2020 05:56:47 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1586323788.5f0f1daa25e4eef751660909610ab247aff50f39.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/_emerge/ X-VCS-Repository: proj/portage X-VCS-Files: lib/_emerge/EbuildBuildDir.py X-VCS-Directories: lib/_emerge/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 5f0f1daa25e4eef751660909610ab247aff50f39 X-VCS-Branch: master Date: Wed, 8 Apr 2020 05:56:47 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 2831c402-f503-49f5-9b4f-88de68dacf38 X-Archives-Hash: e071c3d2b2e70db1aef1d0642e4eaec0 commit: 5f0f1daa25e4eef751660909610ab247aff50f39 Author: Zac Medico gentoo org> AuthorDate: Wed Apr 8 05:02:13 2020 +0000 Commit: Zac Medico gentoo org> CommitDate: Wed Apr 8 05:29:48 2020 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=5f0f1daa Revert "EbuildBuildDir: use async_start method" This reverts commit 2c596f49bab63c6c81dd4d68789823d45341264d. Bug: https://bugs.gentoo.org/716636 Signed-off-by: Zac Medico gentoo.org> lib/_emerge/EbuildBuildDir.py | 122 +++++++++++++++++++++++++++--------------- 1 file 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