summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2008-09-26 12:24:20 (GMT)
committerBrad King <brad.king@kitware.com>2008-09-26 12:24:20 (GMT)
commit014f684317ec67cabc4ee70a6f9e576c0d395834 (patch)
tree3aa1141421a489286bb59b710ae27868451aa1c7 /Source
parent97c7c86898cde67d60d445fe3f6006544ebe5ea2 (diff)
downloadCMake-014f684317ec67cabc4ee70a6f9e576c0d395834.zip
CMake-014f684317ec67cabc4ee70a6f9e576c0d395834.tar.gz
CMake-014f684317ec67cabc4ee70a6f9e576c0d395834.tar.bz2
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.
Diffstat (limited to 'Source')
-rw-r--r--Source/kwsys/SharedForward.h.in34
1 files changed, 33 insertions, 1 deletions
diff --git a/Source/kwsys/SharedForward.h.in b/Source/kwsys/SharedForward.h.in
index 388470d..e2be6c9 100644
--- a/Source/kwsys/SharedForward.h.in
+++ b/Source/kwsys/SharedForward.h.in
@@ -159,6 +159,7 @@
# include <process.h>
#else
# include <unistd.h>
+# include <sys/stat.h>
#endif
/*--------------------------------------------------------------------------*/
@@ -284,6 +285,37 @@ static int kwsys_shared_forward_realpath(const char* in_path, char* out_path)
}
/*--------------------------------------------------------------------------*/
+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)
{
@@ -535,7 +567,7 @@ static int kwsys_shared_forward_get_settings(const char* self_path,
/* 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)
+ kwsys_shared_forward_samepath(self_path_real, build_path_real))
{
/* Running in build tree. Use the build path and exe. */
search_path = search_path_build;