config file save starting to work
This commit is contained in:
parent
c193af11e7
commit
7a547a203d
|
@ -6,28 +6,9 @@ import (
|
|||
|
||||
"go.wit.com/lib/protobuf/forgepb"
|
||||
"go.wit.com/log"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func savePatchsets() error {
|
||||
filename := filepath.Join(LIBDIR, "all-patches.pb")
|
||||
regfile, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
if err != nil {
|
||||
log.Info("filename open error:", filename, err)
|
||||
// fmt.Fprintln(w, "filename open error:", filename, err)
|
||||
return err
|
||||
}
|
||||
defer regfile.Close()
|
||||
|
||||
data, err := me.all.Marshal()
|
||||
if err != nil {
|
||||
log.Infof("savePatchset() proto.Marshal() error %v\n", err)
|
||||
return err
|
||||
}
|
||||
log.Infof("savePatchset() proto.Unmarshal() try to send len(msg)=%d back to the client forge\n", len(data))
|
||||
regfile.Write(data)
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadConfigfile() error {
|
||||
me.all = forgepb.NewPatchsets()
|
||||
|
||||
|
@ -40,9 +21,38 @@ func loadConfigfile() error {
|
|||
|
||||
err = me.all.Unmarshal(data)
|
||||
if err != nil {
|
||||
log.Infof("loadConfigfile() savePatchset() proto.Marshal() error %v\n", err)
|
||||
log.Infof("loadConfigfile() proto.Marshal() error %v\n", err)
|
||||
return err
|
||||
}
|
||||
log.Infof("loadConfigfile() worked ok %d\n", me.all.Len())
|
||||
return nil
|
||||
}
|
||||
|
||||
func savePatchsets() error {
|
||||
filename := filepath.Join(LIBDIR, "all-patches.pb")
|
||||
regfile, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
if err != nil {
|
||||
log.Info("filename open error:", filename, err)
|
||||
// fmt.Fprintln(w, "filename open error:", filename, err)
|
||||
return err
|
||||
}
|
||||
defer regfile.Close()
|
||||
|
||||
log.Info("GOT HERE")
|
||||
newpb := proto.Clone(me.all).(*forgepb.Patchsets)
|
||||
if newpb == nil {
|
||||
for pset := range me.all.IterAll() {
|
||||
showPatchsets(pset)
|
||||
}
|
||||
return log.Errorf("Clone failed!")
|
||||
}
|
||||
|
||||
data, err := newpb.Marshal()
|
||||
if err != nil {
|
||||
log.Infof("savePatchset() proto.Marshal() error %v\n", err)
|
||||
return err
|
||||
}
|
||||
log.Infof("savePatchset() worked (%d) bytes\n", len(data))
|
||||
regfile.Write(data)
|
||||
return nil
|
||||
}
|
||||
|
|
99
doList.go
99
doList.go
|
@ -10,28 +10,10 @@ import (
|
|||
func doList() error {
|
||||
log.Info("do list here")
|
||||
|
||||
me.all = forgepb.NewPatchsets()
|
||||
if err := loadConfigfile(); err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
|
||||
/*
|
||||
err := filepath.WalkDir("/var/lib/forged/patchset", func(path string, d os.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
// Handle possible errors, like permission issues
|
||||
fmt.Fprintf(os.Stderr, "error accessing path %q: %v\n", path, err)
|
||||
return err
|
||||
}
|
||||
|
||||
if d.IsDir() {
|
||||
// log.Info("path is dir", path)
|
||||
return nil
|
||||
} else {
|
||||
_, fname := filepath.Split(path)
|
||||
log.Info("found", fname, path)
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
*/
|
||||
for pset := range me.all.IterAll() {
|
||||
showPatchsets(pset)
|
||||
}
|
||||
|
@ -57,49 +39,6 @@ func showPatchsets(pb *forgepb.Patchset) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
// adds submitted patches not specifically assigned to a patchset
|
||||
// to the generic patchset called "forge auto commit"
|
||||
func addRandomPatch(patch *forgepb.Patch) {
|
||||
for pset := range me.all.IterAll() {
|
||||
if pset.Name == "forge auto commit" {
|
||||
newpb := proto.Clone(patch).(*forgepb.Patch)
|
||||
if newpb != nil {
|
||||
pset.Patches.Append(newpb)
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Warn("patchset.Name == 'forge auto commit' could not be found so the patch in", patch.Namespace, "could not be added")
|
||||
}
|
||||
|
||||
func addPatchset(filename string, pb *forgepb.Patchset) {
|
||||
if pb.Name == "forge auto commit" {
|
||||
author := "Author: " + pb.GitAuthorName
|
||||
author += " <" + pb.GitAuthorEmail + ">"
|
||||
|
||||
// author := "Author: " + os.Getenv("GIT_AUTHOR_NAME")
|
||||
// author += " <" + os.Getenv("GIT_AUTHOR_EMAIL") + ">"
|
||||
fmt.Println(filename, pb.Name, pb.Comment, author)
|
||||
for _, patch := range pb.Patches.Patches {
|
||||
// log.Info("\tnew patch:", i, patch.CommitHash, patch.Namespace)
|
||||
if findPatch(patch) {
|
||||
// log.Info("\talready found!!!!!!!", pset.Uuid, patch.Namespace)
|
||||
} else {
|
||||
log.Info("\tnew patch:", filename, pb.Name, pb.Comment, author)
|
||||
}
|
||||
}
|
||||
// add each of the patches to the general pool
|
||||
} else {
|
||||
// Clone() this protobuf into me.all
|
||||
var newpb *forgepb.Patchset
|
||||
newpb = proto.Clone(pb).(*forgepb.Patchset)
|
||||
if newpb != nil {
|
||||
me.all.Append(newpb)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// returns true if the patch already exists in the protobuf
|
||||
func findPatch(newpatch *forgepb.Patch) bool {
|
||||
// log.Info("\tlook for patch:", newpatch.CommitHash, newpatch.Namespace)
|
||||
|
@ -116,35 +55,3 @@ func findPatch(newpatch *forgepb.Patch) bool {
|
|||
|
||||
return false
|
||||
}
|
||||
|
||||
/*
|
||||
func mergePatchsets() {
|
||||
dirname := filepath.Join(LIBDIR, "patchset/")
|
||||
// Open the directory
|
||||
entries, err := os.ReadDir(dirname)
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading directory: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Iterate through the directory entries
|
||||
for _, entry := range entries {
|
||||
// Check if the entry is a file and matches the *.pb pattern
|
||||
if !entry.IsDir() && filepath.Ext(entry.Name()) == ".pb" {
|
||||
bytes, err := os.ReadFile(filepath.Join(dirname, entry.Name()))
|
||||
if err != nil {
|
||||
fmt.Println(entry.Name(), err)
|
||||
continue
|
||||
}
|
||||
var p *forgepb.Patchset
|
||||
p = new(forgepb.Patchset)
|
||||
err = p.Unmarshal(bytes)
|
||||
if err != nil {
|
||||
fmt.Println(entry.Name(), err)
|
||||
continue
|
||||
}
|
||||
addPatchset(entry.Name(), p)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -12,14 +12,17 @@ import (
|
|||
|
||||
func doMerge() error {
|
||||
if err := loadConfigfile(); err != nil {
|
||||
badExit(err)
|
||||
return err
|
||||
}
|
||||
|
||||
mergePatchsets()
|
||||
for pset := range me.all.IterAll() {
|
||||
showPatchsets(pset)
|
||||
}
|
||||
// savePatchsets()
|
||||
if err := savePatchsets(); err != nil {
|
||||
log.Warn("savePatchsets() failed", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -59,7 +62,7 @@ func addPatchset(filename string, pb *forgepb.Patchset) {
|
|||
var newpb *forgepb.Patchset
|
||||
newpb = proto.Clone(pb).(*forgepb.Patchset)
|
||||
if newpb != nil {
|
||||
me.all.Append(newpb)
|
||||
me.all.Patchsets = append(me.all.Patchsets, newpb)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue