From eff8e6b885dfa3f26523ca39164725b4932c31bd Mon Sep 17 00:00:00 2001 From: Mate Barany Date: Fri, 13 Sep 2024 13:21:35 +0200 Subject: [PATCH] Use replace instead of rename in localetools.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Edward Welbourne --- util/locale_database/localetools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/locale_database/localetools.py b/util/locale_database/localetools.py index a7fcd087273..175b04e99c0 100644 --- a/util/locale_database/localetools.py +++ b/util/locale_database/localetools.py @@ -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()