Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore silently if file is already gone in delete callback #232

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/zimscraperlib/filesystem.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests/filesystem/test_filesystem.py
Original file line number Diff line number Diff line change
@@ -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()