-
Notifications
You must be signed in to change notification settings - Fork 5
Add archive verification command #18
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -90,8 +90,10 @@ def backup_fastq( | |||||||||||
|
|
||||||||||||
| ### All the checks are done and the files are safe to archive! | ||||||||||||
|
|
||||||||||||
| # move the files to the archive location and remove permission | ||||||||||||
| permission = stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | ||||||||||||
| # move the files to the archive location and set readable permissions | ||||||||||||
| # keep the files writable by the owner to allow intentional updates or tests | ||||||||||||
| # that simulate corruption | ||||||||||||
| permission = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH | ||||||||||||
| md5s = [] | ||||||||||||
| for fp in RI_fps: | ||||||||||||
| if "_L" in fp.name: | ||||||||||||
|
|
@@ -114,6 +116,48 @@ def backup_fastq( | |||||||||||
| return write_dir | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def verify_archive(archive_dir: Path) -> bool: | ||||||||||||
| md5_files = list(archive_dir.glob("*.md5")) | ||||||||||||
| if not md5_files: | ||||||||||||
| raise FileNotFoundError(f"No md5 file found in {archive_dir}") | ||||||||||||
|
|
||||||||||||
| if len(md5_files) > 1: | ||||||||||||
| warnings.warn( | ||||||||||||
| f"Multiple md5 files found in {archive_dir}. Using {md5_files[0].name}." | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| md5_fp = md5_files[0] | ||||||||||||
| missing_files = [] | ||||||||||||
| mismatched_hashes = [] | ||||||||||||
|
|
||||||||||||
| with open(md5_fp) as md5_file: | ||||||||||||
| for line in md5_file: | ||||||||||||
| expected = line.strip().split("\t") | ||||||||||||
|
||||||||||||
| expected = line.strip().split("\t") | |
| line = line.strip() | |
| if not line: # Skip empty or whitespace-only lines | |
| continue | |
| expected = line.split("\t") |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message could be more helpful. When an invalid MD5 line is encountered, the error includes the entire line in the message, but doesn't indicate which specific field or format issue was detected.
Consider improving the error message to be more specific:
raise ValueError(
f"Invalid md5 line in {md5_fp}: expected 2 tab-separated values, "
f"got {len(expected)} in line: {line.strip()}"
)| raise ValueError(f"Invalid md5 line in {md5_fp}: {line}") | |
| raise ValueError( | |
| f"Invalid md5 line in {md5_fp}: expected 2 tab-separated values, " | |
| f"got {len(expected)} in line: {line.strip()}" | |
| ) |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Potential performance issue: The function processes all files before reporting any errors. For large archives with many files, this means the entire verification must complete even if the first file fails.
While collecting all errors provides comprehensive feedback, consider whether early termination on first failure would be more appropriate for this use case. If comprehensive reporting is desired, the current approach is acceptable but could benefit from progress logging for large archives.
Uh oh!
There was an error while loading. Please reload this page.