fix(init): clean up stale dtvem shims entries from PATH#249
Merged
CalvinAllen merged 1 commit intomainfrom May 6, 2026
Merged
Conversation
When XDG_DATA_HOME is set on Windows/macOS, dtvem honors it for both data storage and PATH configuration. However, users who upgraded from a pre-XDG-support version (or who set XDG_DATA_HOME after a prior install) end up with a stale `~/.dtvem/shims` entry in PATH pointing at an empty directory, while the real shims live at the XDG-resolved location. `dtvem init` now scans PATH for any entry that looks like a dtvem shims directory (matches `*/dtvem/shims` or `*/.dtvem/shims`, case-insensitive on Windows) and treats entries that don't equal the currently-resolved ShimsDir() as stale. On Windows, stale entries are removed from the registry during the existing PATH-modify pass and reported in the success output. On Unix, stale entries are surfaced as a warning with manual cleanup instructions (removing them automatically would risk clobbering user edits in .bashrc/.zshrc/etc).
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.
Summary
When
XDG_DATA_HOMEis set on Windows/macOS, dtvem honors it for data storage and PATH config. But users who upgraded from a pre-XDG version (or setXDG_DATA_HOMEafter a prior install) end up with a stale~/.dtvem/shimsentry in PATH pointing at an empty directory, while the real shims live at the XDG-resolved location.dtvem initpreviously only managed the path it currently resolves to and didnt notice the stale leftover.This PR teaches
dtvem initto:*/dtvem/shimsor*/.dtvem/shims, case-insensitive on Windows) but dont match the currently-resolvedShimsDir()..bashrc/.zshrcbecause users often customize them heavily).What this fixes
The original bug from #247:
XDG_DATA_HOMEset, real shims correctly created at~/.local/share/dtvem/shims~/.dtvem/shimsentry (empty dir) from a prior installdtvem initpreviously didnt touch the stale entryAfter this PR, running
dtvem init(then restarting the terminal) on a machine in this state will:~/.dtvem/shimsentry~/.local/share/dtvem/shimsentryImplementation notes
src/internal/path/path.go:IsDtvemShimsPath(path)— matches bothdtvem/shimsand.dtvem/shimsparents (case-insensitive on Windows)FindStaleShimsEntries(entries, currentShimsDir)— returns entries that look like dtvem shims dirs but arent the current oneSplitPath(pathEnv)— splits PATH using the OS-appropriate separatorpath_windows.go:checkSystemPath/checkUserPathnow flag stale entries as needing an update even when the currentshimsDiris already at position 0modifySystemPath/modifyUserPathfilter out stale entries during the registry rewrite and log each removalpath_unix.go:AddToPathnow callswarnAboutStaleShimsEntriesto surface stale entries with manual cleanup instructionsTest plan
./rnr checkpasses (lint + all tests)IsDtvemShimsPath(incl. Windows case-insensitivity) andFindStaleShimsEntries(incl..dtvemvsdtvemparents, ordering preservation, Windows case-insensitive comparison)~/.dtvem/shimsand~/.local/share/dtvem/shimsin PATH: rundtvem init, confirm stale entry is removed and current entry is addedResolves
Resolves #247