ChildPathObjectOrFunc returns the child object from the permanode o, given by the "camliPath:xxxx" attribute, where xxx is the provided path. If the path doesn't exist, the provided func should return an appropriate object. If the func fails, the return error is returned directly without any attempt
(path string, fn func() (*Object, error))
| 1587 | // appropriate object. If the func fails, the return error is |
| 1588 | // returned directly without any attempt to make a permanode. |
| 1589 | func (o *Object) ChildPathObjectOrFunc(path string, fn func() (*Object, error)) (*Object, error) { |
| 1590 | attrName := "camliPath:" + path |
| 1591 | if v := o.Attr(attrName); v != "" { |
| 1592 | br, ok := blob.Parse(v) |
| 1593 | if !ok { |
| 1594 | return nil, fmt.Errorf("invalid blobref %q already stored at camliPath %q", br, path) |
| 1595 | } |
| 1596 | return o.h.ObjectFromRef(br) |
| 1597 | } |
| 1598 | newObj, err := fn() |
| 1599 | if err != nil { |
| 1600 | return nil, err |
| 1601 | } |
| 1602 | if err := o.SetAttr(attrName, newObj.PermanodeRef().String()); err != nil { |
| 1603 | return nil, err |
| 1604 | } |
| 1605 | return newObj, nil |
| 1606 | } |
| 1607 | |
| 1608 | // ObjectFromRef returns the object given by the named permanode |
| 1609 | func (h *Host) ObjectFromRef(permanodeRef blob.Ref) (*Object, error) { |
no test coverage detected