Skip to content

Commit

Permalink
Add handling migration of Recent file data from previous format
Browse files Browse the repository at this point in the history
Based on changes by MatrixCrawler in 64d6bec
  • Loading branch information
MatthewJohn committed May 27, 2024
1 parent cb64930 commit 13b73a4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/recent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
)

type RecentFile struct {
Expand Down Expand Up @@ -63,6 +64,15 @@ func addRecentVersion(product Product, requestedVersion string, installPath stri
}
}

func convertLegacyRecentData(content []byte, recentFileContent *RecentFile) {
lines := strings.Split(string(content), "\n")
for _, s := range lines {
if s != "" {
recentFileContent.Terraform = append(recentFileContent.Terraform, s)
}
}
}

func getRecentFileData(installPath string) RecentFile {
installLocation = GetInstallLocation(installPath) //get installation location - this is where we will put our terraform binary file
recentFilePath := filepath.Join(installLocation, recentFile)
Expand All @@ -76,6 +86,10 @@ func getRecentFileData(installPath string) RecentFile {
return outputRecent
}

if !strings.HasPrefix(string(content), "{") {
convertLegacyRecentData(content, &outputRecent)
}

err = json.Unmarshal(content, &outputRecent)
if err != nil {
logger.Warnf("Error during unmarshalling recent versions data from %s file: %v. Ignoring", recentFilePath, err)
Expand Down

0 comments on commit 13b73a4

Please sign in to comment.