@@ -90,7 +90,7 @@ func install(tfversion string, binPath string, installPath string, mirrorURL str
90
90
/* set symlink to desired version */
91
91
CreateSymlink (installFileVersionPath , binPath )
92
92
logger .Infof ("Switched terraform to version %q" , tfversion )
93
- addRecent (tfversion , installPath ) //add to recent file for faster lookup
93
+ addRecent (tfversion , installPath , distributionTerraform ) //add to recent file for faster lookup
94
94
return
95
95
}
96
96
@@ -134,99 +134,11 @@ func install(tfversion string, binPath string, installPath string, mirrorURL str
134
134
/* set symlink to desired version */
135
135
CreateSymlink (installFileVersionPath , binPath )
136
136
logger .Infof ("Switched terraform to version %q" , tfversion )
137
- addRecent (tfversion , installPath ) //add to recent file for faster lookup
137
+ addRecent (tfversion , installPath , distributionTerraform ) //add to recent file for faster lookup
138
138
return
139
139
}
140
140
141
- // addRecent : add to recent file
142
- func addRecent (requestedVersion string , installPath string ) {
143
-
144
- installLocation = GetInstallLocation (installPath ) //get installation location - this is where we will put our terraform binary file
145
- versionFile := filepath .Join (installLocation , recentFile )
146
-
147
- fileExist := CheckFileExist (versionFile )
148
- if fileExist {
149
- lines , errRead := ReadLines (versionFile )
150
-
151
- if errRead != nil {
152
- logger .Errorf ("Error reading %q file: %v" , versionFile , errRead )
153
- return
154
- }
155
-
156
- for _ , line := range lines {
157
- if ! validVersionFormat (line ) {
158
- logger .Infof ("File %q is dirty (recreating cache file)" , versionFile )
159
- RemoveFiles (versionFile )
160
- CreateRecentFile (requestedVersion , installPath )
161
- return
162
- }
163
- }
164
-
165
- versionExist := versionExist (requestedVersion , lines )
166
-
167
- if ! versionExist {
168
- if len (lines ) >= 3 {
169
- _ , lines = lines [len (lines )- 1 ], lines [:len (lines )- 1 ]
170
-
171
- lines = append ([]string {requestedVersion }, lines ... )
172
- _ = WriteLines (lines , versionFile )
173
- } else {
174
- lines = append ([]string {requestedVersion }, lines ... )
175
- _ = WriteLines (lines , versionFile )
176
- }
177
- }
178
-
179
- } else {
180
- CreateRecentFile (requestedVersion , installPath )
181
- }
182
- }
183
-
184
- // getRecentVersions : get recent version from file
185
- func getRecentVersions (installPath string ) ([]string , error ) {
186
-
187
- installLocation = GetInstallLocation (installPath ) //get installation location - this is where we will put our terraform binary file
188
- versionFile := filepath .Join (installLocation , recentFile )
189
-
190
- fileExist := CheckFileExist (versionFile )
191
- if fileExist {
192
-
193
- lines , errRead := ReadLines (versionFile )
194
- var outputRecent []string
195
-
196
- if errRead != nil {
197
- logger .Errorf ("Error reading %q file: %f" , versionFile , errRead )
198
- return nil , errRead
199
- }
200
-
201
- for _ , line := range lines {
202
- /* checks if versions in the recent file are valid.
203
- If any version is invalid, it will be considered dirty
204
- and the recent file will be removed
205
- */
206
- if ! validVersionFormat (line ) {
207
- RemoveFiles (versionFile )
208
- return nil , errRead
209
- }
210
-
211
- /* output can be confusing since it displays the 3 most recent used terraform version
212
- append the string *recent to the output to make it more user friendly
213
- */
214
- outputRecent = append (outputRecent , fmt .Sprintf ("%s *recent" , line ))
215
- }
216
-
217
- return outputRecent , nil
218
- }
219
-
220
- return nil , nil
221
- }
222
-
223
- // CreateRecentFile : create RECENT file
224
- func CreateRecentFile (requestedVersion string , installPath string ) {
225
- installLocation = GetInstallLocation (installPath ) //get installation location - this is where we will put our terraform binary file
226
- _ = WriteLines ([]string {requestedVersion }, filepath .Join (installLocation , recentFile ))
227
- }
228
-
229
- // ConvertExecutableExt : convert excutable with local OS extension
141
+ // ConvertExecutableExt : convert executable with local OS extension
230
142
func ConvertExecutableExt (fpath string ) string {
231
143
switch runtime .GOOS {
232
144
case "windows" :
@@ -314,7 +226,7 @@ func InstallVersion(dryRun bool, version, customBinaryPath, installPath, mirrorU
314
226
if recentDownloadFile {
315
227
ChangeSymlink (installFileVersionPath , customBinaryPath )
316
228
logger .Infof ("Switched terraform to version %q" , requestedVersion )
317
- addRecent (requestedVersion , installPath ) //add to recent file for faster lookup
229
+ addRecent (requestedVersion , installPath , distributionTerraform ) //add to recent file for faster lookup
318
230
return
319
231
}
320
232
@@ -341,10 +253,10 @@ func InstallVersion(dryRun bool, version, customBinaryPath, installPath, mirrorU
341
253
/* listAll = true - all versions including beta and rc will be displayed */
342
254
/* listAll = false - only official stable release are displayed */
343
255
func InstallOption (listAll , dryRun bool , customBinaryPath , installPath string , mirrorURL string ) {
344
- tflist , _ := getTFList (mirrorURL , listAll ) // Get list of versions
345
- recentVersions , _ := getRecentVersions (installPath ) // Get recent versions from RECENT file
346
- tflist = append (recentVersions , tflist ... ) // Append recent versions to the top of the list
347
- tflist = removeDuplicateVersions (tflist ) // Remove duplicate version
256
+ tflist , _ := getTFList (mirrorURL , listAll ) // Get list of versions
257
+ recentVersions , _ := getRecentVersions (installPath , distributionTerraform ) // Get recent versions from RECENT file
258
+ tflist = append (recentVersions , tflist ... ) // Append recent versions to the top of the list
259
+ tflist = removeDuplicateVersions (tflist ) // Remove duplicate version
348
260
349
261
if len (tflist ) == 0 {
350
262
logger .Fatalf ("Terraform version list is empty: %s" , mirrorURL )
0 commit comments