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

Added more robust archive file corruption handling #370

Merged
merged 1 commit into from
Jun 16, 2023
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
13 changes: 13 additions & 0 deletions gwsumm/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,19 @@ def read_data_archive(sourcefile, rm_source_on_fail=True):

with File(sourcefile, 'r') as h5file:

# Make sure that each part of the archive file is not corrupted by
# trying to read the data. If any part is broken, delete the file and
# return without loading anything into the gwsumm.globalv variables
try:
# simple lambda function here to do nothing but visit each item
h5file.visititems(lambda name, obj: None)
except RuntimeError as exc:
if not rm_source_on_fail:
raise
warnings.warn(f"failed to read {sourcefile} [{exc}], removing...")
os.remove(sourcefile)
return

# -- channels ---------------------------

try:
Expand Down