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: replace symlinks with hard links on windows #3564

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all 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
22 changes: 22 additions & 0 deletions pkg/installpackage/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@
return nil
}

func (is *Installer) createLink(logE *logrus.Entry, linkPath, linkDest string) error {

Check failure on line 142 in pkg/installpackage/link.go

View workflow job for this annotation

GitHub Actions / test / test

cognitive complexity 31 of func `(*Installer).createLink` is high (> 30) (gocognit)
if fileInfo, err := is.linker.Lstat(linkPath); err == nil {

Check failure on line 143 in pkg/installpackage/link.go

View workflow job for this annotation

GitHub Actions / test / test

`if err == nil` has complex nested blocks (complexity: 10) (nestif)
switch mode := fileInfo.Mode(); {
case mode.IsDir():
// if file is a directory, raise error
Expand All @@ -153,16 +153,38 @@
if err := is.fs.Remove(linkPath); err != nil {
return fmt.Errorf("remove a file to create a symbolic link (%s): %w", linkPath, err)
}
if is.realRuntime.IsWindows() {
if err := is.linker.Hardlink(linkDest, linkPath); err != nil {
return fmt.Errorf("create a hard link: %w", err)
}
return nil
}
if err := is.linker.Symlink(linkDest, linkPath); err != nil {
return fmt.Errorf("create a symbolic link: %w", err)
}
return nil
case mode&os.ModeSymlink != 0:
if is.realRuntime.IsWindows() {
if err := is.fs.Remove(linkPath); err != nil {
return fmt.Errorf("remove a file to create a symbolic link (%s): %w", linkPath, err)
}
if err := is.linker.Hardlink(linkDest, linkPath); err != nil {
return fmt.Errorf("create a hard link: %w", err)
}
return nil
}
return is.recreateLink(logE, linkPath, linkDest)
default:
return fmt.Errorf("unexpected file mode %s: %s", linkPath, mode.String())
}
}
if is.realRuntime.IsWindows() {
logE.Info("create a hard link")
if err := is.linker.Hardlink(linkDest, linkPath); err != nil {
return fmt.Errorf("create a hard link: %w", err)
}
return nil
}
logE.Info("create a symbolic link")
if err := is.linker.Symlink(linkDest, linkPath); err != nil {
return fmt.Errorf("create a symbolic link: %w", err)
Expand Down
Loading