Skip to content

Commit

Permalink
repository: Normalize handling of nil values in Hash
Browse files Browse the repository at this point in the history
This removes nil boolean values from Hash calculation.
  • Loading branch information
ezr-ondrej authored and ondrejbudai committed Dec 13, 2023
1 parent 9462de0 commit 20808e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
34 changes: 17 additions & 17 deletions pkg/dnfjson/dnfjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ func TestMakeDepsolveRequest(t *testing.T) {
ID: baseOS.Hash(),
Name: "baseos",
BaseURLs: []string{"https://example.org/baseos"},
repoHash: "fdc2e5bb6cda8e113308df9396a005b81a55ec00ec29aa0a447952ad4248d803",
repoHash: "f177f580cf201f52d1c62968d5b85cddae3e06cb9d5058987c07de1dbd769d4b",
},
{
ID: appstream.Hash(),
Name: "appstream",
BaseURLs: []string{"https://example.org/appstream"},
repoHash: "71c280f63a779a8bf53961ec2f15d51d052021de024a4e06ae499b8029701808",
repoHash: "5c4a57bbb1b6a1886291819f2ceb25eb7c92e80065bc986a75c5837cf3d55a1f",
},
},
},
Expand Down Expand Up @@ -163,19 +163,19 @@ func TestMakeDepsolveRequest(t *testing.T) {
ID: baseOS.Hash(),
Name: "baseos",
BaseURLs: []string{"https://example.org/baseos"},
repoHash: "fdc2e5bb6cda8e113308df9396a005b81a55ec00ec29aa0a447952ad4248d803",
repoHash: "f177f580cf201f52d1c62968d5b85cddae3e06cb9d5058987c07de1dbd769d4b",
},
{
ID: appstream.Hash(),
Name: "appstream",
BaseURLs: []string{"https://example.org/appstream"},
repoHash: "71c280f63a779a8bf53961ec2f15d51d052021de024a4e06ae499b8029701808",
repoHash: "5c4a57bbb1b6a1886291819f2ceb25eb7c92e80065bc986a75c5837cf3d55a1f",
},
{
ID: userRepo.Hash(),
Name: "user-repo",
BaseURLs: []string{"https://example.org/user-repo"},
repoHash: "ffbdcbe6fefded88354e22cc292a62f1dac41b23f83c5eb95c1cdae84257a713",
repoHash: "1d3b23c311a5597ae217a0023eab3a401e7ba569066a0b91ffdcae04795af184",
},
},
},
Expand Down Expand Up @@ -210,13 +210,13 @@ func TestMakeDepsolveRequest(t *testing.T) {
ID: baseOS.Hash(),
Name: "baseos",
BaseURLs: []string{"https://example.org/baseos"},
repoHash: "fdc2e5bb6cda8e113308df9396a005b81a55ec00ec29aa0a447952ad4248d803",
repoHash: "f177f580cf201f52d1c62968d5b85cddae3e06cb9d5058987c07de1dbd769d4b",
},
{
ID: appstream.Hash(),
Name: "appstream",
BaseURLs: []string{"https://example.org/appstream"},
repoHash: "71c280f63a779a8bf53961ec2f15d51d052021de024a4e06ae499b8029701808",
repoHash: "5c4a57bbb1b6a1886291819f2ceb25eb7c92e80065bc986a75c5837cf3d55a1f",
},
},
},
Expand Down Expand Up @@ -259,19 +259,19 @@ func TestMakeDepsolveRequest(t *testing.T) {
ID: baseOS.Hash(),
Name: "baseos",
BaseURLs: []string{"https://example.org/baseos"},
repoHash: "fdc2e5bb6cda8e113308df9396a005b81a55ec00ec29aa0a447952ad4248d803",
repoHash: "f177f580cf201f52d1c62968d5b85cddae3e06cb9d5058987c07de1dbd769d4b",
},
{
ID: appstream.Hash(),
Name: "appstream",
BaseURLs: []string{"https://example.org/appstream"},
repoHash: "71c280f63a779a8bf53961ec2f15d51d052021de024a4e06ae499b8029701808",
repoHash: "5c4a57bbb1b6a1886291819f2ceb25eb7c92e80065bc986a75c5837cf3d55a1f",
},
{
ID: userRepo.Hash(),
Name: "user-repo",
BaseURLs: []string{"https://example.org/user-repo"},
repoHash: "ffbdcbe6fefded88354e22cc292a62f1dac41b23f83c5eb95c1cdae84257a713",
repoHash: "1d3b23c311a5597ae217a0023eab3a401e7ba569066a0b91ffdcae04795af184",
},
},
},
Expand Down Expand Up @@ -315,25 +315,25 @@ func TestMakeDepsolveRequest(t *testing.T) {
ID: baseOS.Hash(),
Name: "baseos",
BaseURLs: []string{"https://example.org/baseos"},
repoHash: "fdc2e5bb6cda8e113308df9396a005b81a55ec00ec29aa0a447952ad4248d803",
repoHash: "f177f580cf201f52d1c62968d5b85cddae3e06cb9d5058987c07de1dbd769d4b",
},
{
ID: appstream.Hash(),
Name: "appstream",
BaseURLs: []string{"https://example.org/appstream"},
repoHash: "71c280f63a779a8bf53961ec2f15d51d052021de024a4e06ae499b8029701808",
repoHash: "5c4a57bbb1b6a1886291819f2ceb25eb7c92e80065bc986a75c5837cf3d55a1f",
},
{
ID: userRepo.Hash(),
Name: "user-repo",
BaseURLs: []string{"https://example.org/user-repo"},
repoHash: "ffbdcbe6fefded88354e22cc292a62f1dac41b23f83c5eb95c1cdae84257a713",
repoHash: "1d3b23c311a5597ae217a0023eab3a401e7ba569066a0b91ffdcae04795af184",
},
{
ID: userRepo2.Hash(),
Name: "user-repo-2",
BaseURLs: []string{"https://example.org/user-repo-2"},
repoHash: "67d1ea4f70638dbcd397c70c9a78a477f3f4ae0ac819a1f479bebfde700160c4",
repoHash: "9fca2ee4a26933d0b2f8e318b398d5e2bff53cb8c14d3c7a8c47f4429ccb4c41",
},
},
},
Expand Down Expand Up @@ -396,20 +396,20 @@ func TestMakeDepsolveRequest(t *testing.T) {
ID: baseOS.Hash(),
Name: "baseos",
BaseURLs: []string{"https://example.org/baseos"},
repoHash: "fdc2e5bb6cda8e113308df9396a005b81a55ec00ec29aa0a447952ad4248d803",
repoHash: "f177f580cf201f52d1c62968d5b85cddae3e06cb9d5058987c07de1dbd769d4b",
},
{
ID: appstream.Hash(),
Name: "appstream",
BaseURLs: []string{"https://example.org/appstream"},
repoHash: "71c280f63a779a8bf53961ec2f15d51d052021de024a4e06ae499b8029701808",
repoHash: "5c4a57bbb1b6a1886291819f2ceb25eb7c92e80065bc986a75c5837cf3d55a1f",
},
{
ID: moduleHotfixRepo.Hash(),
Name: "module-hotfixes",
BaseURLs: []string{"https://example.org/nginx"},
ModuleHotfixes: common.ToPtr(true),
repoHash: "6ab05f54094ff2a0ee86facecae3e75e4065a01cc8caffbbbeb7505c6bfac283",
repoHash: "b7d998ee8657964c17709e35ea7eaaffe4c84f9e41cc05250a1d16e8352d52e4",
},
},
},
Expand Down
7 changes: 2 additions & 5 deletions pkg/rpmmd/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,10 @@ func (r *RepoConfig) Hash() string {
return fmt.Sprintf("%T", b)
}
bpts := func(b *bool) string {
return fmt.Sprintf("%T", b)
}
bptsIgnoreNil := func(b *bool) string {
if b == nil {
return ""
}
return bts(*b)
return fmt.Sprintf("%T", b)
}
ats := func(s []string) string {
return strings.Join(s, "")
Expand All @@ -78,7 +75,7 @@ func (r *RepoConfig) Hash() string {
bpts(r.IgnoreSSL)+
r.MetadataExpire+
bts(r.RHSM)+
bptsIgnoreNil(r.ModuleHotfixes))))
bpts(r.ModuleHotfixes))))
}

type DistrosRepoConfigs map[string]map[string][]RepoConfig
Expand Down

0 comments on commit 20808e9

Please sign in to comment.