From 78110464b430d04b6167392333f288332c20e8cb Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Thu, 7 Sep 2023 15:45:34 +0000 Subject: [PATCH] zones: ignore machine-less zones Signed-off-by: Alejandro Mery --- pkg/zones/scan.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/pkg/zones/scan.go b/pkg/zones/scan.go index d13879a..069b144 100644 --- a/pkg/zones/scan.go +++ b/pkg/zones/scan.go @@ -3,6 +3,8 @@ package zones import ( "io/fs" "sort" + + "darvaza.org/core" ) func (m *Zones) scan(opts *ScanOptions) error { @@ -31,22 +33,31 @@ func (m *Zones) scanDirectory(_ *ScanOptions) error { for _, e := range entries { if e.IsDir() { - z := &Zone{ - zones: m, - Name: e.Name(), + z, err := m.newZone(e.Name()) + switch { + case err != nil: + return core.Wrap(err, e.Name()) + case z.Machines.Len() > 0: + m.Zones = append(m.Zones, z) } - - if err := z.scan(); err != nil { - return err - } - - m.Zones = append(m.Zones, z) } } return nil } +func (m *Zones) newZone(name string) (*Zone, error) { + z := &Zone{ + zones: m, + Name: name, + } + + if err := z.scan(); err != nil { + return nil, err + } + return z, nil +} + func (m *Zones) scanMachines(opts *ScanOptions) error { var err error m.ForEachMachine(func(p *Machine) bool {