Skip to content

Commit 5382a20

Browse files
author
Alex Couture-Beil
committed
Treat unix sockets as regular files
This fix is similar to the fix in moby#1144; but was hit in a different code path. Signed-off-by: Alex Couture-Beil <[email protected]>
1 parent 4d1f260 commit 5382a20

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

cache/contenthash/filehash.go

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

4242
func NewFromStat(stat *fstypes.Stat) (hash.Hash, error) {
43+
// Clear the socket bit since archive/tar.FileInfoHeader does not handle it
44+
stat.Mode &^= uint32(os.ModeSocket)
45+
4346
fi := &statInfo{stat}
4447
hdr, err := tar.FileInfoHeader(fi, stat.Linkname)
4548
if err != nil {

client/client_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func TestIntegration(t *testing.T) {
113113
testCacheMountNoCache,
114114
testExporterTargetExists,
115115
testTarExporterWithSocket,
116+
testTarExporterWithSocketCopy,
116117
testTarExporterSymlink,
117118
testMultipleRegistryCacheImportExport,
118119
testSourceMap,
@@ -1653,6 +1654,30 @@ func testTarExporterWithSocket(t *testing.T, sb integration.Sandbox) {
16531654
require.NoError(t, err)
16541655
}
16551656

1657+
func testTarExporterWithSocketCopy(t *testing.T, sb integration.Sandbox) {
1658+
if os.Getenv("TEST_DOCKERD") == "1" {
1659+
t.Skip("tar exporter is temporarily broken on dockerd")
1660+
}
1661+
1662+
requiresLinux(t)
1663+
c, err := New(context.TODO(), sb.Address())
1664+
require.NoError(t, err)
1665+
defer c.Close()
1666+
1667+
alpine := llb.Image("docker.io/library/alpine:latest")
1668+
state := alpine.Run(llb.Args([]string{"sh", "-c", "nc -l -s local:/root/socket.sock & usleep 100000; kill %1"})).Root()
1669+
1670+
fa := llb.Copy(state, "/root", "/roo2", &llb.CopyInfo{})
1671+
1672+
scratchCopy := llb.Scratch().File(fa)
1673+
1674+
def, err := scratchCopy.Marshal(context.TODO())
1675+
require.NoError(t, err)
1676+
1677+
_, err = c.Solve(context.TODO(), def, SolveOpt{}, nil)
1678+
require.NoError(t, err)
1679+
}
1680+
16561681
// moby/buildkit#1418
16571682
func testTarExporterSymlink(t *testing.T, sb integration.Sandbox) {
16581683
requiresLinux(t)

0 commit comments

Comments
 (0)