Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX #71: old symlink should be removed on Windows #72

Merged
merged 7 commits into from
Apr 11, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions cli/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bufio"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -40,9 +39,11 @@ func (z *ZVM) setBin(ver string) error {
version_path := filepath.Join(z.baseDir, ver)
bin_dir := filepath.Join(z.baseDir, "bin")

// Remove "bin" dir only if it already exists

if _, err := os.Stat(bin_dir); errors.Is(err, fs.ErrExist) {
// Came across https://pkg.go.dev/os#Lstat
// which is specifically to check symbolic links.
// Seemed like the more appropriate solution here
stat, err := os.Lstat(bin_dir);
if errors.Is(err, os.ErrExist) || stat != nil {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why back to os.ErrExist instead of fs.ErrExist?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just check to see if the error is nil. If true the file exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can't mix up the os with the fs stuff, as they are different packages? But it's only my educated guess. Honestly it feels like there's way too many ways to do this in golang 😓 the best way maybe is to use os.Lstat and just see if the link is nil? 🤔

fmt.Printf("Removing old %s", bin_dir)
if err := os.Remove(bin_dir); err != nil {
return err
Expand Down
Loading