Fix deletion of old build logs

The code rotating the old build logs expects to delete directories
(since it uses rmtree) but tries to delete all items returned by
os.listdir(...) which may includes symbolic links or regular files.

Change it to only consider the old build logs directories instead.

Based on crrev/5028323, with fix to unit test.

Fixed: b/310900283
Change-Id: I4c618e6618c0193331c063028ebf02d8c4e7baee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5038467
Auto-Submit: Michael Savigny <msavigny@google.com>
Reviewed-by: Ramy Medhat <abdelaal@google.com>
Commit-Queue: Michael Savigny <msavigny@google.com>
This commit is contained in:
Michael Savigny
2023-11-17 20:16:53 +00:00
committed by LUCI CQ
parent 06c4261af7
commit af69249965
2 changed files with 13 additions and 4 deletions

View File

@@ -219,7 +219,11 @@ def set_reproxy_path_flags(out_dir, make_dirs=True):
os.makedirs(run_log_dir, exist_ok=True)
os.makedirs(cache_dir, exist_ok=True)
os.makedirs(racing_dir, exist_ok=True)
old_log_dirs = os.listdir(log_dir)
old_log_dirs = [
d for d in os.listdir(log_dir)
if os.path.isdir(os.path.join(log_dir, d))
]
if len(old_log_dirs) > 5:
old_log_dirs.sort(key=lambda dir: dir.split("_"), reverse=True)
for d in old_log_dirs[5:]:
@@ -269,8 +273,8 @@ def build_context(argv, tool):
try:
set_reproxy_path_flags(ninja_out)
except OSError:
print("Error creating reproxy_tmp in output dir", file=sys.stderr)
except OSError as e:
print(f"Error creating reproxy_tmp in output dir: {e}", file=sys.stderr)
yield 1
return