diff --git a/src/zimscraperlib/filesystem.py b/src/zimscraperlib/filesystem.py index 7d22065..7ce6f90 100644 --- a/src/zimscraperlib/filesystem.py +++ b/src/zimscraperlib/filesystem.py @@ -2,7 +2,6 @@ Shortcuts to retrieve mime type using magic""" -import os import pathlib from contextlib import contextmanager from tempfile import TemporaryDirectory @@ -40,10 +39,9 @@ def get_content_mimetype(content: bytes | str) -> str: return MIME_OVERRIDES.get(detected_mime, detected_mime) -def delete_callback(fpath: str | pathlib.Path): +def delete_callback(fpath: pathlib.Path): """helper deleting passed filepath""" - - os.unlink(fpath) + fpath.unlink(missing_ok=True) @contextmanager diff --git a/tests/filesystem/test_filesystem.py b/tests/filesystem/test_filesystem.py index 6518c59..a25fcb1 100644 --- a/tests/filesystem/test_filesystem.py +++ b/tests/filesystem/test_filesystem.py @@ -57,6 +57,12 @@ def test_delete_callback(tmp_path: pathlib.Path): assert not fpath.exists() + # file already gone should not be a problem + delete_callback(fpath) + + # wrong path should not be a problem + delete_callback(pathlib.Path("/foo.txt")) + def test_path_from_tmp_dir(): tempdir = TemporaryDirectory()