Skip to content

Commit 5887a6c

Browse files
committed
contenthash: clear ModeIrregular before sending to archive/tar
Clears ModeIrregular from the checksum generation. This may be sent by the client when the version of Go used is post Go 1.23. The behavior of `os.Stat` was modified in Go 1.23 to set `ModeIrregular` on reparse points in Windows. This clears `ModeIrregular` when any mode is set which was the previous behavior of `os.Stat`. Signed-off-by: Jonathan A. Sternberg <[email protected]>
1 parent 78bcf8d commit 5887a6c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cache/contenthash/filehash.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ func NewFileHash(path string, fi os.FileInfo) (hash.Hash, error) {
4343
func NewFromStat(stat *fstypes.Stat) (hash.Hash, error) {
4444
// Clear the socket bit since archive/tar.FileInfoHeader does not handle it
4545
stat.Mode &^= uint32(os.ModeSocket)
46+
if stat.Mode&uint32(os.ModeType) != 0 {
47+
// Pre-Go 1.23 the mode of unknown reparse points on Windows would be set to
48+
// zero and treated as a normal file. The behavior has changed so any reparse
49+
// point that is not a unix socket, symlink, or dedup will cause ModeIrregular
50+
// to be set. This restores the previous behavior to avoid an error from
51+
// archive/tar.
52+
stat.Mode &^= uint32(os.ModeIrregular)
53+
}
4654

4755
fi := &statInfo{stat}
4856
hdr, err := tar.FileInfoHeader(fi, stat.Linkname)

0 commit comments

Comments
 (0)