Skip to content

Commit bbd5249

Browse files
committed
contenthash: unconditionally clear ModeIrregular during content hash
Go 1.23 changed the behavior of `os.Stat` to set `ModeIrregular` when it encountered a mount point reparse point on Windows. These were previously labeled as symlinks. We attempted to fix this by clearing `ModeIrregular` during checksum generation, but we only cleared it in the case where `ModeIrregular` and at least one other mode type was set. After reviewing the original solution and issue, I believe that this was too conservative. The original issue seems to indicate that only the `ModeIrregular` bit was set so the condition would not have triggered and cleared it properly. I thought mount points would have both `ModeDir` and `ModeIrregular` set, but they only seem to have `ModeIrregular` set. This unconditionally clears the bit similar to socket files which should properly fix the issue on Windows.
1 parent 25c7c80 commit bbd5249

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

cache/contenthash/filehash.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,9 @@ 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-
53-
// Clear the socket bit since archive/tar.FileInfoHeader does not handle it
44+
// Clear the socket and irregular bits since archive/tar.FileInfoHeader do not handle them
5445
stat.Mode &^= uint32(os.ModeSocket)
46+
stat.Mode &^= uint32(os.ModeIrregular)
5547

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

0 commit comments

Comments
 (0)