diff --git a/applyPatch.go b/applyPatch.go index 0985345..a0ddbab 100644 --- a/applyPatch.go +++ b/applyPatch.go @@ -6,11 +6,17 @@ import ( "os" "path/filepath" + "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/log" ) func applyPatches(pset *forgepb.Patchs) error { + var everythingworked bool = true + tmpdir, err := os.MkdirTemp("", "forge") + if err != nil { + return err + } // log.Info("got to applyPatches() pset", pset) log.Info("applyPatches() NAME", pset.Name) log.Info("applyPatches() COMMENT", pset.Comment) @@ -23,11 +29,30 @@ func applyPatches(pset *forgepb.Patchs) error { basepath, filename := filepath.Split(p.Filename) fullpath := filepath.Join(me.forge.GetGoSrc(), basepath) log.Info("pset filename FILENAME IS REAL? fullpath", fullpath) - log.Info("pset filename FILENAME IS REAL? filename", filename) - fullname := filepath.Join(fullpath, filename) - raw, _ := os.OpenFile(fullname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + fullTmpdir := filepath.Join(tmpdir, basepath) + err := os.MkdirAll(fullTmpdir, os.ModePerm) + if err != nil { + log.Info("applyPathces() MkdirAll failed for", fullTmpdir) + log.Info("applyPathces() MkdirAll failed err", err) + everythingworked = false + continue + } + log.Info("pset filename FILENAME IS REAL? tmp fullTmpdir", fullTmpdir) + tmpname := filepath.Join(fullTmpdir, filename) + raw, _ := os.OpenFile(tmpname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) raw.Write(p.Data) raw.Close() + cmd := []string{"git", "am", tmpname} + result := shell.PathRun(fullpath, cmd) + if result.Exit != 0 { + log.Info("cmd failed", cmd, result.Exit) + everythingworked = false + } + // until 'git am' works + everythingworked = false + } + if everythingworked { + os.RemoveAll(tmpdir) // clean up } log.Info("THIS IS THE END MY FRIEND") return nil