posadka/primitive.go
Simon de Vlieger bea17a4077
setup: start sketching out some bits
Tiny sketch of what we'd like to do. We'll be having an entrypoint,
modifications we can apply to directory structures and some primitives
to support those modifications.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2024-10-28 11:08:27 +01:00

31 lines
412 B
Go

package posadka
import (
"bytes"
"os"
)
// Replace `a` with `b` in a given file at `path`. This function is non-atomic
// so be careful with crashing.
func ReplaceInFile(path string, a, b []byte) error {
data, err := os.ReadFile(path)
if err != nil {
return err
}
data = bytes.Replace(
data,
a,
b,
1,
)
err = os.WriteFile(path, data, 0644)
if err != nil {
return err
}
return nil
}