MCPcopy Index your code
hub / github.com/opencloud-eu/opencloud / writePatch

Function writePatch

opencloud/pkg/init/functions.go:87–117  ·  view source on GitHub ↗

writePatch writes the diff to a file

(configPath string, yamlOutput []byte)

Source from the content-addressed store, hash-verified

85
86// writePatch writes the diff to a file
87func writePatch(configPath string, yamlOutput []byte) error {
88 fmt.Println("running in diff mode")
89 tmpFile := path.Join(configPath, "opencloud.yaml.tmp")
90 err := os.WriteFile(tmpFile, yamlOutput, 0600)
91 if err != nil {
92 return err
93 }
94 fmt.Println("diff -u " + path.Join(configPath, configFilename) + " " + tmpFile)
95 cmd := exec.Command("diff", "-u", path.Join(configPath, configFilename), tmpFile)
96 stdout, err := cmd.Output()
97 if err == nil {
98 err = os.Remove(tmpFile)
99 if err != nil {
100 return err
101 }
102 fmt.Println("no changes, your config is up to date")
103 return nil
104 }
105 fmt.Println(string(stdout))
106 err = os.Remove(tmpFile)
107 if err != nil {
108 return err
109 }
110 patchPath := path.Join(configPath, "opencloud.config.patch")
111 err = os.WriteFile(patchPath, stdout, 0600)
112 if err != nil {
113 return err
114 }
115 fmt.Printf("diff written to %s\n", patchPath)
116 return nil
117}

Callers 1

CreateConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected