Compare commits

..

1 Commits

Author SHA1 Message Date
amery d036abd816 jpictl: create machine directories on jpictl write
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-10-28 20:42:16 +00:00
3 changed files with 17 additions and 21 deletions
-9
View File
@@ -48,12 +48,3 @@ func (m *Cluster) ReadFile(name string, args ...any) ([]byte, error) {
return fs.ReadFile(m.dir, name)
}
// MkdirAll creates directories relative to the cluster's config directory
func (m *Cluster) MkdirAll(name string, args ...any) error {
if len(args) > 0 {
name = fmt.Sprintf(name, args...)
}
return fs.MkdirAll(m.dir, name, 0755)
}
+8 -7
View File
@@ -76,13 +76,6 @@ func (m *Machine) WriteStringFile(value string, name string, args ...any) error
return err
}
// MkdirAll creates directories relative to the machine's config directory
func (m *Machine) MkdirAll(name string, args ...any) error {
fullName := m.getFilename(name, args...)
return m.zone.zones.MkdirAll(fullName)
}
func (m *Machine) getFilename(name string, args ...any) string {
if len(args) > 0 {
name = fmt.Sprintf(name, args...)
@@ -96,3 +89,11 @@ func (m *Machine) getFilename(name string, args ...any) string {
return filepath.Join(s...)
}
// MkdirAll creates the directory representing this [Machine]
func (m *Machine) MkdirAll() error {
base := m.zone.zones.dir
fullName := m.getFilename(".")
return fs.MkdirAll(base, fullName, 0755)
}
+9 -5
View File
@@ -1,9 +1,13 @@
package cluster
import (
"github.com/hack-pad/hackpadfs"
)
// SyncAll updates all config files
func (m *Cluster) SyncAll() error {
for _, fn := range []func() error{
m.SyncMkdirAll,
m.MkdirAll,
m.SyncAllWireguard,
m.SyncAllCeph,
m.WriteHosts,
@@ -16,13 +20,13 @@ func (m *Cluster) SyncAll() error {
return nil
}
// SyncMkdirAll creates the directories needed to store files
// MkdirAll creates the directories needed to store files
// required to represent the cluster.
func (m *Cluster) SyncMkdirAll() error {
err := m.MkdirAll(".")
func (m *Cluster) MkdirAll() error {
err := hackpadfs.MkdirAll(m.dir, ".", 0755)
if err == nil {
m.ForEachMachine(func(p *Machine) bool {
err = p.MkdirAll(".")
err = p.MkdirAll()
return err != nil
})
}