Skip to content

fix(init): clean up stale dtvem shims entries from PATH#249

Merged
CalvinAllen merged 1 commit intomainfrom
fix/init/clean-stale-shims-path
May 6, 2026
Merged

fix(init): clean up stale dtvem shims entries from PATH#249
CalvinAllen merged 1 commit intomainfrom
fix/init/clean-stale-shims-path

Conversation

@CalvinAllen
Copy link
Copy Markdown
Contributor

@CalvinAllen CalvinAllen commented May 6, 2026

Summary

When XDG_DATA_HOME is set on Windows/macOS, dtvem honors it for data storage and PATH config. But users who upgraded from a pre-XDG version (or 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 previously only managed the path it currently resolves to and didnt notice the stale leftover.

This PR teaches dtvem init to:

  • Detect entries in PATH that look like a dtvem shims directory (*/dtvem/shims or */.dtvem/shims, case-insensitive on Windows) but dont match the currently-resolved ShimsDir().
  • On Windows: remove them from the registry during the existing PATH-modify pass; log each removal in the success output.
  • On Unix: warn the user with manual cleanup instructions (we dont auto-rewrite .bashrc/.zshrc because users often customize them heavily).

What this fixes

The original bug from #247:

  • XDG_DATA_HOME set, real shims correctly created at ~/.local/share/dtvem/shims
  • PATH contains stale ~/.dtvem/shims entry (empty dir) from a prior install
  • dtvem init previously didnt touch the stale entry

After this PR, running dtvem init (then restarting the terminal) on a machine in this state will:

  • Remove the stale ~/.dtvem/shims entry
  • Add the correct ~/.local/share/dtvem/shims entry
  • Print which stale entries were removed

Implementation notes

  • New cross-platform helpers in src/internal/path/path.go:
    • IsDtvemShimsPath(path) — matches both dtvem/shims and .dtvem/shims parents (case-insensitive on Windows)
    • FindStaleShimsEntries(entries, currentShimsDir) — returns entries that look like dtvem shims dirs but arent the current one
    • SplitPath(pathEnv) — splits PATH using the OS-appropriate separator
  • path_windows.go:
    • checkSystemPath / checkUserPath now flag stale entries as needing an update even when the current shimsDir is already at position 0
    • modifySystemPath / modifyUserPath filter out stale entries during the registry rewrite and log each removal
  • path_unix.go:
    • AddToPath now calls warnAboutStaleShimsEntries to surface stale entries with manual cleanup instructions

Test plan

  • ./rnr check passes (lint + all tests)
  • New unit tests cover IsDtvemShimsPath (incl. Windows case-insensitivity) and FindStaleShimsEntries (incl. .dtvem vs dtvem parents, ordering preservation, Windows case-insensitive comparison)
  • Manual verification on a setup with both ~/.dtvem/shims and ~/.local/share/dtvem/shims in PATH: run dtvem init, confirm stale entry is removed and current entry is added
  • Verify Unix warning output matches expectation when a stale entry is in PATH

Resolves

Resolves #247

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).
@CalvinAllen CalvinAllen merged commit df83c11 into main May 6, 2026
21 checks passed
@CalvinAllen CalvinAllen deleted the fix/init/clean-stale-shims-path branch May 6, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: reshim isn't creating shims

1 participant