Skip to content

Commit

Permalink
EbuildBuildDir: cancel current tasks for CancelledError
Browse files Browse the repository at this point in the history
Signed-off-by: Zac Medico <zmedico@gentoo.org>
  • Loading branch information
zmedico committed Mar 1, 2020
1 parent 27a6ee3 commit 899d5e6
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions lib/_emerge/EbuildBuildDir.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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

Expand Down Expand Up @@ -69,22 +70,29 @@ def async_lock(self):
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)
Expand Down Expand Up @@ -113,8 +121,14 @@ def async_unlock(self):
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)
Expand Down

0 comments on commit 899d5e6

Please sign in to comment.