Skip to content

Commit 077aa73

Browse files
committed
Ignore silently if file is already gone in delete callback
1 parent b7b5e46 commit 077aa73

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/zimscraperlib/filesystem.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import magic
1414

15+
from zimscraperlib import logger
16+
1517
# override some MIME-types found by libmagic to different ones
1618
MIME_OVERRIDES = {
1719
"image/svg": "image/svg+xml",
@@ -44,5 +46,7 @@ def get_content_mimetype(content: bytes | str) -> str:
4446

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

tests/filesystem/test_filesystem.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
# vim: ai ts=4 sts=4 et sw=4 nu
33

4+
import pathlib
5+
46
import magic
57

68
from zimscraperlib.filesystem import (
@@ -51,3 +53,5 @@ def test_delete_callback(tmp_path):
5153
delete_callback(fpath)
5254

5355
assert not fpath.exists()
56+
57+
delete_callback(pathlib.Path("/foo.txt"))

0 commit comments

Comments
 (0)