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

Remove file after download of checksum is not correct. #103

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion mltb2/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""


import contextlib
import os
from typing import Optional

Expand Down Expand Up @@ -45,5 +46,10 @@ def fetch_remote_file(dirname, filename, url, sha256_checksum) -> str:
IOError: if the sha256 checksum is wrong
"""
remote = RemoteFileMetadata(filename=filename, url=url, checksum=sha256_checksum)
fetch_remote_file_path = _fetch_remote(remote, dirname=dirname)
try:
fetch_remote_file_path = _fetch_remote(remote, dirname=dirname)
except Exception:
with contextlib.suppress(FileNotFoundError):
os.remove(os.path.join(dirname, filename))
raise
return fetch_remote_file_path
2 changes: 2 additions & 0 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_fetch_remote_file(tmpdir):
sha256_checksum="8d834de97b095fbf4bf6075743827862be2c6c404594ae04606d9c56d8f1017b",
)
assert remote_file == os.path.join(tmpdir, filename)
assert os.path.exists(os.path.join(tmpdir, filename))


def test_fetch_remote_file_wrong_checksum(tmpdir):
Expand All @@ -29,6 +30,7 @@ def test_fetch_remote_file_wrong_checksum(tmpdir):
url="https://raw.githubusercontent.com/telekom/mltb2/main/LICENSE",
sha256_checksum="wrong",
)
assert not os.path.exists(os.path.join(tmpdir, filename))


def test_get_and_create_mltb2_data_dir(tmpdir):
Expand Down