Mon 24 Mar 2008 12:37:47 AM UTC, original submission:
In the cvs 1.11.22 sources, file src/vers_ts.c, function time_stamp(), there is a block comment that appears to document how the function is intended to work. It says:
/* If it's a symlink, return whichever is the newest mtime of
the link and its target, for safety.
*/
And there is code that does both an lstat and a stat, and computes the lesser of the two modification times, e.g.
struct stat sb;
time_t mtime = 0L;
if (!CVS_LSTAT (file, &sb))
{
mtime = sb.st_mtime;
}
if (!CVS_STAT (file, &sb))
{
if (mtime < sb.st_mtime)
mtime = sb.st_mtime;
}
But the value of this computed mtime is not used in the
subsequent computations. Instead, the value of sb.st_mtime
is subsequently used.
tm_p = gmtime (&sb.st_mtime);
cp = tm_p ? asctime (tm_p) : ctime (&sb.st_mtime);
This means that the comparison of the two mtimes is not used.
The actual behavior is to use the value left in the stat buf
after stat() returns. Most of the time, this will be the
value returned by stat. The only way that sb.st_mtime can be
the value from lstat is if lstat succeeds but stat fails.
This tiny patch makes the code work the way that the comment
says it was intended to work.
- tm_p = gmtime (&sb.st_mtime);
- cp = tm_p ? asctime (tm_p) : ctime (&sb.st_mtime);
+ tm_p = gmtime (&mtime);
+ cp = tm_p ? asctime (tm_p) : ctime (&mtime);
However, it's not entirely clear to me which is the more
desirable behavior: the way the code actually works now,
or the way that the comments say it was intended to work.
|