Fix version compare failing when old version is not present

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-01-10 22:29:38 +01:00
parent 2e88a0b090
commit 994d2d2aba
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5
2 changed files with 6 additions and 1 deletions

View file

@ -26,6 +26,11 @@ const (
) )
func (c Constraint) ShouldApply(oldVersion, newVersion string) (bool, error) { func (c Constraint) ShouldApply(oldVersion, newVersion string) (bool, error) {
if oldVersion == "" && newVersion != "" {
// The old version does not exist, the new one does, update it!
return true, nil
}
comp := c.getComparer() comp := c.getComparer()
if comp == nil { if comp == nil {
return false, errors.New("invalid version type specified") return false, errors.New("invalid version type specified")

View file

@ -79,7 +79,7 @@ func checkForUpdates(ce *database.CatalogEntry) error {
cm.Error = err.Error() cm.Error = err.Error()
case compareErr != nil: case compareErr != nil:
logger.WithError(err).Error("Version compare caused error, error is stored in entry") logger.WithError(compareErr).Error("Version compare caused error, error is stored in entry")
cm.Error = compareErr.Error() cm.Error = compareErr.Error()
case cm.CurrentVersion != ver && !shouldUpdate: case cm.CurrentVersion != ver && !shouldUpdate: