From 86075eb47f97f228c002dfdf212767cb56d6bf96 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Wed, 23 Aug 2023 18:12:06 +0000 Subject: [PATCH] zones: move Machine.ReadFile to a dedicated machine_file.go Signed-off-by: Alejandro Mery --- pkg/zones/machine.go | 25 ------------------------- pkg/zones/machine_file.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 pkg/zones/machine_file.go diff --git a/pkg/zones/machine.go b/pkg/zones/machine.go index 8d04a0e..f9ceefe 100644 --- a/pkg/zones/machine.go +++ b/pkg/zones/machine.go @@ -1,10 +1,7 @@ package zones import ( - "fmt" - "io/fs" "net/netip" - "path/filepath" "strings" ) @@ -36,28 +33,6 @@ func (m *Machine) FullName() string { return m.Name } -// 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 - fullName := m.getFilename(name, args...) - - return fs.ReadFile(base, fullName) -} - -func (m *Machine) getFilename(name string, args ...any) string { - if len(args) > 0 { - name = fmt.Sprintf(name, args...) - } - - s := []string{ - m.zone.Name, - m.Name, - name, - } - - return filepath.Join(s...) -} - // IsGateway tells if the Machine is a ring0 gateway func (m *Machine) IsGateway() bool { _, ok := m.getRingInfo(0) diff --git a/pkg/zones/machine_file.go b/pkg/zones/machine_file.go new file mode 100644 index 0000000..44a6ad6 --- /dev/null +++ b/pkg/zones/machine_file.go @@ -0,0 +1,29 @@ +package zones + +import ( + "fmt" + "io/fs" + "path/filepath" +) + +// 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 + fullName := m.getFilename(name, args...) + + return fs.ReadFile(base, fullName) +} + +func (m *Machine) getFilename(name string, args ...any) string { + if len(args) > 0 { + name = fmt.Sprintf(name, args...) + } + + s := []string{ + m.zone.Name, + m.Name, + name, + } + + return filepath.Join(s...) +}