id improved parent method
This commit is contained in:
parent
aac1ca8891
commit
aa82cd938c
@ -52,17 +52,28 @@ func (i ID) Raw() interface{} {
|
|||||||
return i
|
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 {
|
func (i ID) Parent() *ID {
|
||||||
if i.Key == "/" {
|
if i.Key == "/" {
|
||||||
// Already at root. We dont have a parent
|
// Already at root. We dont have a parent
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
parent := &ID{
|
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,
|
Bucket: i.Bucket,
|
||||||
Key: filepath.Dir(i.Key) + "/",
|
Key: filepath.Dir(i.Key) + "/",
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
parent.Normalize()
|
parent.Normalize()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user