8000 Treat unix sockets as regular files · moby/buildkit@3a0727e · GitHub
[go: up one dir, main page]

Skip to content

Commit 3a0727e

Browse files
Alex Couture-Beiltonistiigi
authored andcommitted
Treat unix sockets as regular files
This fix is similar to the fix in #1144; but was hit in a different code path. Signed-off-by: Alex Couture-Beil <alex@earthly.dev> (cherry picked from commit 5382a20) Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
1 parent 4ece504 commit 3a0727e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func TestClientIntegration(t *testing.T) {
103103
testCacheMountNoCache,
104104
testExporterTargetExists,
105105
testTarExporterWithSocket,
106+
testTarExporterWithSocketCopy,
106107
testMultipleRegistryCacheImportExport,
107108
}, mirrors)
108109

@@ -1504,6 +1505,26 @@ func testTarExporterWithSocket(t *testing.T, sb integration.Sandbox) {
15041505
require.NoError(t, err)
15051506
}
15061507

1508+
func testTarExporterWithSocketCopy(t *testing.T, sb integration.Sandbox) {
1509+
requiresLinux(t)
1510+
c, err := New(context.TODO(), sb.Address())
1511+
require.NoError(t, err)
1512+
defer c.Close()
1513+
1514+
alpine := llb.Image("docker.io/library/alpine:latest")
1515+
state := alpine.Run(llb.Args([]string{"sh", "-c", "nc -l -s local:/root/socket.sock & usleep 100000; kill %1"})).Root()
1516+
1517+
fa := llb.Copy(state, "/root", "/roo2", &llb.CopyInfo{})
1518+
1519+
scratchCopy := llb.Scratch().File(fa)
1520+
1521+
def, err := scratchCopy.Marshal()
1522+
require.NoError(t, err)
1523+
1524+
_, err = c.Solve(context.TODO(), def, SolveOpt{}, nil)
1525+
require.NoError(t, err)
1526+
}
1527+
15071528
func testBuildPushAndValidate(t *testing.T, sb integration.Sandbox) {
15081529
requiresLinux(t)
15091530
c, err := New(context.TODO(), sb.Address())

0 commit comments

Comments
 (0)
0