Repository navigation
Resolve /tmp the way the MSYS runtime does - #28
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the
/tmppart of #27: when a launcher passesTMP/TEMPin MSYS form (TMP=/tmp), gash and the MSYS programs it runs could use different folders for/tmp, somkdir -p /tmp/x; cd /tmp/xfailed.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
TEMPbeforeTMPand took the raw value.TEMP=/tmpwas read as\tmpon the current drive, or replaced with<root>\tmpwhen that wasn't a folder./tmpwhateverGetTempPathWreturns:TMP, thenTEMP, made a full path, whether or not the folder exists.TMP=/tmp) fixed/tmpfor every MSYS tool gash ran, regardless of theTMPgash passed them.Change
src/sys.rs,src/path.rs: gash callsGetTempPathWitself.std::env::temp_dir(): that isGetTempPath2W, which ignoresTMP/TEMPfor processes running as SYSTEM.%LOCALAPPDATA%\Temp(or%USERPROFILE%\AppData\Local\Temp), then<root>\tmp.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 ownTMPnames, so they failed when that folder didn't exist./tmpcomes from, and the case gash can't fix: an MSYS process from the same install already running with differentTMP/TEMP.Reviewer notes
One visible side effect: a launcher passing
TMP=/tmpon a machine withoutC:\tmpnow getsC:\tmpcreated. That matches what MSYS mounts. Git Bash itself wouldn't create it, butmkdir -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 passesTMP=/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:TMPbeforeTEMPTMPEach 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