|
4 | 4 | # --- BEGIN_HEADER ---
|
5 | 5 | #
|
6 | 6 | # verifyarchives - Search for missing files in user Archives
|
7 |
| -# Copyright (C) 2021-2022 The MiG Project lead by Brian Vinter |
| 7 | +# Copyright (C) 2021-2024 The MiG Project lead by Brian Vinter |
8 | 8 | #
|
9 | 9 | # This file is part of MiG.
|
10 | 10 | #
|
|
42 | 42 | from mig.shared.defaults import freeze_meta_filename, freeze_lock_filename, \
|
43 | 43 | public_archive_index, public_archive_files, public_archive_doi, \
|
44 | 44 | keyword_pending, keyword_final
|
| 45 | +from mig.shared.freezefunctions import sorted_hash_algos, checksum_file |
45 | 46 |
|
46 | 47 |
|
47 | 48 | def fuzzy_match(i, j, offset=2.0):
|
@@ -110,12 +111,29 @@ def check_archive_integrity(configuration, user_id, freeze_path, verbose=False):
|
110 | 111 | archive_path)
|
111 | 112 | # NOTE: we allow a minor time offset to accept various fs hiccups
|
112 | 113 | elif not fuzzy_match(entry['timestamp'], archived_created) and \
|
113 |
| - not fuzzy_match(entry['timestamp'], archived_modified): |
| 114 | + not fuzzy_match(entry['timestamp'], archived_modified) and \ |
| 115 | + not fuzzy_match(entry.get('file_mtime', -1), archived_modified): |
114 | 116 | if meta_state == keyword_final:
|
115 | 117 | print("Archive entry %s has wrong timestamp %f / %f (expected %f, %s)" %
|
116 | 118 | (archive_path, archived_created, archived_modified,
|
117 | 119 | entry['timestamp'], archived_stat))
|
118 |
| - return False |
| 120 | + chksum_verified = False |
| 121 | + for algo in sorted_hash_algos: |
| 122 | + chksum = entry.get(algo, '') |
| 123 | + if not chksum or ' ' in chksum: |
| 124 | + continue |
| 125 | + print("Checking that %s of %r matches %r" % |
| 126 | + (algo, archive_path, chksum)) |
| 127 | + verify_chksum = checksum_file(archive_path, algo, |
| 128 | + max_chunks=-1) |
| 129 | + if verify_chksum == chksum: |
| 130 | + chksum_verified = True |
| 131 | + break |
| 132 | + if chksum_verified: |
| 133 | + print("Verified that %s of %r matches %r" % |
| 134 | + (algo, archive_path, chksum)) |
| 135 | + else: |
| 136 | + return False |
119 | 137 | elif verbose:
|
120 | 138 | print("ignore ctime mismatch on non-final %s" %
|
121 | 139 | archive_path)
|
|
0 commit comments