diff --git a/drivers/copy/copy_linux.go b/drivers/copy/copy_linux.go index caf07602ba..a190923986 100644 --- a/drivers/copy/copy_linux.go +++ b/drivers/copy/copy_linux.go @@ -199,10 +199,13 @@ func DirCopy(srcDir, dstDir string, copyMode Mode, copyXattrs bool) error { } case mode&os.ModeSocket != 0: - s, err := net.Listen("unix", dstPath) + s, err := net.ListenUnix("unix", dstPath) if err != nil { return err } + if unixListener, ok := listener.(*net.UnixListener); ok { + unixListener.SetUnlinkOnClose(false) + } s.Close() case mode&os.ModeDevice != 0: diff --git a/drivers/copy/copy_test.go b/drivers/copy/copy_test.go index 9c69908840..790232555b 100644 --- a/drivers/copy/copy_test.go +++ b/drivers/copy/copy_test.go @@ -5,6 +5,7 @@ package copy import ( "fmt" "math/rand" + "net" "os" "path/filepath" "syscall" @@ -83,6 +84,13 @@ func randomMode(baseMode int) os.FileMode { func populateSrcDir(t *testing.T, srcDir string, remainingDepth int) { if remainingDepth == 0 { + socketName := filepath.Join(srcDir, "srcsocket") + s, err := net.ListenUnix("unix", socketName) + assert.NilError(t, err) + if unixListener, ok := listener.(*net.UnixListener); ok { + unixListener.SetUnlinkOnClose(false) + } + s.Close() return } aTime := time.Unix(rand.Int63(), 0)