aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2012-11-13 17:48:55 (GMT)
committerZac Medico <zmedico@gentoo.org>2012-11-13 17:48:55 (GMT)
commitca49f2541f6c9a70459a389e86437681881d260d (patch)
tree6b9b450dc8dd70c45d76e45470424bc09b6a7423
parentpkg_pretend: keep temp on failure for bug #442536 (diff)
downloadportage-ca49f2541f6c9a70459a389e86437681881d260d.zip
portage-ca49f2541f6c9a70459a389e86437681881d260d.tar.gz
portage-ca49f2541f6c9a70459a389e86437681881d260d.tar.bz2
elog/mod_save: wrap IOException for bug #441948
-rw-r--r--pym/portage/elog/mod_save.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/pym/portage/elog/mod_save.py b/pym/portage/elog/mod_save.py
index c69f4a3..7b1cd46 100644
--- a/pym/portage/elog/mod_save.py
+++ b/pym/portage/elog/mod_save.py
@@ -1,7 +1,8 @@
# elog/mod_save.py - elog dispatch module
-# Copyright 2006-2011 Gentoo Foundation
+# Copyright 2006-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
+import errno
import io
import time
import portage
@@ -47,11 +48,22 @@ def process(mysettings, key, logentries, fulltext):
elogfilename = os.path.join(log_subdir, cat + ':' + elogfilename)
_ensure_log_subdirs(logdir, log_subdir)
- elogfile = io.open(_unicode_encode(elogfilename,
- encoding=_encodings['fs'], errors='strict'),
- mode='w', encoding=_encodings['content'], errors='backslashreplace')
- elogfile.write(_unicode_decode(fulltext))
- elogfile.close()
+ try:
+ with io.open(_unicode_encode(elogfilename,
+ encoding=_encodings['fs'], errors='strict'), mode='w',
+ encoding=_encodings['content'],
+ errors='backslashreplace') as elogfile:
+ elogfile.write(_unicode_decode(fulltext))
+ except IOError as e:
+ func_call = "open('%s', 'w')" % elogfilename
+ if e.errno == errno.EACCES:
+ raise portage.exception.PermissionDenied(func_call)
+ elif e.errno == errno.EPERM:
+ raise portage.exception.OperationNotPermitted(func_call)
+ elif e.errno == errno.EROFS:
+ raise portage.exception.ReadOnlyFileSystem(func_call)
+ else:
+ raise
# Copy group permission bits from parent directory.
elogdir_st = os.stat(log_subdir)