Skip to content

Commit

Permalink
contenthash: clear ModeIrregular before sending to archive/tar
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jsternberg committed Jan 15, 2025
1 parent 78bcf8d commit 45177da
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cache/contenthash/filehash.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ func NewFileHash(path string, fi os.FileInfo) (hash.Hash, error) {
}

func NewFromStat(stat *fstypes.Stat) (hash.Hash, error) {
// Clear the irregular file bit if this is some kind of special
// file. Pre-Go 1.23 behavior would only add the irregular file
// bit to regular files with non-handled reparse points.
// Current versions of Go now apply them to directories too.
// archive/tar.FileInfoHeader does not handle the irregular bit.
if stat.Mode&uint32(os.ModeType&^os.ModeIrregular) != 0 {
stat.Mode &^= uint32(os.ModeIrregular)
}

// Clear the socket bit since archive/tar.FileInfoHeader does not handle it
stat.Mode &^= uint32(os.ModeSocket)

Expand Down

0 comments on commit 45177da

Please sign in to comment.