summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go87
1 files changed, 82 insertions, 5 deletions
diff --git a/main.go b/main.go
index 066d374..d610ed0 100644
--- a/main.go
+++ b/main.go
@@ -2,11 +2,17 @@ package main
import (
"embed"
+ "errors"
+ "os"
+ "path/filepath"
+ "strings"
"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
@@ -23,11 +29,9 @@ func main() {
me = new(mainType)
me.sh = prep.Bash3(&argv) // add support for bash autocomplete with go-arg
- me.mirrorsDir = "/home/mirrors/wit"
-
// read in protobuf file
me.pb = zoopb.NewPackages()
- me.pb.Filename = "/home/mirrors/mirrors.wit.com.pb"
+ me.pb.Filename = "/home/mirrors/wit/mirrors.wit.com.pb"
if err := me.pb.Load(); err != nil {
if argv.Force {
config.Save(me.pb)
@@ -35,10 +39,16 @@ 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"
+ me.pb.Save()
+ panic("missing /home/mirrors/wit as BaseDir")
+ }
if me.sh.Cmd == "" {
// default behavior when no argv
- s := log.Sprintf("You have %d packages in %s", me.pb.Len(), me.mirrorsDir)
+ s := log.Sprintf("You have %d packages in %s", me.pb.Len(), me.pb.BaseDir)
me.sh.GoodExit(s)
}
@@ -57,12 +67,16 @@ func main() {
s, err = doList()
}
+ if argv.Verify != nil {
+ s, err = doVerify()
+ }
+
if argv.Update != nil {
err = doDistro()
}
if argv.MakeDists != nil {
- s, err = doMakeDists("/home/mirrors/wit")
+ s, err = doMakeDists()
}
if err != nil {
@@ -70,3 +84,66 @@ func main() {
}
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/")
+ }
+ 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 == "" {
+ 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
+ }
+ }
+
+ log.Info("there were", counter, "errors")
+ if counter != 0 {
+ me.pb.Save()
+ }
+
+ return "verified ok", nil
+}