Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: lib/_emerge/
Date: Mon, 24 Feb 2020 06:07:39
Message-Id: 1582495263.2c596f49bab63c6c81dd4d68789823d45341264d.zmedico@gentoo
1 commit: 2c596f49bab63c6c81dd4d68789823d45341264d
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Sat Feb 22 22:20:00 2020 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Sun Feb 23 22:01:03 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=2c596f49
7
8 EbuildBuildDir: use async_start method
9
10 Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
11
12 lib/_emerge/EbuildBuildDir.py | 122 +++++++++++++++---------------------------
13 1 file changed, 44 insertions(+), 78 deletions(-)
14
15 diff --git a/lib/_emerge/EbuildBuildDir.py b/lib/_emerge/EbuildBuildDir.py
16 index 477113db8..77dbff1fb 100644
17 --- a/lib/_emerge/EbuildBuildDir.py
18 +++ b/lib/_emerge/EbuildBuildDir.py
19 @@ -1,13 +1,12 @@
20 -# Copyright 1999-2012 Gentoo Foundation
21 +# Copyright 1999-2020 Gentoo Authors
22 # Distributed under the terms of the GNU General Public License v2
23
24 -import functools
25 -
26 from _emerge.AsynchronousLock import AsynchronousLock
27
28 import portage
29 from portage import os
30 from portage.exception import PortageException
31 +from portage.util.futures.compat_coroutine import coroutine
32 from portage.util.SlotObject import SlotObject
33
34 class EbuildBuildDir(SlotObject):
35 @@ -39,6 +38,7 @@ class EbuildBuildDir(SlotObject):
36 except OSError:
37 pass
38
39 + @coroutine
40 def async_lock(self):
41 """
42 Acquire the lock asynchronously. Notification is available
43 @@ -59,47 +59,6 @@ class EbuildBuildDir(SlotObject):
44 raise AssertionError('PORTAGE_BUILDDIR is unset')
45 catdir = os.path.dirname(dir_path)
46 self._catdir = catdir
47 - catdir_lock = AsynchronousLock(path=catdir, scheduler=self.scheduler)
48 - builddir_lock = AsynchronousLock(path=dir_path, scheduler=self.scheduler)
49 - result = self.scheduler.create_future()
50 -
51 - def catdir_locked(catdir_lock):
52 - try:
53 - self._assert_lock(catdir_lock)
54 - except AssertionError as e:
55 - result.set_exception(e)
56 - return
57 -
58 - try:
59 - portage.util.ensure_dirs(catdir,
60 - gid=portage.portage_gid,
61 - mode=0o70, mask=0)
62 - except PortageException as e:
63 - if not os.path.isdir(catdir):
64 - result.set_exception(e)
65 - return
66 -
67 - builddir_lock.addExitListener(builddir_locked)
68 - builddir_lock.start()
69 -
70 - def builddir_locked(builddir_lock):
71 - try:
72 - self._assert_lock(builddir_lock)
73 - except AssertionError as e:
74 - catdir_lock.async_unlock.add_done_callback(
75 - functools.partial(catdir_unlocked, exception=e))
76 - return
77 -
78 - self._lock_obj = builddir_lock
79 - self.locked = True
80 - self.settings['PORTAGE_BUILDDIR_LOCKED'] = '1'
81 - catdir_lock.async_unlock().add_done_callback(catdir_unlocked)
82 -
83 - def catdir_unlocked(future, exception=None):
84 - if not (exception is None and future.exception() is None):
85 - result.set_exception(exception or future.exception())
86 - else:
87 - result.set_result(None)
88
89 try:
90 portage.util.ensure_dirs(os.path.dirname(catdir),
91 @@ -109,10 +68,36 @@ class EbuildBuildDir(SlotObject):
92 if not os.path.isdir(os.path.dirname(catdir)):
93 raise
94
95 - catdir_lock.addExitListener(catdir_locked)
96 - catdir_lock.start()
97 - return result
98 + catdir_lock = AsynchronousLock(path=catdir, scheduler=self.scheduler)
99 + yield catdir_lock.async_start()
100 + yield catdir_lock.async_wait()
101 +
102 + self._assert_lock(catdir_lock)
103 +
104 + try:
105 + portage.util.ensure_dirs(catdir,
106 + gid=portage.portage_gid,
107 + mode=0o70, mask=0)
108 + except PortageException:
109 + if not os.path.isdir(catdir):
110 + raise
111 +
112 + builddir_lock = AsynchronousLock(path=dir_path, scheduler=self.scheduler)
113 + yield builddir_lock.async_start()
114 + yield builddir_lock.async_wait()
115 +
116 + try:
117 + self._assert_lock(builddir_lock)
118 + except AssertionError:
119 + yield catdir_lock.async_unlock()
120 + raise
121
122 + self._lock_obj = builddir_lock
123 + self.locked = True
124 + self.settings['PORTAGE_BUILDDIR_LOCKED'] = '1'
125 + yield catdir_lock.async_unlock()
126 +
127 + @coroutine
128 def async_unlock(self):
129 """
130 Release the lock asynchronously. Release notification is available
131 @@ -120,41 +105,22 @@ class EbuildBuildDir(SlotObject):
132
133 @returns: Future, result is None
134 """
135 - result = self.scheduler.create_future()
136 -
137 - def builddir_unlocked(future):
138 - if future.exception() is not None:
139 - result.set_exception(future.exception())
140 - else:
141 - self._lock_obj = None
142 - self.locked = False
143 - self.settings.pop('PORTAGE_BUILDDIR_LOCKED', None)
144 - catdir_lock = AsynchronousLock(
145 - path=self._catdir, scheduler=self.scheduler)
146 - catdir_lock.addExitListener(catdir_locked)
147 - catdir_lock.start()
148 -
149 - def catdir_locked(catdir_lock):
150 - if catdir_lock.wait() != os.EX_OK:
151 - result.set_result(None)
152 - else:
153 + if self._lock_obj is not None:
154 + yield self._lock_obj.async_unlock()
155 +
156 + self._lock_obj = None
157 + self.locked = False
158 + self.settings.pop('PORTAGE_BUILDDIR_LOCKED', None)
159 + catdir_lock = AsynchronousLock(
160 + path=self._catdir, scheduler=self.scheduler)
161 + yield catdir_lock.async_start()
162 + yield catdir_lock.async_wait()
163 + if catdir_lock.returncode == os.EX_OK:
164 try:
165 os.rmdir(self._catdir)
166 except OSError:
167 pass
168 - catdir_lock.async_unlock().add_done_callback(catdir_unlocked)
169 -
170 - def catdir_unlocked(future):
171 - if future.exception() is None:
172 - result.set_result(None)
173 - else:
174 - result.set_exception(future.exception())
175 -
176 - if self._lock_obj is None:
177 - self.scheduler.call_soon(result.set_result, None)
178 - else:
179 - self._lock_obj.async_unlock().add_done_callback(builddir_unlocked)
180 - return result
181 + yield catdir_lock.async_unlock()
182
183 class AlreadyLocked(portage.exception.PortageException):
184 pass