mirror of
https://github.com/markqvist/NomadNet.git
synced 2026-12-05 14:19:58 -05:00
Atomic writes for config fields, don't overwrite intro_time, Node editor allow fixes
This commit is contained in:
parent
0d3b519a07
commit
5d0ffce51c
5 changed files with 143 additions and 46 deletions
|
|
@ -1,6 +1,39 @@
|
|||
import os
|
||||
import re
|
||||
import unicodedata
|
||||
|
||||
|
||||
def write_config_atomic(config):
|
||||
path = getattr(config, "filename", None)
|
||||
if not path:
|
||||
config.write()
|
||||
return
|
||||
|
||||
directory = os.path.dirname(path) or "."
|
||||
tmp = os.path.join(directory, "."+os.path.basename(path)+".tmp")
|
||||
try:
|
||||
try:
|
||||
existing_mode = os.stat(path).st_mode
|
||||
except OSError:
|
||||
existing_mode = None
|
||||
|
||||
with open(tmp, "wb") as tmp_file:
|
||||
config.write(tmp_file)
|
||||
tmp_file.flush()
|
||||
try: os.fsync(tmp_file.fileno())
|
||||
except Exception: pass
|
||||
|
||||
if existing_mode is not None:
|
||||
try: os.chmod(tmp, existing_mode)
|
||||
except Exception: pass
|
||||
|
||||
os.replace(tmp, path)
|
||||
except Exception:
|
||||
try: os.remove(tmp)
|
||||
except Exception: pass
|
||||
raise
|
||||
|
||||
|
||||
invalid_rendering = ["🕵️", "☝"]
|
||||
|
||||
# Unicode blocks to strip (symbols, dingbats, emoji ranges)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue