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/posener/complete/cmd/install/utils.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/posener/complete/cmd/install/utils.go')
-rw-r--r-- | vendor/github.com/posener/complete/cmd/install/utils.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/vendor/github.com/posener/complete/cmd/install/utils.go b/vendor/github.com/posener/complete/cmd/install/utils.go index 2c8b44c..d34ac8c 100644 --- a/vendor/github.com/posener/complete/cmd/install/utils.go +++ b/vendor/github.com/posener/complete/cmd/install/utils.go | |||
@@ -6,6 +6,7 @@ import ( | |||
6 | "io" | 6 | "io" |
7 | "io/ioutil" | 7 | "io/ioutil" |
8 | "os" | 8 | "os" |
9 | "path/filepath" | ||
9 | ) | 10 | ) |
10 | 11 | ||
11 | func lineInFile(name string, lookFor string) bool { | 12 | func lineInFile(name string, lookFor string) bool { |
@@ -36,6 +37,24 @@ func lineInFile(name string, lookFor string) bool { | |||
36 | } | 37 | } |
37 | } | 38 | } |
38 | 39 | ||
40 | func createFile(name string, content string) error { | ||
41 | // make sure file directory exists | ||
42 | if err := os.MkdirAll(filepath.Dir(name), 0775); err != nil { | ||
43 | return err | ||
44 | } | ||
45 | |||
46 | // create the file | ||
47 | f, err := os.Create(name) | ||
48 | if err != nil { | ||
49 | return err | ||
50 | } | ||
51 | defer f.Close() | ||
52 | |||
53 | // write file content | ||
54 | _, err = f.WriteString(fmt.Sprintf("%s\n", content)) | ||
55 | return err | ||
56 | } | ||
57 | |||
39 | func appendToFile(name string, content string) error { | 58 | func appendToFile(name string, content string) error { |
40 | f, err := os.OpenFile(name, os.O_RDWR|os.O_APPEND, 0) | 59 | f, err := os.OpenFile(name, os.O_RDWR|os.O_APPEND, 0) |
41 | if err != nil { | 60 | if err != nil { |
@@ -96,7 +115,10 @@ func removeContentToTempFile(name, content string) (string, error) { | |||
96 | if str == content { | 115 | if str == content { |
97 | continue | 116 | continue |
98 | } | 117 | } |
99 | wf.WriteString(str + "\n") | 118 | _, err = wf.WriteString(str + "\n") |
119 | if err != nil { | ||
120 | return "", err | ||
121 | } | ||
100 | prefix = prefix[:0] | 122 | prefix = prefix[:0] |
101 | } | 123 | } |
102 | return wf.Name(), nil | 124 | return wf.Name(), nil |