diff options
author | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
---|---|---|
committer | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
commit | bae9f6d2fd5eb5bc80929bd393932b23f14d7c93 (patch) | |
tree | ca9ab12a7d78b1fc27a8f734729081357ce6d252 /vendor/github.com/hashicorp/go-getter/folder_storage.go | |
parent | 254c495b6bebab3fb72a243c4bce858d79e6ee99 (diff) | |
download | terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.gz terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.zst terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.zip |
Initial transfer of provider code
Diffstat (limited to 'vendor/github.com/hashicorp/go-getter/folder_storage.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-getter/folder_storage.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-getter/folder_storage.go b/vendor/github.com/hashicorp/go-getter/folder_storage.go new file mode 100644 index 0000000..647ccf4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/folder_storage.go | |||
@@ -0,0 +1,65 @@ | |||
1 | package getter | ||
2 | |||
3 | import ( | ||
4 | "crypto/md5" | ||
5 | "encoding/hex" | ||
6 | "fmt" | ||
7 | "os" | ||
8 | "path/filepath" | ||
9 | ) | ||
10 | |||
11 | // FolderStorage is an implementation of the Storage interface that manages | ||
12 | // modules on the disk. | ||
13 | type FolderStorage struct { | ||
14 | // StorageDir is the directory where the modules will be stored. | ||
15 | StorageDir string | ||
16 | } | ||
17 | |||
18 | // Dir implements Storage.Dir | ||
19 | func (s *FolderStorage) Dir(key string) (d string, e bool, err error) { | ||
20 | d = s.dir(key) | ||
21 | _, err = os.Stat(d) | ||
22 | if err == nil { | ||
23 | // Directory exists | ||
24 | e = true | ||
25 | return | ||
26 | } | ||
27 | if os.IsNotExist(err) { | ||
28 | // Directory doesn't exist | ||
29 | d = "" | ||
30 | e = false | ||
31 | err = nil | ||
32 | return | ||
33 | } | ||
34 | |||
35 | // An error | ||
36 | d = "" | ||
37 | e = false | ||
38 | return | ||
39 | } | ||
40 | |||
41 | // Get implements Storage.Get | ||
42 | func (s *FolderStorage) Get(key string, source string, update bool) error { | ||
43 | dir := s.dir(key) | ||
44 | if !update { | ||
45 | if _, err := os.Stat(dir); err == nil { | ||
46 | // If the directory already exists, then we're done since | ||
47 | // we're not updating. | ||
48 | return nil | ||
49 | } else if !os.IsNotExist(err) { | ||
50 | // If the error we got wasn't a file-not-exist error, then | ||
51 | // something went wrong and we should report it. | ||
52 | return fmt.Errorf("Error reading module directory: %s", err) | ||
53 | } | ||
54 | } | ||
55 | |||
56 | // Get the source. This always forces an update. | ||
57 | return Get(dir, source) | ||
58 | } | ||
59 | |||
60 | // dir returns the directory name internally that we'll use to map to | ||
61 | // internally. | ||
62 | func (s *FolderStorage) dir(key string) string { | ||
63 | sum := md5.Sum([]byte(key)) | ||
64 | return filepath.Join(s.StorageDir, hex.EncodeToString(sum[:])) | ||
65 | } | ||