_emerge/EbuildMetadataPhase.py: use os.read()
authorZac Medico <zmedico@gentoo.org>
Thu, 1 Dec 2011 21:22:00 +0000 (13:22 -0800)
committerZac Medico <zmedico@gentoo.org>
Thu, 1 Dec 2011 21:22:00 +0000 (13:22 -0800)
There's no need for a file object, and file objects introduce
complexity that can lead to bugs as mentioned in bug 337465 comment 31,
so use os.read() directly on the file descriptor.

pym/_emerge/EbuildMetadataPhase.py

index 16948df76062ee9fd31cb6b3dda7a96bf35d8d15..e068e8f249101e5cb06c6dc27012950ce1bc098b 100644 (file)
@@ -10,6 +10,7 @@ from portage import os
 from portage import _encodings
 from portage import _unicode_decode
 from portage import _unicode_encode
+import errno
 import fcntl
 import io
 
@@ -75,7 +76,6 @@ class EbuildMetadataPhase(SubProcess):
                        if fd == sys.stderr.fileno():
                                sys.stderr.flush()
 
-               fd_pipes_orig = fd_pipes.copy()
                self._files = self._files_dict()
                files = self._files
 
@@ -86,8 +86,8 @@ class EbuildMetadataPhase(SubProcess):
                fd_pipes[self._metadata_fd] = slave_fd
 
                self._raw_metadata = []
-               files.ebuild = os.fdopen(master_fd, 'rb', 0)
-               self._reg_id = self.scheduler.register(files.ebuild.fileno(),
+               files.ebuild = master_fd
+               self._reg_id = self.scheduler.register(files.ebuild,
                        self._registered_events, self._output_handler)
                self._registered = True
 
@@ -112,10 +112,16 @@ class EbuildMetadataPhase(SubProcess):
        def _output_handler(self, fd, event):
 
                if event & PollConstants.POLLIN:
-                       self._raw_metadata.append(self._files.ebuild.read())
-                       if not self._raw_metadata[-1]:
-                               self._unregister()
-                               self.wait()
+                       try:
+                               self._raw_metadata.append(
+                                       os.read(self._files.ebuild, self._bufsize))
+                       except IOError as e:
+                               if e.errno not in (errno.EAGAIN,):
+                                       raise
+                       else:
+                               if not self._raw_metadata[-1]:
+                                       self._unregister()
+                                       self.wait()
 
                self._unregister_if_appropriate(event)