Keep file permissions on update rename workaround

This commit is contained in:
shortcutme 2019-09-04 20:15:37 +02:00
parent 4f0613689a
commit eab63c6af8
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 3 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import os
import sys
import json
import re
import shutil
def update():
@ -94,13 +95,14 @@ def update():
num_ok += 1
except Exception as err:
try:
print("Error writing: %s. Renaming old file to avoid lock on Windows..." % err)
print("Error writing: %s. Renaming old file as workaround..." % err)
path_to_tmp = path_to + "-old"
if os.path.isfile(path_to_tmp):
os.unlink(path_to_tmp)
os.rename(path_to, path_to_tmp)
num_rename += 1
open(path_to, 'wb').write(data)
shutil.copymode(path_to_tmp, path_to) # Copy permissions
print("Write done after rename!")
num_ok += 1
except Exception as err: