mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #38053 from tiborvass/bk-fix-filters
builder: fix bugs when pruning buildkit cache with filters
This commit is contained in:
commit
c21c9b5fad
1 changed files with 15 additions and 9 deletions
|
@ -530,20 +530,26 @@ func toBuildkitPruneInfo(opts types.BuildCachePruneOptions) (client.PruneInfo, e
|
||||||
|
|
||||||
bkFilter := make([]string, 0, opts.Filters.Len())
|
bkFilter := make([]string, 0, opts.Filters.Len())
|
||||||
for cacheField := range cacheFields {
|
for cacheField := range cacheFields {
|
||||||
values := opts.Filters.Get(cacheField)
|
if opts.Filters.Include(cacheField) {
|
||||||
switch len(values) {
|
values := opts.Filters.Get(cacheField)
|
||||||
case 0:
|
switch len(values) {
|
||||||
bkFilter = append(bkFilter, cacheField)
|
case 0:
|
||||||
case 1:
|
bkFilter = append(bkFilter, cacheField)
|
||||||
bkFilter = append(bkFilter, cacheField+"=="+values[0])
|
case 1:
|
||||||
default:
|
if cacheField == "id" {
|
||||||
return client.PruneInfo{}, errMultipleFilterValues
|
bkFilter = append(bkFilter, cacheField+"~="+values[0])
|
||||||
|
} else {
|
||||||
|
bkFilter = append(bkFilter, cacheField+"=="+values[0])
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return client.PruneInfo{}, errMultipleFilterValues
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return client.PruneInfo{
|
return client.PruneInfo{
|
||||||
All: opts.All,
|
All: opts.All,
|
||||||
KeepDuration: unusedFor,
|
KeepDuration: unusedFor,
|
||||||
KeepBytes: opts.KeepStorage,
|
KeepBytes: opts.KeepStorage,
|
||||||
Filter: bkFilter,
|
Filter: []string{strings.Join(bkFilter, ",")},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue