(ctx context.Context, doc document)
| 442 | } |
| 443 | |
| 444 | func (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 |
no test coverage detected