summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doPatchsets.go39
-rw-r--r--http.go12
2 files changed, 33 insertions, 18 deletions
diff --git a/doPatchsets.go b/doPatchsets.go
index 7a22c0a..a3630d8 100644
--- a/doPatchsets.go
+++ b/doPatchsets.go
@@ -11,6 +11,7 @@ import (
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
+ "google.golang.org/protobuf/proto"
)
func doSendPatchsets(w http.ResponseWriter) {
@@ -135,23 +136,17 @@ func listPatchsets(w http.ResponseWriter) {
}
}
-func savePatchset(w http.ResponseWriter, msg []byte) {
- log.Info("proto.Unmarshal() try message len", len(msg))
+func savePatchset(w http.ResponseWriter, msg []byte) error {
+ // log.Info("proto.Unmarshal() try message len", len(msg))
var m *forgepb.Patchset
m = new(forgepb.Patchset)
if err := m.Unmarshal(msg); err != nil {
log.Info("proto.Unmarshal() failed on wire message len", len(msg))
log.Info("error =", err)
- return
+ return err
}
log.Info("GOT patchset:", len(msg))
- fmt.Fprintln(w, "GOT patchset:", len(msg))
- all := m.Patches.SortByFilename()
- for all.Scan() {
- repo := all.Next()
- log.Info("filename:", repo.Filename)
- fmt.Fprintln(w, "filename:", repo.Filename)
- }
+ // fmt.Fprintln(w, "GOT patchset:", len(msg))
now := time.Now()
// timestamp := now.Format("2022.07.18.190545") // 50yr shout out to K&R
timestamp := now.Format("2006.01.02.150405") // bummer. other date doesn't work?
@@ -159,11 +154,31 @@ func savePatchset(w http.ResponseWriter, msg []byte) {
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
+ // fmt.Fprintln(w, "filename open error:", filename, err)
+ return err
}
regfile.Write(msg)
regfile.Close()
+
+ response := forgepb.NewPatches() // this sets the proper handshake protobuf UUID
+ all := m.Patches.SortByFilename()
+ for all.Scan() {
+ p := all.Next()
+ log.Info("filename:", p.Filename)
+ var newp *forgepb.Patch
+ newp = p
+ newp = proto.Clone(p).(*forgepb.Patch)
+ // fmt.Fprintln(w, "filename:", repo.Filename)
+ response.Append(newp)
+ }
+ data, err := response.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))
+ w.Write(data)
+ return nil
}
func lookupRepos(msg []byte) (*gitpb.Repos, error) {
diff --git a/http.go b/http.go
index 93664f6..c9abaf7 100644
--- a/http.go
+++ b/http.go
@@ -21,13 +21,11 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
log.Info("ioutil.ReadAll() error =", err)
return
}
- // fmt.Fprintln(w, "ioutil.ReadAll() msg =", len(msg))
- // dumpClient(accessf, clientf, r)
+
var route string
- // tmp = r.URL.String()
route = cleanURL(r.URL.Path)
parts := strings.Split(route, "?")
- log.Info("client sent url =", route, parts)
+ // log.Info("client sent url =", route, parts)
requrl := parts[0]
if route == "/" {
@@ -47,7 +45,9 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
log.Warn("forged REQUEST URL =", requrl, "msg =", len(msg))
if route == "/patchset" {
- savePatchset(w, msg)
+ if err := savePatchset(w, msg); err != nil {
+ log.Warn("forged /patchset error", err)
+ }
return
}
@@ -124,7 +124,7 @@ func writeFile(w http.ResponseWriter, filename string) {
var repohtml string
repohtml = string(pfile)
fmt.Fprintln(w, repohtml)
- log.Println("writeFile() found internal file:", filename)
+ // log.Println("writeFile() found internal file:", filename)
}
func badurl(w http.ResponseWriter, badurl string) {