summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-02-13 06:18:00 -0800
committerZac Medico <zmedico@gentoo.org>2011-02-13 06:18:00 -0800
commitef41f7367c57a69fe88f37d2e31d48a59394aac4 (patch)
tree355fc30dcff16305a7f742e3544ae7094f1ec942
parentf5eaf39529393b0b68f656b06600920791d9bec0 (diff)
downloadportage-ef41f7367c57a69fe88f37d2e31d48a59394aac4.tar.gz
portage-ef41f7367c57a69fe88f37d2e31d48a59394aac4.tar.bz2
portage-ef41f7367c57a69fe88f37d2e31d48a59394aac4.zip
egencache: --preserve-comments allow missing file
This will fix bug #354687.
-rwxr-xr-xbin/egencache30
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