File tree 2 files changed +14
-2
lines changed 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -404,8 +404,15 @@ func (d *Directory) Path() string {
404
404
cur := d
405
405
var out string
406
406
for cur != nil {
407
- out = path .Join (cur .name , out )
408
- cur = cur .parent .(* Directory )
407
+ switch parent := cur .parent .(type ) {
408
+ case * Directory :
409
+ out = path .Join (cur .name , out )
410
+ cur = parent
411
+ case * Root :
412
+ return "/" + out
413
+ default :
414
+ panic ("directory parent neither a directory nor a root" )
415
+ }
409
416
}
410
417
return out
411
418
}
Original file line number Diff line number Diff line change @@ -324,6 +324,11 @@ func TestDirectoryLoadFromDag(t *testing.T) {
324
324
325
325
topd := topi .(* Directory )
326
326
327
+ path := topd .Path ()
328
+ if path != "/foo" {
329
+ t .Fatalf ("Expected path '/foo', got '%s'" , path )
330
+ }
331
+
327
332
// mkdir over existing but unloaded child file should fail
328
333
_ , err = topd .Mkdir ("a" )
329
334
if err == nil {
You can’t perform that action at this time.
0 commit comments