Skip to content

Commit 8758ca9

Browse files
committed
Fix windows tests after cleanup (2)
1 parent 97b367b commit 8758ca9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/crawlee/_utils/file.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async def atomic_write_text(path: Path, data: str) -> None:
6060
def _sync_write_text() -> str:
6161
# create a temp file in the target dir, return its name
6262
fd, tmp_path = tempfile.mkstemp(
63-
suffix=path.suffix,
63+
suffix=f'{path.suffix}.tmp',
6464
prefix=f'{path.name}.',
6565
dir=str(dir_path),
6666
)
@@ -79,14 +79,16 @@ def _sync_write_text() -> str:
7979
except (FileNotFoundError, PermissionError):
8080
# fallback if tmp went missing
8181
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)
8284

8385

8486
async def atomic_write_bytes(path: Path, data: bytes) -> None:
8587
dir_path = path.parent
8688

8789
def _sync_write_bytes() -> str:
8890
fd, tmp_path = tempfile.mkstemp(
89-
suffix=path.suffix,
91+
suffix=f'{path.suffix}.tmp',
9092
prefix=f'{path.name}.',
9193
dir=str(dir_path),
9294
)
@@ -105,6 +107,8 @@ def _sync_write_bytes() -> str:
105107
except (FileNotFoundError, PermissionError):
106108
# fallback if tmp went missing
107109
await asyncio.to_thread(path.write_bytes, data)
110+
finally:
111+
await asyncio.to_thread(Path(tmp_path).unlink, missing_ok=True)
108112

109113

110114
async def export_json_to_stream(

0 commit comments

Comments
 (0)