Keep the rule for which commands reach run-heavy's docker beside that docker in capped_docker.py
This commit is contained in:
@@ -6,6 +6,7 @@ import sys
|
||||
import typing
|
||||
|
||||
from docker_command import capped
|
||||
from shell_command import tool_name
|
||||
|
||||
# The folder run-heavy puts first on its command's PATH, holding the docker that runs main.
|
||||
PATH_ENTRY = pathlib.Path(__file__).resolve().parent / "path_entry"
|
||||
@@ -33,3 +34,13 @@ def main(argv: list[str], env: typing.Mapping[str, str]) -> int:
|
||||
def without_path_entry(path: str) -> str:
|
||||
"""path less PATH_ENTRY, so the real docker is the one found."""
|
||||
return os.pathsep.join(entry for entry in path.split(os.pathsep) if pathlib.Path(entry).resolve() != PATH_ENTRY)
|
||||
|
||||
|
||||
def finds_this_docker(word: str, before: list[str]) -> bool:
|
||||
"""Whether a command that runs under run-heavy reaches this docker, given the word that names docker and the words before it: docker named bare, since a path names another, and no word before it resets the PATH that run-heavy set. Only where run-heavy knows the memory, as on Linux."""
|
||||
return word == "docker" and not any(resets_path(earlier) for earlier in before)
|
||||
|
||||
|
||||
def resets_path(word: str) -> bool:
|
||||
"""Whether a word before docker drops the PATH run-heavy set: a PATH= of its own, env's -i or -u, or sudo or doas, which reset it."""
|
||||
return word.startswith(("PATH=", "--unset")) or word in ("-i", "--ignore-environment", "-u") or tool_name(word) in ("doas", "sudo")
|
||||
|
||||
Reference in New Issue
Block a user