Merge pull request #4844 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
commit 2c0bb93a6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -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
}

View File

@ -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 {