summaryrefslogtreecommitdiff
path: root/doWalk.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-12 20:41:59 -0500
committerJeff Carr <[email protected]>2025-10-13 03:28:20 -0500
commitaca9033f21dae1b9862248582827d05151bbe592 (patch)
tree4110f7526d08da098d8561c34e6b35c6c91adb3d /doWalk.go
parent4cefe0bf52f9d60d25858ebb51b870433004a4a6 (diff)
parsing dpkg -I the right way
Diffstat (limited to 'doWalk.go')
-rw-r--r--doWalk.go106
1 files changed, 28 insertions, 78 deletions
diff --git a/doWalk.go b/doWalk.go
index 516345a..913aea4 100644
--- a/doWalk.go
+++ b/doWalk.go
@@ -1,95 +1,45 @@
package main
import (
+ "errors"
"os"
- "time"
+ "path/filepath"
+ "strings"
- "go.wit.com/lib/debian"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log"
- "google.golang.org/protobuf/types/known/timestamppb"
)
+var errStopWalk = errors.New("walk stopped by user")
+
func doWalk() (string, error) {
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)
- debInfos, err := scanDebs(poolDir, 200)
- if err != nil {
- log.Printf("Failed to scan .deb files: %v\n", err)
- me.sh.BadExit("scan pool scan dir", err)
- }
-
var counter int
- for _, deb := range debInfos {
- newdeb := new(zoopb.Package)
- newdeb.DebInfo = new(zoopb.DebInfo)
- newdeb.Filename = deb.Filename
- newdeb.DebInfo.Filename = deb.Filename
- newdeb.DebInfo.MD5SUM = deb.MD5Sum
- // newdeb.DebInfo.SHA1 = deb.SHA1Sum
- newdeb.DebInfo.SHA256 = deb.SHA256Sum
-
- // log.Info("len(CONTROLDATA)", len(deb.ControlData))
- // log.Sprintf("VAR='%s' VAL='%s'\n", varname, varvalue)
- // log.Info("%v", deb.ControlData)
- for varname, varvalue := range deb.ControlData {
- switch varname {
- case "Package":
- newdeb.Package = varvalue
- case "Version":
- newdeb.Version = varvalue
- case "Architecture":
- newdeb.Architecture = varvalue
- case "Git-Tag-Date":
- if argv.Verbose {
- log.Info("CONVERT THIS TO TIME", varname, varvalue)
- }
- case "Depends":
- newdeb.DebInfo.Depends = varvalue
- case "Build-Depends":
- newdeb.DebInfo.BuildDepends = varvalue
- case "Packager":
- newdeb.DebInfo.Packager = varvalue
- case "Package-Build-Date":
- varname = "PackageBuildDate"
- const layout = "2006/01/02 15:04:05 MST"
- parsedTime, err := time.Parse(layout, varvalue)
- if err != nil {
- log.Info("CONVERT TO TIME failed", varname, varvalue, err)
- }
- newdeb.BuildDate = timestamppb.New(parsedTime)
- case "URL":
- newdeb.DebInfo.Homepage = varvalue
- default:
- if err := debian.SetDebInfoString(newdeb, varname, varvalue); err == nil {
- if argv.Verbose {
- log.Printf("Searching for Sugarman WORKED: VAR='%-30s' VAL='%s'\n", varname, varvalue)
- }
- } else {
- log.Printf("Searching for Sugarman (unknwon var): VAR='%-30s' VAL='%s' err=%v\n", varname, varvalue, err)
- }
- // todo: add to protomap
- }
+ err := filepath.Walk("pool", func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ return err
}
- counter += 1
- me.pb.AppendByFilename(newdeb)
- if newdeb.Filename == "" {
- log.Info(deb)
- log.Info("file=", deb.Filename)
- panic("newdeb.Filename = ''")
- }
- if argv.Verbose {
- newdeb.Print()
+ if !info.IsDir() && strings.HasSuffix(info.Name(), ".deb") {
+ found := me.pb.FindByFilename(path)
+ if found != nil {
+ return nil
+ }
+ counter += 1
+ // if counter > 10 {
+ // return errStopWalk
+ // }
+ newdeb := new(zoopb.Package)
+ newdeb.Filename = path
+ me.pb.AppendByFilename(newdeb)
+ log.Info("added new", path)
}
- // arch := deb.ControlData["Architecture"]
- }
+ return nil
+ })
- // footer := me.pb.PrintTable()
- // log.Info("found so far:", footer)
-
- me.pb.Save()
- log.Printf("add %d new packages. Total packages.Len()=%d\n", counter, me.pb.Len())
- return "mirrors/ has been scanned for new files", nil
+ if counter > 0 {
+ me.pb.Save()
+ }
+ s := log.Sprintf("add %d new packages. Total packages.Len()=%d", counter, me.pb.Len())
+ return s, err
}