]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
More precise exception handling in replace_file. 2489.write_downloaded_file.0
authorDaira Hopwood <daira@jacaranda.org>
Mon, 31 Aug 2015 16:56:11 +0000 (17:56 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Mon, 31 Aug 2015 16:56:11 +0000 (17:56 +0100)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/util/fileutil.py

index 2debc7f72833f61a74ceba37ed1d6a0326d415a1..6b44d56b5da4510992bb56591e349cc77117388c 100644 (file)
@@ -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')