diff options
Diffstat (limited to 'doVerify.go')
| -rw-r--r-- | doVerify.go | 89 |
1 files changed, 89 insertions, 0 deletions
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 +} |
