Merge topic 'update-kwsys'

26656865 Merge branch 'upstream-kwsys' into update-kwsys
5e2b418f KWSys 2015-02-25 (1b75ad3d)
This commit is contained in:
Brad King 2015-02-27 10:34:31 -05:00 committed by CMake Topic Stage
commit ee81de5ec3
3 changed files with 59 additions and 30 deletions

View File

@ -223,7 +223,6 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
return; return;
} }
unsigned long cc; unsigned long cc;
kwsys_stl::string fullname;
kwsys_stl::string realname; kwsys_stl::string realname;
kwsys_stl::string fname; kwsys_stl::string fname;
for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ ) for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ )
@ -248,15 +247,6 @@ void Glob::RecurseDirectory(kwsys_stl::string::size_type start,
fname = kwsys::SystemTools::LowerCase(fname); fname = kwsys::SystemTools::LowerCase(fname);
#endif #endif
if ( start == 0 )
{
fullname = dir + fname;
}
else
{
fullname = dir + "/" + fname;
}
bool isDir = kwsys::SystemTools::FileIsDirectory(realname); bool isDir = kwsys::SystemTools::FileIsDirectory(realname);
bool isSymLink = kwsys::SystemTools::FileIsSymlink(realname); bool isSymLink = kwsys::SystemTools::FileIsSymlink(realname);
@ -302,7 +292,6 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
return; return;
} }
unsigned long cc; unsigned long cc;
kwsys_stl::string fullname;
kwsys_stl::string realname; kwsys_stl::string realname;
kwsys_stl::string fname; kwsys_stl::string fname;
for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ ) for ( cc = 0; cc < d.GetNumberOfFiles(); cc ++ )
@ -327,19 +316,10 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
fname = kwsys::SystemTools::LowerCase(fname); fname = kwsys::SystemTools::LowerCase(fname);
#endif #endif
if ( start == 0 )
{
fullname = dir + fname;
}
else
{
fullname = dir + "/" + fname;
}
//kwsys_ios::cout << "Look at file: " << fname << kwsys_ios::endl; //kwsys_ios::cout << "Look at file: " << fname << kwsys_ios::endl;
//kwsys_ios::cout << "Match: " //kwsys_ios::cout << "Match: "
// << this->Internals->TextExpressions[start].c_str() << kwsys_ios::endl; // << this->Internals->TextExpressions[start].c_str() << kwsys_ios::endl;
//kwsys_ios::cout << "Full name: " << fullname << kwsys_ios::endl; //kwsys_ios::cout << "Real name: " << realname << kwsys_ios::endl;
if ( !last && if ( !last &&
!kwsys::SystemTools::FileIsDirectory(realname) ) !kwsys::SystemTools::FileIsDirectory(realname) )
@ -355,7 +335,7 @@ void Glob::ProcessDirectory(kwsys_stl::string::size_type start,
} }
else else
{ {
this->ProcessDirectory(start+1, realname + "/"); this->ProcessDirectory(start+1, realname);
} }
} }
} }

View File

@ -250,17 +250,46 @@ inline int Chdir(const kwsys_stl::string& dir)
return _wchdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str()); return _wchdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str());
#endif #endif
} }
inline void Realpath(const kwsys_stl::string& path, kwsys_stl::string & resolved_path) inline void Realpath(const kwsys_stl::string& path,
kwsys_stl::string& resolved_path,
kwsys_stl::string* errorMessage = 0)
{ {
kwsys_stl::wstring tmp = KWSYS_NAMESPACE::Encoding::ToWide(path); kwsys_stl::wstring tmp = KWSYS_NAMESPACE::Encoding::ToWide(path);
wchar_t *ptemp; wchar_t *ptemp;
wchar_t fullpath[MAX_PATH]; wchar_t fullpath[MAX_PATH];
if( GetFullPathNameW(tmp.c_str(), sizeof(fullpath)/sizeof(fullpath[0]), DWORD bufferLen = GetFullPathNameW(tmp.c_str(),
fullpath, &ptemp) ) sizeof(fullpath) / sizeof(fullpath[0]),
fullpath, &ptemp);
if( bufferLen < sizeof(fullpath)/sizeof(fullpath[0]) )
{ {
resolved_path = KWSYS_NAMESPACE::Encoding::ToNarrow(fullpath); resolved_path = KWSYS_NAMESPACE::Encoding::ToNarrow(fullpath);
KWSYS_NAMESPACE::SystemTools::ConvertToUnixSlashes(resolved_path); KWSYS_NAMESPACE::SystemTools::ConvertToUnixSlashes(resolved_path);
} }
else if(errorMessage)
{
if(bufferLen)
{
*errorMessage = "Destination path buffer size too small.";
}
else if(unsigned int errorId = GetLastError())
{
LPSTR message = NULL;
DWORD size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorId,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&message, 0, NULL);
*errorMessage = std::string(message, size);
LocalFree(message);
}
else
{
*errorMessage = "Unknown error.";
}
resolved_path = "";
}
else else
{ {
resolved_path = path; resolved_path = path;
@ -287,15 +316,31 @@ inline int Chdir(const kwsys_stl::string& dir)
{ {
return chdir(dir.c_str()); return chdir(dir.c_str());
} }
inline void Realpath(const kwsys_stl::string& path, kwsys_stl::string & resolved_path) inline void Realpath(const kwsys_stl::string& path,
kwsys_stl::string& resolved_path,
kwsys_stl::string* errorMessage = 0)
{ {
char resolved_name[KWSYS_SYSTEMTOOLS_MAXPATH]; char resolved_name[KWSYS_SYSTEMTOOLS_MAXPATH];
errno = 0;
char *ret = realpath(path.c_str(), resolved_name); char *ret = realpath(path.c_str(), resolved_name);
if(ret) if(ret)
{ {
resolved_path = ret; resolved_path = ret;
} }
else if(errorMessage)
{
if(errno)
{
*errorMessage = strerror(errno);
}
else
{
*errorMessage = "Unknown error.";
}
resolved_path = "";
}
else else
{ {
// if path resolution fails, return what was passed in // if path resolution fails, return what was passed in
@ -3046,10 +3091,11 @@ kwsys_stl::string SystemTools
return ""; return "";
} }
kwsys_stl::string SystemTools::GetRealPath(const kwsys_stl::string& path) kwsys_stl::string SystemTools::GetRealPath(const kwsys_stl::string& path,
kwsys_stl::string* errorMessage)
{ {
kwsys_stl::string ret; kwsys_stl::string ret;
Realpath(path, ret); Realpath(path, ret, errorMessage);
return ret; return ret;
} }

View File

@ -385,9 +385,12 @@ public:
/** /**
* Get the real path for a given path, removing all symlinks. In * Get the real path for a given path, removing all symlinks. In
* the event of an error (non-existent path, permissions issue, * the event of an error (non-existent path, permissions issue,
* etc.) the original path is returned. * etc.) the original path is returned if errorMessage pointer is
* NULL. Otherwise empty string is returned and errorMessage
* contains error description.
*/ */
static kwsys_stl::string GetRealPath(const kwsys_stl::string& path); static kwsys_stl::string GetRealPath(const kwsys_stl::string& path,
kwsys_stl::string* errorMessage = 0);
/** /**
* Split a path name into its root component and the rest of the * Split a path name into its root component and the rest of the