Tilføj 30 MB grænse for hash-validering

- Spring hash-tjek over for filer over 30 MB for at spare tid ved store filer (f.eks. 65 GB)
- Filer over grænsen sammenlignes kun på størrelse
- Tilføjer logning når hash-tjek springes over
This commit is contained in:
Martin Tranberg
2026-03-29 17:40:55 +02:00
parent ad4166fb03
commit 33fbdc244d

View File

@@ -106,10 +106,20 @@ def quickxorhash(file_path):
result = h.to_bytes(20, byteorder='little')
return base64.b64encode(result).decode('ascii')
# --- Integrity Thresholds ---
HASH_THRESHOLD_BYTES = 30 * 1024 * 1024 # 30 MB
def verify_integrity(local_path, remote_hash):
"""Verifies file integrity using Microsoft QuickXorHash."""
"""Verifies file integrity using Microsoft QuickXorHash.
Skips hash check for files larger than HASH_THRESHOLD_BYTES to save time."""
if not remote_hash:
return True # Intet hash fra remote; fald tilbage til størrelses-check
return True
file_size = os.path.getsize(local_path)
if file_size > HASH_THRESHOLD_BYTES:
logger.info(f"Skipping hash check for large file (>30MB): {os.path.basename(local_path)} ({format_size(file_size)})")
return True
local_hash = quickxorhash(local_path)
if local_hash != remote_hash:
logger.warning(f"Hash mismatch for {local_path}: local={local_hash}, remote={remote_hash}")