Browse Source

zones: Machine.WriteStringFile()

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/1/head
Alejandro Mery 10 months ago
parent
commit
15a98c05ec
  1. 14
      pkg/zones/machine_file.go

14
pkg/zones/machine_file.go

@ -1,6 +1,7 @@
package zones
import (
"bytes"
"fmt"
"io"
"os"
@ -58,6 +59,19 @@ func (m *Machine) ReadFile(name string, args ...any) ([]byte, error) {
return fs.ReadFile(base, fullName)
}
// WriteStringFile writes the given content to a file on the machine's config directory
func (m *Machine) WriteStringFile(value string, name string, args ...any) error {
f, err := m.CreateTruncFile(name, args...)
if err != nil {
return err
}
defer f.Close()
buf := bytes.NewBufferString(value)
_, err = buf.WriteTo(f)
return err
}
func (m *Machine) getFilename(name string, args ...any) string {
if len(args) > 0 {
name = fmt.Sprintf(name, args...)

Loading…
Cancel
Save