@@ -73,20 +73,7 @@ func mimeType(data []byte) (string, error) {
73
73
// version again. If instead behaviour is "keep" it will not download the version
74
74
// if it already exists.
75
75
func (t * Tools ) Download (name , version , behaviour string ) error {
76
- var key string
77
- if version == "latest" {
78
- key = name
79
- } else {
80
- key = name + "-" + version
81
- }
82
76
83
- // Check if it already exists
84
- if version != "latest" && behaviour == "keep" {
85
- if _ , ok := t .installed [key ]; ok {
86
- t .Logger .Println ("The tool is already present on the system" )
87
- return nil
88
- }
89
- }
90
77
// Fetch the index
91
78
resp , err := http .Get (t .IndexURL )
92
79
if err != nil {
@@ -123,6 +110,16 @@ func (t *Tools) Download(name, version, behaviour string) error {
123
110
}
124
111
}
125
112
113
+ key := correctTool .Name + "-" + correctTool .Version
114
+
115
+ // Check if it already exists
116
+ if behaviour == "keep" {
117
+ if _ , ok := t .installed [key ]; ok {
118
+ t .Logger .Println ("The tool is already present on the system" )
119
+ return nil
120
+ }
121
+ }
122
+
126
123
// Download the tool
127
124
t .Logger .Println ("Downloading tool " + name + " from " + correctSystem .URL )
128
125
resp , err = http .Get (correctSystem .URL )
@@ -221,7 +218,10 @@ func findBaseDir(dirList []string) string {
221
218
return baseDir
222
219
}
223
220
}
224
- baseDir = candidateBaseDir
221
+ // avoid setting the candidate if it is the last file
222
+ if dirList [len (dirList )- 1 ] != candidateBaseDir {
223
+ baseDir = candidateBaseDir
224
+ }
225
225
}
226
226
return baseDir
227
227
}
@@ -236,9 +236,7 @@ func extractZip(body []byte, location string) (string, error) {
236
236
var dirList []string
237
237
238
238
for _ , f := range r .File {
239
- if f .FileInfo ().IsDir () {
240
- dirList = append (dirList , f .Name )
241
- }
239
+ dirList = append (dirList , f .Name )
242
240
}
243
241
244
242
basedir := findBaseDir (dirList )
@@ -288,9 +286,7 @@ func extractTarGz(body []byte, location string) (string, error) {
288
286
if err == io .EOF {
289
287
break
290
288
}
291
- if header .FileInfo ().IsDir () {
292
- dirList = append (dirList , header .Name )
293
- }
289
+ dirList = append (dirList , header .Name )
294
290
}
295
291
296
292
basedir := findBaseDir (dirList )
@@ -358,9 +354,7 @@ func extractBz2(body []byte, location string) (string, error) {
358
354
if err == io .EOF {
359
355
break
360
356
}
361
- if header .FileInfo ().IsDir () {
362
- dirList = append (dirList , header .Name )
363
- }
357
+ dirList = append (dirList , header .Name )
364
358
}
365
359
366
360
basedir := findBaseDir (dirList )
0 commit comments