]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/go-getter/get_file_windows.go
Merge branch 'add_ssl_tests' of github.com:alexandreFre/terraform-provider-statuscake
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / go-getter / get_file_windows.go
index f87ed0a0becb528c47a15bcab81191c099a9ecd0..24f1acb1762b14fe651f1d2bf96e2cf324def86d 100644 (file)
@@ -4,15 +4,16 @@ package getter
 
 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
@@ -51,7 +52,7 @@ func (g *FileGetter) Get(dst string, u *url.URL) error {
        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)
        }
@@ -60,6 +61,7 @@ func (g *FileGetter) Get(dst string, u *url.URL) error {
 }
 
 func (g *FileGetter) GetFile(dst string, u *url.URL) error {
+       ctx := g.Context()
        path := u.Path
        if u.RawPath != "" {
                path = u.RawPath
@@ -92,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
@@ -108,7 +124,7 @@ func (g *FileGetter) GetFile(dst string, u *url.URL) error {
        }
        defer dstF.Close()
 
-       _, err = io.Copy(dstF, srcF)
+       _, err = Copy(ctx, dstF, srcF)
        return err
 }