old is an optimization, in case the caller already had fetched the old scan. If nil, the current scan will be fetched for comparison with new.
(ctx context.Context, pn blob.Ref, new, old *mediaObject)
| 325 | // old is an optimization, in case the caller already had fetched the old scan. |
| 326 | // If nil, the current scan will be fetched for comparison with new. |
| 327 | func (h *handler) updateScan(ctx context.Context, pn blob.Ref, new, old *mediaObject) error { |
| 328 | if old == nil { |
| 329 | mo, err := h.fetchScan(pn) |
| 330 | if err != nil { |
| 331 | return fmt.Errorf("scan %v not found: %v", pn, err) |
| 332 | } |
| 333 | old = &mo |
| 334 | } |
| 335 | if new.contentRef.Valid() && old.contentRef != new.contentRef { |
| 336 | if err := h.setAttribute(ctx, pn, "camliContent", new.contentRef.String()); err != nil { |
| 337 | return fmt.Errorf("could not set contentRef for scan %v: %v", pn, err) |
| 338 | } |
| 339 | } |
| 340 | if new.documentRef.Valid() && old.documentRef != new.documentRef { |
| 341 | if err := h.setAttribute(ctx, pn, "document", new.documentRef.String()); err != nil { |
| 342 | return fmt.Errorf("could not set documentRef for scan %v: %v", pn, err) |
| 343 | } |
| 344 | } |
| 345 | if !old.creation.Equal(new.creation) { |
| 346 | if new.creation.IsZero() { |
| 347 | if err := h.delAttribute(ctx, pn, nodeattr.DateCreated, ""); err != nil { |
| 348 | return fmt.Errorf("could not delete creation date for scan %v: %v", pn, err) |
| 349 | } |
| 350 | } else { |
| 351 | if err := h.setAttribute(ctx, pn, nodeattr.DateCreated, new.creation.UTC().Format(time.RFC3339)); err != nil { |
| 352 | return fmt.Errorf("could not set creation date for scan %v: %v", pn, err) |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | return nil |
| 357 | } |
| 358 | |
| 359 | func (h *handler) updateDocument(ctx context.Context, pn blob.Ref, new *document) error { |
| 360 | old, err := h.fetchDocument(pn) |
no test coverage detected