condition: change operator logic to use $= instead of =$ for glob comparisons

So this is a bit of a bikeshedding thing. But I think we should do this
nonetheless, before this is released.

Playing around with the glob matches I realized that "=$" is really hard
to grep for, since in shell code it's an often seen construct. Also,
when reading code I often found myself thinking first that the "$"
belongs to the rvalue instead of the operator, in a variable expansion
scheme.

If we move the $ character to the left hand, I think we are on the safer
side, since usually lvalues are much more restricted in character sets
than rvalues (at least most programming languages do enforce limits on
the character set for identifiers).

It makes it much easier to grep for the new operator, and easier to read
too. Example:

before:
    ConditionOSRelease=ID=$fedora-*
after:
    ConditionOSRelease=ID$=fedora-*
This commit is contained in:
Lennart Poettering
2022-09-01 23:16:13 +02:00
parent 06219747f5
commit 71a3ff036b
3 changed files with 14 additions and 14 deletions
+2 -2
View File
@@ -12,8 +12,8 @@ CompareOperator parse_compare_operator(const char **s, CompareOperatorParseFlags
CompareOperatorParseFlags valid_mask; /* If this operator appears when flags in mask not set, fail */
CompareOperatorParseFlags need_mask; /* Skip over this operattor when flags in mask not set */
} table[] = {
{ COMPARE_FNMATCH_EQUAL, "=$", .valid_mask = COMPARE_ALLOW_FNMATCH },
{ COMPARE_FNMATCH_UNEQUAL, "!=$", .valid_mask = COMPARE_ALLOW_FNMATCH },
{ COMPARE_FNMATCH_EQUAL, "$=", .valid_mask = COMPARE_ALLOW_FNMATCH },
{ COMPARE_FNMATCH_UNEQUAL, "!$=", .valid_mask = COMPARE_ALLOW_FNMATCH },
{ COMPARE_UNEQUAL, "<>" },
{ COMPARE_LOWER_OR_EQUAL, "<=" },