fs: Implement UnWrapObject and UnWrapFs

This commit is contained in:
Nick Craig-Wood
2019-08-12 22:03:53 +01:00
parent 7c146e2618
commit 752d43d6fa
3 changed files with 35 additions and 22 deletions

View File

@@ -1023,6 +1023,38 @@ type ObjectPair struct {
Src, Dst Object
}
// UnWrapFs unwraps f as much as possible and returns the base Fs
func UnWrapFs(f Fs) Fs {
for {
unwrap := f.Features().UnWrap
if unwrap == nil {
break // not a wrapped Fs, use current
}
next := unwrap()
if next == nil {
break // no base Fs found, use current
}
f = next
}
return f
}
// UnWrapObject unwraps o as much as possible and returns the base object
func UnWrapObject(o Object) Object {
for {
u, ok := o.(ObjectUnWrapper)
if !ok {
break // not a wrapped object, use current
}
next := u.UnWrap()
if next == nil {
break // no base object found, use current
}
o = next
}
return o
}
// Find looks for an RegInfo object for the name passed in. The name
// can be either the Name or the Prefix.
//