| 179 | } |
| 180 | |
| 181 | static bool sh_index_build(sh_index_t *ix, cbm_pipeline_ctx_t *ctx) { |
| 182 | ix->ctx = ctx; |
| 183 | ix->file_ids = cbm_ht_create(0); |
| 184 | ix->kusts = cbm_ht_create(0); |
| 185 | ix->charts = cbm_ht_create(0); |
| 186 | if (!ix->file_ids || !ix->kusts || !ix->charts) { |
| 187 | return false; |
| 188 | } |
| 189 | const cbm_gbuf_node_t **nodes = NULL; |
| 190 | int n = 0; |
| 191 | if (cbm_gbuf_find_by_label(ctx->gbuf, "File", &nodes, &n) == 0) { |
| 192 | for (int i = 0; i < n; i++) { |
| 193 | if (nodes[i]->file_path) { |
| 194 | sh_paths_push(&ix->files, nodes[i]->file_path); |
| 195 | cbm_ht_set(ix->file_ids, nodes[i]->file_path, (void *)(intptr_t)nodes[i]->id); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | if (cbm_gbuf_find_by_label(ctx->gbuf, "Resource", &nodes, &n) == 0) { |
| 200 | for (int i = 0; i < n; i++) { |
| 201 | const char *fp = nodes[i]->file_path; |
| 202 | if (!fp) { |
| 203 | continue; |
| 204 | } |
| 205 | bool kust_file = sh_kustomize_base(sh_basename(fp)); |
| 206 | if (kust_file && sh_eq(nodes[i]->name, "Kustomization")) { |
| 207 | cbm_ht_set(ix->kusts, fp, (void *)(intptr_t)nodes[i]->id); |
| 208 | } else if (!kust_file && sh_manifest_ext(fp)) { |
| 209 | sh_paths_push(&ix->manifests, fp); |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | if (cbm_gbuf_find_by_label(ctx->gbuf, "Chart", &nodes, &n) == 0) { |
| 214 | for (int i = 0; i < n; i++) { |
| 215 | const char *fp = nodes[i]->file_path; |
| 216 | const char *base = fp ? sh_basename(fp) : ""; |
| 217 | const char *qn = nodes[i]->qualified_name; |
| 218 | if ((strcmp(base, "Chart.yaml") == 0 || strcmp(base, "Chart.yml") == 0) && qn && |
| 219 | !cbm_pipeline_chart_is_external(nodes[i])) { |
| 220 | cbm_ht_set(ix->charts, fp, (void *)(intptr_t)nodes[i]->id); |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | sh_paths_sort_unique(&ix->files); |
| 225 | sh_paths_sort_unique(&ix->manifests); |
| 226 | return true; |
| 227 | } |
| 228 | |
| 229 | static void sh_index_free(sh_index_t *ix) { |
| 230 | cbm_free(CBM_MEM_CLASS_OTHER, (void *)ix->files.items); |
no test coverage detected