anishathalye / dotbot

A tool that bootstraps your dotfiles ⚡️
MIT License
6.91k stars 288 forks source link

Windows symlinks are always recreated #307

Closed kurtmckee closed 1 year ago

kurtmckee commented 2 years ago

On Windows, os.readlink() returns a UNC path that never matches the anticipated symlink destination. This causes dotbot to always recreate the links (example dotbot output below):

Incorrect link ~/.gitconfig -> \\?\C:\Users\Me\Documents\dev\dotfiles\gitconfig

I tested two possible fixes:

  1. Use os.path.realpath() instead of os.readlink()
  2. Conditionally remove the \\?\ prefix when dotbot is running on Windows.

Option 1 results in a unit test failure:

[42/55] (link-relink-relative-leaves-file.bash)
relink relative does not incorrectly relink file
- test failed.
-> fail!

Therefore I recommend going with option 2, which gives expected results (example dotbot output below):

Link exists ~/.gitconfig -> C:\Users\Me\Documents\dev\dotfiles\gitconfig