From: Daira Hopwood Date: Mon, 31 Aug 2015 16:56:11 +0000 (+0100) Subject: More precise exception handling in replace_file. X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/vdrive?a=commitdiff_plain;h=4fbba62f34fc91207005fd170812880f666f1e28;p=tahoe-lafs%2Ftahoe-lafs.git More precise exception handling in replace_file. Signed-off-by: Daira Hopwood --- 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')