Michael Potter <mega...@gmail.com> writes:

> Ok...your definition of if_ok seems non-standard (I always understood it to
> be define X if kept *or repaired). Maybe your one should be called
> kept_or_repaired.

This was just to understand how it works, making tests.

> I am not really sure why you are getting non-convergent behavior...although
> this looks strange:
>
> cf3  -> Looking at pattern ^(smtp_host)\s+(?!smtp.example.net$).*$
>
> Why is there a $ before the closing bracket? I am not even sure what effect
> that has on the regex if not an outright error...

This match 'smtp_host' followed by one or more space followed by not
'smtp.example.net till the end of line'.

I made a mistake in a previous version of the recipe, and finish with
'smtp_host smtp.example.netsmtp.example.net'.

/^(smtp_host)\s+(?!smtp.example.net).*$/ do not match, since smtp_host is
followed by a space and smtp.example.net, the rest of the line is not
taken into account[2].

/^(smtp_host)\s+(?!smtp.example.net$)$/ does not match since after the
looking-ahead[1] expression, the pointer is just after the space (on the
's' of the first smtp.example.net) because looking-ahead do not consume
characters (zero width assertion)[3].

/^(smtp_host)\s+(?!smtp.example.net)$/ does not work since I must
replace the whole line[4].

/^(smtp_host)\s+(?!smtp.example.net$).*$/ the last $ is useless, but if
someone change the regular expression, by adding something behind the
'.*', it's explicit that it's at the end[5].

I do not look at cf code, I assumed that if the matching regexp matched
then the promise is kept, if not, a replacement is done, something like:

$match_regexp || s/$match_regexp/$replace_with/

Regards.

Footnotes: 
[1]  http://www.regular-expressions.info/lookaround.html

[2]  echo "smtp_host smtp.example.netsmtp.example.net" | perl -pi -e 
's/^(smtp_host)\s+(?!smtp.example.net).*$/$1 smtp.example.net/'

[3]  echo "smtp_host smtp.example.netsmtp.example.net" | perl -pi -e 
's/^(smtp_host)\s+(?!smtp.example.net$)$/$1 smtp.example.net/'

[4]  echo "smtp_host smtp.example.netsmtp.example.net" | perl -pi -e 
's/^(smtp_host)\s+(?!smtp.example.net)$/$1 smtp.example.net/'

[5]  echo "smtp_host smtp.example.netsmtp.example.net" | perl -pi -e 
's/^(smtp_host)\s+(?!smtp.example.net$).*$/$1 smtp.example.net/'

-- 
Daniel Dehennin
Récupérer ma clef GPG:
gpg --keyserver pgp.mit.edu --recv-keys 0x6A2540D1

Attachment: pgpAALgynPB08.pgp
Description: PGP signature

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to