]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
replace_file should allow the replaced file not to exist on Windows.
authorDaira Hopwood <daira@jacaranda.org>
Sat, 24 Oct 2015 00:14:56 +0000 (01:14 +0100)
committermeejah <meejah@meejah.ca>
Wed, 20 Jan 2016 08:30:17 +0000 (01:30 -0700)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/util/fileutil.py

index b35fe2dc4210ce30c76041080f079b41656825bb..74afd0084a6dc7647cdca5231107980d1e610865 100644 (file)
@@ -591,6 +591,9 @@ if sys.platform == "win32":
 
     REPLACEFILE_IGNORE_MERGE_ERRORS = 0x00000002
 
+    # <https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx>
+    ERROR_FILE_NOT_FOUND = 2
+
     def rename_no_overwrite(source_path, dest_path):
         os.rename(source_path, dest_path)
 
@@ -605,7 +608,13 @@ if sys.platform == "win32":
             # The UnableToUnlinkReplacementError case does not happen on Windows;
             # all errors should be treated as signalling a conflict.
             err = get_last_error()
-            raise ConflictError("WinError: %s" % (WinError(err)))
+            if err != ERROR_FILE_NOT_FOUND:
+                raise ConflictError("WinError: %s" % (WinError(err),))
+
+            try:
+                rename_no_overwrite(replacement_path, replaced_path)
+            except EnvironmentError:
+                reraise(ConflictError)
 else:
     def rename_no_overwrite(source_path, dest_path):
         # link will fail with EEXIST if there is already something at dest_path.