7 "github.com/hashicorp/go-getter"
10 // GetMode is an enum that describes how modules are loaded.
12 // GetModeLoad says that modules will not be downloaded or updated, they will
13 // only be loaded from the storage.
15 // GetModeGet says that modules can be initially downloaded if they don't
16 // exist, but otherwise to just load from the current version in storage.
18 // GetModeUpdate says that modules should be checked for updates and
19 // downloaded prior to loading. If there are no updates, we load the version
20 // from disk, otherwise we download first and then load.
24 GetModeNone GetMode = iota
29 // GetCopy is the same as Get except that it downloads a copy of the
30 // module represented by source.
32 // This copy will omit and dot-prefixed files (such as .git/, .hg/) and
33 // can't be updated on its own.
34 func GetCopy(dst, src string) error {
35 // Create the temporary directory to do the real Get to
36 tmpDir, err := ioutil.TempDir("", "tf")
40 // FIXME: This isn't completely safe. Creating and removing our temp path
41 // exposes where to race to inject files.
42 if err := os.RemoveAll(tmpDir); err != nil {
45 defer os.RemoveAll(tmpDir)
47 // Get to that temporary dir
48 if err := getter.Get(tmpDir, src); err != nil {
52 // Make sure the destination exists
53 if err := os.MkdirAll(dst, 0755); err != nil {
57 // Copy to the final location
58 return copyDir(dst, tmpDir)
61 func getStorage(s getter.Storage, key string, src string, mode GetMode) (string, bool, error) {
62 // Get the module with the level specified if we were told to.
63 if mode > GetModeNone {
64 if err := s.Get(key, src, mode == GetModeUpdate); err != nil {
69 // Get the directory where the module is.