@@ -43,8 +43,8 @@ func getDefaultManager() *cacheManager {
43
43
// header, "/dir" is for contents. For the root node "" (empty string) is the
44
44
// key for root, "/" for the root header
45
45
46
- func Checksum (ctx context.Context , ref cache.ImmutableRef , path string ) (digest.Digest , error ) {
47
- return getDefaultManager ().Checksum (ctx , ref , path )
46
+ func Checksum (ctx context.Context , ref cache.ImmutableRef , path string , followLinks bool ) (digest.Digest , error ) {
47
+ return getDefaultManager ().Checksum (ctx , ref , path , followLinks )
48
48
}
49
49
50
50
func GetCacheContext (ctx context.Context , md * metadata.StorageItem ) (CacheContext , error ) {
@@ -56,7 +56,8 @@ func SetCacheContext(ctx context.Context, md *metadata.StorageItem, cc CacheCont
56
56
}
57
57
58
58
type CacheContext interface {
59
- Checksum (ctx context.Context , ref cache.Mountable , p string ) (digest.Digest , error )
59
+ Checksum (ctx context.Context , ref cache.Mountable , p string , followLinks bool ) (digest.Digest , error )
60
+ ChecksumWildcard (ctx context.Context , ref cache.Mountable , p string , followLinks bool ) (digest.Digest , error )
60
61
HandleChange (kind fsutil.ChangeKind , p string , fi os.FileInfo , err error ) error
61
62
}
62
63
@@ -75,12 +76,12 @@ type cacheManager struct {
75
76
lruMu sync.Mutex
76
77
}
77
78
78
- func (cm * cacheManager ) Checksum (ctx context.Context , ref cache.ImmutableRef , p string ) (digest.Digest , error ) {
79
+ func (cm * cacheManager ) Checksum (ctx context.Context , ref cache.ImmutableRef , p string , followLinks bool ) (digest.Digest , error ) {
79
80
cc , err := cm .GetCacheContext (ctx , ensureOriginMetadata (ref .Metadata ()))
80
81
if err != nil {
81
82
return "" , nil
82
83
}
83
- return cc .Checksum (ctx , ref , p )
84
+ return cc .Checksum (ctx , ref , p , followLinks )
84
85
}
85
86
86
87
func (cm * cacheManager ) GetCacheContext (ctx context.Context , md * metadata.StorageItem ) (CacheContext , error ) {
@@ -334,7 +335,7 @@ func (cc *cacheContext) ChecksumWildcard(ctx context.Context, mountable cache.Mo
334
335
if followLinks {
335
336
for i , w := range wildcards {
336
337
if w .Record .Type == CacheRecordTypeSymlink {
337
- dgst , err := cc .checksumFollow (ctx , m , w .Path )
338
+ dgst , err := cc .checksumFollow (ctx , m , w .Path , followLinks )
338
339
if err == nil {
339
340
wildcards [i ].Record = & CacheRecord {Digest : dgst }
340
341
}
@@ -360,10 +361,10 @@ func (cc *cacheContext) Checksum(ctx context.Context, mountable cache.Mountable,
360
361
m := & mount {mountable : mountable }
361
362
defer m .clean ()
362
363
363
- return cc .checksumFollow (ctx , m , p )
364
+ return cc .checksumFollow (ctx , m , p , followLinks )
364
365
}
365
366
366
- func (cc * cacheContext ) checksumFollow (ctx context.Context , m * mount , p string ) (digest.Digest , error ) {
367
+ func (cc * cacheContext ) checksumFollow (ctx context.Context , m * mount , p string , follow bool ) (digest.Digest , error ) {
367
368
const maxSymlinkLimit = 255
368
369
i := 0
369
370
for {
@@ -374,7 +375,7 @@ func (cc *cacheContext) checksumFollow(ctx context.Context, m *mount, p string)
374
375
if err != nil {
375
376
return "" , err
376
377
}
377
- if cr .Type == CacheRecordTypeSymlink {
378
+ if cr .Type == CacheRecordTypeSymlink && follow {
378
379
link := cr .Linkname
379
380
if ! path .IsAbs (cr .Linkname ) {
380
381
link = path .Join (path .Dir (p ), link )
0 commit comments