From e8a7433c9588827b275cbcf7a8745f886dd59ad4 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 22 Oct 2025 11:08:59 -0500 Subject: adapt to the new lib/config and lib/ENV --- config.go | 6 ++++-- doPatches.go | 19 ++++++++++--------- doRepos.go | 17 +++++++++-------- handlePatches.go | 4 ++-- http.go | 6 +++--- main.go | 13 +++++++++---- structs.go | 13 +++++++------ 7 files changed, 44 insertions(+), 34 deletions(-) diff --git a/config.go b/config.go index eb70086..7a7f119 100644 --- a/config.go +++ b/config.go @@ -15,7 +15,8 @@ import ( ) func configSave() error { - return me.configs.Save() + // return me.configs.SavePB() + panic("not done") } func configInit() *forgepb.ForgeConfigs { @@ -24,7 +25,8 @@ func configInit() *forgepb.ForgeConfigs { } configs := new(forgepb.ForgeConfigs) - filename, err := config.LoadByAppName(configs, APPNAME) + configs.Filename = config.MakeConfigFilename("forged", "forge") + err := config.ReLoad(configs) if errors.Is(err, os.ErrNotExist) { ENV.Set("ReposDir", "/var/cache/forged") ENV.Set("ReposPB", filepath.Join(ENV.Get("ReposDir"), "repos.pb")) diff --git a/doPatches.go b/doPatches.go index e4008c6..b2ea050 100644 --- a/doPatches.go +++ b/doPatches.go @@ -1,6 +1,7 @@ package main import ( + "go.wit.com/lib/ENV" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/log" ) @@ -8,13 +9,13 @@ import ( func doPatches() error { if argv.Patch.List != nil { log.Printf("forge.Init() %s len()=%d\n", me.forge.Config.Filename, me.forge.Repos.Len()) - me.forge.Config.DumpENV() + ENV.PrintTable() return doList() } if argv.Patch.Clean != nil { log.Printf("forge.Init() %s len()=%d\n", me.forge.Config.Filename, me.forge.Repos.Len()) - me.forge.Config.DumpENV() + ENV.PrintTable() return doClean() } @@ -22,17 +23,17 @@ func doPatches() error { } func doList() error { - log.Infof("do list here. Patchsets.Len()=%d\n", me.forge.Patchsets.Len()) - for pset := range me.forge.Patchsets.IterAll() { + log.Infof("do list here. Patchsets.Len()=%d\n", me.Patchsets.Len()) + for pset := range me.Patchsets.IterAll() { pset.PrintTable() } return nil } func doClean() error { - log.Infof("clean Patchsets.Len()=%d\n", me.forge.Patchsets.Len()) + log.Infof("clean Patchsets.Len()=%d\n", me.Patchsets.Len()) // show all the patchsets with Names - for pset := range me.forge.Patchsets.IterAll() { + for pset := range me.Patchsets.IterAll() { for patch := range pset.Patches.IterAll() { if patch.PatchId == "" { log.Info("Delete", patch.CommitHash, patch.PatchId, patch.Namespace) @@ -42,7 +43,7 @@ func doClean() error { } } } - me.forge.SavePatchsets() + me.Patchsets.Save() return nil } @@ -50,7 +51,7 @@ func doClean() error { func findPatch(newpatch *forgepb.Patch) bool { // log.Info("\tlook for patch:", newpatch.CommitHash, newpatch.Namespace) - for pset := range me.forge.Patchsets.IterAll() { + for pset := range me.Patchsets.IterAll() { for _, patch := range pset.Patches.Patches { if patch.CommitHash == newpatch.CommitHash { // log.Info("\tfound pset!!!!!!", pset.Uuid, patch.Namespace) @@ -67,7 +68,7 @@ func findPatch(newpatch *forgepb.Patch) bool { func expirePatch(newpatch *forgepb.Patch) bool { // log.Info("\tlook for patch:", newpatch.CommitHash, newpatch.Namespace) - for pset := range me.forge.Patchsets.IterAll() { + for pset := range me.Patchsets.IterAll() { for _, patch := range pset.Patches.Patches { if patch.CommitHash == newpatch.CommitHash { patch.NewHash = newpatch.NewHash diff --git a/doRepos.go b/doRepos.go index 29b8f3d..42162b8 100644 --- a/doRepos.go +++ b/doRepos.go @@ -4,6 +4,7 @@ import ( "os" "time" + "go.wit.com/lib/ENV" "go.wit.com/lib/config" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/forgepb" @@ -43,15 +44,15 @@ func doRepos() error { } log.Info("repos reloaded:", count) if count > 0 { - me.forge.SaveRepos() + me.forge.Save() } return nil } if argv.Repos.Scan != nil { - log.Infof("start repos scan repos.Len()=%d %s\n", me.forge.Repos.Len(), me.forge.Config.ReposDir) - _, err := scanForgedDir(me.forge.Config.ReposDir) - me.forge.SaveRepos() + log.Infof("start repos scan repos.Len()=%d %s\n", me.forge.Repos.Len(), ENV.Get("ReposDir")) + _, err := scanForgedDir(ENV.Get("ReposDir")) + me.forge.Save() return err } @@ -89,11 +90,11 @@ func doRepos() error { continue } } - me.forge.SaveRepos() + me.forge.Save() /* count := me.forge.RillReload() if count != 0 { - me.forge.SaveRepos() + me.forge.Save() log.Infof("%d repos changed\n", count) return nil } @@ -125,7 +126,7 @@ func doRepos() error { } } if count != 0 { - me.forge.SaveRepos() + me.forge.Save() } return nil } @@ -160,7 +161,7 @@ func verifyForged() { // repo is fine } if changed { - me.forge.Repos.ConfigSave(me.forge.Config.ReposPB) + me.forge.Save() } } diff --git a/handlePatches.go b/handlePatches.go index 0bc6dff..03ea1c7 100644 --- a/handlePatches.go +++ b/handlePatches.go @@ -30,7 +30,7 @@ func handleMergedPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgep func sendPendingPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb.Patches { allPatchesPB := new(forgepb.Patches) - for pset := range me.forge.Patchsets.IterAll() { + for pset := range me.Patchsets.IterAll() { for newpatch := range pset.Patches.IterAll() { allPatchesPB.Append(newpatch) } @@ -40,7 +40,7 @@ func sendPendingPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb func sendPendingPatchsets(pb *forgepb.Sets, reqPB *httppb.HttpRequest) *forgepb.Sets { allPatchsetsPB := new(forgepb.Sets) - for pset := range me.forge.Patchsets.IterAll() { + for pset := range me.Patchsets.IterAll() { allPatchsetsPB.Append(pset) } return allPatchsetsPB diff --git a/http.go b/http.go index 128de8b..e965061 100644 --- a/http.go +++ b/http.go @@ -77,8 +77,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) { result := new(forgepb.Set) switch route { case "/set/new": - me.forge.Patchsets.Append(pb) - reqPB.Logf("addNewPatches() pb.Patches.Len()=%d Patchsets.Len()=%d", pb.Patches.Len(), me.forge.Patchsets.Len()) + me.Patchsets.Append(pb) + reqPB.Logf("addNewPatches() pb.Patches.Len()=%d Patchsets.Len()=%d", pb.Patches.Len(), me.Patchsets.Len()) me.forge.SavePatchsets() result.Uuid = pb.Uuid default: @@ -101,7 +101,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) { reqPB.Logf("Patches Unmarshal() len=%d", pb.Len()) switch route { case "/sets/get": - if err := me.forge.Patchsets.SendReply(w, reqPB); err != nil { + if err := me.Patchsets.SendReply(w, reqPB); err != nil { reqPB.Logf("Oh well, Send to client failed. err=%v", err) } else { reqPB.Logf("SendReply() worked") diff --git a/main.go b/main.go index 4a4e39c..fffa906 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "path/filepath" "time" + "go.wit.com/lib/ENV" "go.wit.com/lib/protobuf/argvpb" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/gitpb" @@ -21,7 +22,7 @@ var resources embed.FS var HOSTNAME string = "forge.wit.com" func saveMissing() error { - err := me.missing.SaveValidate(filepath.Join(me.forge.Config.ReposDir, "missing.pb")) + err := me.missing.SaveValidate(filepath.Join(ENV.Get("ReposDir"), "missing.pb")) if err != nil { log.Info("failed to save missing.pb", err) } @@ -32,8 +33,12 @@ func main() { me = new(mainType) me.argv = argvpb.Autocomplete(&argv) // adds shell auto complete to go-args - me.forge = forgepb.InitByFullpath("/etc/forged/forge.text") - me.forge.Config.DumpENV() + var err error + me.forge, err = forgepb.InitByFullpath("/etc/forged/forge.text") + if err != nil { + panic("forge.InitByFullPath() failed") + } + ENV.PrintTable() if err := me.forge.InitPatchsets(); err != nil { log.Info("patches failed to open", err) @@ -48,7 +53,7 @@ func main() { } me.missing = gitpb.NewRepos() - err := me.missing.ConfigLoad(filepath.Join(me.forge.Config.ReposDir, "missing.pb")) + err = me.missing.ConfigLoad(filepath.Join(ENV.Get("ReposDir"), "missing.pb")) if errors.Is(err, os.ErrNotExist) { saveMissing() } else if err != nil { diff --git a/structs.go b/structs.go index f6a09ea..8de8f18 100644 --- a/structs.go +++ b/structs.go @@ -15,10 +15,11 @@ var me *mainType // this app's variables type mainType struct { - argv *argvpb.Argv // more experiments for bash handling - pp *arg.Parser // for parsing the command line args. Yay to alexf lint! - myGui *fhelp.GuiPrep // for initializing the GUI toolkits - forge *forgepb.Forge // your customized repo preferences and settings - configs *forgepb.ForgeConfigs // for holding the forge protobuf files - missing *gitpb.Repos // repos we are missing + argv *argvpb.Argv // more experiments for bash handling + pp *arg.Parser // for parsing the command line args. Yay to alexf lint! + myGui *fhelp.GuiPrep // for initializing the GUI toolkits + forge *forgepb.Forge // your customized repo preferences and settings + configs *forgepb.ForgeConfigs // for holding the forge protobuf files + Patchsets *forgepb.Sets // for holding the forge protobuf files + missing *gitpb.Repos // repos we are missing } -- cgit v1.2.3