Skip to content

Commit

Permalink
fix(fetcher/fedora): ignore errors with missing modular updateinfo (#370
Browse files Browse the repository at this point in the history
)
  • Loading branch information
MaineK00n authored Feb 20, 2024
1 parent bece3ee commit 78a8966
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/fetch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ jobs:
--health-timeout 5s
--health-retries 5
env:
Version: 32 33 34 35 36 37 38
Version: 32 33 34 35 36 37 38 39
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
Expand Down Expand Up @@ -664,7 +664,7 @@ jobs:
--health-timeout 5s
--health-retries 5
env:
Version: 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17
Version: 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
Expand Down
30 changes: 5 additions & 25 deletions fetcher/fedora/fedora.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"encoding/xml"
"errors"
"fmt"
"net/url"
"regexp"
Expand Down Expand Up @@ -42,7 +43,7 @@ func FetchUpdateInfosFedora(versions []string) (map[string]*models.Updates, erro
}

moduleResults, err := fetchModulesFedora(moduleReqs, arch)
if err != nil {
if err != nil && !errors.Is(err, errNoUpdateInfoField) {
return nil, xerrors.Errorf("fetchModulesFedora. err: %w", err)
}

Expand Down Expand Up @@ -187,6 +188,8 @@ func fetchFeedFilesFedora(reqs []util.FetchRequest) ([]util.FetchResult, error)
return results, nil
}

var errNoUpdateInfoField = xerrors.New("No updateinfo field in the repomd")

func fetchUpdateInfosFedora(results []util.FetchResult) ([]util.FetchResult, error) {
log15.Info("start fetch updateinfo in repomd.xml")
updateInfoReqs, err := extractInfoFromRepoMd(results, "updateinfo", util.MIMETypeXz)
Expand All @@ -195,7 +198,7 @@ func fetchUpdateInfosFedora(results []util.FetchResult) ([]util.FetchResult, err
}

if len(updateInfoReqs) == 0 {
return nil, xerrors.New("No updateinfo field in the repomd")
return nil, errNoUpdateInfoField
}

results, err = util.FetchFeedFiles(updateInfoReqs)
Expand Down Expand Up @@ -443,26 +446,3 @@ func newKojiPkgsRequest(arch, uinfoTitle string) (util.FetchRequest, error) {
}
return req, nil
}

// uniquePackages returns deduplicated []Package by Filename
// If Filename is the same, all other information is considered to be the same
func uniquePackages(pkgs []models.Package) []models.Package {
tmp := make(map[string]models.Package)
ret := []models.Package{}
for _, pkg := range pkgs {
tmp[pkg.Filename] = pkg
}
for _, v := range tmp {
ret = append(ret, v)
}
return ret
}

func mergeUpdates(source map[string]*models.Updates, target map[string]*models.Updates) map[string]*models.Updates {
for osVer, sourceUpdates := range source {
if targetUpdates, ok := target[osVer]; ok {
source[osVer].UpdateList = append(sourceUpdates.UpdateList, targetUpdates.UpdateList...)
}
}
return source
}
23 changes: 23 additions & 0 deletions fetcher/fedora/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,26 @@ func (r Rpm) NewPackageFromRpm() (models.Package, error) {
}
return pkg, nil
}

// uniquePackages returns deduplicated []Package by Filename
// If Filename is the same, all other information is considered to be the same
func uniquePackages(pkgs []models.Package) []models.Package {
tmp := make(map[string]models.Package)
ret := []models.Package{}
for _, pkg := range pkgs {
tmp[pkg.Filename] = pkg
}
for _, v := range tmp {
ret = append(ret, v)
}
return ret
}

func mergeUpdates(source map[string]*models.Updates, target map[string]*models.Updates) map[string]*models.Updates {
for osVer, sourceUpdates := range source {
if targetUpdates, ok := target[osVer]; ok {
source[osVer].UpdateList = append(sourceUpdates.UpdateList, targetUpdates.UpdateList...)
}
}
return source
}
22 changes: 22 additions & 0 deletions fetcher/fedora/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,28 @@ func TestUpdatesPerVersionMerge(t *testing.T) {
},
},
},
{
name: "target is nil",
source: map[string]*models.Updates{
"39": {
UpdateList: []models.UpdateInfo{
{
Title: "update39",
},
},
},
},
target: nil,
want: map[string]*models.Updates{
"39": {
UpdateList: []models.UpdateInfo{
{
Title: "update39",
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 78a8966

Please sign in to comment.