refactor: real-home and terminal temp-dir fallbacks stop naming /tmp
get_real_home() fell back to a literal /tmp when no OS home could be found, and LocalEnvironment.get_temp_dir() probed /tmp by hand before consulting tempfile.gettempdir(), whose own candidate walk already covers the system temp dir (and honours the scratch TMPDIR Hermes now exports). Both defer to tempfile.gettempdir(); a relative gettempdir() result is made absolute instead of being swapped for /tmp.
This commit is contained in:
@@ -921,7 +921,8 @@ def get_real_home(env: dict[str, str] | None = None) -> str:
|
||||
seen.add(key)
|
||||
if not _is_profile_home(candidate, profile_home):
|
||||
return candidate
|
||||
return "/tmp"
|
||||
import tempfile
|
||||
return tempfile.gettempdir()
|
||||
|
||||
|
||||
_HOME_MODE_ALIASES = {"isolated": "profile", "profile_home": "profile", "profile-home": "profile",
|
||||
|
||||
@@ -826,8 +826,8 @@ class LocalEnvironment(BaseEnvironment):
|
||||
|
||||
def get_temp_dir(self) -> str:
|
||||
"""Shell-safe writable temp dir. Precedence: ``TERMINAL_TEMP_DIR``, TMPDIR/TMP/TEMP
|
||||
(Termux has no /tmp), ``HERMES_HOME/cache/terminal`` (real storage: tmpfs /tmp
|
||||
fills under Hermes load; pruned by ``cleanup_terminal_temp_cache``), /tmp,
|
||||
(Termux has no system temp dir), ``HERMES_HOME/cache/terminal`` (real storage: a
|
||||
tmpfs system temp dir fills under Hermes load; pruned by ``cleanup_terminal_temp_cache``),
|
||||
``tempfile.gettempdir()``; backend env before process env so terminal.env
|
||||
overrides work. Windows: ``%TEMP%`` often has spaces that break unquoted bash,
|
||||
so always the HERMES_HOME cache dir with forward slashes (bash- and Python-valid)."""
|
||||
@@ -853,10 +853,9 @@ class LocalEnvironment(BaseEnvironment):
|
||||
return _posix(resolved)
|
||||
except Exception:
|
||||
pass
|
||||
if os.path.isdir("/tmp") and os.access("/tmp", os.W_OK | os.X_OK):
|
||||
return "/tmp"
|
||||
# tempfile's own candidate walk already covers the system temp dir.
|
||||
fallback = tempfile.gettempdir()
|
||||
return _posix(fallback) if fallback.startswith("/") else "/tmp"
|
||||
return _posix(fallback if fallback.startswith("/") else os.path.abspath(fallback))
|
||||
|
||||
@staticmethod
|
||||
def _quote_cwd_for_cd(cwd: str) -> str:
|
||||
|
||||
Reference in New Issue
Block a user