From 14b3d91191b914571bdf45765a2adf73464ec555 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Sun, 29 Oct 2023 01:04:54 +0000 Subject: [PATCH] cluster: introduce Cluster.RemoveFile() Signed-off-by: Alejandro Mery --- pkg/cluster/cluster_file.go | 15 +++++++++++++++ pkg/cluster/machine_file.go | 9 +-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pkg/cluster/cluster_file.go b/pkg/cluster/cluster_file.go index e1deb11..c4f5ac7 100644 --- a/pkg/cluster/cluster_file.go +++ b/pkg/cluster/cluster_file.go @@ -40,6 +40,21 @@ func (m *Cluster) openWriter(name string, flags int, args ...any) (io.WriteClose panic("unreachable") } +// RemoveFile deletes a file from the cluster's config directory +func (m *Cluster) RemoveFile(name string, args ...any) error { + if len(args) > 0 { + name = fmt.Sprintf(name, args...) + } + + err := fs.Remove(m.dir, name) + switch { + case os.IsNotExist(err): + return nil + default: + return err + } +} + // ReadFile reads a file from the cluster's config directory func (m *Cluster) ReadFile(name string, args ...any) ([]byte, error) { if len(args) > 0 { diff --git a/pkg/cluster/machine_file.go b/pkg/cluster/machine_file.go index 40dde3a..1b2b3ae 100644 --- a/pkg/cluster/machine_file.go +++ b/pkg/cluster/machine_file.go @@ -43,16 +43,9 @@ func (m *Machine) openWriter(name string, flags int, args ...any) (io.WriteClose // RemoveFile deletes a file from the machine's config directory func (m *Machine) RemoveFile(name string, args ...any) error { - base := m.zone.zones.dir fullName := m.getFilename(name, args...) - err := fs.Remove(base, fullName) - switch { - case os.IsNotExist(err): - return nil - default: - return err - } + return m.zone.zones.RemoveFile(fullName) } // ReadFile reads a file from the machine's config directory