1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-24 11:15:43 +08:00

Merge pull request from ipfs/fix/4800

fix(mfs): Directory.Path not working, add test
This commit is contained in:
Whyrusleeping
2018-03-22 23:34:05 -07:00
committed by GitHub
2 changed files with 14 additions and 2 deletions

@ -404,8 +404,15 @@ func (d *Directory) Path() string {
cur := d
var out string
for cur != nil {
out = path.Join(cur.name, out)
cur = cur.parent.(*Directory)
switch parent := cur.parent.(type) {
case *Directory:
out = path.Join(cur.name, out)
cur = parent
case *Root:
return "/" + out
default:
panic("directory parent neither a directory nor a root")
}
}
return out
}

@ -324,6 +324,11 @@ func TestDirectoryLoadFromDag(t *testing.T) {
topd := topi.(*Directory)
path := topd.Path()
if path != "/foo" {
t.Fatalf("Expected path '/foo', got '%s'", path)
}
// mkdir over existing but unloaded child file should fail
_, err = topd.Mkdir("a")
if err == nil {