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

getfile on windows: when a file cannot be symlinked for privilege reasons, copy it #159

Merged
merged 3 commits into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion get_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
type FileGetter struct {
getter

// Copy, if set to true, will copy data instead of using a symlink
// Copy, if set to true, will copy data instead of using a symlink. If
// false, attempts to symlink to speed up the operation and to lower the
// disk space usage. If the symlink fails, may attempt to copy on windows.
Copy bool
}

Expand Down
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