Skip to content

Commit

Permalink
Ignore silently if file is already gone in delete callback
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit74 committed Dec 20, 2024
1 parent b7b5e46 commit 2dda861
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/zimscraperlib/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import magic

from zimscraperlib import logger

# override some MIME-types found by libmagic to different ones
MIME_OVERRIDES = {
"image/svg": "image/svg+xml",
Expand Down Expand Up @@ -44,5 +46,7 @@ def get_content_mimetype(content: bytes | str) -> str:

def delete_callback(fpath: str | pathlib.Path):
"""helper deleting passed filepath"""

os.unlink(fpath)
if not pathlib.Path(fpath).exists():
logger.warning(f"delete callback: file {fpath} is already gone")

Check warning on line 50 in src/zimscraperlib/filesystem.py

View check run for this annotation

Codecov / codecov/patch

src/zimscraperlib/filesystem.py#L50

Added line #L50 was not covered by tests
else:
os.unlink(fpath)

0 comments on commit 2dda861

Please sign in to comment.