diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/memfs/memfs.go | 14 | ||||
| -rw-r--r-- | lib/memfs/memfs_test.go | 4 |
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/memfs/memfs.go b/lib/memfs/memfs.go index c55311bd..c1fccea9 100644 --- a/lib/memfs/memfs.go +++ b/lib/memfs/memfs.go @@ -42,6 +42,9 @@ type MemFS struct { // Merge one or more instances of MemFS into single hierarchy. // +// The returned MemFS instance will have SysPath set to the first +// MemFS.SysPath in parameter. +// // If there are two instance of Node that have the same path, the last // instance will be ignored. func Merge(params ...*MemFS) (merged *MemFS) { @@ -57,7 +60,16 @@ func Merge(params ...*MemFS) (merged *MemFS) { merged.PathNodes.Set("/", merged.Root) - for _, mfs := range params { + var ( + x int + mfs *MemFS + ) + + for x, mfs = range params { + if x == 0 { + merged.Root.SysPath = mfs.Root.SysPath + } + for _, child := range mfs.Root.Childs { gotNode := merged.PathNodes.Get(child.Path) if gotNode != nil { diff --git a/lib/memfs/memfs_test.go b/lib/memfs/memfs_test.go index 22c71bf5..f61d2930 100644 --- a/lib/memfs/memfs_test.go +++ b/lib/memfs/memfs_test.go @@ -576,7 +576,7 @@ func TestMerge(t *testing.T) { PathNodes: &PathNode{ v: map[string]*Node{ "/": &Node{ - SysPath: "..", + SysPath: mfsDirect.Root.SysPath, Path: "/", Childs: []*Node{ mfsDirect.MustGet("/add"), @@ -596,7 +596,7 @@ func TestMerge(t *testing.T) { PathNodes: &PathNode{ v: map[string]*Node{ "/": &Node{ - SysPath: "..", + SysPath: mfsDirect.Root.SysPath, Path: "/", Childs: []*Node{ mfsDirect.MustGet("/add"), |
