From 4fbba62f34fc91207005fd170812880f666f1e28 Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Mon, 31 Aug 2015 17:56:11 +0100 Subject: [PATCH] More precise exception handling in replace_file. Signed-off-by: Daira Hopwood --- src/allmydata/util/fileutil.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/allmydata/util/fileutil.py b/src/allmydata/util/fileutil.py index 2debc7f7..6b44d56b 100644 --- a/src/allmydata/util/fileutil.py +++ b/src/allmydata/util/fileutil.py @@ -619,14 +619,15 @@ else: if not os.path.exists(replacement_path): raise ConflictError("Replacement file not found: %r" % (replacement_path,)) try: + os.rename(replaced_path, backup_path) + except OSError as e: + if e.errno != EEXIST: + raise + else: try: - os.rename(replaced_path, backup_path) - except OSError as e: - if e.errno != errno.EEXIST: - raise - rename_no_overwrite(replacement_path, replaced_path) - except EnvironmentError: - reraise(ConflictError) + rename_no_overwrite(replacement_path, replaced_path) + except EnvironmentError: + reraise(ConflictError) PathInfo = namedtuple('PathInfo', 'isdir isfile islink exists size ctime mtime') -- 2.45.2