Skip to content

Commit 50d297d

Browse files
committed
contenthash: add nofollow support
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 1814a01 commit 50d297d

File tree

3 files changed

+104
-48
lines changed

3 files changed

+104
-48
lines changed

cache/contenthash/checksum.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func getDefaultManager() *cacheManager {
4343
// header, "/dir" is for contents. For the root node "" (empty string) is the
4444
// key for root, "/" for the root header
4545

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)
4848
}
4949

5050
func GetCacheContext(ctx context.Context, md *metadata.StorageItem) (CacheContext, error) {
@@ -56,7 +56,8 @@ func SetCacheContext(ctx context.Context, md *metadata.StorageItem, cc CacheCont
5656
}
5757

5858
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)
6061
HandleChange(kind fsutil.ChangeKind, p string, fi os.FileInfo, err error) error
6162
}
6263

@@ -75,12 +76,12 @@ type cacheManager struct {
7576
lruMu sync.Mutex
7677
}
7778

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) {
7980
cc, err := cm.GetCacheContext(ctx, ensureOriginMetadata(ref.Metadata()))
8081
if err != nil {
8182
return "", nil
8283
}
83-
return cc.Checksum(ctx, ref, p)
84+
return cc.Checksum(ctx, ref, p, followLinks)
8485
}
8586

8687
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
334335
if followLinks {
335336
for i, w := range wildcards {
336337
if w.Record.Type == CacheRecordTypeSymlink {
337-
dgst, err := cc.checksumFollow(ctx, m, w.Path)
338+
dgst, err := cc.checksumFollow(ctx, m, w.Path, followLinks)
338339
if err == nil {
339340
wildcards[i].Record = &CacheRecord{Digest: dgst}
340341
}
@@ -360,10 +361,10 @@ func (cc *cacheContext) Checksum(ctx context.Context, mountable cache.Mountable,
360361
m := &mount{mountable: mountable}
361362
defer m.clean()
362363

363-
return cc.checksumFollow(ctx, m, p)
364+
return cc.checksumFollow(ctx, m, p, followLinks)
364365
}
365366

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) {
367368
const maxSymlinkLimit = 255
368369
i := 0
369370
for {
@@ -374,7 +375,7 @@ func (cc *cacheContext) checksumFollow(ctx context.Context, m *mount, p string)
374375
if err != nil {
375376
return "", err
376377
}
377-
if cr.Type == CacheRecordTypeSymlink {
378+
if cr.Type == CacheRecordTypeSymlink && follow {
378379
link := cr.Linkname
379380
if !path.IsAbs(cr.Linkname) {
380381
link = path.Join(path.Dir(p), link)

0 commit comments

Comments
 (0)