Skip to content

Resolve /tmp the way the MSYS runtime does - #28

Merged
hex2f merged 1 commit into
mainfrom
leah/gash-issue-27-85b22f
Nov 7, 2026
Merged

hex2f merged 1 commit into
mainfrom
leah/gash-issue-27-85b22f

Conversation

@hex2f

@hex2f hex2f commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Fixes the /tmp part of #27: when a launcher passes TMP/TEMP in MSYS form (TMP=/tmp), gash and the MSYS programs it runs could use different folders for /tmp, so mkdir -p /tmp/x; cd /tmp/x failed.

The other two reports in #27 (pwd -W, cmd //c) were already fixed on main by #10 and #11, after v0.2.0. They need a release, not code.

Cause

  • gash read TEMP before TMP and took the raw value. TEMP=/tmp was read as \tmp on the current drive, or replaced with <root>\tmp when that wasn't a folder.
  • The MSYS runtime mounts at /tmp whatever GetTempPathW returns: TMP, then TEMP, made a full path, whether or not the folder exists.
  • All running MSYS processes of an install share one mount table. So an MSYS process the launcher had already started (with the same TMP=/tmp) fixed /tmp for every MSYS tool gash ran, regardless of the TMP gash passed them.

Change

  • src/sys.rs, src/path.rs: gash calls GetTempPathW itself.
    • Not std::env::temp_dir(): that is GetTempPath2W, which ignores TMP/TEMP for processes running as SYSTEM.
    • If the folder is missing, gash creates it, since an MSYS process may already have it mounted.
    • Only if creating it fails does gash use %LOCALAPPDATA%\Temp (or %USERPROFILE%\AppData\Local\Temp), then <root>\tmp.
  • Native programs now get the folder as a full Windows path in TMP/TEMP. Before, they could get /tmp.
  • src/io.rs: heredoc temp files go in the folder behind /tmp. Before, they went in the folder the process's own TMP names, so they failed when that folder didn't exist.
  • README: a note on where /tmp comes from, and the case gash can't fix: an MSYS process from the same install already running with different TMP/TEMP.

Reviewer notes

  • One visible side effect: a launcher passing TMP=/tmp on a machine without C:\tmp now gets C:\tmp created. That matches what MSYS mounts. Git Bash itself wouldn't create it, but mkdir -p /tmp/... in any MSYS tool would.

  • When gash and MSYS still disagree: only when an unrelated MSYS process (for example a Git Bash window) was started with a different TMP, and is still running, when the launcher passes TMP=/tmp. That's the same as for Git Bash.

  • Tests (tests/msys_tmp.rs): each test uses a private copy of the MSYS runtime, so its mount table is separate from any Git Bash running on the machine. They cover:

    • TMP before TEMP
    • an MSYS-form TMP
    • a missing folder while a launcher-started MSYS process is running
    • a folder that can't be created, including heredocs in that case
    • native programs getting full Windows paths

    Each test has its own scratch folder; reusing one made them flaky when run in parallel.

  • Against the old code: the original code fails 4 of the 5 tests. A fallback-only version without folder creation fails the missing-folder test.

  • Verified: the full suite passes, with no failures in 30 repeat runs of msys_tmp. I also reproduced the issue's scenario against the real Git install, with a launcher-started MSYS process running, and it now works.

🤖 Generated with Claude Code

When a launcher passed TMP/TEMP in MSYS form (TMP=/tmp), gash and the MSYS
programs it ran could use different folders for /tmp, so a folder made with
mkdir in /tmp was missing for cd (issue #27). gash read TEMP before TMP and
used the raw value, falling back to <root>\tmp when it wasn't a folder, while
the MSYS runtime mounts what GetTempPathW returns: TMP, then TEMP, made a
full path, so /tmp on the current drive, whether or not it exists.

gash now calls GetTempPathW itself (not std::env::temp_dir, which is
GetTempPath2W and ignores TMP/TEMP under SYSTEM) and creates the folder when
it is missing, since an MSYS process the launcher started may already have
mounted it. Only if that fails does it use %LOCALAPPDATA%\Temp, then
<root>\tmp. Native programs now get that folder as a full Windows path rather
than /tmp, and heredoc temp files go there too instead of to the folder the
process's own TMP names.

The msys_tmp tests now cover TMP before TEMP, an MSYS-form TMP, a missing
folder with an MSYS process already running, and a folder that can't be
created, and each test gets its own scratch folder so they can run in
parallel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hex2f
hex2f merged commit 3834816 into main Nov 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant