Skip to content

Commit

Permalink
getfile on windows: when a file cannot be symlinked because there is …
Browse files Browse the repository at this point in the history
…no privilege, copy it

Symlinking allows to optimize the space taken by go-get in case the operation runs locally.
But running the go getter without the symlinking privilege can fail in this case.

This will copy the file instead of symlinking it in case we don't have the priviledge.
  • Loading branch information
azr committed Jan 29, 2019
1 parent dde89f9 commit e2da0a0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion get_file_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os/exec"
"path/filepath"
"strings"
"syscall"
)

func (g *FileGetter) Get(dst string, u *url.URL) error {
Expand Down Expand Up @@ -93,7 +94,21 @@ func (g *FileGetter) GetFile(dst string, u *url.URL) error {

// If we're not copying, just symlink and we're done
if !g.Copy {
return os.Symlink(path, dst)
if err = os.Symlink(path, dst); err == nil {
return err
}
lerr, ok := err.(*os.LinkError)
if !ok {
return err
}
switch lerr.Err {
case syscall.ERROR_PRIVILEGE_NOT_HELD:
// no symlink privilege, let's
// fallback to a copy to avoid an error.
break
default:
return err
}
}

// Copy
Expand Down

0 comments on commit e2da0a0

Please sign in to comment.