MCPcopy
hub / github.com/perkeep/perkeep / createDocument

Method createDocument

app/scanningcabinet/datastore.go:444–470  ·  view source on GitHub ↗
(ctx context.Context, doc document)

Source from the content-addressed store, hash-verified

442}
443
444func (h *handler) createDocument(ctx context.Context, doc document) (blob.Ref, error) {
445 pn, err := h.newPermanode()
446 if err != nil {
447 return pn, fmt.Errorf("could not create document: %v", err)
448 }
449
450 // make it a document
451 if err := h.setAttribute(ctx, pn, nodeattr.Type, documentNodeType); err != nil {
452 return pn, fmt.Errorf("could not set %v as a document: %v", pn, err)
453 }
454
455 // set creationTime
456 if err := h.setAttribute(ctx, pn, nodeattr.DateCreated, doc.creation.UTC().Format(time.RFC3339)); err != nil {
457 return pn, fmt.Errorf("could not set creationTime for document %v: %v", pn, err)
458 }
459
460 // set its pages
461 // TODO(mpl,bradfitz): camliPath vs camliMember vs camliPathOrder vs something else ?
462 // https://groups.google.com/d/msg/camlistore/xApHFjJKn3M/9Q5BfNbbptkJ
463 for pageNumber, pageRef := range doc.pages {
464 if err := h.setAttribute(ctx, pn, fmt.Sprintf("camliPath:%d", pageNumber), pageRef.String()); err != nil {
465 return pn, fmt.Errorf("could not set document %v page %d to scan %q: %v", doc.permanode, pageNumber, pageRef, err)
466 }
467 }
468
469 return pn, nil
470}
471
472// persistDocAndPages creates a new Document struct that represents
473// the given mediaObject structs and stores it in the datastore, updates each of

Callers 1

persistDocAndPagesMethod · 0.95

Calls 3

newPermanodeMethod · 0.95
setAttributeMethod · 0.95
StringMethod · 0.45

Tested by

no test coverage detected