forked from Shinonome/caelestia-cli
theme: ensure atomic writes for configuration files (#76)
* fix: ensure atomic writes for configuration files * requested changes
This commit is contained in:
@@ -2,6 +2,8 @@ import json
|
|||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import tempfile
|
||||||
|
import shutil
|
||||||
|
|
||||||
from caelestia.utils.colour import get_dynamic_colours
|
from caelestia.utils.colour import get_dynamic_colours
|
||||||
from caelestia.utils.logging import log_exception
|
from caelestia.utils.logging import log_exception
|
||||||
@@ -101,8 +103,11 @@ def gen_sequences(colours: dict[str, str]) -> str:
|
|||||||
|
|
||||||
def write_file(path: Path, content: str) -> None:
|
def write_file(path: Path, content: str) -> None:
|
||||||
path.parent.mkdir(parents=True, exist_ok=True)
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
path.write_text(content)
|
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile("w") as f:
|
||||||
|
f.write(content)
|
||||||
|
f.flush()
|
||||||
|
shutil.move(f.name, path)
|
||||||
|
|
||||||
@log_exception
|
@log_exception
|
||||||
def apply_terms(sequences: str) -> None:
|
def apply_terms(sequences: str) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user