From 3f5944885b3a937fb459d4e2ad4268e27e8c64ee Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Fri, 27 Sep 2024 14:06:36 -0600 Subject: [PATCH] Update copy.DirCopy to not unlink sockets - Closes #2113 `copy.DirCopy` contains code to create named sockets matching those on the source; however, this operation closes the socket, removing it implicitly from the destination and causing later chown and chmod operations to fail. This commit removes configures the socket to not unlink the underlying socket file from the file system during `.Close()`, leaving the socket in place at the destination, as it is in the source. Signed-off-by: Jonathon Anderson --- drivers/copy/copy_linux.go | 1 + drivers/copy/copy_test.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/drivers/copy/copy_linux.go b/drivers/copy/copy_linux.go index caf07602ba..f23e159273 100644 --- a/drivers/copy/copy_linux.go +++ b/drivers/copy/copy_linux.go @@ -203,6 +203,7 @@ func DirCopy(srcDir, dstDir string, copyMode Mode, copyXattrs bool) error { if err != nil { return err } + s.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..ddc1b220a0 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,11 @@ 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.Listen("unix", socketName) + assert.NilError(t, err) + s.SetUnlinkOnClose(false) + s.Close() return } aTime := time.Unix(rand.Int63(), 0)