diff --git a/e2e-win/symlink.Tests.ps1 b/e2e-win/symlink.Tests.ps1 new file mode 100644 index 0000000000..9f10f7cbf6 --- /dev/null +++ b/e2e-win/symlink.Tests.ps1 @@ -0,0 +1,39 @@ +Describe 'windows runtime symlink' { + + BeforeAll { + $cfg = ".\mise.local.toml" + $tool = "yq" + + $content = @" +[tools] +$tool = "latest" +"@ + $content | Out-File $cfg + Get-Content $cfg + } + + AfterAll { + Remove-Item $cfg -ErrorAction Ignore + } + + It 'version is correct, not latest' { + mise install yq@4.45.4 + + # correct output + # mise/2025.5.15/bin/mise ls yq + # Tool Version Source Requested + # yq 4.45.4 D:\Users\qianlongzt\.config\mise\config.toml latest + + # wrong output + # mise/2025.5.16/bin/mise ls yq + # Tool Version Source Requested + # yq latest D:\Users\qianlongzt\.config\mise\config.toml latest + # yq 4.45.4 + + # https://github.com/jdx/mise/discussions/5254 + + $output = mise ls --json yq + $output | jq '.[] | select(.source ) | .version' | Should -Be '"4.45.4"' + $output | jq '.[] | select(.version == "latest" ) | .version' | Should -Be $null + } +} diff --git a/src/file.rs b/src/file.rs index 131cc54cf9..c58a9cb76c 100644 --- a/src/file.rs +++ b/src/file.rs @@ -393,13 +393,14 @@ pub fn make_symlink_or_file(target: &Path, link: &Path) -> Result<()> { } pub fn resolve_symlink(link: &Path) -> Result> { - if !link.is_symlink() { - return Ok(None); - } - if cfg!(windows) { + // Windows symlink are write in file currently + // may be changed to symlink in the future + if link.is_symlink() { + Ok(Some(fs::read_link(link)?)) + } else if link.is_file() { Ok(Some(fs::read_to_string(link)?.into())) } else { - Ok(Some(fs::read_link(link)?)) + Ok(None) } }