diff options
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | argv.go | 3 | ||||
| -rw-r--r-- | doIncoming.go | 2 | ||||
| -rw-r--r-- | doVerify.go | 89 | ||||
| -rw-r--r-- | main.go | 90 |
5 files changed, 128 insertions, 57 deletions
@@ -5,7 +5,6 @@ GUIVERSION = $(shell git describe --tags) BUILDTIME = $(shell date +%s) all: install - mirrors makedists build: goimports GO111MODULE=off go build \ @@ -23,6 +23,7 @@ type args struct { Verify *EmptyCmd `arg:"subcommand:verify" help:"verify the pb is accurate and doesn't have errors"` Incoming *IncomingCmd `arg:"subcommand:incoming" help:"handle the incoming directory"` MakeDists *EmptyCmd `arg:"subcommand:makedists" help:"make debian mirrors/dists files for 'apt update'"` + Newest *EmptyCmd `arg:"subcommand:newest" help:"make a list of the newest .deb packages"` DryRun bool `arg:"--dry-run" help:"only show what would be packaged"` Verbose bool `arg:"--verbose" help:"be loud about it"` Force bool `arg:"--force" help:"rebuild everything"` @@ -52,7 +53,7 @@ func (args) Appname() string { } func (a args) DoAutoComplete(pb *prep.Auto) { - base := []string{"--version", "oldway", "--dry-run", "--force", "incoming", "walk", "list", "makedists", "verify"} + base := []string{"--version", "oldway", "--dry-run", "--force", "incoming", "walk", "list", "makedists", "verify", "newest"} if pb.Cmd == "" { pb.Autocomplete3(base) diff --git a/doIncoming.go b/doIncoming.go index a683bef..531f99d 100644 --- a/doIncoming.go +++ b/doIncoming.go @@ -61,7 +61,7 @@ func doIncoming(pb *zoopb.Packages) (string, error) { os.Rename(path, newfilename) log.Printf("%s moved incoming oldname %s newname: %s\n", found.Package, path, newfilename) incount += 1 - if counter > 100 { + if incount > 100 { me.sh.GoodExit("file moved") } return nil diff --git a/doVerify.go b/doVerify.go new file mode 100644 index 0000000..b936f24 --- /dev/null +++ b/doVerify.go @@ -0,0 +1,89 @@ +package main + +import ( + "errors" + "os" + "path/filepath" + "strings" + + "go.wit.com/lib/gui/shell" + "go.wit.com/lib/protobuf/zoopb" + "go.wit.com/log" + "google.golang.org/protobuf/types/known/timestamppb" +) + +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/") + } + log.Info("Processing dir", filepath.Join(me.pb.BaseDir, "pool")) + + 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 + continue + } + if p.Filename != strings.TrimSpace(p.Filename) { + log.Printf("%-16.16s %-130.130s\n", "garbage in filename", pdump) + counter += 1 + continue + } + if p.Filename == "" { + log.Printf("filename is blank %-130.130s\n", pdump) + counter += 1 + continue + } + // the filename is now valid + 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 + } + // make sure the fields are valid + if p.Package == "" { + log.Printf("%-16.16s %-130.130s\n", "Package is blank", pdump) + counter += 1 + continue + } + // log.Info("Package", p.Package) + 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 + } + } + + log.Info("there were", counter, "errors") + if counter != 0 { + me.pb.Save() + } + + return "verified ok", nil +} @@ -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 } |
