Browse Source

cluster: introduce Cluster.RemoveFile()

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/36/head
Alejandro Mery 11 months ago
parent
commit
14b3d91191
  1. 15
      pkg/cluster/cluster_file.go
  2. 9
      pkg/cluster/machine_file.go

15
pkg/cluster/cluster_file.go

@ -40,6 +40,21 @@ func (m *Cluster) openWriter(name string, flags int, args ...any) (io.WriteClose
panic("unreachable") 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 // ReadFile reads a file from the cluster's config directory
func (m *Cluster) ReadFile(name string, args ...any) ([]byte, error) { func (m *Cluster) ReadFile(name string, args ...any) ([]byte, error) {
if len(args) > 0 { if len(args) > 0 {

9
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 // RemoveFile deletes a file from the machine's config directory
func (m *Machine) RemoveFile(name string, args ...any) error { func (m *Machine) RemoveFile(name string, args ...any) error {
base := m.zone.zones.dir
fullName := m.getFilename(name, args...) fullName := m.getFilename(name, args...)
err := fs.Remove(base, fullName)
switch { return m.zone.zones.RemoveFile(fullName)
case os.IsNotExist(err):
return nil
default:
return err
}
} }
// ReadFile reads a file from the machine's config directory // ReadFile reads a file from the machine's config directory

Loading…
Cancel
Save