You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package zones
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/fs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (m *Zones) scan() error {
|
|
|
|
// each directory is a zone
|
|
|
|
entries, err := fs.ReadDir(m.dir, ".")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, e := range entries {
|
|
|
|
if e.IsDir() {
|
|
|
|
z := &Zone{
|
|
|
|
zones: m,
|
|
|
|
Name: e.Name(),
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := z.scan(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
m.Zones = append(m.Zones, z)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (z *Zone) scan() error {
|
|
|
|
// each directory is a machine
|
|
|
|
entries, err := fs.ReadDir(z.zones.dir, z.Name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, e := range entries {
|
|
|
|
if e.IsDir() {
|
|
|
|
m := &Machine{
|
|
|
|
zone: z,
|
|
|
|
Name: e.Name(),
|
|
|
|
}
|
|
|
|
|
|
|
|
z.Machines = append(z.Machines, m)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return z.scanMachines()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (z *Zone) scanMachines() error {
|
|
|
|
var err error
|
|
|
|
z.zones.ForEachMachine(func(m *Machine) {
|
|
|
|
if err == nil {
|
|
|
|
err = m.scan()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
}
|