diff --git a/drivers/copy/copy_linux.go b/drivers/copy/copy_linux.go index 8789409451..4aed8eb452 100644 --- a/drivers/copy/copy_linux.go +++ b/drivers/copy/copy_linux.go @@ -17,7 +17,6 @@ import ( "errors" "fmt" "io" - "net" "os" "path/filepath" "strings" @@ -200,11 +199,9 @@ func DirCopy(srcDir, dstDir string, copyMode Mode, copyXattrs bool) error { } case mode&os.ModeSocket != 0: - s, err := net.Listen("unix", dstPath) - if err != nil { + if err := unix.Mknod(dstPath, stat.Mode, int(stat.Rdev)); err != nil { return err } - s.Close() case mode&os.ModeDevice != 0: if unshare.IsRootless() { diff --git a/drivers/copy/copy_test.go b/drivers/copy/copy_test.go index da804a815b..dab85c2d7c 100644 --- a/drivers/copy/copy_test.go +++ b/drivers/copy/copy_test.go @@ -6,6 +6,7 @@ package copy import ( "fmt" "math/rand" + "net" "os" "path/filepath" "syscall" @@ -84,6 +85,11 @@ func randomMode(baseMode int) os.FileMode { func populateSrcDir(t *testing.T, srcDir string, remainingDepth int) { if remainingDepth == 0 { + socketPath := filepath.Join(srcDir, "srcsocket") + s, err := net.ListenUnix("unix", &net.UnixAddr{Name: socketPath, Net: "unix"}) + assert.NilError(t, err) + s.SetUnlinkOnClose(false) + s.Close() return } aTime := time.Unix(rand.Int63(), 0)