diff options
author | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
---|---|---|
committer | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
commit | 107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch) | |
tree | ca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/github.com/hashicorp/terraform/configs/configload/module_mgr.go | |
parent | 844b5a68d8af4791755b8f0ad293cc99f5959183 (diff) | |
download | terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip |
Upgrade to 0.12
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/configs/configload/module_mgr.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/configs/configload/module_mgr.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/configs/configload/module_mgr.go b/vendor/github.com/hashicorp/terraform/configs/configload/module_mgr.go new file mode 100644 index 0000000..3c410ee --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/configs/configload/module_mgr.go | |||
@@ -0,0 +1,76 @@ | |||
1 | package configload | ||
2 | |||
3 | import ( | ||
4 | "os" | ||
5 | "path/filepath" | ||
6 | |||
7 | "github.com/hashicorp/terraform/internal/modsdir" | ||
8 | "github.com/hashicorp/terraform/registry" | ||
9 | "github.com/hashicorp/terraform/svchost/disco" | ||
10 | "github.com/spf13/afero" | ||
11 | ) | ||
12 | |||
13 | type moduleMgr struct { | ||
14 | FS afero.Afero | ||
15 | |||
16 | // CanInstall is true for a module manager that can support installation. | ||
17 | // | ||
18 | // This must be set only if FS is an afero.OsFs, because the installer | ||
19 | // (which uses go-getter) is not aware of the virtual filesystem | ||
20 | // abstraction and will always write into the "real" filesystem. | ||
21 | CanInstall bool | ||
22 | |||
23 | // Dir is the path where descendent modules are (or will be) installed. | ||
24 | Dir string | ||
25 | |||
26 | // Services is a service discovery client that will be used to find | ||
27 | // remote module registry endpoints. This object may be pre-loaded with | ||
28 | // cached discovery information. | ||
29 | Services *disco.Disco | ||
30 | |||
31 | // Registry is a client for the module registry protocol, which is used | ||
32 | // when a module is requested from a registry source. | ||
33 | Registry *registry.Client | ||
34 | |||
35 | // manifest tracks the currently-installed modules for this manager. | ||
36 | // | ||
37 | // The loader may read this. Only the installer may write to it, and | ||
38 | // after a set of updates are completed the installer must call | ||
39 | // writeModuleManifestSnapshot to persist a snapshot of the manifest | ||
40 | // to disk for use on subsequent runs. | ||
41 | manifest modsdir.Manifest | ||
42 | } | ||
43 | |||
44 | func (m *moduleMgr) manifestSnapshotPath() string { | ||
45 | return filepath.Join(m.Dir, modsdir.ManifestSnapshotFilename) | ||
46 | } | ||
47 | |||
48 | // readModuleManifestSnapshot loads a manifest snapshot from the filesystem. | ||
49 | func (m *moduleMgr) readModuleManifestSnapshot() error { | ||
50 | r, err := m.FS.Open(m.manifestSnapshotPath()) | ||
51 | if err != nil { | ||
52 | if os.IsNotExist(err) { | ||
53 | // We'll treat a missing file as an empty manifest | ||
54 | m.manifest = make(modsdir.Manifest) | ||
55 | return nil | ||
56 | } | ||
57 | return err | ||
58 | } | ||
59 | |||
60 | m.manifest, err = modsdir.ReadManifestSnapshot(r) | ||
61 | return err | ||
62 | } | ||
63 | |||
64 | // writeModuleManifestSnapshot writes a snapshot of the current manifest | ||
65 | // to the filesystem. | ||
66 | // | ||
67 | // The caller must guarantee no concurrent modifications of the manifest for | ||
68 | // the duration of a call to this function, or the behavior is undefined. | ||
69 | func (m *moduleMgr) writeModuleManifestSnapshot() error { | ||
70 | w, err := m.FS.Create(m.manifestSnapshotPath()) | ||
71 | if err != nil { | ||
72 | return err | ||
73 | } | ||
74 | |||
75 | return m.manifest.WriteSnapshot(w) | ||
76 | } | ||