import (
"fmt"
- "io"
"net/url"
"os"
"os/exec"
"path/filepath"
"strings"
+ "syscall"
)
func (g *FileGetter) Get(dst string, u *url.URL) error {
+ ctx := g.Context()
path := u.Path
if u.RawPath != "" {
path = u.RawPath
sourcePath := toBackslash(path)
// Use mklink to create a junction point
- output, err := exec.Command("cmd", "/c", "mklink", "/J", dst, sourcePath).CombinedOutput()
+ output, err := exec.CommandContext(ctx, "cmd", "/c", "mklink", "/J", dst, sourcePath).CombinedOutput()
if err != nil {
return fmt.Errorf("failed to run mklink %v %v: %v %q", dst, sourcePath, err, output)
}
}
func (g *FileGetter) GetFile(dst string, u *url.URL) error {
+ ctx := g.Context()
path := u.Path
if u.RawPath != "" {
path = u.RawPath
// 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
}
defer dstF.Close()
- _, err = io.Copy(dstF, srcF)
+ _, err = Copy(ctx, dstF, srcF)
return err
}