commit:     899d5e61010a85702e7c83506d2214ede179c964
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Mar  1 01:34:47 2020 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Mar  1 01:41:03 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=899d5e61

EbuildBuildDir: cancel current tasks for CancelledError

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/_emerge/EbuildBuildDir.py | 46 ++++++++++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/lib/_emerge/EbuildBuildDir.py b/lib/_emerge/EbuildBuildDir.py
index 77dbff1fb..f1c49f041 100644
--- a/lib/_emerge/EbuildBuildDir.py
+++ b/lib/_emerge/EbuildBuildDir.py
@@ -6,6 +6,7 @@ from _emerge.AsynchronousLock import AsynchronousLock
 import portage
 from portage import os
 from portage.exception import PortageException
+from portage.util.futures import asyncio
 from portage.util.futures.compat_coroutine import coroutine
 from portage.util.SlotObject import SlotObject
 
@@ -69,22 +70,29 @@ class EbuildBuildDir(SlotObject):
                                raise
 
                catdir_lock = AsynchronousLock(path=catdir, 
scheduler=self.scheduler)
-               yield catdir_lock.async_start()
-               yield catdir_lock.async_wait()
-
-               self._assert_lock(catdir_lock)
-
+               builddir_lock = AsynchronousLock(path=dir_path, 
scheduler=self.scheduler)
                try:
-                       portage.util.ensure_dirs(catdir,
-                               gid=portage.portage_gid,
-                               mode=0o70, mask=0)
-               except PortageException:
-                       if not os.path.isdir(catdir):
-                               raise
+                       yield catdir_lock.async_start()
+                       yield catdir_lock.async_wait()
 
-               builddir_lock = AsynchronousLock(path=dir_path, 
scheduler=self.scheduler)
-               yield builddir_lock.async_start()
-               yield builddir_lock.async_wait()
+                       self._assert_lock(catdir_lock)
+
+                       try:
+                               portage.util.ensure_dirs(catdir,
+                                       gid=portage.portage_gid,
+                                       mode=0o70, mask=0)
+                       except PortageException:
+                               if not os.path.isdir(catdir):
+                                       raise
+
+                       yield builddir_lock.async_start()
+                       yield builddir_lock.async_wait()
+               except asyncio.CancelledError:
+                       if catdir_lock.poll() is None:
+                               catdir_lock.cancel()
+                       if builddir_lock.poll() is None:
+                               builddir_lock.cancel()
+                       raise
 
                try:
                        self._assert_lock(builddir_lock)
@@ -113,8 +121,14 @@ class EbuildBuildDir(SlotObject):
                        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()
+                       try:
+                               yield catdir_lock.async_start()
+                               yield catdir_lock.async_wait()
+                       except asyncio.CancelledError:
+                               if catdir_lock.poll() is None:
+                                       catdir_lock.cancel()
+                               raise
+
                        if catdir_lock.returncode == os.EX_OK:
                                try:
                                        os.rmdir(self._catdir)

Reply via email to