Skip to content

Commit

Permalink
rhel: fix cpe mapping type assertion
Browse files Browse the repository at this point in the history
this commit makes sure a nil pointer of type *repo2cpe.MappingFile is
loaded into the atomic.Value.

type assertions of the atomic.Value should never fail after this.
Loads() of the atomic.Value before a mapping file is downloaded should
return a typed nil.

Signed-off-by: ldelossa <[email protected]>
  • Loading branch information
ldelossa authored and ldelossa committed Feb 12, 2021
1 parent def91ac commit 17a73b5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions rhel/repo2cpe/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ func NewLocalUpdaterJob(url string, client *http.Client) *LocalUpdaterJob {
if client == nil {
client = http.DefaultClient
}
return &LocalUpdaterJob{
lu := &LocalUpdaterJob{
URL: url,
Client: client,
}
lu.mapping.Store((*MappingFile)(nil))
return lu
}

// Get translates repositories into CPEs using a mapping file.
Expand All @@ -49,9 +51,10 @@ func (updater *LocalUpdaterJob) Get(ctx context.Context, repositories []string)
}

cpes := []string{}
var mapping *MappingFile = updater.mapping.Load().(*MappingFile)
// interface conversion guaranteed to pass, see
// constructor.
mapping := updater.mapping.Load().(*MappingFile)
if mapping == nil {
// mapping not set yet. not an error
return cpes, nil
}

Expand Down

0 comments on commit 17a73b5

Please sign in to comment.