diff options
author | Paulo Gomes <pjbgf@linux.com> | 2023-11-20 10:25:24 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-20 10:25:24 +0000 |
commit | fecea417bfc18648757a1bde30ca384548b55197 (patch) | |
tree | f533eb31f3dda7f955b14ab53b46d533be89f48e /utils/merkletrie | |
parent | c114af0cc97ac71f5ac21e7e510eaadec37dfba0 (diff) | |
parent | 5349b8a45ed2712302e85b258d3789808e1bd96d (diff) | |
download | go-git-fecea417bfc18648757a1bde30ca384548b55197.tar.gz |
Merge pull request #930 from steiler/fixSockets
Ignore ModeSocket files
Diffstat (limited to 'utils/merkletrie')
-rw-r--r-- | utils/merkletrie/filesystem/node.go | 4 | ||||
-rw-r--r-- | utils/merkletrie/filesystem/node_test.go | 26 |
2 files changed, 30 insertions, 0 deletions
diff --git a/utils/merkletrie/filesystem/node.go b/utils/merkletrie/filesystem/node.go index ad169ff..7bba0d0 100644 --- a/utils/merkletrie/filesystem/node.go +++ b/utils/merkletrie/filesystem/node.go @@ -103,6 +103,10 @@ func (n *node) calculateChildren() error { continue } + if file.Mode()&os.ModeSocket != 0 { + continue + } + c, err := n.newChildNode(file) if err != nil { return err diff --git a/utils/merkletrie/filesystem/node_test.go b/utils/merkletrie/filesystem/node_test.go index 159e63d..b76abc4 100644 --- a/utils/merkletrie/filesystem/node_test.go +++ b/utils/merkletrie/filesystem/node_test.go @@ -2,9 +2,12 @@ package filesystem import ( "bytes" + "fmt" "io" + "net" "os" "path" + "runtime" "testing" "github.com/go-git/go-git/v5/plumbing" @@ -13,6 +16,7 @@ import ( "github.com/go-git/go-billy/v5" "github.com/go-git/go-billy/v5/memfs" + "github.com/go-git/go-billy/v5/osfs" . "gopkg.in/check.v1" ) @@ -196,6 +200,28 @@ func (s *NoderSuite) TestDiffDirectory(c *C) { c.Assert(a, Equals, merkletrie.Modify) } +func (s *NoderSuite) TestSocket(c *C) { + if runtime.GOOS == "windows" { + c.Skip("socket files do not exist on windows") + } + + td, err := os.MkdirTemp("", "socket-test") + defer os.RemoveAll(td) + c.Assert(err, IsNil) + + sock, err := net.ListenUnix("unix", &net.UnixAddr{Name: fmt.Sprintf("%s/socket", td), Net: "unix"}) + c.Assert(err, IsNil) + defer sock.Close() + + fsA := osfs.New(td) + WriteFile(fsA, "foo", []byte("foo"), 0644) + + noder := NewRootNode(fsA, nil) + childs, err := noder.Children() + c.Assert(err, IsNil) + c.Assert(childs, HasLen, 1) +} + func WriteFile(fs billy.Filesystem, filename string, data []byte, perm os.FileMode) error { f, err := fs.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm) if err != nil { |