From 2fd5947f1b8834387a4a3175699c88159f017340 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Sun, 29 Oct 2023 01:02:19 +0000 Subject: [PATCH] cluster: introduce Cluster.WriteStringFile() Signed-off-by: Alejandro Mery --- pkg/cluster/cluster_file.go | 14 ++++++++++++++ pkg/cluster/machine_file.go | 11 ++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pkg/cluster/cluster_file.go b/pkg/cluster/cluster_file.go index c4f5ac7..c5277be 100644 --- a/pkg/cluster/cluster_file.go +++ b/pkg/cluster/cluster_file.go @@ -1,6 +1,7 @@ package cluster import ( + "bytes" "fmt" "io" "os" @@ -63,3 +64,16 @@ func (m *Cluster) ReadFile(name string, args ...any) ([]byte, error) { return fs.ReadFile(m.dir, name) } + +// WriteStringFile writes the given content to a file on the machine's config directory +func (m *Cluster) 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 +} diff --git a/pkg/cluster/machine_file.go b/pkg/cluster/machine_file.go index 1b2b3ae..0dff58e 100644 --- a/pkg/cluster/machine_file.go +++ b/pkg/cluster/machine_file.go @@ -1,7 +1,6 @@ package cluster import ( - "bytes" "fmt" "io" "os" @@ -58,15 +57,9 @@ func (m *Machine) ReadFile(name string, args ...any) ([]byte, error) { // 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() + fullName := m.getFilename(name, args...) - buf := bytes.NewBufferString(value) - _, err = buf.WriteTo(f) - return err + return m.zone.zones.WriteStringFile(value, fullName) } func (m *Machine) getFilename(name string, args ...any) string {