|
|
|
@ -2,6 +2,7 @@ package zones
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"io" |
|
|
|
|
"os" |
|
|
|
|
"path/filepath" |
|
|
|
|
|
|
|
|
@ -16,6 +17,25 @@ func (m *Machine) OpenFile(name string, flags int, args ...any) (fs.File, error)
|
|
|
|
|
return fs.OpenFile(base, fullName, flags, 0644) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// CreateTruncFile creates or truncates a file on the machine's config directory
|
|
|
|
|
func (m *Machine) CreateTruncFile(name string, args ...any) (io.WriteCloser, error) { |
|
|
|
|
return m.openWriter(name, os.O_CREATE|os.O_TRUNC, args...) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// CreateFile creates a file on the machine's config directory
|
|
|
|
|
func (m *Machine) CreateFile(name string, args ...any) (io.WriteCloser, error) { |
|
|
|
|
return m.openWriter(name, os.O_CREATE, args...) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Machine) openWriter(name string, flags int, args ...any) (io.WriteCloser, error) { |
|
|
|
|
f, err := m.OpenFile(name, os.O_WRONLY|flags, args...) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return f.(io.WriteCloser), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// RemoveFile deletes a file from the machine's config directory
|
|
|
|
|
func (m *Machine) RemoveFile(name string, args ...any) error { |
|
|
|
|
base := m.zone.zones.dir |
|
|
|
|