From 5cd6e36273f2d5674aa47970eb1207de3ac3bc4a Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 9 Jul 2006 20:18:59 +0000 Subject: [PATCH] Wrap common write_atomic exceptions for easier error handling. svn path=/main/trunk/; revision=3822 --- pym/portage_util.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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. -- 2.26.2