cluster: introduce Cluster.WriteStringFile()
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package cluster
|
package cluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@@ -64,6 +65,19 @@ func (m *Cluster) ReadFile(name string, args ...any) ([]byte, error) {
|
|||||||
return fs.ReadFile(m.dir, name)
|
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
|
||||||
|
}
|
||||||
|
|
||||||
// MkdirAll creates directories relative to the cluster's config directory
|
// MkdirAll creates directories relative to the cluster's config directory
|
||||||
func (m *Cluster) MkdirAll(name string, args ...any) error {
|
func (m *Cluster) MkdirAll(name string, args ...any) error {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package cluster
|
package cluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@@ -56,15 +55,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
|
// 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 {
|
func (m *Machine) WriteStringFile(value string, name string, args ...any) error {
|
||||||
f, err := m.CreateTruncFile(name, args...)
|
fullName := m.getFilename(name, args...)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
buf := bytes.NewBufferString(value)
|
return m.zone.zones.WriteStringFile(value, fullName)
|
||||||
_, err = buf.WriteTo(f)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MkdirAll creates directories relative to the machine's config directory
|
// MkdirAll creates directories relative to the machine's config directory
|
||||||
|
|||||||
Reference in New Issue
Block a user