open and save patchsets to a file
This commit is contained in:
parent
3db2e7ff6c
commit
a491579a6d
54
doPatch.go
54
doPatch.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
"go.wit.com/lib/protobuf/forgepb"
|
||||||
|
@ -16,6 +17,10 @@ func doPatch() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if argv.Patch.Get != nil {
|
||||||
|
return doPatchGet()
|
||||||
|
}
|
||||||
|
|
||||||
if argv.Patch.List != nil {
|
if argv.Patch.List != nil {
|
||||||
return doPatchList()
|
return doPatchList()
|
||||||
}
|
}
|
||||||
|
@ -45,10 +50,49 @@ func doPatchList() error {
|
||||||
dumpPatchset(pset)
|
dumpPatchset(pset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := savePatchsets(psets); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func savePatchsets(psets *forgepb.Patchsets) error {
|
||||||
|
data, err := psets.Marshal()
|
||||||
|
if err != nil {
|
||||||
|
log.Info("protobuf.Marshal() failed:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fullpath := filepath.Join(me.forge.GetGoSrc(), "patchsets.pb")
|
||||||
|
var pfile *os.File
|
||||||
|
pfile, err = os.OpenFile(fullpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("Patchsets save failed:", err, fullpath)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pfile.Write(data)
|
||||||
|
pfile.Close()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func openPatchsets() (*forgepb.Patchsets, error) {
|
||||||
|
fullpath := filepath.Join(me.forge.GetGoSrc(), "patchsets.pb")
|
||||||
|
data, err := os.ReadFile(fullpath)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("Patchsets open failed:", err, fullpath)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
psets := new(forgepb.Patchsets)
|
||||||
|
err = psets.Unmarshal(data)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("Unmarshal patchsets failed", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return psets, nil
|
||||||
|
}
|
||||||
|
|
||||||
// returns bad if patches can not be applied
|
// returns bad if patches can not be applied
|
||||||
|
// logic is not great here but it was a first pass
|
||||||
func dumpPatchset(pset *forgepb.Patchset) bool {
|
func dumpPatchset(pset *forgepb.Patchset) bool {
|
||||||
log.Info("applyPatches() NAME", pset.Name)
|
log.Info("applyPatches() NAME", pset.Name)
|
||||||
log.Info("applyPatches() COMMENT", pset.Comment)
|
log.Info("applyPatches() COMMENT", pset.Comment)
|
||||||
|
@ -100,3 +144,13 @@ func IsValidPatch(p *forgepb.Patch) bool {
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func doPatchGet() error {
|
||||||
|
psets, err := me.forge.GetPatchesets()
|
||||||
|
if err != nil {
|
||||||
|
log.Info("Get Patchsets failed", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Info("Got Patchsets ok", psets.Uuid)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue