From b432a1b3051d91546649e8f3190675767461d8e8 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 1 Dec 2011 13:22:00 -0800 Subject: [PATCH] _emerge/EbuildMetadataPhase.py: use os.read() 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 | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pym/_emerge/EbuildMetadataPhase.py b/pym/_emerge/EbuildMetadataPhase.py index 16948df76..e068e8f24 100644 --- a/pym/_emerge/EbuildMetadataPhase.py +++ b/pym/_emerge/EbuildMetadataPhase.py @@ -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) -- 2.26.2