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.
This commit is contained in:
parent
67ddd0c837
commit
ca096a4596
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue