[Cmake-commits] [cmake-commits] king committed SharedForward.h.in 1.8 1.9

cmake-commits at cmake.org cmake-commits at cmake.org
Fri Sep 26 08:24:22 EDT 2008


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

Modified Files:
	SharedForward.h.in 
Log Message:
BUG: Fix SharedForward in-tree detection

To detect when the launcher is running from the build tree we now test
if the directory containing it is the same as the build-tree directory
using an inode test instead of string comparison.  This makes it more
robust on case-insensitive filesystems and other quirky situations.


Index: SharedForward.h.in
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/kwsys/SharedForward.h.in,v
retrieving revision 1.8
retrieving revision 1.9
diff -C 2 -d -r1.8 -r1.9
*** SharedForward.h.in	26 Sep 2008 12:24:15 -0000	1.8
--- SharedForward.h.in	26 Sep 2008 12:24:20 -0000	1.9
***************
*** 160,163 ****
--- 160,164 ----
  #else
  # include <unistd.h>
+ # include <sys/stat.h>
  #endif
  
***************
*** 285,288 ****
--- 286,320 ----
  
  /*--------------------------------------------------------------------------*/
+ static int kwsys_shared_forward_samepath(const char* file1, const char* file2)
+ {
+ #if defined(_WIN32)
+   int result = 0;
+   HANDLE h1 = CreateFile(file1, GENERIC_READ, FILE_SHARE_READ, NULL,
+                          OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+   HANDLE h2 = CreateFile(file2, GENERIC_READ, FILE_SHARE_READ, NULL,
+                          OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+   if(h1 != INVALID_HANDLE_VALUE && h2 != INVALID_HANDLE_VALUE)
+     {
+     BY_HANDLE_FILE_INFORMATION fi1;
+     BY_HANDLE_FILE_INFORMATION fi2;
+     GetFileInformationByHandle(h1, &fi1);
+     GetFileInformationByHandle(h2, &fi2);
+     result = (fi1.dwVolumeSerialNumber == fi2.dwVolumeSerialNumber &&
+               fi1.nFileIndexHigh == fi2.nFileIndexHigh &&
+               fi1.nFileIndexLow == fi2.nFileIndexLow);
+     }
+    CloseHandle(h1);
+    CloseHandle(h2);
+    return result;
+ #else
+   struct stat fs1, fs2;
+   return (stat(file1, &fs1) == 0 && stat(file2, &fs2) == 0 &&
+           memcmp(&fs2.st_dev, &fs1.st_dev, sizeof(fs1.st_dev)) == 0 &&
+           memcmp(&fs2.st_ino, &fs1.st_ino, sizeof(fs1.st_ino)) == 0 &&
+           fs2.st_size == fs1.st_size);
+ #endif
+ }
+ 
+ /*--------------------------------------------------------------------------*/
  /* Function to report a system error message.  */
  static void kwsys_shared_forward_strerror(char* message)
***************
*** 536,540 ****
    /* Check whether we are running in the build tree or an install tree.  */
    if(kwsys_shared_forward_realpath(build_path, build_path_real) &&
!      strcmp(self_path_real, build_path_real) == 0)
      {
      /* Running in build tree.  Use the build path and exe.  */
--- 568,572 ----
    /* Check whether we are running in the build tree or an install tree.  */
    if(kwsys_shared_forward_realpath(build_path, build_path_real) &&
!      kwsys_shared_forward_samepath(self_path_real, build_path_real))
      {
      /* Running in build tree.  Use the build path and exe.  */



More information about the Cmake-commits mailing list