From 0a64f784003c11e151405b7f708d77770de0ed57 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 25 Mar 2011 08:57:10 -0700 Subject: [PATCH] PollScheduler: handle missing log directory This can be triggered by AbstractPollTask._log_poll_exception(), as reported by Michael Haubenwallner for AIX. --- pym/_emerge/PollScheduler.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) 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 -- 2.26.2