Skip to content

Commit

Permalink
Treat unix sockets as regular files
Browse files Browse the repository at this point in the history
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]>
(cherry picked from commit 5382a20)
Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
alexcb authored and tonistiigi committed Jul 25, 2020
1 parent 4ece504 commit 3a0727e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cache/contenthash/filehash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func TestClientIntegration(t *testing.T) {
testCacheMountNoCache,
testExporterTargetExists,
testTarExporterWithSocket,
testTarExporterWithSocketCopy,
testMultipleRegistryCacheImportExport,
}, mirrors)

Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 3a0727e

Please sign in to comment.