Skip to content

Commit 8146a70

Browse files
committed
fixup! Ignore silently if file is already gone in delete callback
1 parent 077aa73 commit 8146a70

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

src/zimscraperlib/filesystem.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77

88
from __future__ import annotations
99

10-
import os
1110
import pathlib
1211

1312
import magic
1413

15-
from zimscraperlib import logger
16-
1714
# override some MIME-types found by libmagic to different ones
1815
MIME_OVERRIDES = {
1916
"image/svg": "image/svg+xml",
@@ -44,9 +41,6 @@ def get_content_mimetype(content: bytes | str) -> str:
4441
return MIME_OVERRIDES.get(detected_mime, detected_mime)
4542

4643

47-
def delete_callback(fpath: str | pathlib.Path):
44+
def delete_callback(fpath: pathlib.Path):
4845
"""helper deleting passed filepath"""
49-
if not pathlib.Path(fpath).exists():
50-
logger.warning(f"delete callback: file {fpath} is already gone")
51-
else:
52-
os.unlink(fpath)
46+
fpath.unlink(missing_ok=True)

tests/filesystem/test_filesystem.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,8 @@ def test_delete_callback(tmp_path):
5454

5555
assert not fpath.exists()
5656

57+
# file already gone should not be a problem
58+
delete_callback(fpath)
59+
60+
# wrong path should not be a problem
5761
delete_callback(pathlib.Path("/foo.txt"))

tests/zim/test_zim_creator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def test_sourcefile_removal(tmp_path, html_file):
281281

282282
def test_sourcefile_removal_std(tmp_path, html_file):
283283
fpath = tmp_path / "test.zim"
284-
paths = []
284+
paths: list[pathlib.Path] = []
285285
with Creator(fpath, "").config_dev_metadata() as creator:
286286
for idx in range(0, 4):
287287
# copy html to folder

0 commit comments

Comments
 (0)