Keep file permissions on update rename workaround
This commit is contained in:
parent
4f0613689a
commit
eab63c6af8
1 changed files with 3 additions and 1 deletions
|
@ -2,6 +2,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
def update():
|
def update():
|
||||||
|
@ -94,13 +95,14 @@ def update():
|
||||||
num_ok += 1
|
num_ok += 1
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
try:
|
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"
|
path_to_tmp = path_to + "-old"
|
||||||
if os.path.isfile(path_to_tmp):
|
if os.path.isfile(path_to_tmp):
|
||||||
os.unlink(path_to_tmp)
|
os.unlink(path_to_tmp)
|
||||||
os.rename(path_to, path_to_tmp)
|
os.rename(path_to, path_to_tmp)
|
||||||
num_rename += 1
|
num_rename += 1
|
||||||
open(path_to, 'wb').write(data)
|
open(path_to, 'wb').write(data)
|
||||||
|
shutil.copymode(path_to_tmp, path_to) # Copy permissions
|
||||||
print("Write done after rename!")
|
print("Write done after rename!")
|
||||||
num_ok += 1
|
num_ok += 1
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
|
Loading…
Reference in a new issue