diff options
author | Zac Medico <zmedico@gentoo.org> | 2011-02-13 06:18:00 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2011-02-13 20:30:07 -0800 |
commit | 8a3eb0eb28d761efd2607825445bfeef47735a48 (patch) | |
tree | 94423243271827a5618a40f4c0788afde8c889e7 /bin/egencache | |
parent | 463249dfb5a2d715f9dc8e8cd531fad372e9f5fc (diff) | |
download | portage-8a3eb0eb28d761efd2607825445bfeef47735a48.tar.gz portage-8a3eb0eb28d761efd2607825445bfeef47735a48.tar.bz2 portage-8a3eb0eb28d761efd2607825445bfeef47735a48.zip |
egencache: --preserve-comments allow missing file
This will fix bug #354687.
Diffstat (limited to 'bin/egencache')
-rwxr-xr-x | bin/egencache | 30 |
1 files changed, 26 insertions, 4 deletions
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 |