fix(terminal): stop writing the cwd temp file entirely

Follow-up for salvaged PR #63255: with LocalEnvironment._update_cwd
delegating to the stdout marker parser, the cwd temp file has zero
readers left. Drop the 'pwd -P > file' writes from the bootstrap and
_wrap_command so every command stops paying a pointless file write
(and stops littering temp dirs with hermes-cwd-*.txt).
This commit is contained in:
Teknium 2026-07-16 01:10:47 -07:00
parent 0ccd05b78a
commit 49a8c3f836
2 changed files with 9 additions and 9 deletions

View file

@ -68,7 +68,8 @@ class TestWrapCommand:
assert "eval 'echo hello'" in wrapped
assert "__hermes_ec=$?" in wrapped
assert "export -p >" in wrapped
assert "pwd -P >" in wrapped
# cwd travels via the stdout marker only — no temp-file write.
assert "pwd -P >" not in wrapped
assert env._cwd_marker in wrapped
assert "exit $__hermes_ec" in wrapped
@ -357,7 +358,9 @@ class TestSnapshotFileModes:
assert stat.S_IMODE(user_file.stat().st_mode) == 0o644
assert stat.S_IMODE(Path(env._snapshot_path).stat().st_mode) == 0o600
assert stat.S_IMODE(Path(env._cwd_file).stat().st_mode) == 0o600
# The cwd temp file is no longer written (cwd travels via the
# stdout marker for every backend) — nothing to leak on disk.
assert not Path(env._cwd_file).exists()
finally:
os.umask(old_umask)

View file

@ -478,7 +478,6 @@ class BaseEnvironment(ABC):
# ``Directory \\drivers\\etc does not exist`` failure class.
# On POSIX this is plain ``shlex.quote``.
_quoted_snap = self._quote_shell_path(self._snapshot_path)
_quoted_cwd_file = self._quote_shell_path(self._cwd_file)
# Use atomic file replacement: assemble the snapshot in a temp file,
# then mv it over the final path. This prevents concurrent source()
# calls from reading a half-written snapshot when another terminal
@ -523,7 +522,6 @@ class BaseEnvironment(ABC):
# partial temp rather than leave it to be sourced or orphaned.
f"mv -f {_snap_tmp} {_quoted_snap} || rm -f {_snap_tmp}\n"
f"builtin cd -- {_quoted_cwd} 2>/dev/null || true\n"
f"pwd -P > {_quoted_cwd_file} 2>/dev/null || true\n"
f"printf '\\n{self._cwd_marker}%s{self._cwd_marker}\\n' \"$(pwd -P)\"\n"
)
try:
@ -602,10 +600,9 @@ class BaseEnvironment(ABC):
re-dumps env vars, and emits CWD markers."""
escaped = command.replace("'", "'\\''")
# Quote snapshot/cwd-file paths (see init_session — LocalEnvironment
# rewrites ``C:/...`` to ``/c/...`` so MSYS doesn't mangle them).
# Quote the snapshot path (see init_session — LocalEnvironment
# rewrites ``C:/...`` to ``/c/...`` so MSYS doesn't mangle it).
_quoted_snap = self._quote_shell_path(self._snapshot_path)
_quoted_cwd_file = self._quote_shell_path(self._cwd_file)
# Use atomic file replacement for env snapshot updates (issue #38249).
# Assemble into a per-writer-unique temp file, then mv to atomically
# replace the snapshot so concurrent source() calls never read a
@ -651,8 +648,8 @@ class BaseEnvironment(ABC):
f"2>/dev/null || rm -f {_snap_tmp} 2>/dev/null || true"
)
# Write CWD to file (local reads this) and stdout marker (remote parses this)
parts.append(f"pwd -P > {_quoted_cwd_file} 2>/dev/null || true")
# Emit the CWD stdout marker; all backends (including local, since
# PR #63255) parse it from output — no temp-file write needed.
# Use a distinct line for the marker. The leading \n ensures
# the marker starts on its own line even if the command doesn't
# end with a newline (e.g. printf 'exact'). We'll strip this