summaryrefslogtreecommitdiff
path: root/applyPatch.go
blob: 5c1ee12af45272e6bfd6f745ec80f3db72376840 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0

package main

import (
	"os"
	"path/filepath"

	"go.wit.com/lib/protobuf/forgepb"
	"go.wit.com/log"
)

func applyPatches(pset *forgepb.Patchs) error {
	// log.Info("got to applyPatches() pset", pset)
	log.Info("got to applyPatches() name", pset.Name)
	log.Info("got to applyPatches() comment", pset.Comment)
	all := pset.SortByFilename()
	for all.Scan() {
		p := all.Next()
		// log.Info("pset filename FILENAME IS REAL?", p.Filename, pset.Name, pset.Comment)
		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)
		raw.Write(p.Data)
		raw.Close()
	}
	log.Info("THIS IS THE END MY FRIEND")
	return nil
}

func readPatchFile(pbfile string) (*forgepb.Patchs, error) {
	bytes, err := os.ReadFile(pbfile)
	if err != nil {
		log.Info("readfile error", pbfile, err)
		return nil, err
	}
	return handleBytes(bytes)
}

func handleBytes(bytes []byte) (*forgepb.Patchs, error) {
	var pset *forgepb.Patchs
	pset = new(forgepb.Patchs)
	err := pset.Unmarshal(bytes)
	if err != nil {
		log.Info("Unmarshal failed", err)
		return nil, err
	}
	return pset, nil
}

func doit(bytes []byte) error {
	pset, err := handleBytes(bytes)
	if err != nil {
		return err
	}
	return applyPatches(pset)
}