Use replace instead of rename in localetools.py

On Unix, if target exists and it is a file, rename silently replaces it
if the user has permission. However, on Windows, if the target exists,
FileExistError will be raised.

With replace, if target points to an existing file or empty directory,
it will be unconditionally replaced.

Pick-to: 6.8
Change-Id: I2774152fec78a00c4ca6c9d1b927e503df2f2e84
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Mate Barany 2024-09-13 13:21:35 +02:00
parent b3ef2fdd8b
commit eff8e6b885

View File

@ -115,7 +115,7 @@ def AtomicRenameTemporaryFile(originalLocation: Path, *, prefix: str, dir: Path)
yield tempFile
tempFile.close()
# Move the modified file to the original location
Path(tempFile.name).rename(originalLocation)
Path(tempFile.name).replace(originalLocation)
except Exception:
# delete the temporary file in case of error
tempFile.close()