From 65d5c6bc3154c708f771fcee937c406d7a767c2f Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 22 Dec 2021 12:45:32 -0800 Subject: [PATCH] fix bug causing crash in snapshot --- pkg/snapshot/snapshot.go | 3 ++- pkg/snapshot/synology.go | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/snapshot/snapshot.go b/pkg/snapshot/snapshot.go index 9f293282d..88238617b 100644 --- a/pkg/snapshot/snapshot.go +++ b/pkg/snapshot/snapshot.go @@ -9,6 +9,7 @@ import ( "bufio" "bytes" "context" + "errors" "fmt" "os/exec" "sync" @@ -157,7 +158,7 @@ func (c *Config) getSnapshot(ctx context.Context, s *Snapshot) ([]error, []error errs = append(errs, err...) } - if syn, err := GetSynology(c.Uptime); err != nil { + if syn, err := GetSynology(c.Uptime); err != nil && !errors.Is(err, ErrNotSynology) { errs = append(errs, err) } else if syn != nil { syn.SetInfo(s.System.InfoStat) diff --git a/pkg/snapshot/synology.go b/pkg/snapshot/synology.go index e3e56200f..235016e7d 100644 --- a/pkg/snapshot/synology.go +++ b/pkg/snapshot/synology.go @@ -12,6 +12,8 @@ import ( "github.com/shirou/gopsutil/v3/host" ) +var ErrNotSynology = fmt.Errorf("the running host is not a Synology") + // Synology is the data we care about from the config file. type Synology struct { Build string `json:"last_admin_login_build"` // 254263 @@ -30,7 +32,7 @@ type Synology struct { // GetSynology checks if the app is running on a Synology, and gets system info. func GetSynology(run bool) (*Synology, error) { //nolint:cyclop if !run || !mnd.IsSynology { - return &Synology{}, nil + return nil, ErrNotSynology } file, err := os.Open(mnd.Synology)