From ed508302a6241a78a0614e8b7a017dc14e5e8d04 Mon Sep 17 00:00:00 2001 From: Martin Tranberg Date: Sun, 29 Mar 2026 17:45:45 +0200 Subject: [PATCH] =?UTF-8?q?Tilf=C3=B8j=20global=20toggle=20og=20konfigurer?= =?UTF-8?q?bar=20gr=C3=A6nse=20for=20hash-validering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- download_sharepoint.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/download_sharepoint.py b/download_sharepoint.py index 05e3012..ca2c3ba 100644 --- a/download_sharepoint.py +++ b/download_sharepoint.py @@ -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)