Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion grype/db/v6/installation/curator.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func isRehydrationNeeded(fs afero.Fs, dirPath string, currentDBVersion *schemave
return false, fmt.Errorf("unable to parse client version from import metadata: %w", err)
}

hydratedWithOldClient := clientHydrationVersion.LessThan(*currentDBVersion)
hydratedWithOldClient := clientHydrationVersion.LessThanOrEqualTo(*currentDBVersion)
haveNewerClient := clientHydrationVersion.LessThan(currentClientVersion)
doRehydrate := hydratedWithOldClient && haveNewerClient

Expand Down
10 changes: 10 additions & 0 deletions grype/db/v6/installation/curator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,16 @@ func Test_isRehydrationNeeded(t *testing.T) {
currentClientVer: schemaver.New(6, 2, 0),
expectedResult: false,
},
{
// there are cases where new features will result in new columns, thus an old client downloading and hydrating
// a DB should function, however, when the new client is downloaded it should trigger at least a rehydration
// of the existing DB (in cases where the new DB is not availabl for download yet).
name: "rehydration needed - we have a new client version, with an old DB version",
currentDBVersion: schemaver.New(6, 0, 2),
hydrationClientVer: schemaver.New(6, 0, 2),
currentClientVer: schemaver.New(6, 0, 3),
expectedResult: true,
},
}

for _, tt := range tests {
Expand Down
22 changes: 21 additions & 1 deletion internal/schemaver/schema_ver.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ func (s SchemaVer) LessThan(other SchemaVer) bool {
return s.Addition < other.Addition
}

func (s SchemaVer) LessThanOrEqualTo(other SchemaVer) bool {
return s.LessThan(other) || s.Equal(other)
}

func (s SchemaVer) Equal(other SchemaVer) bool {
return s.Model == other.Model && s.Revision == other.Revision && s.Addition == other.Addition
}

func (s SchemaVer) GreaterThan(other SchemaVer) bool {
if s.Model != other.Model {
return s.Model > other.Model
}

if s.Revision != other.Revision {
return s.Revision > other.Revision
}

return s.Addition > other.Addition
}

func (s SchemaVer) GreaterOrEqualTo(other SchemaVer) bool {
return !s.LessThan(other)
return s.GreaterThan(other) || s.Equal(other)
}
Loading
Loading