[cmake-commits] king committed cmFileTimeComparison.cxx 1.6 1.7 cmFileTimeComparison.h 1.2 1.3

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Jan 3 00:01:40 EST 2008


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv956/Source

Modified Files:
	cmFileTimeComparison.cxx cmFileTimeComparison.h 
Log Message:
ENH: Add method cmFileTimeComparison::FileTimesDiffer to check if file times differ by 1 second or more.


Index: cmFileTimeComparison.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileTimeComparison.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cmFileTimeComparison.h	15 Mar 2006 16:02:01 -0000	1.2
+++ cmFileTimeComparison.h	3 Jan 2008 05:01:38 -0000	1.3
@@ -40,6 +40,12 @@
    */
   bool FileTimeCompare(const char* f1, const char* f2, int* result);
 
+  /**
+   *  Compare file modification times.  Return true unless both files
+   *  exist and have modification times less than 1 second apart.
+   */
+  bool FileTimesDiffer(const char* f1, const char* f2);
+
 protected:
   
   cmFileTimeComparisonInternal* Internals;

Index: cmFileTimeComparison.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileTimeComparison.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- cmFileTimeComparison.cxx	10 May 2006 19:46:45 -0000	1.6
+++ cmFileTimeComparison.cxx	3 Jan 2008 05:01:38 -0000	1.7
@@ -38,6 +38,8 @@
   // Internal comparison method.
   inline bool FileTimeCompare(const char* f1, const char* f2, int* result);
 
+  bool FileTimesDiffer(const char* f1, const char* f2);
+
 private:
 #if defined(CMAKE_BUILD_WITH_CMAKE)
   // Use a hash table to efficiently map from file name to modification time.
@@ -59,6 +61,8 @@
   inline bool Stat(const char* fname, cmFileTimeComparison_Type* st);
   inline int Compare(cmFileTimeComparison_Type* st1,
                      cmFileTimeComparison_Type* st2);
+  inline bool TimesDiffer(cmFileTimeComparison_Type* st1,
+                          cmFileTimeComparison_Type* st2);
 };
 
 //----------------------------------------------------------------------------
@@ -124,6 +128,12 @@
 }
 
 //----------------------------------------------------------------------------
+bool cmFileTimeComparison::FileTimesDiffer(const char* f1, const char* f2)
+{
+  return this->Internals->FileTimesDiffer(f1, f2);
+}
+
+//----------------------------------------------------------------------------
 int cmFileTimeComparisonInternal::Compare(cmFileTimeComparison_Type* s1, 
                                           cmFileTimeComparison_Type* s2)
 {
@@ -166,6 +176,66 @@
 }
 
 //----------------------------------------------------------------------------
+bool cmFileTimeComparisonInternal::TimesDiffer(cmFileTimeComparison_Type* s1,
+                                               cmFileTimeComparison_Type* s2)
+{
+#if !defined(_WIN32) || defined(__CYGWIN__)
+# if cmsys_STAT_HAS_ST_MTIM
+  // Times are integers in units of 1ns.
+  long long bil = 1000000000;
+  long long t1 = s1->st_mtim.tv_sec * bil + s1->st_mtim.tv_nsec;
+  long long t2 = s2->st_mtim.tv_sec * bil + s2->st_mtim.tv_nsec;
+  if(t1 < t2)
+    {
+    return (t2 - t1) >= bil;
+    }
+  else if(t2 < t1)
+    {
+    return (t1 - t2) >= bil;
+    }
+  else
+    {
+    return false;
+    }
+# else
+  // Times are integers in units of 1s.
+  if(s1->st_mtime < s2->st_mtime)
+    {
+    return (s2->st_mtime - s1->st_mtime) >= 1;
+    }
+  else if(s1->st_mtime > s2->st_mtime)
+    {
+    return (s1->st_mtime - s2->st_mtime) >= 1;
+    }
+  else
+    {
+    return false;
+    }
+# endif
+#else
+  // Times are integers in units of 100ns.
+  LARGE_INTEGER t1;
+  LARGE_INTEGER t2;
+  t1.LowPart = s1->dwLowDateTime;
+  t1.HighPart = s1->dwHighDateTime;
+  t2.LowPart = s2->dwLowDateTime;
+  t2.HighPart = s2->dwHighDateTime;
+  if(t1.QuadPart < t2.QuadPart)
+    {
+    return (t2.QuadPart - t1.QuadPart) >= static_cast<LONGLONG>(10000000);
+    }
+  else if(t2.QuadPart < t1.QuadPart)
+    {
+    return (t1.QuadPart - t2.QuadPart) >= static_cast<LONGLONG>(10000000);
+    }
+  else
+    {
+    return false;
+    }
+#endif
+}
+
+//----------------------------------------------------------------------------
 bool cmFileTimeComparisonInternal::FileTimeCompare(const char* f1,
                                                    const char* f2,
                                                    int* result)
@@ -187,3 +257,23 @@
     return false;
     }
 }
+
+//----------------------------------------------------------------------------
+bool cmFileTimeComparisonInternal::FileTimesDiffer(const char* f1,
+                                                   const char* f2)
+{
+  // Get the modification time for each file.
+  cmFileTimeComparison_Type s1;
+  cmFileTimeComparison_Type s2;
+  if(this->Stat(f1, &s1) &&
+     this->Stat(f2, &s2))
+    {
+    // Compare the two modification times.
+    return this->TimesDiffer(&s1, &s2);
+    }
+  else
+    {
+    // No comparison available.  Default to different times.
+    return true;
+    }
+}



More information about the Cmake-commits mailing list