提交 48f706b0 作者: Jakub Sztandera

fix(mfs): Directory.Path not working, add test

Credit goes to @ridewindx

License: MIT
Signed-off-by: 's avatarJakub Sztandera <kubuxu@protonmail.ch>
上级 4bdbe1a9
......@@ -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 {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论