MCPcopy
hub / github.com/perkeep/perkeep / fetchSchemaMeta

Method fetchSchemaMeta

pkg/fs/fs.go:342–364  ·  view source on GitHub ↗

Errors returned are: os.ErrNotExist -- blob not found os.ErrInvalid -- not JSON or a camli schema blob

(ctx context.Context, br blob.Ref)

Source from the content-addressed store, hash-verified

340// os.ErrNotExist -- blob not found
341// os.ErrInvalid -- not JSON or a camli schema blob
342func (fs *CamliFileSystem) fetchSchemaMeta(ctx context.Context, br blob.Ref) (*schema.Blob, error) {
343 blobStr := br.String()
344 if blob, ok := fs.blobToSchema.Get(blobStr); ok {
345 return blob.(*schema.Blob), nil
346 }
347
348 rc, _, err := fs.fetcher.Fetch(ctx, br)
349 if err != nil {
350 return nil, err
351 }
352 defer rc.Close()
353 blob, err := schema.BlobFromReader(br, rc)
354 if err != nil {
355 Logger.Printf("Error parsing %s as schema blob: %v", br, err)
356 return nil, os.ErrInvalid
357 }
358 if blob.Type() == "" {
359 Logger.Printf("blob %s is JSON but lacks camliType", br)
360 return nil, os.ErrInvalid
361 }
362 fs.blobToSchema.Add(blobStr, blob)
363 return blob, nil
364}
365
366// consolated logic for determining a node to mount based on an arbitrary blobref
367func (fs *CamliFileSystem) newNodeFromBlobRef(root blob.Ref) (fusefs.Node, error) {

Callers 2

newNodeFromBlobRefMethod · 0.95
schemaMethod · 0.80

Calls 8

BlobFromReaderFunction · 0.92
PrintfMethod · 0.80
GetMethod · 0.65
FetchMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45
TypeMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected