mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-02 06:18:51 -06:00
fix: keep test envs and patches in disk cleanup
This commit is contained in:
1 parent
a5425d69cd
commit
54bed5c235
4 files changed
+51
-7
No files matched your search
@@ -14,8 +14,10 @@ kept, so committed work stays reachable. A worktree with real uncommitted
|
||||
code is listed, never removed.
|
||||
|
||||
tmp/ entries older than --hours that no process uses are removed, except
|
||||
tmp/acquire, git bundles (*.bundle, which are backups) and an entry that
|
||||
holds a linked worktree, which the worktree rule judges.
|
||||
what KEPT_TMP in devtools/diskcleanup.py lists (tmp/acquire, git bundles and
|
||||
patches, the TUI test environments, the Python 3.8 wrapper, the CI
|
||||
guardian's state) and an entry that holds a linked worktree, which the
|
||||
worktree rule judges.
|
||||
|
||||
The last line reports free space, and an ALERT line when it is under
|
||||
--alert-gb. The exit code is 1 under that threshold, so a timer sees it.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import fnmatch
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -13,7 +14,20 @@ from pathlib import Path
|
||||
from core.generated import is_generated
|
||||
from core.paths import AUTORUN_WORKTREE
|
||||
|
||||
KEPT_TMP = ("acquire",)
|
||||
# What tmp/ keeps whatever its age, by name pattern, with the reason printed.
|
||||
KEPT_TMP: dict[str, str] = {
|
||||
# auto_fetch writes the files it found and verified here.
|
||||
"acquire": "backup",
|
||||
# A git bundle or a patch saved before a risky operation.
|
||||
"*.bundle": "backup",
|
||||
"*.patch": "backup",
|
||||
# The TUI pty tests run under tmp/tuienv312 and tmp/tuienv38.
|
||||
"tuienv*": "test environment",
|
||||
# The Python 3.8 wrapper the installer floor is checked with.
|
||||
"py38bin": "test environment",
|
||||
# The CI guardian's log, scripts and the runs it has already seen.
|
||||
"ci_guardian*": "CI guardian state",
|
||||
}
|
||||
ALERT_GB = 100
|
||||
|
||||
|
||||
@@ -107,6 +121,12 @@ def judge_worktree(path: Path, busy: Iterable[str], hours: float, now: float) ->
|
||||
return Decision(path, "worktree", "remove", f"{age:.0f}h old, clean")
|
||||
|
||||
|
||||
def kept_reason(name: str) -> str:
|
||||
"""Why tmp/ keeps an entry of this name whatever its age, or ''."""
|
||||
return next((reason for pattern, reason in KEPT_TMP.items()
|
||||
if fnmatch.fnmatchcase(name, pattern)), "")
|
||||
|
||||
|
||||
def judge_tmp(
|
||||
repo: Path, busy: Iterable[str], hours: float, now: float,
|
||||
worktrees: Iterable[Path] = (),
|
||||
@@ -117,8 +137,9 @@ def judge_tmp(
|
||||
worktrees = list(worktrees)
|
||||
decisions = []
|
||||
for entry in sorted(tmp.iterdir()):
|
||||
if entry.name in KEPT_TMP or entry.name.endswith(".bundle"):
|
||||
action, reason = "keep", "backup"
|
||||
kept = kept_reason(entry.name)
|
||||
if kept:
|
||||
action, reason = "keep", kept
|
||||
elif any(inside(w, entry) for w in worktrees):
|
||||
action, reason = "keep", "holds a worktree"
|
||||
elif age_hours(entry, now) <= hours:
|
||||
|
||||
@@ -843,6 +843,26 @@ class Cleanup(Origin):
|
||||
cd.apply(self.repo, decisions.values())
|
||||
self.assertEqual((work / ".gitignore").read_text(), "edited")
|
||||
|
||||
def test_old_kept_tmp_entries_survive(self):
|
||||
"""What every gate runs under and the backups outlive any age:
|
||||
the scheduled cleaner removed the TUI environments and a wip patch."""
|
||||
tmp = self.repo / "tmp"
|
||||
names = ("acquire", "tuienv312", "tuienv38", "py38bin", "ci_guardian.log",
|
||||
"ci_guardian_seen.txt", "main.bundle", "wip-2026-11-12.patch")
|
||||
stamp = time.time() - 1000 * 3600
|
||||
for name in names:
|
||||
path = tmp / name
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
if "." in name:
|
||||
path.write_bytes(b"")
|
||||
else:
|
||||
path.mkdir()
|
||||
os.utime(path, (stamp, stamp))
|
||||
decisions = cd.judge_tmp(self.repo, [], 72, time.time())
|
||||
self.assertEqual({d.path.name: d.action for d in decisions},
|
||||
dict.fromkeys(names, "keep"))
|
||||
self.assertTrue(all(d.reason for d in decisions))
|
||||
|
||||
def test_low_space_raises_the_alert_line(self):
|
||||
line, low = cd.disk_line(self.tmp, alert_gb=10 ** 9)
|
||||
self.assertTrue(low)
|
||||
|
||||
+3
-2
@@ -895,8 +895,9 @@ theirs. One is removed only when no process uses it, it is older than
|
||||
`CONTRIBUTING.md`, `website/src/data/*.json`). One holding real changes is listed, never removed. Branches
|
||||
are always kept. A worktree elsewhere on disk and the automation worktree are
|
||||
never candidates. `tmp/` entries older than `--hours` that no process uses
|
||||
are removed, except `tmp/acquire`, `*.bundle` and an entry that holds a
|
||||
linked worktree.
|
||||
are removed, except `tmp/acquire`, `*.bundle`, `*.patch`, the TUI test
|
||||
environments (`tuienv*`), the Python 3.8 wrapper (`py38bin`), the CI
|
||||
guardian's files and an entry that holds a linked worktree.
|
||||
|
||||
The last line gives free space, with an `ALERT` line under `--alert-gb`
|
||||
(default 100), and the exit code is then 1. `--check` reports space only.
|
||||
|
||||
Reference in new issue
Block a user