From: Zac Medico Date: Fri, 25 Mar 2011 15:57:10 +0000 (-0700) Subject: PollScheduler: handle missing log directory X-Git-Tag: v2.1.9.45~11 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=35faac42c5958278240ffe7cd3e88f1c050f404b;p=portage.git PollScheduler: handle missing log directory This can be triggered by AbstractPollTask._log_poll_exception(), as reported by Michael Haubenwallner for AIX. --- diff --git a/pym/_emerge/PollScheduler.py b/pym/_emerge/PollScheduler.py index 8f4bd64b9..043f02a8b 100644 --- a/pym/_emerge/PollScheduler.py +++ b/pym/_emerge/PollScheduler.py @@ -2,6 +2,7 @@ # Distributed under the terms of the GNU General Public License v2 import gzip +import errno import logging import select import time @@ -318,22 +319,32 @@ class PollScheduler(object): # (like for parallel-fetch), then use the global value. background = self._background + msg_shown = False if not background: writemsg_level(msg, level=level, noiselevel=noiselevel) + msg_shown = True if log_path is not None: - f = open(_unicode_encode(log_path, - encoding=_encodings['fs'], errors='strict'), - mode='ab') - - if log_path.endswith('.gz'): - # NOTE: The empty filename argument prevents us from triggering - # a bug in python3 which causes GzipFile to raise AttributeError - # if fileobj.name is bytes instead of unicode. - f = gzip.GzipFile(filename='', mode='ab', fileobj=f) - - f.write(_unicode_encode(msg)) - f.close() + try: + f = open(_unicode_encode(log_path, + encoding=_encodings['fs'], errors='strict'), + mode='ab') + except IOError as e: + if e.errno not in (errno.ENOENT, errno.ESTALE): + raise + if not msg_shown: + writemsg_level(msg, level=level, noiselevel=noiselevel) + else: + + if log_path.endswith('.gz'): + # NOTE: The empty filename argument prevents us from + # triggering a bug in python3 which causes GzipFile + # to raise AttributeError if fileobj.name is bytes + # instead of unicode. + f = gzip.GzipFile(filename='', mode='ab', fileobj=f) + + f.write(_unicode_encode(msg)) + f.close() _can_poll_device = None