Race Condition in History File Handling #7
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The file locking in _analyze_smart_trends opens with mode 'r+' or 'w+' but doesn't handle the case where the file is created empty:
file_mode = 'r+' if os.path.exists(historical_file) else 'w+'
...
if os.path.getsize(historical_file) > 0: # This check happens AFTER opening
Fix:
Check file existence and size BEFORE opening
if os.path.exists(historical_file) and os.path.getsize(historical_file) > 0:
file_mode = 'r+'
else:
file_mode = 'w+'