Skip to content

Commit 2fbc0a0

Browse files
authored
fix: nil pointer when no match for any OS (future-architect#1401)
* refactor: rename serverapi.go to scanner.go * fix: nil pointer if no match for any OS
1 parent 7d8a24e commit 2fbc0a0

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

scanner/serverapi.go scanner/scanner.go

+20-27
Original file line numberDiff line numberDiff line change
@@ -580,49 +580,42 @@ func (s Scanner) detectContainerOSesOnServer(containerHost osTypeInterface) (ose
580580
return oses
581581
}
582582

583-
func (s Scanner) detectOS(c config.ServerInfo) (osType osTypeInterface) {
584-
var itsMe bool
585-
var fatalErr error
586-
587-
if itsMe, osType, _ = detectPseudo(c); itsMe {
588-
return
583+
func (s Scanner) detectOS(c config.ServerInfo) osTypeInterface {
584+
if itsMe, osType, _ := detectPseudo(c); itsMe {
585+
return osType
589586
}
590587

591-
itsMe, osType, fatalErr = s.detectDebianWithRetry(c)
592-
if fatalErr != nil {
593-
osType.setErrs([]error{
594-
xerrors.Errorf("Failed to detect OS: %w", fatalErr)})
595-
return
588+
if itsMe, osType, fatalErr := s.detectDebianWithRetry(c); fatalErr != nil {
589+
osType.setErrs([]error{xerrors.Errorf("Failed to detect OS: %w", fatalErr)})
590+
return osType
591+
} else if itsMe {
592+
logging.Log.Debugf("Debian based Linux. Host: %s:%s", c.Host, c.Port)
593+
return osType
596594
}
597595

598-
if itsMe {
599-
logging.Log.Debugf("Debian like Linux. Host: %s:%s", c.Host, c.Port)
600-
return
596+
if itsMe, osType := detectRedhat(c); itsMe {
597+
logging.Log.Debugf("Redhat based Linux. Host: %s:%s", c.Host, c.Port)
598+
return osType
601599
}
602600

603-
if itsMe, osType = detectRedhat(c); itsMe {
604-
logging.Log.Debugf("Redhat like Linux. Host: %s:%s", c.Host, c.Port)
605-
return
606-
}
607-
608-
if itsMe, osType = detectSUSE(c); itsMe {
601+
if itsMe, osType := detectSUSE(c); itsMe {
609602
logging.Log.Debugf("SUSE Linux. Host: %s:%s", c.Host, c.Port)
610-
return
603+
return osType
611604
}
612605

613-
if itsMe, osType = detectFreebsd(c); itsMe {
606+
if itsMe, osType := detectFreebsd(c); itsMe {
614607
logging.Log.Debugf("FreeBSD. Host: %s:%s", c.Host, c.Port)
615-
return
608+
return osType
616609
}
617610

618-
if itsMe, osType = detectAlpine(c); itsMe {
611+
if itsMe, osType := detectAlpine(c); itsMe {
619612
logging.Log.Debugf("Alpine. Host: %s:%s", c.Host, c.Port)
620-
return
613+
return osType
621614
}
622615

623-
//TODO darwin https://github.com/mizzy/specinfra/blob/master/lib/specinfra/helper/detect_os/darwin.rb
616+
osType := &unknown{base{ServerInfo: c}}
624617
osType.setErrs([]error{xerrors.New("Unknown OS Type")})
625-
return
618+
return osType
626619
}
627620

628621
// Retry as it may stall on the first SSH connection
File renamed without changes.

0 commit comments

Comments
 (0)