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
This commit is contained in:
usmannasir
2025-10-26 17:10:13 +05:00
parent f6fd2192c5
commit 7beaa0492f

View File

@@ -1297,10 +1297,17 @@ def scanner_replace_file(request):
chmod_cmd = f'chmod {permissions} "{user_temp_path}"' chmod_cmd = f'chmod {permissions} "{user_temp_path}"'
ProcessUtilities.executioner(chmod_cmd, user=user) 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) # Replace file using cat redirection (more reliable than cp for overwriting)
# This ensures the file contents are actually replaced # This ensures the file contents are actually replaced
replace_cmd = f'cat "{user_temp_path}" > "{full_path}"' 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) replace_result = ProcessUtilities.executioner(replace_cmd, user=user, shell=True)
logging.writeToFile(f'[API] Replace command result: {replace_result}')
# Clean up temp file # Clean up temp file
ProcessUtilities.executioner(f'rm -f "{user_temp_path}"', user=user) ProcessUtilities.executioner(f'rm -f "{user_temp_path}"', user=user)