Skip to content

Commit fecea41

Browse files
authored
Merge pull request #930 from steiler/fixSockets
Ignore ModeSocket files
2 parents c114af0 + 5349b8a commit fecea41

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

utils/merkletrie/filesystem/node.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ func (n *node) calculateChildren() error {
103103
continue
104104
}
105105

106+
if file.Mode()&os.ModeSocket != 0 {
107+
continue
108+
}
109+
106110
c, err := n.newChildNode(file)
107111
if err != nil {
108112
return err

utils/merkletrie/filesystem/node_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package filesystem
22

33
import (
44
"bytes"
5+
"fmt"
56
"io"
7+
"net"
68
"os"
79
"path"
10+
"runtime"
811
"testing"
912

1013
"github.com/go-git/go-git/v5/plumbing"
@@ -13,6 +16,7 @@ import (
1316

1417
"github.com/go-git/go-billy/v5"
1518
"github.com/go-git/go-billy/v5/memfs"
19+
"github.com/go-git/go-billy/v5/osfs"
1620
. "gopkg.in/check.v1"
1721
)
1822

@@ -196,6 +200,28 @@ func (s *NoderSuite) TestDiffDirectory(c *C) {
196200
c.Assert(a, Equals, merkletrie.Modify)
197201
}
198202

203+
func (s *NoderSuite) TestSocket(c *C) {
204+
if runtime.GOOS == "windows" {
205+
c.Skip("socket files do not exist on windows")
206+
}
207+
208+
td, err := os.MkdirTemp("", "socket-test")
209+
defer os.RemoveAll(td)
210+
c.Assert(err, IsNil)
211+
212+
sock, err := net.ListenUnix("unix", &net.UnixAddr{Name: fmt.Sprintf("%s/socket", td), Net: "unix"})
213+
c.Assert(err, IsNil)
214+
defer sock.Close()
215+
216+
fsA := osfs.New(td)
217+
WriteFile(fsA, "foo", []byte("foo"), 0644)
218+
219+
noder := NewRootNode(fsA, nil)
220+
childs, err := noder.Children()
221+
c.Assert(err, IsNil)
222+
c.Assert(childs, HasLen, 1)
223+
}
224+
199225
func WriteFile(fs billy.Filesystem, filename string, data []byte, perm os.FileMode) error {
200226
f, err := fs.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
201227
if err != nil {

0 commit comments

Comments
 (0)