aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-11-20 02:28:13 +0100
committerGitHub <noreply@github.com>2017-11-20 02:28:13 +0100
commitdcec8517e203aa22f28b72e3015a4b3406d7cc62 (patch)
treeff18981c9cfc235434c5cee206b9a9344855e308 /utils
parent4cbf210eb44ae648545e84da2414e3215a3399a1 (diff)
parentc0e26a107c56b23127a633af6c4c52220f9a2207 (diff)
downloadgo-git-dcec8517e203aa22f28b72e3015a4b3406d7cc62.tar.gz
Merge pull request #640 from cesanta/fixdirsymlink
utils: merkletrie, filesystem fix symlinks to dir
Diffstat (limited to 'utils')
-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)