The online documentation for cfengine(2) says that AccessedBefore(f1,f2) is true if f1's atime is more recent than f2's atime. It also says that ChangedBefore(f1,f2) is true if f1's ctime is more recent than f2's ctime.

In fact AccessedBefore(f1,f2) is true if f2's atime is more recent and ChangedBefore(f1,f2) is true if f2's ctime is more recent.

IsNewerThan(f1,f2) behaves as documented. It is true if f2's mtime is more recent.

However I suspect that the documentation for the *Before() functions is incorrect and that the functions themselves behave as intended, while IsNewerThan() does not behave as intended. Here's why:

The documentation says that IsGreaterThan(s1,s2) is true if s1 > s2 and that IsLessThan(s1,s2) is true if s1 < s2. Both these functions behave as documented. AccessedBefore(f1,f2) actually is true if f1 was accessed before f2. ChangedBefore(f1,f2) actually is true if f1 was changed before f2. In each of these cases, the first argument to the function fits the description provided by the function's name.

For consistency, therefore, the attached patch changes IsNewerThan() so that IsNewerThan(f1,f2) is true if f1's mtime is more recent than f2's mtime. It also changes the documentation for all three file comparison functions to match the (new) actual behaviour.
--- doc/cfengine-Reference.texinfo      (revision 623)
+++ doc/cfengine-Reference.texinfo      (working copy)
@@ -1777,7 +1777,8 @@
 AccessedBefore(@var{f1},@var{f2})
 @end smallexample 
 
-True if file 1 was accessed more recently than file 2 (UNIX atime)
+True if file 2 was accessed more recently than file 1 (UNIX atime), ie file 1 
+was Accessed Before file 2.
 
 @node ChangedBefore, ClassMatch, AccessedBefore, Cfengine classes
 @subsection ChangedBefore
@@ -1785,7 +1786,7 @@
 @smallexample 
 ChangedBefore(@var{f1},@var{f2})
 @end smallexample 
-True if file 1's attributes were changed in any way more recently than file 
2's (UNIX ctime)
+True if file 2's attributes were changed in any way more recently than file 
1's (UNIX ctime), ie file 1 was Changed Before file 2.
 
 @node ClassMatch, FileExists, ChangedBefore, Cfengine classes
 @subsection ClassMatch
@@ -1868,7 +1869,8 @@
 @smallexample 
 IsNewerThan(@var{f1},@var{f2})
 @end smallexample 
-True if file 2 was modified more recently than file 1 (UNIX mtime)
+True if file 1 was modified more recently than file 2 (UNIX mtime), ie file 1 
+Is Newer Than file2.
 
 @node IPRange, PrepModule, IsNewerThan, Cfengine classes
 @subsection IPRange
--- src/functions.c     (revision 623)
+++ src/functions.c     (working copy)
@@ -509,7 +509,7 @@
 switch(fn)
    {
    case fn_newerthan:
-       if (frombuf.st_mtime < tobuf.st_mtime)
+       if (frombuf.st_mtime > tobuf.st_mtime)
           {
           strcpy(value,CF_ANYCLASS);
           return;
_______________________________________________
Bug-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/bug-cfengine

Reply via email to