From 0f1f1ce968e215056c49e655b917abedcfee74eb Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Wed, 23 Aug 2023 19:36:26 +0000 Subject: [PATCH] zones: introduce Machine.RemoveFile() Signed-off-by: Alejandro Mery --- pkg/zones/machine_file.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/zones/machine_file.go b/pkg/zones/machine_file.go index 44a6ad6..a9f6eae 100644 --- a/pkg/zones/machine_file.go +++ b/pkg/zones/machine_file.go @@ -2,10 +2,26 @@ package zones import ( "fmt" - "io/fs" + "os" "path/filepath" + + fs "github.com/hack-pad/hackpadfs" ) +// 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 + } +} + // ReadFile reads a file from the machine's config directory func (m *Machine) ReadFile(name string, args ...any) ([]byte, error) { base := m.zone.zones.dir