@@ -60,7 +60,7 @@ async def atomic_write_text(path: Path, data: str) -> None:
60
60
def _sync_write_text () -> str :
61
61
# create a temp file in the target dir, return its name
62
62
fd , tmp_path = tempfile .mkstemp (
63
- suffix = path .suffix ,
63
+ suffix = f' { path .suffix } .tmp' ,
64
64
prefix = f'{ path .name } .' ,
65
65
dir = str (dir_path ),
66
66
)
@@ -79,14 +79,16 @@ def _sync_write_text() -> str:
79
79
except (FileNotFoundError , PermissionError ):
80
80
# fallback if tmp went missing
81
81
await asyncio .to_thread (path .write_text , data , encoding = 'utf-8' )
82
+ finally :
83
+ await asyncio .to_thread (Path (tmp_path ).unlink , missing_ok = True )
82
84
83
85
84
86
async def atomic_write_bytes (path : Path , data : bytes ) -> None :
85
87
dir_path = path .parent
86
88
87
89
def _sync_write_bytes () -> str :
88
90
fd , tmp_path = tempfile .mkstemp (
89
- suffix = path .suffix ,
91
+ suffix = f' { path .suffix } .tmp' ,
90
92
prefix = f'{ path .name } .' ,
91
93
dir = str (dir_path ),
92
94
)
@@ -105,6 +107,8 @@ def _sync_write_bytes() -> str:
105
107
except (FileNotFoundError , PermissionError ):
106
108
# fallback if tmp went missing
107
109
await asyncio .to_thread (path .write_bytes , data )
110
+ finally :
111
+ await asyncio .to_thread (Path (tmp_path ).unlink , missing_ok = True )
108
112
109
113
110
114
async def export_json_to_stream (
0 commit comments