From: Daira Hopwood Date: Sat, 24 Oct 2015 00:14:56 +0000 (+0100) Subject: replace_file should allow the replaced file not to exist on Windows. X-Git-Url: https://git.rkrishnan.org/%5B/FOOURL?a=commitdiff_plain;h=7bf8d7c40d3e57e3c41610a30c8d14e60df45e46;p=tahoe-lafs%2Ftahoe-lafs.git replace_file should allow the replaced file not to exist on Windows. Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/util/fileutil.py b/src/allmydata/util/fileutil.py index 23152026..29e6d1b1 100644 --- a/src/allmydata/util/fileutil.py +++ b/src/allmydata/util/fileutil.py @@ -582,6 +582,9 @@ if sys.platform == "win32": REPLACEFILE_IGNORE_MERGE_ERRORS = 0x00000002 + # + ERROR_FILE_NOT_FOUND = 2 + def rename_no_overwrite(source_path, dest_path): os.rename(source_path, dest_path) @@ -596,7 +599,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.