zones: Machine.WriteStringFile()

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-25 14:41:12 +00:00
parent a005823d44
commit 15a98c05ec
+14
View File
@@ -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...)