From: Zac Medico Date: Sun, 13 Feb 2011 14:18:00 +0000 (-0800) Subject: egencache: --preserve-comments allow missing file X-Git-Tag: v2.1.9.40~17 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8a3eb0eb28d761efd2607825445bfeef47735a48;p=portage.git egencache: --preserve-comments allow missing file This will fix bug #354687. --- diff --git a/bin/egencache b/bin/egencache index 89d2fdec4..e5685c4dc 100755 --- a/bin/egencache +++ b/bin/egencache @@ -396,11 +396,33 @@ class GenUseLocalDesc(object): mode='w', encoding=_encodings['repo.content'], errors='replace') except IOError as e: + if not self._preserve_comments or \ + os.path.isfile(desc_path): + writemsg_level( + "ERROR: failed to open output file %s: %s\n" \ + % (desc_path, e), level=logging.ERROR, noiselevel=-1) + self.returncode |= 2 + return + + # Open in r+b mode failed because the file doesn't + # exist yet. We can probably recover if we disable + # preserve_comments mode now. writemsg_level( - "ERROR: failed to open output file %s: %s\n" % (desc_path,e,), - level=logging.ERROR, noiselevel=-1) - self.returncode |= 2 - return + "WARNING: --preserve-comments enabled, but " + \ + "output file not found: %s\n" % (desc_path,), + level=logging.WARNING, noiselevel=-1) + self._preserve_comments = False + try: + output = codecs.open(_unicode_encode(desc_path, + encoding=_encodings['fs'], errors='strict'), + mode='w', encoding=_encodings['repo.content'], + errors='replace') + except IOError as e: + writemsg_level( + "ERROR: failed to open output file %s: %s\n" \ + % (desc_path, e), level=logging.ERROR, noiselevel=-1) + self.returncode |= 2 + return else: output = sys.stdout