EbuildBuildDir: handle AsynchronousLock failure
authorZac Medico <zmedico@gentoo.org>
Mon, 16 May 2011 07:10:07 +0000 (00:10 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 16 May 2011 07:10:07 +0000 (00:10 -0700)
pym/_emerge/EbuildBuildDir.py

index 1da3c93ae2c755aa3b6fff3b4a74a1c9b77c15ab..3e0aefbf25361f2bdb395b36f9ee6ff5bc05f64d 100644 (file)
@@ -43,6 +43,8 @@ class EbuildBuildDir(SlotObject):
                catdir_lock = AsynchronousLock(path=catdir, scheduler=self.scheduler)
                catdir_lock.start()
                catdir_lock.wait()
+               self._assert_lock(catdir_lock)
+
                try:
                        try:
                                portage.util.ensure_dirs(catdir,
@@ -55,12 +57,19 @@ class EbuildBuildDir(SlotObject):
                                scheduler=self.scheduler)
                        builddir_lock.start()
                        builddir_lock.wait()
+                       self._assert_lock(builddir_lock)
                        self._lock_obj = builddir_lock
                        self.settings['PORTAGE_BUILDIR_LOCKED'] = '1'
                finally:
                        self.locked = self._lock_obj is not None
                        catdir_lock.unlock()
 
+       def _assert_lock(self, async_lock):
+               if async_lock.returncode != os.EX_OK:
+                       # TODO: create a better way to propagate this error to the caller
+                       raise AssertionError("AsynchronousLock failed with returncode %s" \
+                               % (async_lock.returncode,))
+
        def clean_log(self):
                """Discard existing log. The log will not be be discarded
                in cases when it would not make sense, like when FEATURES=keepwork
@@ -85,15 +94,15 @@ class EbuildBuildDir(SlotObject):
                self.settings.pop('PORTAGE_BUILDIR_LOCKED', None)
                catdir_lock = AsynchronousLock(path=self._catdir, scheduler=self.scheduler)
                catdir_lock.start()
-               catdir_lock.wait()
-               try:
-                       os.rmdir(self._catdir)
-               except OSError as e:
-                       if e.errno not in (errno.ENOENT,
-                               errno.ENOTEMPTY, errno.EEXIST, errno.EPERM):
-                               raise
-               finally:
-                       catdir_lock.unlock()
+               if catdir_lock.wait() == os.EX_OK:
+                       try:
+                               os.rmdir(self._catdir)
+                       except OSError as e:
+                               if e.errno not in (errno.ENOENT,
+                                       errno.ENOTEMPTY, errno.EEXIST, errno.EPERM):
+                                       raise
+                       finally:
+                               catdir_lock.unlock()
 
        class AlreadyLocked(portage.exception.PortageException):
                pass