mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Prevent fd leak if copystat fails
This commit is contained in:
@@ -24,8 +24,8 @@ posix_template = '''
|
||||
def atomic_write(path: str, data: Union[str, bytes]) -> None:
|
||||
mode = 'w' + ('b' if isinstance(data, bytes) else '')
|
||||
fd, tpath = mkstemp(dir=os.path.dirname(path), text=isinstance(data, str))
|
||||
shutil.copystat(path, tpath)
|
||||
with open(fd, mode) as f:
|
||||
shutil.copystat(path, tpath)
|
||||
f.write(data)
|
||||
os.rename(tpath, path)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user