Skip to content

Commit e9919eb

Browse files
committed
test state
1 parent 9ef2878 commit e9919eb

File tree

2 files changed

+526
-1
lines changed

2 files changed

+526
-1
lines changed

src/modules/job-list/match.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static bool match_not (struct list_constraint *c, const struct job *job)
8585
}
8686

8787
static struct list_constraint *conditional_constraint (const char *type,
88+
match_f match_or_cb,
8889
match_f match_not_cb,
8990
create_f create_cb,
9091
json_t *values,
@@ -104,7 +105,7 @@ static struct list_constraint *conditional_constraint (const char *type,
104105
if (streq (type, "and"))
105106
c->match = match_and;
106107
else if (streq (type, "or"))
107-
c->match = match_or;
108+
c->match = match_or_cb;
108109
else if (streq (type, "not"))
109110
c->match = match_not_cb;
110111
zlistx_set_destructor (c->values, list_constraint_destructor);
@@ -454,6 +455,7 @@ struct list_constraint *list_constraint_create (json_t *constraint,
454455
return create_since_constraint (values, errp);
455456
else if (streq (op, "or") || streq (op, "and") || streq (op, "not"))
456457
return conditional_constraint (op,
458+
match_or,
457459
match_not,
458460
list_constraint_create,
459461
values,
@@ -473,6 +475,22 @@ bool job_match (const struct job *job, struct list_constraint *constraint)
473475
return constraint->match (constraint, job);
474476
}
475477

478+
static bool match_or_checkempty (struct list_constraint *c, const struct job *job)
479+
{
480+
struct list_constraint *cp = zlistx_first (c->values);
481+
bool ran_a_match = false;
482+
while (cp) {
483+
if (cp->match (cp, job))
484+
return true;
485+
ran_a_match = true;
486+
cp = zlistx_next (c->values);
487+
}
488+
/* corner case: if no ops, assume this is true */
489+
if (!ran_a_match)
490+
return true;
491+
return false;
492+
}
493+
476494
static bool match_not_checkempty (struct list_constraint *c, const struct job *job)
477495
{
478496
struct list_constraint *cp = zlistx_first (c->values);
@@ -519,6 +537,7 @@ struct list_constraint *state_constraint_create (json_t *constraint,
519537
return create_states_constraint (values, errp);
520538
else if (streq (op, "or") || streq (op, "and") || streq (op, "not"))
521539
return conditional_constraint (op,
540+
match_or_checkempty,
522541
match_not_checkempty,
523542
state_constraint_create,
524543
values,

0 commit comments

Comments
 (0)