Browse Source

BUG: Fix GetRealPath when realpath fails

This patch from Philip Lowman teaches SystemTools::GetRealPath to deal
with paths that do not exist by dealing with the case that realpath
returns NULL.  See issue #8423.
Brad King 16 years ago
parent
commit
ca096a4596
2 changed files with 17 additions and 3 deletions
  1. 14 2
      Source/kwsys/SystemTools.cxx
  2. 3 1
      Source/kwsys/SystemTools.hxx.in

+ 14 - 2
Source/kwsys/SystemTools.cxx

@@ -205,6 +205,10 @@ inline void Realpath(const char *path, kwsys_stl::string & resolved_path)
     resolved_path = fullpath;
     KWSYS_NAMESPACE::SystemTools::ConvertToUnixSlashes(resolved_path);
     }
+  else
+    {
+    resolved_path = path;
+    }
 }
 #else
 #include <sys/types.h>
@@ -237,8 +241,16 @@ inline void Realpath(const char *path, kwsys_stl::string & resolved_path)
 {
   char resolved_name[KWSYS_SYSTEMTOOLS_MAXPATH];
 
-  realpath(path, resolved_name);
-  resolved_path = resolved_name;
+  char *ret = realpath(path, resolved_name);
+  if(ret)
+    {
+    resolved_path = ret;
+    }
+  else
+    {
+    // if path resolution fails, return what was passed in
+    resolved_path = path;
+    }
 }
 #endif
 

+ 3 - 1
Source/kwsys/SystemTools.hxx.in

@@ -351,7 +351,9 @@ public:
                                             const char* in_base);
 
   /** 
-   * Get the real path for a given path, removing all symlinks.
+   * Get the real path for a given path, removing all symlinks.  In
+   * the event of an error (non-existent path, permissions issue,
+   * etc.) the original path is returned.
    */
   static kwsys_stl::string GetRealPath(const char* path);