Don't match regexp if empty

This commit is contained in:
dmaes 2022-04-08 11:37:37 +02:00
parent f769e3e5f9
commit a939599a1c
No known key found for this signature in database
GPG Key ID: EC714BCF2F94B6A6

View File

@ -86,9 +86,13 @@ func PurgeOldTags(client *Client, purgeDryRun bool, purgeTagsKeepDays, purgeTags
// Filter out tags by retention days and regexp // Filter out tags by retention days and regexp
for _, tag := range repos[repo] { for _, tag := range repos[repo] {
regexpMatch, _ := regexp.MatchString(purgeTagsKeepRegexp, tag.name) regexpKeep := false
if purgeTagsKeepRegexp != "" {
regexpMatch, _ := regexp.MatchString(purgeTagsKeepRegexp, tag.name)
regexpKeep = regexpMatch
}
delta := int(now.Sub(tag.created).Hours() / 24) delta := int(now.Sub(tag.created).Hours() / 24)
if !regexpMatch && delta > purgeTagsKeepDays { if !regexpKeep && delta > purgeTagsKeepDays {
purgeTags[repo] = append(purgeTags[repo], tag.name) purgeTags[repo] = append(purgeTags[repo], tag.name)
} else { } else {
keepTags[repo] = append(keepTags[repo], tag.name) keepTags[repo] = append(keepTags[repo], tag.name)