diff options
author | steiler <github@vahlenkamp.net> | 2023-11-16 12:08:26 +0100 |
---|---|---|
committer | steiler <github@vahlenkamp.net> | 2023-11-19 13:39:38 +0100 |
commit | 5349b8a45ed2712302e85b258d3789808e1bd96d (patch) | |
tree | dd390632c5c05551a221f2a3ab012be6578ac662 | |
parent | e24e0f714c4ecaf086b5783f099a885e6a2c9a1a (diff) | |
download | go-git-5349b8a45ed2712302e85b258d3789808e1bd96d.tar.gz |
utils: merkletrie, Skip loading sockets as filesystem nodes. Fixes #312
-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 { |