Skip to content

Commit

Permalink
Update copy.DirCopy to not unlink sockets
Browse files Browse the repository at this point in the history
- Closes containers#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 <[email protected]>
  • Loading branch information
anderbubble committed Sep 28, 2024
1 parent c90a35b commit 370a3f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/copy/copy_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ func DirCopy(srcDir, dstDir string, copyMode Mode, copyXattrs bool) error {
if err != nil {
return err
}
if unixListener, ok := listener.(*net.UnixListener); ok {
unixListener.SetUnlinkOnClose(false)
}
s.Close()

case mode&os.ModeDevice != 0:
Expand Down
8 changes: 8 additions & 0 deletions drivers/copy/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package copy
import (
"fmt"
"math/rand"
"net"
"os"
"path/filepath"
"syscall"
Expand Down Expand Up @@ -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.Listen("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)
Expand Down

0 comments on commit 370a3f9

Please sign in to comment.