@@ -3,7 +3,6 @@ package contenthash
33import (
44 "bytes"
55 "context"
6- "crypto/sha256"
76 "io"
87 "os"
98 "path"
@@ -18,6 +17,7 @@ import (
1817 "github.com/moby/buildkit/cache"
1918 "github.com/moby/buildkit/session"
2019 "github.com/moby/buildkit/snapshot"
20+ "github.com/moby/buildkit/util/cachedigest"
2121 "github.com/moby/locker"
2222 "github.com/moby/patternmatcher"
2323 digest "github.com/opencontainers/go-digest"
@@ -450,15 +450,15 @@ func (cc *cacheContext) Checksum(ctx context.Context, mountable cache.Mountable,
450450 return digest .Digest (includedPaths [0 ].record .Digest ), nil
451451 }
452452
453- digester := digest . Canonical . Digester ( )
453+ h := cachedigest . NewHash ( cachedigest . TypeFileList )
454454 for i , w := range includedPaths {
455455 if i != 0 {
456- digester . Hash () .Write ([]byte {0 })
456+ h .Write ([]byte {0 })
457457 }
458- digester . Hash () .Write ([]byte (path .Base (w .path )))
459- digester . Hash () .Write ([]byte (w .record .Digest ))
458+ h .Write ([]byte (path .Base (w .path )))
459+ h .Write ([]byte (w .record .Digest ))
460460 }
461- return digester . Digest (), nil
461+ return h . Sum (), nil
462462}
463463
464464func (cc * cacheContext ) includedPaths (ctx context.Context , m * mount , p string , opts ChecksumOpts ) ([]* includedPath , error ) {
@@ -881,7 +881,7 @@ func (cc *cacheContext) checksum(ctx context.Context, root *iradix.Node[*CacheRe
881881
882882 switch cr .Type {
883883 case CacheRecordTypeDir :
884- h := sha256 . New ( )
884+ h := cachedigest . NewHash ( cachedigest . TypeFileList )
885885 next := append (k , 0 )
886886 iter := root .Iterator ()
887887 iter .SeekLowerBound (append (slices .Clone (next ), 0 ))
@@ -906,7 +906,7 @@ func (cc *cacheContext) checksum(ctx context.Context, root *iradix.Node[*CacheRe
906906 }
907907 subk , _ , ok = iter .Next ()
908908 }
909- dgst = digest . NewDigest ( digest . SHA256 , h )
909+ dgst = h . Sum ( )
910910
911911 default :
912912 p := convertKeyToPath (bytes .TrimSuffix (k , []byte {0 }))
0 commit comments