EbuildPhase: AsynchronousLock for ebuild-locks
authorZac Medico <zmedico@gentoo.org>
Sun, 15 May 2011 08:03:14 +0000 (01:03 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 15 May 2011 08:03:14 +0000 (01:03 -0700)
pym/_emerge/EbuildPhase.py

index ff76fc641dcbead425e74f9e9a90199060c7ff4a..0b4afe7e87026a09609f99ed40ea9dc8fa0e92db 100644 (file)
@@ -5,13 +5,12 @@ import gzip
 import sys
 import tempfile
 
+from _emerge.AsynchronousLock import AsynchronousLock
 from _emerge.BinpkgEnvExtractor import BinpkgEnvExtractor
 from _emerge.MiscFunctionsProcess import MiscFunctionsProcess
 from _emerge.EbuildProcess import EbuildProcess
 from _emerge.CompositeTask import CompositeTask
 from portage.util import writemsg
-from portage.locks import lockdir
-from portage.locks import unlockdir
 from portage.xml.metadata import MetaDataXML
 import portage
 portage.proxy.lazyimport.lazyimport(globals(),
@@ -121,6 +120,25 @@ class EbuildPhase(CompositeTask):
                        self.wait()
                        return
 
+               self._start_lock()
+
+       def _start_lock(self):
+               if (self.phase in self._locked_phases and
+                       "ebuild-locks" in self.settings.features):
+                       eroot = self.settings["EROOT"]
+                       lock_path = os.path.join(eroot, portage.VDB_PATH + "-ebuild")
+                       if os.access(os.path.dirname(lock_path), os.W_OK):
+                               self._ebuild_lock = AsynchronousLock(path=lock_path,
+                                       scheduler=self.scheduler)
+                               self._start_task(self._ebuild_lock, self._lock_exit)
+                               return
+
+               self._start_ebuild()
+
+       def _lock_exit(self, ebuild_lock):
+               if self._default_exit(ebuild_lock) != os.EX_OK:
+                       self.wait()
+                       return
                self._start_ebuild()
 
        def _start_ebuild(self):
@@ -144,18 +162,12 @@ class EbuildPhase(CompositeTask):
                        phase=self.phase, scheduler=self.scheduler,
                        settings=self.settings)
 
-               if (self.phase in self._locked_phases and
-                       "ebuild-locks" in self.settings.features):
-                       eroot = self.settings["EROOT"]
-                       lock_path = os.path.join(eroot, portage.VDB_PATH + "-ebuild")
-                       if os.access(os.path.dirname(lock_path), os.W_OK):
-                               self._ebuild_lock = lockdir(lock_path)
                self._start_task(ebuild_process, self._ebuild_exit)
 
        def _ebuild_exit(self, ebuild_process):
 
                if self._ebuild_lock is not None:
-                       unlockdir(self._ebuild_lock)
+                       self._ebuild_lock.unlock()
                        self._ebuild_lock = None
 
                fail = False