| 1 | package control |
| 2 | |
| 3 | import "context" |
| 4 | |
| 5 | func hasExplicitImageAttachment(line string) bool { |
| 6 | for _, token := range parseRefTokens(line) { |
| 7 | if isAttachmentRef(token) && isImageAttachmentRef(token) { |
| 8 | return true |
| 9 | } |
| 10 | } |
| 11 | return false |
| 12 | } |
| 13 | |
| 14 | func (c *Controller) runPreparedRefTurn( |
| 15 | input, refLine, display, original string, |
| 16 | resolve func(context.Context, string) resolvedReferences, |
| 17 | decorate func(context.Context) context.Context, |
| 18 | admission turnAdmission, |
| 19 | ) { |
| 20 | if !hasExplicitImageAttachment(refLine) { |
| 21 | c.runGuardedWithAdmission(func(ctx context.Context) error { |
| 22 | return c.runRefTurnWithResolverSync(decorate(ctx), input, refLine, display, original, resolve) |
| 23 | }, admission) |
| 24 | return |
| 25 | } |
| 26 | // Freeze image bytes before admission so later file changes cannot alter the accepted turn. |
| 27 | resolveCtx := admission.durableCtx |
| 28 | if resolveCtx == nil { |
| 29 | resolveCtx = c.attachmentContext() |
| 30 | } |
| 31 | resolveCtx = contextWithPreparedImageReferences(resolveCtx, admission.images) |
| 32 | resolved := resolve(resolveCtx, refLine) |
| 33 | if len(resolved.imageErrs) > 0 { |
| 34 | err := ImageReferenceFailures(resolved.imageErrs) |
| 35 | c.notice(err.Error()) |
| 36 | return |
| 37 | } |
| 38 | c.runGuardedWithAdmission(func(ctx context.Context) error { |
| 39 | return c.runResolvedRefTurnSync(decorate(ctx), input, display, original, resolved) |
| 40 | }, admission) |
| 41 | } |
| 42 |