diff options
author | Kristoffer <kristoffer@walkbase.com> | 2024-01-20 13:11:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-20 13:11:50 +0100 |
commit | 7f7d84b10ffbfbb699c0d95c17e94ce9a610ac44 (patch) | |
tree | 5f2163162fb0859aaf570a5082eaf10bcf7efde1 | |
parent | build(deps): bump actions/upload-artifact from 3 to 4 (#2133) (diff) | |
download | forgejo-act-7f7d84b10ffbfbb699c0d95c17e94ce9a610ac44.tar.xz forgejo-act-7f7d84b10ffbfbb699c0d95c17e94ce9a610ac44.zip |
fix: match cache `restore-keys` in creation reverse order (#2153)
* Match cache restore-keys in creation reverse order
* Match full prefix when selecting cache
---------
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
-rw-r--r-- | pkg/artifactcache/handler.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/pkg/artifactcache/handler.go b/pkg/artifactcache/handler.go index b6600b6..3178260 100644 --- a/pkg/artifactcache/handler.go +++ b/pkg/artifactcache/handler.go @@ -9,6 +9,7 @@ import ( "net/http" "os" "path/filepath" + "regexp" "strconv" "strings" "sync/atomic" @@ -386,7 +387,12 @@ func (h *Handler) findCache(db *bolthold.Store, keys []string, version string) ( for _, prefix := range keys[1:] { found := false - if err := db.ForEach(bolthold.Where("Key").Ge(prefix).And("Version").Eq(version).SortBy("Key"), func(v *Cache) error { + prefixPattern := fmt.Sprintf("^%s", regexp.QuoteMeta(prefix)) + re, err := regexp.Compile(prefixPattern) + if err != nil { + continue + } + if err := db.ForEach(bolthold.Where("Key").RegExp(re).And("Version").Eq(version).SortBy("CreatedAt").Reverse(), func(v *Cache) error { if !strings.HasPrefix(v.Key, prefix) { return stop } |