Skip to content

Commit 45177da

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 45177da

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cache/contenthash/filehash.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ func NewFileHash(path string, fi os.FileInfo) (hash.Hash, error) {
4141
}
4242

4343
func NewFromStat(stat *fstypes.Stat) (hash.Hash, error) {
44+
// Clear the irregular file bit if this is some kind of special
45+
// file. Pre-Go 1.23 behavior would only add the irregular file
46+
// bit to regular files with non-handled reparse points.
47+
// Current versions of Go now apply them to directories too.
48+
// archive/tar.FileInfoHeader does not handle the irregular bit.
49+
if stat.Mode&uint32(os.ModeType&^os.ModeIrregular) != 0 {
50+
stat.Mode &^= uint32(os.ModeIrregular)
51+
}
52+
4453
// Clear the socket bit since archive/tar.FileInfoHeader does not handle it
4554
stat.Mode &^= uint32(os.ModeSocket)
4655

0 commit comments

Comments
 (0)