From e57b35fc33e59930ae526e8beb18caae19473337 Mon Sep 17 00:00:00 2001 From: MaineK00n Date: Mon, 24 Jan 2022 21:17:54 +0900 Subject: [PATCH] fix(rocky): skip when repository is extras and there is no updateinfo in repomd.xml (#132) --- rocky/rocky.go | 15 ++-- rocky/rocky_test.go | 18 ++++- .../fixtures/no_updateinfo_field/repomd.xml | 69 +++++++++++++++++++ 3 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 rocky/testdata/fixtures/no_updateinfo_field/repomd.xml diff --git a/rocky/rocky.go b/rocky/rocky.go index ab0d31e..84dbf65 100644 --- a/rocky/rocky.go +++ b/rocky/rocky.go @@ -4,6 +4,7 @@ import ( "bytes" "compress/gzip" "encoding/xml" + "errors" "fmt" "log" "net/url" @@ -163,6 +164,10 @@ func (c Config) update(release, repo, arch string) error { u.Path = path.Join(rootPath, "repodata/repomd.xml") updateInfoPath, err := c.fetchUpdateInfoPath(u.String()) if err != nil { + if errors.Is(err, ErrorNoUpdateInfoField) && repo == "extras" { + log.Printf("skip extras repository because updateinfo field is not in repomd.xml: %s", err) + return nil + } return xerrors.Errorf("failed to fetch updateInfo path from repomd.xml: %w", err) } u.Path = path.Join(rootPath, updateInfoPath) @@ -201,6 +206,8 @@ func (c Config) update(release, repo, arch string) error { return nil } +var ErrorNoUpdateInfoField = xerrors.New("no updateinfo field in the repomd") + func (c Config) fetchUpdateInfoPath(repomdURL string) (updateInfoPath string, err error) { res, err := utils.FetchURL(repomdURL, "", c.retry) if err != nil { @@ -214,14 +221,10 @@ func (c Config) fetchUpdateInfoPath(repomdURL string) (updateInfoPath string, er for _, repo := range repoMd.RepoList { if repo.Type == "updateinfo" { - updateInfoPath = repo.Location.Href - break + return repo.Location.Href, nil } } - if updateInfoPath == "" { - return "", xerrors.New("no updateinfo field in the repomd") - } - return updateInfoPath, nil + return "", ErrorNoUpdateInfoField } func (c Config) fetchUpdateInfo(url string) (*UpdateInfo, error) { diff --git a/rocky/rocky_test.go b/rocky/rocky_test.go index 219b7a0..706d67c 100644 --- a/rocky/rocky_test.go +++ b/rocky/rocky_test.go @@ -18,23 +18,39 @@ func Test_Update(t *testing.T) { tests := []struct { name string rootDir string + repository []string expectedError error }{ { name: "happy path", rootDir: "testdata/fixtures/happy", + repository: []string{"BaseOS"}, expectedError: nil, }, { name: "bad repomd response", rootDir: "testdata/fixtures/repomd_invalid", + repository: []string{"BaseOS"}, expectedError: xerrors.Errorf("failed to update security advisories of Rocky Linux 8 BaseOS x86_64: %w", errors.New("failed to fetch updateInfo path from repomd.xml")), }, { name: "bad updateInfo response", rootDir: "testdata/fixtures/updateinfo_invalid", + repository: []string{"BaseOS"}, expectedError: xerrors.Errorf("failed to update security advisories of Rocky Linux 8 BaseOS x86_64: %w", errors.New("failed to fetch updateInfo")), }, + { + name: "no updateInfo field(BaseOS)", + rootDir: "testdata/fixtures/no_updateinfo_field", + repository: []string{"BaseOS"}, + expectedError: xerrors.Errorf("failed to update security advisories of Rocky Linux 8 BaseOS x86_64: %w", xerrors.Errorf("failed to fetch updateInfo path from repomd.xml: %w", rocky.ErrorNoUpdateInfoField)), + }, + { + name: "no updateInfo field(extras)", + rootDir: "testdata/fixtures/no_updateinfo_field", + repository: []string{"extras"}, + expectedError: nil, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -42,7 +58,7 @@ func Test_Update(t *testing.T) { defer tsUpdateInfoURL.Close() dir := t.TempDir() - rc := rocky.NewConfig(rocky.With(tsUpdateInfoURL.URL+"/pub/rocky/%s/%s/%s/os/", dir, 0, []string{"8"}, []string{"BaseOS"}, []string{"x86_64"})) + rc := rocky.NewConfig(rocky.With(tsUpdateInfoURL.URL+"/pub/rocky/%s/%s/%s/os/", dir, 0, []string{"8"}, tt.repository, []string{"x86_64"})) if err := rc.Update(); tt.expectedError != nil { require.Error(t, err) assert.Contains(t, err.Error(), tt.expectedError.Error()) diff --git a/rocky/testdata/fixtures/no_updateinfo_field/repomd.xml b/rocky/testdata/fixtures/no_updateinfo_field/repomd.xml new file mode 100644 index 0000000..8b4483c --- /dev/null +++ b/rocky/testdata/fixtures/no_updateinfo_field/repomd.xml @@ -0,0 +1,69 @@ + + + 8.4 + + Rocky Linux 8 + + + 9d25370cf8f2bdf046145fa51ef3d0229ecc6862cbe35281a70184cc39089f54 + 554780b39c8a31f3b92eb2356f38099bd6135834c51542c8ffb889aa6d37c1a0 + + 1632166291 + 4136440 + 29944727 + + + 3f9875964fcb58abd0c3b88ae317450d124020d81e873f1db05c695e84fc1c3b + 483a4f0494e31ae0d100714ddae8eab680c408ff354979636d7bec849c1b6e4d + + 1632166291 + 3284862 + 45704869 + + + 201204bd642f240caaa2d8cd8b8fcf0bf0071fdf7ba67c68b79c209163995057 + ab9351e393e2f08997754411263a7b51114209668d453a62ad998981789c091d + + 1632166291 + 621783 + 6152523 + + + 2e35bd95b02d3bf3d99b82f3bbb6b0381f55b671226771d9d7db975b5d0f205b + b1af8fb023566905067e07bfcffed71ce73ebc6e4ed0af2a010ac7ea6bbfbefa + + 1632166306 + 3599636 + 34222080 + + + 06510a9c700387c4c670654f6440386d6e91e0628116492a4a38228f67ec4d61 + 19df9e2e5a6e66214ddf95569d50ce1c73cfed99c109e453b043a68b8609fd95 + + 1632166298 + 2665240 + 24879104 + + + dddb998b6aca861c3b0724e13ee6f99a74e516b659299ec47c682a08f414cf25 + 46d0a6ae8562e93c729361fa1b28ccf10d26bed3d9d2ff1e464ff807b6201688 + + 1632166293 + 423132 + 6062080 + + + 5eedac6f334681aa51e154d77025db287c33ce1491b14368be9b477ff8208152 + + 1632166276 + 297208 + + + 32e04847f7cc2872db5ac9e92ea540ef2a7999d1c2be0c8c3d47a359b3e2d613 + 5eedac6f334681aa51e154d77025db287c33ce1491b14368be9b477ff8208152 + + 1632166291 + 56668 + 297208 + + \ No newline at end of file