Tilføj global toggle og konfigurerbar grænse for hash-validering
- ENABLE_HASH_VALIDATION (True/False) tilføjet til toppen af scriptet - HASH_THRESHOLD_MB tilføjet for nem justering af størrelsesgrænsen - verify_integrity opdateret til at respektere begge indstillinger
This commit is contained in:
@@ -18,6 +18,10 @@ CHUNK_SIZE = 1024 * 1024 # 1MB Chunks
|
||||
MAX_FOLDER_DEPTH = 50
|
||||
LOG_FILE = "sharepoint_download.log"
|
||||
|
||||
# Hash Validation Settings
|
||||
ENABLE_HASH_VALIDATION = True # Set to False to only check file size
|
||||
HASH_THRESHOLD_MB = 30 # Only hash files smaller than this (in MB)
|
||||
|
||||
# Setup Logging
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
@@ -106,18 +110,16 @@ 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.
|
||||
Skips hash check for files larger than HASH_THRESHOLD_BYTES to save time."""
|
||||
if not remote_hash:
|
||||
"""Verifies file integrity based on global settings."""
|
||||
if not remote_hash or not ENABLE_HASH_VALIDATION:
|
||||
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)})")
|
||||
threshold_bytes = HASH_THRESHOLD_MB * 1024 * 1024
|
||||
|
||||
if file_size > threshold_bytes:
|
||||
logger.info(f"Skipping hash check (size > {HASH_THRESHOLD_MB}MB): {os.path.basename(local_path)}")
|
||||
return True
|
||||
|
||||
local_hash = quickxorhash(local_path)
|
||||
|
||||
Reference in New Issue
Block a user