* This won't work:
editfiles:
{
/path/to/file
ReplaceAll "bad text" With ""
}
cfagent will say "ReplaceAll without With" because the replacement
text is empty. The solution is to do this:
control:
empty = ( "" )
editfiles:
{
/path/to/file
ReplaceAll "bad text" With "$(empty)"
}
It might be helpful to have $(empty) as a special variable for this
case. Patch attached if you agree that this could be beneficial.
* The following doesn't work:
control:
ActionSequence = ( editfiles )
editfiles:
{
/path/to/file
EditMode "Binary"
ReplaceAll "string" With "string"
}
cfagent says "Search and replace patterns are identical in binary
edit /path/to/file" in a loop forever.
This works correctly if EditMode is not "Binary". In this case
cfagent will note that "Replacement matches search string and will
thus replace every time - edit was not done" and skip the replacement.
* The following works if the file is an ASCII file but not if it is a
binary file:
control:
ActionSequence = ( editfiles )
editfiles:
{
/path/to/file
EditMode "Binary"
ReplaceAll "string" With "strung"
}
For example:
# echo string > /path/to/file
# cfagent
# cat /path/to/file
strung
# cat << EOF > testcase.c
#include <stdio.h>
int main() { printf("string\n"); }
EOF
# gcc -o /path/to/file testcase.c
# cfagent
# /path/to/file | sed -n l
string$
This appears to be because cfagent is getting confused with the
requirement that the replacement string be at most the same length as
the search string. The following works:
control:
ActionSequence = ( editfiles )
editfiles:
{
/path/to/file
EditMode "Binary"
ReplaceAll "string" with "strun"
}
With the same testcase.c as above:
# gcc -o /path/to/file testcase.c
# cfagent
# /path/to/file | sed -n l
strun $
--- cfengine-2.2.3/src/cf.defs.h.orig 2008-02-14 10:37:50.644036000 +0000
+++ cfengine-2.2.3/src/cf.defs.h 2008-02-14 15:55:23.055946000 +0000
@@ -988,6 +988,7 @@
cfcr,
cfn,
cfdblquote,
+ cfempty,
cfcolon,
cfquote,
cfdollar,
--- cfengine-2.2.3/src/varstring.c.orig 2008-02-14 10:36:48.634870000 +0000
+++ cfengine-2.2.3/src/varstring.c 2008-02-14 15:55:16.342227000 +0000
@@ -79,6 +79,7 @@
"cr",
"n",
"dblquote",
+ "empty",
"colon",
"quote",
"dollar",
@@ -748,6 +749,10 @@
break;
+ case cfempty:
+ /* NOP */
+ break;
+
case cfdollar:
if (!PARSING)
_______________________________________________
Bug-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/bug-cfengine