Skip to content

Commit

Permalink
utils: restore the error handling when extracting a file from a tar
Browse files Browse the repository at this point in the history
This was removed in #70 mistakenly
  • Loading branch information
Arno500 authored Jan 9, 2025
1 parent 1607ed7 commit 8fc7bc8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions hwbench/utils/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ def extract_file_from_tar(tarfilename: str, filename: str) -> bytes | None:
"""return a specific file in a tar archive as bytes if
the file exists."""
# may raise tarfile.ReadError if tarfilename is not a tar file
with tarfile.open(tarfilename, "r") as tarfd:
file = tarfd.extractfile(filename)
if not file:
tarfd.close()
return None
ret = file.read(-1)
return ret
try:
with tarfile.open(tarfilename, "r") as tarfd:
file = tarfd.extractfile(filename)
if not file:
tarfd.close()
return None
ret = file.read(-1)
return ret
except KeyError:
return None


def copy_file(filename: str, destination_dir: str) -> None:
Expand Down

0 comments on commit 8fc7bc8

Please sign in to comment.