giteabot backport / giteabot (push) Canceled after 0s
giteabot / giteabot (push) Canceled after 0s
release-nightly / nightly-binary (push) Canceled after 0s
release-nightly / nightly-container (push) Canceled after 0s
release-nightly-snapcraft / build-and-publish (push) Canceled after 0s
Assisted-by: Codex:GPT-5
21 lines
675 B
Python
21 lines
675 B
Python
from __future__ import annotations
|
|
|
|
import re
|
|
from pathlib import Path
|
|
|
|
|
|
_SHA = re.compile(r"^(?:[0-9a-f]{40}|[0-9a-f]{64})$")
|
|
|
|
|
|
class ArtifactCleaner:
|
|
def __init__(self, deepwiki_data_root: Path):
|
|
self.database_root = (deepwiki_data_root / "databases").resolve()
|
|
|
|
def remove_index(self, commit_sha: str) -> None:
|
|
if not _SHA.fullmatch(commit_sha):
|
|
raise ValueError("refusing to clean an invalid commit SHA")
|
|
path = (self.database_root / f"{commit_sha}.pkl").resolve()
|
|
if self.database_root not in path.parents:
|
|
raise ValueError("DeepWiki index path escapes database root")
|
|
path.unlink(missing_ok=True)
|