aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--utils/merkletrie/filesystem/node.go4
-rw-r--r--utils/merkletrie/filesystem/node_test.go36
2 files changed, 40 insertions, 0 deletions
diff --git a/utils/merkletrie/filesystem/node.go b/utils/merkletrie/filesystem/node.go
index f763e08..42a58a3 100644
--- a/utils/merkletrie/filesystem/node.go
+++ b/utils/merkletrie/filesystem/node.go
@@ -77,6 +77,10 @@ func (n *node) NumChildren() (int, error) {
}
func (n *node) calculateChildren() error {
+ if !n.IsDir() {
+ return nil
+ }
+
if len(n.children) != 0 {
return nil
}
diff --git a/utils/merkletrie/filesystem/node_test.go b/utils/merkletrie/filesystem/node_test.go
index 42dd82e..7aa0d97 100644
--- a/utils/merkletrie/filesystem/node_test.go
+++ b/utils/merkletrie/filesystem/node_test.go
@@ -82,6 +82,42 @@ func (s *NoderSuite) TestDiffChangeContent(c *C) {
c.Assert(ch, HasLen, 1)
}
+func (s *NoderSuite) TestDiffSymlinkDirOnA(c *C) {
+ fsA := memfs.New()
+ WriteFile(fsA, "qux/qux", []byte("foo"), 0644)
+
+ fsB := memfs.New()
+ fsB.Symlink("qux", "foo")
+ WriteFile(fsB, "qux/qux", []byte("foo"), 0644)
+
+ ch, err := merkletrie.DiffTree(
+ NewRootNode(fsA, nil),
+ NewRootNode(fsB, nil),
+ IsEquals,
+ )
+
+ c.Assert(err, IsNil)
+ c.Assert(ch, HasLen, 1)
+}
+
+func (s *NoderSuite) TestDiffSymlinkDirOnB(c *C) {
+ fsA := memfs.New()
+ fsA.Symlink("qux", "foo")
+ WriteFile(fsA, "qux/qux", []byte("foo"), 0644)
+
+ fsB := memfs.New()
+ WriteFile(fsB, "qux/qux", []byte("foo"), 0644)
+
+ ch, err := merkletrie.DiffTree(
+ NewRootNode(fsA, nil),
+ NewRootNode(fsB, nil),
+ IsEquals,
+ )
+
+ c.Assert(err, IsNil)
+ c.Assert(ch, HasLen, 1)
+}
+
func (s *NoderSuite) TestDiffChangeMissing(c *C) {
fsA := memfs.New()
WriteFile(fsA, "foo", []byte("foo"), 0644)