From: Zac Medico Date: Sun, 9 Jul 2006 20:18:59 +0000 (-0000) Subject: Wrap common write_atomic exceptions for easier error handling. X-Git-Tag: v2.1.1~257 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5cd6e36273f2d5674aa47970eb1207de3ac3bc4a;p=portage.git Wrap common write_atomic exceptions for easier error handling. svn path=/main/trunk/; revision=3822 --- diff --git a/pym/portage_util.py b/pym/portage_util.py index a8f396c51..79babe05c 100644 --- a/pym/portage_util.py +++ b/pym/portage_util.py @@ -707,13 +707,25 @@ class atomic_ofstream(file): base_destructor() def write_atomic(file_path, content): - f = atomic_ofstream(file_path) + f = None try: + f = atomic_ofstream(file_path) f.write(content) f.close() - except IOError, ioe: - f.abort() - raise ioe + except (IOError, OSError), e: + if f: + f.abort() + func_call = "write_atomic('%s')" % file_path + if e.errno == errno.EPERM: + raise OperationNotPermitted(func_call) + elif e.errno == errno.EACCES: + raise PermissionDenied(func_call) + elif e.errno == errno.EROFS: + raise ReadOnlyFileSystem(func_call) + elif e.errno == errno.ENOENT: + raise FileNotFound(file_path) + else: + raise def ensure_dirs(dir_path, *args, **kwargs): """Create a directory and call apply_permissions.