From 3a0727e2dfb667b906e5195dfeef4e84851f0fc6 Mon Sep 17 00:00:00 2001 From: Alex Couture-Beil Date: Fri, 17 Jul 2020 17:17:23 -0700 Subject: [PATCH] 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 (cherry picked from commit 5382a2056e5b0b2a7d40cbeafeca5f79408624a0) Signed-off-by: Tonis Tiigi --- cache/contenthash/filehash.go | 3 +++ client/client_test.go | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/cache/contenthash/filehash.go b/cache/contenthash/filehash.go index 84018e785226..27b6570ba74f 100644 --- a/cache/contenthash/filehash.go +++ b/cache/contenthash/filehash.go @@ -40,6 +40,9 @@ func NewFileHash(path string, fi os.FileInfo) (hash.Hash, error) { } func NewFromStat(stat *fstypes.Stat) (hash.Hash, error) { + // Clear the socket bit since archive/tar.FileInfoHeader does not handle it + stat.Mode &^= uint32(os.ModeSocket) + fi := &statInfo{stat} hdr, err := tar.FileInfoHeader(fi, stat.Linkname) if err != nil { diff --git a/client/client_test.go b/client/client_test.go index 67240a7a9260..8122cd14dba3 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -103,6 +103,7 @@ func TestClientIntegration(t *testing.T) { testCacheMountNoCache, testExporterTargetExists, testTarExporterWithSocket, + testTarExporterWithSocketCopy, testMultipleRegistryCacheImportExport, }, mirrors) @@ -1504,6 +1505,26 @@ func testTarExporterWithSocket(t *testing.T, sb integration.Sandbox) { require.NoError(t, err) } +func testTarExporterWithSocketCopy(t *testing.T, sb integration.Sandbox) { + requiresLinux(t) + c, err := New(context.TODO(), sb.Address()) + require.NoError(t, err) + defer c.Close() + + alpine := llb.Image("docker.io/library/alpine:latest") + state := alpine.Run(llb.Args([]string{"sh", "-c", "nc -l -s local:/root/socket.sock & usleep 100000; kill %1"})).Root() + + fa := llb.Copy(state, "/root", "/roo2", &llb.CopyInfo{}) + + scratchCopy := llb.Scratch().File(fa) + + def, err := scratchCopy.Marshal() + require.NoError(t, err) + + _, err = c.Solve(context.TODO(), def, SolveOpt{}, nil) + require.NoError(t, err) +} + func testBuildPushAndValidate(t *testing.T, sb integration.Sandbox) { requiresLinux(t) c, err := New(context.TODO(), sb.Address())