Skip to content

Commit

Permalink
Use replace instead of rename in localetools.py
Browse files Browse the repository at this point in the history
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.

Change-Id: I2774152fec78a00c4ca6c9d1b927e503df2f2e84
Reviewed-by: Mårten Nordheim <[email protected]>
Reviewed-by: Edward Welbourne <[email protected]>
(cherry picked from commit eff8e6b)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
  • Loading branch information
Mate Barany authored and Qt Cherry-pick Bot committed Sep 18, 2024
1 parent d8e1416 commit 9709c4f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion util/locale_database/localetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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()
Expand Down

0 comments on commit 9709c4f

Please sign in to comment.