From 18edcd67cf1c1d176d793182f6bfae33ab4206e4 Mon Sep 17 00:00:00 2001 From: Yufeng Duan <55268016+pomodorox@users.noreply.github.com> Date: Mon, 9 Oct 2023 09:49:06 -0700 Subject: [PATCH] Reconfigure the RPM URLs if checksum changed. Currently if for some reason the RPM entry changed, bazeldnf won't reconfigure the URLs if they are already set. While this behavior aims to cover cases like mirror urls getting added out of band, there is a case where the URLs are messed up and do match the checksum. Therefore with this change it reconfigures the RPM URLs when the checksum changed. Signed-off-by: Yufeng Duan <55268016+pomodorox@users.noreply.github.com> Signed-off-by: Yufeng Duan <55268016+didovesei@users.noreply.github.com> --- pkg/bazel/bazel.go | 7 +++++-- pkg/bazel/testdata/WORKSPACE | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/bazel/bazel.go b/pkg/bazel/bazel.go index ef522ff..64580e8 100644 --- a/pkg/bazel/bazel.go +++ b/pkg/bazel/bazel.go @@ -122,14 +122,17 @@ func AddWorkspaceRPMs(workspace *build.File, pkgs []*api.Package, arch string) e rpms[pkgName] = rule } rule.SetName(pkgName) - rule.SetSHA256(pkg.Checksum.Text) urls := rule.URLs() - if len(urls) == 0 { + // Configure/re-configure the URLs when + // 1) no URLs are set, or + // 2) the checksum changed. + if len(urls) == 0 || (rule.SHA256() != pkg.Checksum.Text) { err := rule.SetURLs(pkg.Repository.Mirrors, pkg.Location.Href) if err != nil { return err } } + rule.SetSHA256(pkg.Checksum.Text) } rules := []*RPMRule{} diff --git a/pkg/bazel/testdata/WORKSPACE b/pkg/bazel/testdata/WORKSPACE index 2418fa6..b0c99e8 100644 --- a/pkg/bazel/testdata/WORKSPACE +++ b/pkg/bazel/testdata/WORKSPACE @@ -11,3 +11,12 @@ rpm( name = "test.rpm", urls = ["http://something.rpm"], ) + +rpm( + name = "a-0__2.3.4.myarch", + sha256 = "0000", + urls = [ + "old/url/1", + "old/url/2", + ], +)