diff options
| author | Jeff Carr <[email protected]> | 2025-10-11 08:54:40 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-11 09:26:40 -0500 |
| commit | 20c8b7a721064197d42b8f1447abfca98d7bd350 (patch) | |
| tree | 8f0aa2c4b5c400f278d4aa9a035b315e263ab3d8 /main.go | |
| parent | 8561ed36abf865c261184dea856c42c20f01d155 (diff) | |
working on finding the newest packages
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 90 |
1 files changed, 36 insertions, 54 deletions
@@ -5,14 +5,14 @@ import ( "errors" "os" "path/filepath" - "strings" + "time" + "go.wit.com/lib/cobol" "go.wit.com/lib/config" "go.wit.com/lib/gui/prep" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/zoopb" "go.wit.com/log" - "google.golang.org/protobuf/types/known/timestamppb" ) // sent via -ldflags @@ -39,6 +39,7 @@ func main() { me.sh.BadExit("no config found. use --force to create one", err) } } + if me.pb.BaseDir != "/home/mirrors/wit" { me.pb.Filename = "/home/mirrors/wit/mirrors.wit.com.pb" me.pb.BaseDir = "/home/mirrors/wit" @@ -46,6 +47,14 @@ func main() { panic("missing /home/mirrors/wit as BaseDir") } + if err := os.Chdir(me.pb.BaseDir); err != nil { + me.sh.BadExit("no '"+me.pb.BaseDir+"' directory", err) + } + + if !shell.IsDir("pool/") { + me.sh.BadExit("no "+filepath.Join(me.pb.BaseDir, "pool")+" directory", errors.New("mount -a ? missing wit/pool/")) + } + if me.sh.Cmd == "" { // default behavior when no argv s := log.Sprintf("You have %d packages in %s", me.pb.Len(), me.pb.BaseDir) @@ -79,71 +88,44 @@ func main() { s, err = doMakeDists() } + if argv.Newest != nil { + s, err = doNewest() + } + if err != nil { me.sh.BadExit(s, err) } me.sh.GoodExit(s) } -func doVerify() (string, error) { - if err := os.Chdir(me.pb.BaseDir); err != nil { - return "no '" + me.pb.BaseDir + "' directory", err - } - if !shell.IsDir("pool/") { - return "no " + filepath.Join(me.pb.BaseDir, "pool") + " directory", errors.New("mount -a ? missing wit/pool/") - } +// make a list of the newest .deb files +func doNewest() (string, error) { log.Info("Processing dir", filepath.Join(me.pb.BaseDir, "pool")) + newest := zoopb.NewPackages() var counter int - filemap := make(map[string]*zoopb.Package) for p := range me.pb.IterAll() { - pdump := log.Sprintf("%v", p) - if p.DebInfo == nil { - log.Printf("debinfo == nil %-130.130s\n", pdump) - counter += 1 + 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 } - if p.Filename == "" { - log.Printf("filename is blank %-130.130s\n", pdump) - counter += 1 - continue - } - fullname := filepath.Join(me.pb.BaseDir, p.Filename) - if !shell.Exists(p.Filename) { - log.Printf("no file Exists() %-130.130s\n", fullname) - me.pb.Delete(p) - counter += 1 - continue - } - if dupname, ok := filemap[p.Filename]; ok { - dupdump := log.Sprintf("%v", dupname) - log.Printf("dup filename 1 %-130.130s\n", pdump) - log.Printf("dup filename 2 %-130.130s\n", dupdump) - counter += 1 - continue - } - if strings.Contains(p.Filename, "dirty") { - log.Printf("dirty .deb build %-130.130s\n", fullname) - counter += 1 - continue - } - if p.Ctime == nil { - log.Printf("ctime is nil %-130.130s\n", fullname) - stat, err := os.Stat(fullname) - if err != nil { - log.Printf("stat error %-130.130s %v\n", fullname, err) - continue - } - p.Ctime = timestamppb.New(stat.ModTime()) - counter += 1 - 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) + newest.Delete(found) + newest.Clone(p) + } else { + log.Printf("%-20.20s %-20.20s %-80.80s %s\n", "found is older", p.Package, p.Filename, durs) } } - log.Info("there were", counter, "errors") - if counter != 0 { - me.pb.Save() - } - - return "verified ok", nil + newest.SortPackage() + footer := newest.PrintTable() + log.Info("newest packages ?", footer, counter) + return "doNewest", nil } |
