ENH: Added FileTimeCompare method to compare file modification times. Currently the resolution is limited to one second.
This commit is contained in:
parent
4b20a7ad2d
commit
b4176dcab9
@ -1317,3 +1317,33 @@ bool cmSystemTools::PutEnv(const char* value)
|
||||
return ret == 0;
|
||||
}
|
||||
|
||||
bool cmSystemTools::FileTimeCompare(const char* f1, const char* f2,
|
||||
int* result)
|
||||
{
|
||||
struct stat stat1, stat2;
|
||||
if(stat(f1, &stat1) == 0 && stat(f2, &stat2) == 0)
|
||||
{
|
||||
*result = 0;
|
||||
if(stat1.st_mtime < stat2.st_mtime)
|
||||
{
|
||||
*result = -1;
|
||||
}
|
||||
else if(stat1.st_mtime > stat2.st_mtime)
|
||||
{
|
||||
*result = 1;
|
||||
}
|
||||
#if 0
|
||||
// TODO: Support resolution higher than one second.
|
||||
// Use st_mtim.tv_nsec if available and GetFileTime on Windows.
|
||||
else if(stat1.st_mtim.tv_nsec < stat2.st_mtim.tv_nsec)
|
||||
{
|
||||
*result = 1;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -290,6 +290,12 @@ public:
|
||||
of the form var=value */
|
||||
static bool PutEnv(const char* value);
|
||||
|
||||
/** Compare file modification times.
|
||||
Returns true for successful comparison and false for error.
|
||||
When true is returned, result has -1, 0, +1 for
|
||||
f1 older, same, or newer than f2. */
|
||||
static bool FileTimeCompare(const char* f1, const char* f2,
|
||||
int* result);
|
||||
private:
|
||||
static bool s_ForceUnixPaths;
|
||||
static bool s_RunCommandHideConsole;
|
||||
|
Loading…
x
Reference in New Issue
Block a user