Unverified Commit 2c0bb93a authored by Whyrusleeping's avatar Whyrusleeping Committed by GitHub

Merge pull request #4844 from ipfs/fix/4800

fix(mfs): Directory.Path not working, add test
parents 036d3bda 48f706b0
...@@ -404,8 +404,15 @@ func (d *Directory) Path() string { ...@@ -404,8 +404,15 @@ func (d *Directory) Path() string {
cur := d cur := d
var out string var out string
for cur != nil { for cur != nil {
out = path.Join(cur.name, out) switch parent := cur.parent.(type) {
cur = cur.parent.(*Directory) 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 return out
} }
......
...@@ -324,6 +324,11 @@ func TestDirectoryLoadFromDag(t *testing.T) { ...@@ -324,6 +324,11 @@ func TestDirectoryLoadFromDag(t *testing.T) {
topd := topi.(*Directory) 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 // mkdir over existing but unloaded child file should fail
_, err = topd.Mkdir("a") _, err = topd.Mkdir("a")
if err == nil { if err == nil {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment