fix(logs): Correct path resolution in LogPruner to handle paths starting with 'logs/'

This commit is contained in:
2026-03-07 12:41:23 -05:00
parent 3c9e03dd3c
commit 046ccc7225
2 changed files with 43 additions and 5 deletions

View File

@@ -41,12 +41,24 @@ class LogPruner:
for session_info in old_sessions_to_check:
session_id = session_info['session_id']
session_path = session_info['path']
if not session_path or not os.path.isdir(session_path):
if not session_path:
continue
# Calculate total size of files in the directory
# Resolve path
resolved_path = session_path
if not os.path.isabs(resolved_path):
if resolved_path.startswith('logs' + os.sep) or resolved_path.startswith('logs/'):
# Resolve relative to the project root (two levels up from self.logs_dir)
project_root = os.path.dirname(os.path.dirname(os.path.abspath(self.logs_dir)))
resolved_path = os.path.join(project_root, resolved_path)
if not os.path.isdir(resolved_path):
continue
# Calculate total size of files in the directory
total_size = 0
try:
for entry in os.scandir(session_path):
for entry in os.scandir(resolved_path):
if entry.is_file():
total_size += entry.stat().st_size
except OSError:
@@ -54,7 +66,7 @@ class LogPruner:
# Prune if the total size is less than threshold
if total_size < (min_size_kb * 1024):
try:
shutil.rmtree(session_path)
shutil.rmtree(resolved_path)
# Also remove from registry to keep it in sync
if session_id in self.log_registry.data:
del self.log_registry.data[session_id]