COPY / ADD as Docker reads it, from the instruction's own text: flags * first, then the JSON form or whitespace-separated words (a heredoc * source is unknown). The grammar loses a JSON form opening with `/` * (otel accounting) and, after a word with trailing blanks, takes the * instructions that follow for more words (awesome-compose wasmedge). */
| 620 | * (otel accounting) and, after a word with trailing blanks, takes the |
| 621 | * instructions that follow for more words (awesome-compose wasmedge). */ |
| 622 | static void dk_copy(dk_t *d, TSNode ins) { |
| 623 | static const char FROM[] = "--from="; |
| 624 | const char *words[DK_MAX_WORDS]; |
| 625 | int nw = 0; |
| 626 | dk_copy_t *c = cbm_arena_alloc(d->a, sizeof(*c)); |
| 627 | char *p = dk_logical_line(d, ts_node_start_byte(ins)); |
| 628 | if (!c || !p) { |
| 629 | return; |
| 630 | } |
| 631 | *c = (dk_copy_t){.workdir = d->workdir}; |
| 632 | p += strcspn(p, " \t"); /* the keyword */ |
| 633 | for (;;) { |
| 634 | p += strspn(p, " \t"); |
| 635 | if (strncmp(p, "--", PAIR_LEN) != 0) { |
| 636 | break; |
| 637 | } |
| 638 | size_t l = strcspn(p, " \t"); |
| 639 | if (l > sizeof(FROM) - SKIP_ONE && strncmp(p, FROM, sizeof(FROM) - SKIP_ONE) == 0) { |
| 640 | const char *v = |
| 641 | cbm_arena_strndup(d->a, p + sizeof(FROM) - SKIP_ONE, l - (sizeof(FROM) - SKIP_ONE)); |
| 642 | const char *ref = v ? dk_expand(d, d->local, v) : NULL; |
| 643 | c->has_from = true; |
| 644 | c->from = ref; |
| 645 | if (ref && ref[0] && !dk_is_stage(d, ref)) { |
| 646 | dk_link(d, ref, "copy-from", dk_line(ins)); |
| 647 | } |
| 648 | } |
| 649 | p += l; |
| 650 | } |
| 651 | bool json = *p == '[' && (nw = dk_copy_json(d, p, words, DK_MAX_WORDS)) > 0; |
| 652 | while (!json && *p && nw < DK_MAX_WORDS) { |
| 653 | size_t l = strcspn(p, " \t"); |
| 654 | const char *w = cbm_arena_strndup(d->a, p, l); |
| 655 | words[nw++] = w && strncmp(w, "<<", PAIR_LEN) != 0 ? dk_expand(d, d->local, w) : NULL; |
| 656 | p += l; |
| 657 | p += strspn(p, " \t"); |
| 658 | } |
| 659 | if (nw < PAIR_LEN || d->stage >= DK_MAX_STAGES) { |
| 660 | return; |
| 661 | } |
| 662 | c->srcs = cbm_arena_alloc(d->a, (size_t)(nw - SKIP_ONE) * sizeof(*c->srcs)); |
| 663 | if (!c->srcs) { |
| 664 | return; |
| 665 | } |
| 666 | memcpy((void *)c->srcs, words, (size_t)(nw - SKIP_ONE) * sizeof(*c->srcs)); |
| 667 | c->nsrc = nw - SKIP_ONE; |
| 668 | c->dst = words[nw - SKIP_ONE]; |
| 669 | c->next = d->st[d->stage].copies; |
| 670 | d->st[d->stage].copies = c; |
| 671 | } |
| 672 | |
| 673 | /* ── Paths in the image and in the repository ────────────────────────── */ |
| 674 |
no test coverage detected