diff --git "a/.changes/unreleased/\360\237\220\233 Bug Fix-20230118-161022.yaml" "b/.changes/unreleased/\360\237\220\233 Bug Fix-20230118-161022.yaml" new file mode 100644 index 00000000..961a0d2c --- /dev/null +++ "b/.changes/unreleased/\360\237\220\233 Bug Fix-20230118-161022.yaml" @@ -0,0 +1,10 @@ +kind: "\U0001F41B Bug Fix" +body: + Fix reading cache file for checking cli versions. Save just one using link on + update. +time: 2023-01-18T16:10:22.406877401+02:00 +custom: + azure-boards-workitemid-fixed: '482447' + azure-boards-workitemid-related: '482427' + github-contributor: '' + github-link: '' diff --git a/version/update.go b/version/update.go index 7fb73cf6..41950ff4 100644 --- a/version/update.go +++ b/version/update.go @@ -41,26 +41,31 @@ func CheckLatestVersion() (*update, error) { return nil, err } cacheFilePath := filepath.Join(thyDir, cacheFileName) - + platform := runtime.GOOS + "/" + runtime.GOARCH latest := readCache(cacheFilePath) - if latest == nil { pageContent, err := fetchContent(versionsURL) if err != nil { return nil, err } - latest = &latestInfo{} err = json.Unmarshal(pageContent, latest) if err != nil { return nil, err } - + actualLink, ok := latest.Links[platform] + if !ok { + return nil, errors.New("links malformed") + } + latest.Links = map[string]string{platform: actualLink} + pageContent, err = json.Marshal(latest) + if err != nil { + return nil, err + } updateCache(cacheFilePath, pageContent) } - if isVersionOutdated(Version, latest.Latest) { - actualLink, ok := latest.Links[runtime.GOOS+"/"+runtime.GOARCH] + actualLink, ok := latest.Links[platform] if !ok { return nil, errors.New("links malformed") } @@ -82,8 +87,9 @@ func readCache(updateFilePath string) *latestInfo { return nil } - contents := strings.Split(string(fileContent), "\n") - if len(contents) < 2 { + const fileParts int = 2 + contents := strings.SplitN(string(fileContent), "\n", fileParts) + if len(contents) < fileParts { log.Printf("Wrong file %s format", updateFilePath) return nil }