osrelease-detector: avoid colliding with other detectors
Due to the detector registration and fact that their in a non-ordered map, it is random whether the osrelease or redhatrelease detector would hit. And likely resulted in alternately formatted namespace strings. This change causes the osrelease to not detect when data has centos-release or redhat-release, which is not _great_ because if the redhatrelease detector is not compiled in, then that would not be a fallback that the osrelease detector could rely on. :-\ Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
c28d2b3a66
commit
d88f797821
@ -24,6 +24,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
//log = capnslog.NewPackageLogger("github.com/coreos/clair", "worker/detectors/namespace/osrelease")
|
||||
|
||||
osReleaseOSRegexp = regexp.MustCompile(`^ID=(.*)`)
|
||||
osReleaseVersionRegexp = regexp.MustCompile(`^VERSION_ID=(.*)`)
|
||||
)
|
||||
@ -42,6 +44,12 @@ func init() {
|
||||
func (detector *OsReleaseNamespaceDetector) Detect(data map[string][]byte) *database.Namespace {
|
||||
var OS, version string
|
||||
|
||||
for _, filePath := range detector.getExcludeFiles() {
|
||||
if _, hasFile := data[filePath]; hasFile {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
for _, filePath := range detector.GetRequiredFiles() {
|
||||
f, hasFile := data[filePath]
|
||||
if !hasFile {
|
||||
@ -74,3 +82,8 @@ func (detector *OsReleaseNamespaceDetector) Detect(data map[string][]byte) *data
|
||||
func (detector *OsReleaseNamespaceDetector) GetRequiredFiles() []string {
|
||||
return []string{"etc/os-release", "usr/lib/os-release"}
|
||||
}
|
||||
|
||||
// getExcludeFiles returns the list of files that are ought to exclude this detector from Detect()
|
||||
func (detector *OsReleaseNamespaceDetector) getExcludeFiles() []string {
|
||||
return []string{"etc/redhat-release", "usr/lib/centos-release"}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user