changeset 8226:103bb1129d44

ssh: use py3 os.replace
author Mads Kiilerich <mads@kiilerich.com>
date Thu, 06 Feb 2020 03:39:22 +0100
parents 4b68fbe195b6
children 5a3cef4a331f
files kallithea/model/ssh_key.py
diffstat 1 files changed, 2 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/model/ssh_key.py	Thu Feb 06 03:03:58 2020 +0100
+++ b/kallithea/model/ssh_key.py	Thu Feb 06 03:39:22 2020 +0100
@@ -134,8 +134,5 @@
             for key in UserSshKeys.query().join(UserSshKeys.user).filter(User.active == True):
                 f.write(ssh.authorized_keys_line(kallithea_cli_path, config['__file__'], key))
         os.chmod(tmp_authorized_keys, stat.S_IRUSR | stat.S_IWUSR)
-        # This preliminary remove is needed for Windows, not for Unix.
-        # TODO In Python 3, the remove+rename sequence below should become os.replace.
-        if os.path.exists(authorized_keys):
-            os.remove(authorized_keys)
-        os.rename(tmp_authorized_keys, authorized_keys)
+        # Note: simple overwrite / rename isn't enough to replace the file on Windows
+        os.replace(tmp_authorized_keys, authorized_keys)