summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--argv.go3
-rw-r--r--doIncoming.go2
-rw-r--r--doList.go2
-rw-r--r--doMakeDists.go9
-rw-r--r--doWalk.go4
-rw-r--r--main.go87
-rw-r--r--structs.go9
7 files changed, 93 insertions, 23 deletions
diff --git a/argv.go b/argv.go
index 2fde2f2..f1e54ee 100644
--- a/argv.go
+++ b/argv.go
@@ -20,6 +20,7 @@ type args struct {
List *EmptyCmd `arg:"subcommand:list" help:"show the packages"`
Walk *WalkCmd `arg:"subcommand:walk" help:"walk the filesystem for new .deb files"`
Update *EmptyCmd `arg:"subcommand:oldway" help:"the old code to update the apt repo"`
+ 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'"`
DryRun bool `arg:"--dry-run" help:"only show what would be packaged"`
@@ -51,7 +52,7 @@ func (args) Appname() string {
}
func (a args) DoAutoComplete(pb *prep.Auto) {
- base := []string{"--version", "oldway", "--dry-run", "--force", "incoming", "walk", "list", "makedists"}
+ base := []string{"--version", "oldway", "--dry-run", "--force", "incoming", "walk", "list", "makedists", "verify"}
if pb.Cmd == "" {
pb.Autocomplete3(base)
diff --git a/doIncoming.go b/doIncoming.go
index a977cb3..a683bef 100644
--- a/doIncoming.go
+++ b/doIncoming.go
@@ -13,7 +13,7 @@ import (
)
func doIncoming(pb *zoopb.Packages) (string, error) {
- os.Chdir(me.mirrorsDir)
+ os.Chdir(me.pb.BaseDir)
var counter int
var incount int
diff --git a/doList.go b/doList.go
index e46e7db..ffcf8d5 100644
--- a/doList.go
+++ b/doList.go
@@ -8,7 +8,7 @@ import (
)
func doList() (string, error) {
- os.Chdir(me.mirrorsDir)
+ os.Chdir(me.pb.BaseDir)
footer := me.pb.PrintTable()
log.Info("found so far:", footer)
diff --git a/doMakeDists.go b/doMakeDists.go
index b4d537f..7cdea78 100644
--- a/doMakeDists.go
+++ b/doMakeDists.go
@@ -2,18 +2,11 @@ package main
import (
"os"
-
- "go.wit.com/log"
)
// os.Chdir(me.mirrorsDir)
// makes the dists/ for 'apt update'
-func doMakeDists(mirrorshome string) (string, error) {
- if me.pb.BaseDir != mirrorshome {
- log.Info("Changed mirrors base directory", me.pb.BaseDir, mirrorshome)
- me.pb.BaseDir = mirrorshome
- }
-
+func doMakeDists() (string, error) {
os.Chdir(me.pb.BaseDir)
for p := range me.pb.IterAll() {
diff --git a/doWalk.go b/doWalk.go
index 7df92e9..b02a0d0 100644
--- a/doWalk.go
+++ b/doWalk.go
@@ -11,7 +11,7 @@ import (
)
func doWalk() (string, error) {
- os.Chdir(me.mirrorsDir)
+ os.Chdir(me.pb.BaseDir)
// 2. Scan pool directory for .deb files and gather info
log.Printf("Scanning for .deb files in %s\n", poolDir)
@@ -91,5 +91,5 @@ func doWalk() (string, error) {
me.pb.Save()
log.Printf("add %d new packages. Total packages.Len()=%d\n", counter, me.pb.Len())
- return "/home/mirrors/wit/ has been scanned for ne files", nil
+ return "mirrors/ has been scanned for new files", nil
}
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
+}
diff --git a/structs.go b/structs.go
index 85083a6..be576d2 100644
--- a/structs.go
+++ b/structs.go
@@ -34,9 +34,8 @@ var me *mainType
// this app's variables
type mainType struct {
- once sync.Once // one-time initialized data
- sh *prep.Auto // more experiments for bash handling
- pb *zoopb.Packages // the mirrors packages
- mirrorsDir string // "/home/mirrors/wit")
- config *config.Config // the mirrors packages
+ once sync.Once // one-time initialized data
+ sh *prep.Auto // more experiments for bash handling
+ pb *zoopb.Packages // the mirrors packages
+ config *config.Config // the mirrors packages
}