commit:     90fa156df0e6ef4fa9ef1a80c495511f4630de86
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Apr 20 15:21:58 2018 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Apr 20 15:50:43 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=90fa156d

EbuildBuildDir: remove synchronous unlock method (bug 614108)

The synchronous unlock method can trigger event loop recursion if the
event loop is already running, which is incompatible with asyncio's
default event loop. Therefore, migrate the last consumers to use the
async_unlock method, and remove the synchronous unlock method.

Bug: https://bugs.gentoo.org/614108
Bug: https://bugs.gentoo.org/649588

 pym/_emerge/EbuildBuildDir.py               | 21 ---------------------
 pym/_emerge/Scheduler.py                    |  2 +-
 pym/portage/dbapi/vartree.py                |  3 ++-
 pym/portage/package/ebuild/doebuild.py      |  9 ++++++---
 pym/portage/tests/ebuild/test_ipc_daemon.py |  2 +-
 5 files changed, 10 insertions(+), 27 deletions(-)

diff --git a/pym/_emerge/EbuildBuildDir.py b/pym/_emerge/EbuildBuildDir.py
index 1f1385a3b..69f694992 100644
--- a/pym/_emerge/EbuildBuildDir.py
+++ b/pym/_emerge/EbuildBuildDir.py
@@ -84,27 +84,6 @@ class EbuildBuildDir(SlotObject):
                        except OSError:
                                pass
 
-       def unlock(self):
-               if self._lock_obj is None:
-                       return
-
-               # Keep this legacy implementation until all consumers have 
migrated
-               # to async_unlock, since run_until_complete(self.async_unlock())
-               # would add unwanted event loop recursion here.
-               self._lock_obj.unlock()
-               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.start()
-               if catdir_lock.wait() == os.EX_OK:
-                       try:
-                               os.rmdir(self._catdir)
-                       except OSError:
-                               pass
-                       finally:
-                               catdir_lock.unlock()
-
        def async_unlock(self):
                """
                Release the lock asynchronously. Release notification is 
available

diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py
index eb1cd0108..a248f5974 100644
--- a/pym/_emerge/Scheduler.py
+++ b/pym/_emerge/Scheduler.py
@@ -911,7 +911,7 @@ class Scheduler(PollScheduler):
                                                clean_phase.start()
                                                clean_phase.wait()
 
-                               build_dir.unlock()
+                               
sched_iface.run_until_complete(build_dir.async_unlock())
 
                if failures:
                        return FAILURE

diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index c274248e3..8ad6957a3 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -2199,7 +2199,8 @@ class dblink(object):
                                                retval = phase.wait()
                        finally:
                                        if builddir_lock is not None:
-                                               builddir_lock.unlock()
+                                               scheduler.run_until_complete(
+                                                       
builddir_lock.async_unlock())
 
                if log_path is not None:
 

diff --git a/pym/portage/package/ebuild/doebuild.py 
b/pym/portage/package/ebuild/doebuild.py
index 8436c0b10..bdcdfbe87 100644
--- a/pym/portage/package/ebuild/doebuild.py
+++ b/pym/portage/package/ebuild/doebuild.py
@@ -819,7 +819,8 @@ def doebuild(myebuild, mydo, _unused=DeprecationWarning, 
settings=None, debug=0,
                                        fd_pipes=fd_pipes, returnpid=returnpid)
                        finally:
                                if builddir_lock is not None:
-                                       builddir_lock.unlock()
+                                       
builddir_lock.scheduler.run_until_complete(
+                                               builddir_lock.async_unlock())
 
                # get possible slot information from the deps file
                if mydo == "depend":
@@ -943,7 +944,8 @@ def doebuild(myebuild, mydo, _unused=DeprecationWarning, 
settings=None, debug=0,
                                                _spawn_phase("clean", 
mysettings)
                                        finally:
                                                if builddir_lock is not None:
-                                                       builddir_lock.unlock()
+                                                       
builddir_lock.scheduler.run_until_complete(
+                                                               
builddir_lock.async_unlock())
                                                        builddir_lock = None
                                else:
                                        writemsg_stdout(_(">>> WORKDIR is 
up-to-date, keeping...\n"))
@@ -1243,7 +1245,8 @@ def doebuild(myebuild, mydo, _unused=DeprecationWarning, 
settings=None, debug=0,
        finally:
 
                if builddir_lock is not None:
-                       builddir_lock.unlock()
+                       builddir_lock.scheduler.run_until_complete(
+                               builddir_lock.async_unlock())
                if tmpdir:
                        mysettings["PORTAGE_TMPDIR"] = tmpdir_orig
                        shutil.rmtree(tmpdir)

diff --git a/pym/portage/tests/ebuild/test_ipc_daemon.py 
b/pym/portage/tests/ebuild/test_ipc_daemon.py
index 1152f31b4..b45177f7e 100644
--- a/pym/portage/tests/ebuild/test_ipc_daemon.py
+++ b/pym/portage/tests/ebuild/test_ipc_daemon.py
@@ -137,7 +137,7 @@ class IpcDaemonTestCase(TestCase):
 
                finally:
                        if build_dir is not None:
-                               build_dir.unlock()
+                               
event_loop.run_until_complete(build_dir.async_unlock())
                        shutil.rmtree(tmpdir)
 
        def _timeout_callback(self, task_scheduler):

Reply via email to