commit:     17604fd598d799c6af24b66fc2c240f90dddd420
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri May  4 16:47:49 2018 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri May  4 16:51:32 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=17604fd5

EbuildMerge: wait build dir to unlock (bug 654812)

Wait for the build dir to unlock, in order to ensure that
the category directory is removed when appropriate.

Fixes: 720fef408d07 ("Binpkg: use async_unlock (bug 614108)")
Fixes: 5ca8ef781952 ("EbuildBuild: use async_unlock (bug 614108)")
Bug: https://bugs.gentoo.org/654812

 pym/_emerge/Binpkg.py      | 12 +++++++++++-
 pym/_emerge/EbuildBuild.py | 12 +++++++++++-
 pym/_emerge/EbuildMerge.py | 26 +++++++++++++++++++++-----
 3 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/pym/_emerge/Binpkg.py b/pym/_emerge/Binpkg.py
index e9c5ef568..2b67816e8 100644
--- a/pym/_emerge/Binpkg.py
+++ b/pym/_emerge/Binpkg.py
@@ -1,4 +1,4 @@
-# Copyright 1999-2013 Gentoo Foundation
+# Copyright 1999-2018 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import functools
@@ -428,6 +428,10 @@ class Binpkg(CompositeTask):
                return task
 
        def _install_exit(self, task):
+               """
+               @returns: Future, result is the returncode from an
+                       EbuildBuildDir.async_unlock() task
+               """
                self.settings.pop("PORTAGE_BINPKG_FILE", None)
                if task.returncode == os.EX_OK and \
                        'binpkg-logs' not in self.settings.features and \
@@ -437,3 +441,9 @@ class Binpkg(CompositeTask):
                        except OSError:
                                pass
                self._async_unlock_builddir()
+               if self._current_task is None:
+                       result = self.scheduler.create_future()
+                       self.scheduler.call_soon(result.set_result, os.EX_OK)
+               else:
+                       result = self._current_task.async_wait()
+               return result

diff --git a/pym/_emerge/EbuildBuild.py b/pym/_emerge/EbuildBuild.py
index e5b96691a..00d4680f5 100644
--- a/pym/_emerge/EbuildBuild.py
+++ b/pym/_emerge/EbuildBuild.py
@@ -1,4 +1,4 @@
-# Copyright 1999-2014 Gentoo Foundation
+# Copyright 1999-2018 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from __future__ import unicode_literals
@@ -494,4 +494,14 @@ class EbuildBuild(CompositeTask):
                return task
 
        def _install_exit(self, task):
+               """
+               @returns: Future, result is the returncode from an
+                       EbuildBuildDir.async_unlock() task
+               """
                self._async_unlock_builddir()
+               if self._current_task is None:
+                       result = self.scheduler.create_future()
+                       self.scheduler.call_soon(result.set_result, os.EX_OK)
+               else:
+                       result = self._current_task.async_wait()
+               return result

diff --git a/pym/_emerge/EbuildMerge.py b/pym/_emerge/EbuildMerge.py
index 07d9134c3..bedea902d 100644
--- a/pym/_emerge/EbuildMerge.py
+++ b/pym/_emerge/EbuildMerge.py
@@ -1,9 +1,12 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2018 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+import functools
+
 from _emerge.CompositeTask import CompositeTask
 from portage import os
 from portage.dbapi._MergeProcess import MergeProcess
+from portage.util._async.AsyncTaskFuture import AsyncTaskFuture
 
 class EbuildMerge(CompositeTask):
 
@@ -35,8 +38,7 @@ class EbuildMerge(CompositeTask):
 
        def _merge_exit(self, merge_task):
                if self._final_exit(merge_task) != os.EX_OK:
-                       self.exit_hook(self)
-                       self.wait()
+                       self._start_exit_hook(self.returncode)
                        return
 
                self.postinst_failure = merge_task.postinst_failure
@@ -55,5 +57,19 @@ class EbuildMerge(CompositeTask):
                logger.log(" ::: completed emerge (%s of %s) %s to %s" % \
                        (pkg_count.curval, pkg_count.maxval, pkg.cpv, pkg.root))
 
-               self.exit_hook(self)
-               self.wait()
+               self._start_exit_hook(self.returncode)
+
+       def _start_exit_hook(self, returncode):
+               """
+               Start the exit hook, and set returncode after it completes.
+               """
+               # The returncode will be set after exit hook is complete.
+               self.returncode = None
+               self._start_task(
+                       AsyncTaskFuture(future=self.exit_hook(self)),
+                       functools.partial(self._exit_hook_exit, returncode))
+
+       def _exit_hook_exit(self, returncode, task):
+               self._assert_current(task)
+               self.returncode = returncode
+               self._async_wait()

Reply via email to