From 8e9ec30b29ae53e28592e8ac7f48b2f46b8f935b Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 1 Dec 2024 10:46:32 -0600 Subject: save GoDeps at the time of publication to pkg.go.dev --- goDep.redoGoMod.go | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'goDep.redoGoMod.go') diff --git a/goDep.redoGoMod.go b/goDep.redoGoMod.go index ccf64ef..db64a1e 100644 --- a/goDep.redoGoMod.go +++ b/goDep.redoGoMod.go @@ -138,3 +138,67 @@ func (repo *Repo) RepoType() string { output = strings.Trim(output, "'") return output } + +// reads and parses the go.sum file +func (repo *Repo) UpdatePublished() (bool, error) { + // empty out what was there before + repo.Published = nil + tmp := filepath.Join(repo.FullPath, "go.sum") + gosum, err := os.Open(tmp) + if err != nil { + log.Warn("missing go.sum", repo.FullPath) + return false, err + } + defer gosum.Close() + + scanner := bufio.NewScanner(gosum) + log.Info("gosum:", tmp) + for scanner.Scan() { + line := strings.TrimSpace(scanner.Text()) + + parts := strings.Split(line, " ") + if len(parts) == 3 { + godep := strings.TrimSpace(parts[0]) + version := strings.TrimSpace(parts[1]) + if strings.HasSuffix(version, "/go.mod") { + version = strings.TrimSuffix(version, "/go.mod") + } + new1 := GoDep{ + GoPath: godep, + Version: version, + } + if repo.Published == nil { + repo.Published = new(GoDeps) + } + repo.Published.AppendUniqueGoPath(&new1) + /* + found := repo.FindGoDepByPath(godep) + if found == nil { + currentversion, ok := deps[godep] + if ok { + // only use the first value found in the file? + // this shouldn't have been possible. this function should + // only be called from MakeRedomod() + // todo: make go things a seperate package so this function + // isn't exported? + if version != currentversion { + log.Warn("\tgo.sum ", godep, "had both", version, currentversion) + } + } else { + deps[godep] = version + log.Info("\t", godep, "=", version) + } + */ + } else { + // I've never seen this happen yet + panic(errors.New("go.sum invalid: " + line)) + // return false, errors.New("go.sum invalid: " + line) + } + } + + if err := scanner.Err(); err != nil { + repo.Published = nil + return false, err + } + return true, nil +} -- cgit v1.2.3