@@ -11,7 +11,7 @@ import (
11
11
"strings"
12
12
"sync"
13
13
14
- iradix "github.com/hashicorp/go-immutable-radix"
14
+ iradix "github.com/hashicorp/go-immutable-radix/v2 "
15
15
"github.com/hashicorp/golang-lru/simplelru"
16
16
"github.com/moby/buildkit/cache"
17
17
"github.com/moby/buildkit/session"
@@ -159,12 +159,12 @@ func (cm *cacheManager) clearCacheContext(id string) {
159
159
type cacheContext struct {
160
160
mu sync.RWMutex
161
161
md cacheMetadata
162
- tree * iradix.Tree
162
+ tree * iradix.Tree [ * CacheRecord ]
163
163
dirty bool // needs to be persisted to disk
164
164
165
165
// used in HandleChange
166
- txn * iradix.Txn
167
- node * iradix.Node
166
+ txn * iradix.Txn [ * CacheRecord ]
167
+ node * iradix.Node [ * CacheRecord ]
168
168
dirtyMap map [string ]struct {}
169
169
linkMap map [string ][][]byte
170
170
}
@@ -224,7 +224,7 @@ func (m *mount) clean() error {
224
224
func newCacheContext (md cache.RefMetadata ) (* cacheContext , error ) {
225
225
cc := & cacheContext {
226
226
md : cacheMetadata {md },
227
- tree : iradix .New (),
227
+ tree : iradix .New [ * CacheRecord ] (),
228
228
dirtyMap : map [string ]struct {}{},
229
229
linkMap : map [string ][][]byte {},
230
230
}
@@ -263,10 +263,10 @@ func (cc *cacheContext) save() error {
263
263
264
264
var l CacheRecords
265
265
node := cc .tree .Root ()
266
- node .Walk (func (k []byte , v interface {} ) bool {
266
+ node .Walk (func (k []byte , v * CacheRecord ) bool {
267
267
l .Paths = append (l .Paths , & CacheRecordWithPath {
268
268
Path : string (k ),
269
- Record : v .( * CacheRecord ) ,
269
+ Record : v ,
270
270
})
271
271
return false
272
272
})
@@ -294,7 +294,7 @@ func (cc *cacheContext) HandleChange(kind fsutil.ChangeKind, p string, fi os.Fil
294
294
295
295
deleteDir := func (cr * CacheRecord ) {
296
296
if cr .Type == CacheRecordTypeDir {
297
- cc .node .WalkPrefix (append (k , 0 ), func (k []byte , v interface {} ) bool {
297
+ cc .node .WalkPrefix (append (k , 0 ), func (k []byte , v * CacheRecord ) bool {
298
298
cc .txn .Delete (k )
299
299
return false
300
300
})
@@ -322,7 +322,7 @@ func (cc *cacheContext) HandleChange(kind fsutil.ChangeKind, p string, fi os.Fil
322
322
if kind == fsutil .ChangeKindDelete {
323
323
v , ok := cc .txn .Delete (k )
324
324
if ok {
325
- deleteDir (v .( * CacheRecord ) )
325
+ deleteDir (v )
326
326
}
327
327
d := path .Dir (p )
328
328
if d == "/" {
@@ -344,7 +344,7 @@ func (cc *cacheContext) HandleChange(kind fsutil.ChangeKind, p string, fi os.Fil
344
344
345
345
v , ok := cc .node .Get (k )
346
346
if ok {
347
- deleteDir (v .( * CacheRecord ) )
347
+ deleteDir (v )
348
348
}
349
349
350
350
cr := & CacheRecord {
@@ -371,7 +371,7 @@ func (cc *cacheContext) HandleChange(kind fsutil.ChangeKind, p string, fi os.Fil
371
371
ln := path .Join ("/" , filepath .ToSlash (stat .Linkname ))
372
372
v , ok := cc .txn .Get (convertPathToKey (ln ))
373
373
if ok {
374
- cp := * v .( * CacheRecord )
374
+ cp := * v
375
375
cr = & cp
376
376
}
377
377
cc .linkMap [ln ] = append (cc .linkMap [ln ], k )
@@ -496,7 +496,7 @@ func (cc *cacheContext) includedPaths(ctx context.Context, m *mount, p string, o
496
496
root = txn .Root ()
497
497
var (
498
498
updated bool
499
- iter * iradix.Iterator
499
+ iter * iradix.Iterator [ * CacheRecord ]
500
500
k []byte
501
501
keyOk bool
502
502
origPrefix string
@@ -716,7 +716,7 @@ func shouldIncludePath(
716
716
return true , nil
717
717
}
718
718
719
- func wildcardPrefix (root * iradix.Node , p string ) (string , []byte , bool , error ) {
719
+ func wildcardPrefix (root * iradix.Node [ * CacheRecord ] , p string ) (string , []byte , bool , error ) {
720
720
// For consistency with what the copy implementation in fsutil
721
721
// does: split pattern into non-wildcard prefix and rest of
722
722
// pattern, then follow symlinks when resolving the non-wildcard
@@ -849,7 +849,7 @@ func (cc *cacheContext) scanChecksum(ctx context.Context, m *mount, p string, fo
849
849
return cr , err
850
850
}
851
851
852
- func (cc * cacheContext ) checksum (ctx context.Context , root * iradix.Node , txn * iradix.Txn , m * mount , k []byte , followTrailing bool ) (* CacheRecord , bool , error ) {
852
+ func (cc * cacheContext ) checksum (ctx context.Context , root * iradix.Node [ * CacheRecord ] , txn * iradix.Txn [ * CacheRecord ] , m * mount , k []byte , followTrailing bool ) (* CacheRecord , bool , error ) {
853
853
origk := k
854
854
k , cr , err := getFollowLinks (root , k , followTrailing )
855
855
if err != nil {
@@ -930,7 +930,7 @@ func (cc *cacheContext) checksum(ctx context.Context, root *iradix.Node, txn *ir
930
930
931
931
// needsScan returns false if path is in the tree or a parent path is in tree
932
932
// and subpath is missing.
933
- func (cc * cacheContext ) needsScan (root * iradix.Node , path string , followTrailing bool ) (bool , error ) {
933
+ func (cc * cacheContext ) needsScan (root * iradix.Node [ * CacheRecord ] , path string , followTrailing bool ) (bool , error ) {
934
934
var (
935
935
lastGoodPath string
936
936
hasParentInTree bool
@@ -1047,7 +1047,7 @@ func (cc *cacheContext) scanPath(ctx context.Context, m *mount, p string, follow
1047
1047
type followLinksCallback func (path string , cr * CacheRecord ) error
1048
1048
1049
1049
// getFollowLinks is shorthand for getFollowLinksCallback(..., nil).
1050
- func getFollowLinks (root * iradix.Node , k []byte , followTrailing bool ) ([]byte , * CacheRecord , error ) {
1050
+ func getFollowLinks (root * iradix.Node [ * CacheRecord ] , k []byte , followTrailing bool ) ([]byte , * CacheRecord , error ) {
1051
1051
return getFollowLinksCallback (root , k , followTrailing , nil )
1052
1052
}
1053
1053
@@ -1063,10 +1063,10 @@ func getFollowLinks(root *iradix.Node, k []byte, followTrailing bool) ([]byte, *
1063
1063
// The callback cb is called after each cache lookup done by
1064
1064
// getFollowLinksCallback, except for the first lookup where the verbatim key
1065
1065
// is looked up in the cache.
1066
- func getFollowLinksCallback (root * iradix.Node , k []byte , followTrailing bool , cb followLinksCallback ) ([]byte , * CacheRecord , error ) {
1066
+ func getFollowLinksCallback (root * iradix.Node [ * CacheRecord ] , k []byte , followTrailing bool , cb followLinksCallback ) ([]byte , * CacheRecord , error ) {
1067
1067
v , ok := root .Get (k )
1068
- if ok && (! followTrailing || v .( * CacheRecord ). Type != CacheRecordTypeSymlink ) {
1069
- return k , v .( * CacheRecord ) , nil
1068
+ if ok && (! followTrailing || v .Type != CacheRecordTypeSymlink ) {
1069
+ return k , v , nil
1070
1070
}
1071
1071
if len (k ) == 0 {
1072
1072
return k , nil , nil
@@ -1104,11 +1104,7 @@ func getFollowLinksCallback(root *iradix.Node, k []byte, followTrailing bool, cb
1104
1104
continue
1105
1105
}
1106
1106
1107
- cr = nil
1108
- v , ok := root .Get (convertPathToKey (nextPath ))
1109
- if ok {
1110
- cr = v .(* CacheRecord )
1111
- }
1107
+ cr , ok = root .Get (convertPathToKey (nextPath ))
1112
1108
if cb != nil {
1113
1109
if err := cb (nextPath , cr ); err != nil {
1114
1110
return nil , nil , err
@@ -1137,12 +1133,8 @@ func getFollowLinksCallback(root *iradix.Node, k []byte, followTrailing bool, cb
1137
1133
// trailing slash in the original path, we need to do the lookup again with
1138
1134
// the slash applied.
1139
1135
if hadTrailingSlash {
1140
- cr = nil
1141
1136
currentPath += "/"
1142
- v , ok := root .Get (convertPathToKey (currentPath ))
1143
- if ok {
1144
- cr = v .(* CacheRecord )
1145
- }
1137
+ cr , _ = root .Get (convertPathToKey (currentPath ))
1146
1138
if cb != nil {
1147
1139
if err := cb (currentPath , cr ); err != nil {
1148
1140
return nil , nil , err
0 commit comments