mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-24 11:15:43 +08:00
Merge pull request #4844 from ipfs/fix/4800
fix(mfs): Directory.Path not working, add test
This commit is contained in:
11
mfs/dir.go
11
mfs/dir.go
@ -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 {
|
||||
|
Reference in New Issue
Block a user