From 7beaa0492f95e1d1621f2d06e945fbf259015707 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Sun, 26 Oct 2025 17:10:13 +0500 Subject: [PATCH] Add debug logging for file replacement operation - Log temp file size before replacement - Log exact replace command being executed - Log replace command result - Helps debug why files are becoming empty after replace --- aiScanner/api.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/aiScanner/api.py b/aiScanner/api.py index ccb965efb..2fe6eb6ed 100644 --- a/aiScanner/api.py +++ b/aiScanner/api.py @@ -1297,10 +1297,17 @@ def scanner_replace_file(request): chmod_cmd = f'chmod {permissions} "{user_temp_path}"' ProcessUtilities.executioner(chmod_cmd, user=user) + # Verify temp file has content before replacing + check_cmd = f'wc -c "{user_temp_path}"' + check_result = ProcessUtilities.outputExecutioner(check_cmd, user=user, retRequired=True) + logging.writeToFile(f'[API] Temp file size check: {check_result}') + # Replace file using cat redirection (more reliable than cp for overwriting) # This ensures the file contents are actually replaced replace_cmd = f'cat "{user_temp_path}" > "{full_path}"' + logging.writeToFile(f'[API] Executing replace command: {replace_cmd}') replace_result = ProcessUtilities.executioner(replace_cmd, user=user, shell=True) + logging.writeToFile(f'[API] Replace command result: {replace_result}') # Clean up temp file ProcessUtilities.executioner(f'rm -f "{user_temp_path}"', user=user)