summaryrefslogtreecommitdiff
path: root/goDep.redoGoMod.go
diff options
context:
space:
mode:
Diffstat (limited to 'goDep.redoGoMod.go')
-rw-r--r--goDep.redoGoMod.go64
1 files changed, 64 insertions, 0 deletions
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
+}