fix(plugin): skip sockets when copying repositories

Signed-off-by: Ruslan Shaydullin <shaydullin.r.d@outlook.com>
pull/32637/head
Ruslan Shaydullin 1 month ago
parent 87268ee077
commit c2689c955b

@ -132,6 +132,10 @@ func CopyDir(src, dst string) error {
srcPath := filepath.Join(src, entry.Name()) srcPath := filepath.Join(src, entry.Name())
dstPath := filepath.Join(dst, entry.Name()) dstPath := filepath.Join(dst, entry.Name())
if entry.Type()&os.ModeSocket != 0 {
continue
}
if entry.IsDir() { if entry.IsDir() {
if err = CopyDir(srcPath, dstPath); err != nil { if err = CopyDir(srcPath, dstPath); err != nil {
return fmt.Errorf("copying directory failed: %w", err) return fmt.Errorf("copying directory failed: %w", err)

@ -32,6 +32,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package fs package fs
import ( import (
"net"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -118,6 +119,30 @@ func TestCopyDir(t *testing.T) {
} }
} }
func TestCopyDirSkipsSocket(t *testing.T) {
dir := t.TempDir()
srcdir := filepath.Join(dir, "src")
require.NoError(t, os.MkdirAll(srcdir, 0o755))
require.NoError(t, os.WriteFile(filepath.Join(srcdir, "file"), []byte("contents"), 0o644))
socketPath := filepath.Join(srcdir, "socket")
listener, err := (&net.ListenConfig{}).Listen(t.Context(), "unix", socketPath)
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, listener.Close())
})
destdir := filepath.Join(dir, "dest")
require.NoError(t, CopyDir(srcdir, destdir))
contents, err := os.ReadFile(filepath.Join(destdir, "file"))
require.NoError(t, err)
require.Equal(t, "contents", string(contents))
_, err = os.Lstat(filepath.Join(destdir, "socket"))
require.ErrorIs(t, err, os.ErrNotExist)
}
func TestCopyDirFail_SrcInaccessible(t *testing.T) { func TestCopyDirFail_SrcInaccessible(t *testing.T) {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
// XXX: setting permissions works differently in // XXX: setting permissions works differently in

Loading…
Cancel
Save