Skip to content

Commit 6f56d9c

Browse files
committed
Catalog validate: recognize Class[x] refs via the classes list
puppet_catalog_validate_refs treated Class[foo::bar] the same way it treats File['/x'] — scanned catalog->resources for a match. But classes are stored in a separate catalog->classes list (fed by include/require/contain), not as resource entries. Every notify => Class[apt::update] or require => Class[foo] was therefore flagged "Could not find resource 'Class[x]'". Extend catalog_has_resource to check catalog->classes first when the requested type is "class" (case-insensitive), normalising leading :: on both sides before comparing.
1 parent 07e2438 commit 6f56d9c

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

compiler/puppet_catalog_validate.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ static int type_eq_ci(const char *a, const char *b) {
4040
static int catalog_has_resource(const puppet_catalog_t *cat,
4141
const char *type, const char *title) {
4242
if (!cat || !type || !title) return 0;
43+
/* Class[foo::bar] isn't stored in resources[]; it lives in the
44+
* classes[] list populated by include/require. Match there too. */
45+
if (type_eq_ci(type, "class")) {
46+
const char *t = title;
47+
if (strncmp(t, "::", 2) == 0) t += 2;
48+
for (size_t i = 0; i < cat->class_count; i++) {
49+
const char *cn = cat->classes[i];
50+
if (!cn) continue;
51+
if (strncmp(cn, "::", 2) == 0) cn += 2;
52+
if (strcmp(cn, t) == 0) return 1;
53+
}
54+
}
4355
for (size_t i = 0; i < cat->resource_count; i++) {
4456
const puppet_catalog_resource_t *r = &cat->resources[i];
4557
if (type_eq_ci(r->type, type) && r->title && strcmp(r->title, title) == 0) {

0 commit comments

Comments
 (0)