summaryrefslogtreecommitdiff
path: root/doNewest.go
blob: ad91d1795105c58c8d8d5e9148c665b5abf4f094 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main

import (
	"time"

	"go.wit.com/lib/cobol"
	"go.wit.com/lib/protobuf/zoopb"
	"go.wit.com/log"
)

// make a list of the newest .deb files
func doGetNewest(arch string) *zoopb.Packages {
	newest := zoopb.NewPackages()
	for p := range me.pb.IterAll() {
		if p.Architecture != arch {
			continue
		}
		found := newest.FindByPackage(p.Package)
		if found == nil {
			// package is new
			log.Printf("%-20.20s %-20.20s %-80.80s\n", "new package", p.Package, p.Filename)
			newest.Clone(p)
			continue
		}
		curtime := p.Ctime.AsTime()
		newtime := found.Ctime.AsTime()
		durs := cobol.Since(p.Ctime) + " vs found " + cobol.Since(found.Ctime)
		if time.Since(curtime) > time.Since(newtime) {
			log.Printf("%-20.20s %-20.20s %-80.80s %s\n", "found is newer", p.Package, p.Filename, durs)
		} else {
			if argv.Verbose {
				log.Printf("%-20.20s %-20.20s %-80.80s %s\n", "found is older", p.Package, p.Filename, durs)
			}
			newest.Delete(found)
			newest.Clone(p)
		}
	}

	newest.SortPackage()
	return newest
}