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 980731382C5 for ; Sun, 22 Apr 2018 21:52:18 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id AF921E0894; Sun, 22 Apr 2018 21:52:16 +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 80433E0894 for ; Sun, 22 Apr 2018 21:52:15 +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 26810335C30 for ; Sun, 22 Apr 2018 21:52:14 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 8084227E for ; Sun, 22 Apr 2018 21:52:12 +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: <1524421852.9d7b43779d17ca9f698bb90e0ac7b1f43afa9575.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/_emerge/ X-VCS-Repository: proj/portage X-VCS-Files: pym/_emerge/EbuildBuildDir.py X-VCS-Directories: pym/_emerge/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 9d7b43779d17ca9f698bb90e0ac7b1f43afa9575 X-VCS-Branch: master Date: Sun, 22 Apr 2018 21:52:12 +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-Archives-Salt: ce2c2779-7238-4c0a-be8b-a2f92212eccb X-Archives-Hash: 120c175df69691e5ba45c4a7958bf43e commit: 9d7b43779d17ca9f698bb90e0ac7b1f43afa9575 Author: Zac Medico gentoo org> AuthorDate: Sat Apr 21 06:05:34 2018 +0000 Commit: Zac Medico gentoo org> CommitDate: Sun Apr 22 18:30:52 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=9d7b4377 EbuildBuildDir: add async_lock method (bug 614112) Asynchronoulsy handle locking of both the category directory and build directory. Bug: https://bugs.gentoo.org/614112 pym/_emerge/EbuildBuildDir.py | 76 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/pym/_emerge/EbuildBuildDir.py b/pym/_emerge/EbuildBuildDir.py index 69f694992..9163deacf 100644 --- a/pym/_emerge/EbuildBuildDir.py +++ b/pym/_emerge/EbuildBuildDir.py @@ -1,6 +1,8 @@ # 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 @@ -84,6 +86,80 @@ class EbuildBuildDir(SlotObject): except OSError: pass + def async_lock(self): + """ + Acquire the lock asynchronously. Notification is available + via the add_done_callback method of the returned Future instance. + + This raises an AlreadyLocked exception if async_lock() is called + while a lock is already held. In order to avoid this, call + async_unlock() or check whether the "locked" attribute is True + or False before calling async_lock(). + + @returns: Future, result is None + """ + if self._lock_obj is not None: + raise self.AlreadyLocked((self._lock_obj,)) + + dir_path = self.settings.get('PORTAGE_BUILDDIR') + if not dir_path: + raise AssertionError('PORTAGE_BUILDDIR is unset') + catdir = os.path.dirname(dir_path) + self._catdir = catdir + catdir_lock = AsynchronousLock(path=catdir, scheduler=self.scheduler) + builddir_lock = AsynchronousLock(path=dir_path, scheduler=self.scheduler) + result = self.scheduler.create_future() + + 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(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.addExitListener(catdir_locked) + catdir_lock.start() + return result + def async_unlock(self): """ Release the lock asynchronously. Release notification is available