BUG: fix for bug number 3320

This commit is contained in:
Ken Martin 2007-02-01 14:11:06 -05:00
parent 0b4bd97210
commit 3dd4a53d97
1 changed files with 34 additions and 4 deletions

View File

@ -2513,6 +2513,8 @@ void SystemTools::AddTranslationPath(const char * a, const char * b)
if( SystemTools::FileIsDirectory( path_a.c_str() ) ) if( SystemTools::FileIsDirectory( path_a.c_str() ) )
{ {
// Make sure the path is a full path and does not contain no '..' // Make sure the path is a full path and does not contain no '..'
// Ken--the following code is incorrect. .. can be in a valid path
// for example /home/martink/MyHubba...Hubba/Src
if( SystemTools::FileIsFullPath(path_b.c_str()) && path_b.find("..") if( SystemTools::FileIsFullPath(path_b.c_str()) && path_b.find("..")
== kwsys_stl::string::npos ) == kwsys_stl::string::npos )
{ {
@ -2605,6 +2607,9 @@ kwsys_stl::string SystemTools::CollapseFullPath(const char* in_path,
// Split the input path components. // Split the input path components.
kwsys_stl::vector<kwsys_stl::string> path_components; kwsys_stl::vector<kwsys_stl::string> path_components;
SystemTools::SplitPath(in_path, path_components); SystemTools::SplitPath(in_path, path_components);
// clean the input path to remove any /./
// If the input path is relative, start with a base path. // If the input path is relative, start with a base path.
if(path_components[0].length() == 0) if(path_components[0].length() == 0)
{ {
@ -2640,11 +2645,36 @@ kwsys_stl::string SystemTools::CollapseFullPath(const char* in_path,
path_components.begin(), path_components.begin(),
path_components.end()); path_components.end());
// Transform the path back to a string. // remove any . components as they do nothing
kwsys_stl::string newPath = SystemTools::JoinPath(out_components); kwsys_stl::vector<kwsys_stl::string> clean_components;
kwsys_stl::vector<kwsys_stl::string>::iterator i =
out_components.begin();
for (; i != out_components.end(); ++i)
{
if (*i != ".")
{
clean_components.push_back(*i);
}
}
// Transform the path back to a string.
kwsys_stl::string newPath = SystemTools::JoinPath(clean_components);
// Update the translation table with this potentially new path. I am not
// sure why this line is here, it seems really questionable, but yet I
// would put good money that if I remove it something will break, basically
// from what I can see it created a mapping from the collapsed path, to be
// replaced by the input path, which almost completely does the opposite of
// this function, the only thing preventing this from happening a lot is
// that if the in_path has a .. in it, then it is not added to the
// translation table. So for most calls this either does nothing due to the
// .. or it adds a translation between identical paths as nothing was
// collapsed, so I am going to try to comment it out, and see what hits the
// fan, hopefully quickly.
// Commented out line below:
//SystemTools::AddTranslationPath(newPath.c_str(), in_path);
// Update the translation table with this potentially new path.
SystemTools::AddTranslationPath(newPath.c_str(), in_path);
SystemTools::CheckTranslationPath(newPath); SystemTools::CheckTranslationPath(newPath);
#ifdef _WIN32 #ifdef _WIN32
newPath = SystemTools::GetActualCaseForPath(newPath.c_str()); newPath = SystemTools::GetActualCaseForPath(newPath.c_str());