diff options
| author | Jeff Carr <[email protected]> | 2025-10-22 11:08:59 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-22 11:08:59 -0500 | 
| commit | e8a7433c9588827b275cbcf7a8745f886dd59ad4 (patch) | |
| tree | 727fc242f5d5da8ea36a50a09af9324ad903aa9d | |
| parent | de85934267a150290d4ffff052027a3363f3ce10 (diff) | |
adapt to the new lib/config and lib/ENVv0.0.65
| -rw-r--r-- | config.go | 6 | ||||
| -rw-r--r-- | doPatches.go | 19 | ||||
| -rw-r--r-- | doRepos.go | 17 | ||||
| -rw-r--r-- | handlePatches.go | 4 | ||||
| -rw-r--r-- | http.go | 6 | ||||
| -rw-r--r-- | main.go | 13 | ||||
| -rw-r--r-- | structs.go | 13 | 
7 files changed, 44 insertions, 34 deletions
@@ -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 @@ -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 @@ -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") @@ -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 { @@ -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  }  | 
