diff --git a/internal/types/id.go b/internal/types/id.go index cc57033..ca1d006 100644 --- a/internal/types/id.go +++ b/internal/types/id.go @@ -52,16 +52,27 @@ func (i ID) Raw() interface{} { return i } -// Parent returns the parent dir ID. +// Parent returns the parent dir ID. If its a file then return containing directory. +// If this is a directory then return the dir one up. func (i ID) Parent() *ID { if i.Key == "/" { // Already at root. We dont have a parent return nil } - parent := &ID{ - Bucket: i.Bucket, - Key: filepath.Dir(i.Key) + "/", + var parent *ID + + if i.IsDirectory() { + parts := strings.Split(i.Key, "/") + parent = &ID{ + Bucket: i.Bucket, + Key: strings.Join(parts[:len(parts)-2], "/") + "/", + } + } else { + parent = &ID{ + Bucket: i.Bucket, + Key: filepath.Dir(i.Key) + "/", + } } parent.Normalize()