mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-10-24 14:12:02 +00:00
Atomic save should preserve stat if the file exists
This commit is contained in:
parent
71f1f3aa64
commit
b7d603c4de
1 changed files with 4 additions and 0 deletions
|
|
@ -35,12 +35,16 @@ def build_ansi_color_table(opts: Optional[Options] = None) -> int:
|
|||
|
||||
|
||||
def atomic_save(data: bytes, path: str) -> None:
|
||||
import shutil
|
||||
import tempfile
|
||||
path = os.path.realpath(path)
|
||||
fd, p = tempfile.mkstemp(dir=os.path.dirname(path), suffix='.tmp')
|
||||
try:
|
||||
with os.fdopen(fd, 'wb') as f:
|
||||
f.write(data)
|
||||
with suppress(FileNotFoundError):
|
||||
shutil.copystat(path, p)
|
||||
os.utime(p)
|
||||
os.replace(p, path)
|
||||
finally:
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue