MCPcopy
hub / github.com/perkeep/perkeep / ChildPathObjectOrFunc

Method ChildPathObjectOrFunc

pkg/importer/importer.go:1589–1606  ·  view source on GitHub ↗

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))

Source from the content-addressed store, hash-verified

1587// appropriate object. If the func fails, the return error is
1588// returned directly without any attempt to make a permanode.
1589func (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
1609func (h *Host) ObjectFromRef(permanodeRef blob.Ref) (*Object, error) {

Callers 5

ChildPathObjectMethod · 0.95
GetRequiredChildPathObjFunction · 0.80
updatePhotoMethod · 0.80
importBookmarkMethod · 0.80
updatePhotoInAlbumMethod · 0.80

Calls 6

AttrMethod · 0.95
SetAttrMethod · 0.95
ParseFunction · 0.92
ObjectFromRefMethod · 0.80
PermanodeRefMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected