jh
This commit is contained in:
1 parent
ed76261303
commit
918bc45ee0
4 files changed
+20
-5
No files matched your search
+4
-1
@@ -36,13 +36,16 @@ def save_settings(data, path=DEFAULT_PATH):
|
||||
flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
|
||||
if hasattr(os, 'O_BINARY'):
|
||||
flags |= os.O_BINARY
|
||||
created = False
|
||||
try:
|
||||
descriptor = os.open(temporary, flags, 0o600)
|
||||
created = True
|
||||
with os.fdopen(descriptor, 'w', encoding='utf-8') as output:
|
||||
output.write(json.dumps(data, indent=2, ensure_ascii=False) + '\n')
|
||||
os.replace(temporary, path)
|
||||
except BaseException:
|
||||
temporary.unlink(missing_ok=True)
|
||||
if created:
|
||||
temporary.unlink(missing_ok=True)
|
||||
raise
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user