Skip to content

Commit

Permalink
Copy local files
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar committed Feb 23, 2016
1 parent 8de39eb commit c7661b1
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion client/getter/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,42 @@ import (
"path/filepath"
"runtime"
"strings"
"sync"
"syscall"

gg "github.com/hashicorp/go-getter"
)

var (
// getters is the map of getters suitable for Nomad. It is initialized once
// and the lock is used to guard access to it.
getters map[string]gg.Getter
lock sync.Mutex
)

// getClient returns a client that is suitable for Nomad.
func getClient(src, dst string) *gg.Client {
lock.Lock()
defer lock.Unlock()

// Return the pre-initialized client
if getters == nil {
getters = make(map[string]gg.Getter, len(gg.Getters))
for k, v := range gg.Getters {
getters[k] = v
}

getters["file"] = &gg.FileGetter{Copy: true}
}

return &gg.Client{
Src: src,
Dst: dst,
Dir: false, // Only support a single file for now.
Getters: getters,
}
}

func GetArtifact(destDir, source, checksum string, logger *log.Logger) (string, error) {
if source == "" {
return "", fmt.Errorf("Source url is empty in Artifact Getter")
Expand All @@ -29,7 +60,7 @@ func GetArtifact(destDir, source, checksum string, logger *log.Logger) (string,
}

artifactFile := filepath.Join(destDir, path.Base(u.Path))
if err := gg.GetFile(artifactFile, source); err != nil {
if err := getClient(source, artifactFile).Get(); err != nil {
return "", fmt.Errorf("Error downloading artifact: %s", err)
}

Expand Down

0 comments on commit c7661b1

Please sign in to comment.