Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore ModeSocket files #930

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions utils/merkletrie/filesystem/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions utils/merkletrie/filesystem/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package filesystem

import (
"bytes"
"fmt"
"io"
"net"
"os"
"path"
"runtime"
"testing"

"github.com/go-git/go-git/v5/plumbing"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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")
pjbgf marked this conversation as resolved.
Show resolved Hide resolved
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 {
Expand Down