aboutsummaryrefslogtreecommitdiffstats
path: root/utils/merkletrie/filesystem
diff options
context:
space:
mode:
authorsteiler <github@vahlenkamp.net>2023-11-16 12:08:26 +0100
committersteiler <github@vahlenkamp.net>2023-11-19 13:39:38 +0100
commit5349b8a45ed2712302e85b258d3789808e1bd96d (patch)
treedd390632c5c05551a221f2a3ab012be6578ac662 /utils/merkletrie/filesystem
parente24e0f714c4ecaf086b5783f099a885e6a2c9a1a (diff)
downloadgo-git-5349b8a45ed2712302e85b258d3789808e1bd96d.tar.gz
utils: merkletrie, Skip loading sockets as filesystem nodes. Fixes #312
Diffstat (limited to 'utils/merkletrie/filesystem')
-rw-r--r--utils/merkletrie/filesystem/node.go4
-rw-r--r--utils/merkletrie/filesystem/node_test.go26
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 {