From ca096a4596c8993cbadd5fc6e612ac349db6355c Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 9 Feb 2009 09:23:13 -0500 Subject: 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. --- Source/kwsys/SystemTools.cxx | 16 ++++++++++++++-- Source/kwsys/SystemTools.hxx.in | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 65f6259..a46cc5b 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/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 @@ -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 diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index b092764..07118c2 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/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); -- cgit v0.12