File tree Expand file tree Collapse file tree 4 files changed +18
-23
lines changed Expand file tree Collapse file tree 4 files changed +18
-23
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import (
17
17
"strings"
18
18
19
19
urlhelper "github.com/hashicorp/go-getter/helper/url"
20
+ "github.com/hashicorp/go-safetemp"
20
21
)
21
22
22
23
// Client is a client for downloading things.
@@ -100,17 +101,14 @@ func (c *Client) Get() error {
100
101
dst := c .Dst
101
102
src , subDir := SourceDirSubdir (src )
102
103
if subDir != "" {
103
- tmpDir , err := ioutil . TempDir ("" , "tf " )
104
+ td , tdcloser , err := safetemp . Dir ("" , "getter " )
104
105
if err != nil {
105
106
return err
106
107
}
107
- if err := os .RemoveAll (tmpDir ); err != nil {
108
- return err
109
- }
110
- defer os .RemoveAll (tmpDir )
108
+ defer tdcloser .Close ()
111
109
112
110
realDst = dst
113
- dst = tmpDir
111
+ dst = td
114
112
}
115
113
116
114
u , err := urlhelper .Parse (src )
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import (
11
11
"strings"
12
12
13
13
urlhelper "github.com/hashicorp/go-getter/helper/url"
14
+ "github.com/hashicorp/go-safetemp"
14
15
"github.com/hashicorp/go-version"
15
16
)
16
17
@@ -105,13 +106,11 @@ func (g *GitGetter) Get(dst string, u *url.URL) error {
105
106
// GetFile for Git doesn't support updating at this time. It will download
106
107
// the file every time.
107
108
func (g * GitGetter ) GetFile (dst string , u * url.URL ) error {
108
- td , err := ioutil . TempDir ("" , "getter-git " )
109
+ td , tdcloser , err := safetemp . Dir ("" , "getter" )
109
110
if err != nil {
110
111
return err
111
112
}
112
- if err := os .RemoveAll (td ); err != nil {
113
- return err
114
- }
113
+ defer tdcloser .Close ()
115
114
116
115
// Get the filename, and strip the filename from the URL so we can
117
116
// just get the repository directly.
Original file line number Diff line number Diff line change @@ -2,14 +2,14 @@ package getter
2
2
3
3
import (
4
4
"fmt"
5
- "io/ioutil"
6
5
"net/url"
7
6
"os"
8
7
"os/exec"
9
8
"path/filepath"
10
9
"runtime"
11
10
12
11
urlhelper "github.com/hashicorp/go-getter/helper/url"
12
+ "github.com/hashicorp/go-safetemp"
13
13
)
14
14
15
15
// HgGetter is a Getter implementation that will download a module from
@@ -64,13 +64,13 @@ func (g *HgGetter) Get(dst string, u *url.URL) error {
64
64
// GetFile for Hg doesn't support updating at this time. It will download
65
65
// the file every time.
66
66
func (g * HgGetter ) GetFile (dst string , u * url.URL ) error {
67
- td , err := ioutil .TempDir ("" , "getter-hg" )
67
+ // Create a temporary directory to store the full source. This has to be
68
+ // a non-existent directory.
69
+ td , tdcloser , err := safetemp .Dir ("" , "getter" )
68
70
if err != nil {
69
71
return err
70
72
}
71
- if err := os .RemoveAll (td ); err != nil {
72
- return err
73
- }
73
+ defer tdcloser .Close ()
74
74
75
75
// Get the filename, and strip the filename from the URL so we can
76
76
// just get the repository directly.
Original file line number Diff line number Diff line change @@ -4,12 +4,13 @@ import (
4
4
"encoding/xml"
5
5
"fmt"
6
6
"io"
7
- "io/ioutil"
8
7
"net/http"
9
8
"net/url"
10
9
"os"
11
10
"path/filepath"
12
11
"strings"
12
+
13
+ "github.com/hashicorp/go-safetemp"
13
14
)
14
15
15
16
// HttpGetter is a Getter implementation that will download from an HTTP
@@ -149,16 +150,13 @@ func (g *HttpGetter) GetFile(dst string, u *url.URL) error {
149
150
// getSubdir downloads the source into the destination, but with
150
151
// the proper subdir.
151
152
func (g * HttpGetter ) getSubdir (dst , source , subDir string ) error {
152
- // Create a temporary directory to store the full source
153
- td , err := ioutil .TempDir ("" , "tf" )
153
+ // Create a temporary directory to store the full source. This has to be
154
+ // a non-existent directory.
155
+ td , tdcloser , err := safetemp .Dir ("" , "getter" )
154
156
if err != nil {
155
157
return err
156
158
}
157
- defer os .RemoveAll (td )
158
-
159
- // We have to create a subdirectory that doesn't exist for the file
160
- // getter to work.
161
- td = filepath .Join (td , "data" )
159
+ defer tdcloser .Close ()
162
160
163
161
// Download that into the given directory
164
162
if err := Get (td , source ); err != nil {
You can’t perform that action at this time.
0 commit comments