From 3dd4a53d97e8b4726c732e39b67df1c0eb2cc7eb Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Thu, 1 Feb 2007 14:11:06 -0500 Subject: [PATCH] BUG: fix for bug number 3320 --- Source/kwsys/SystemTools.cxx | 38 ++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 8df1a65a6..1a5a42164 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -2513,6 +2513,8 @@ void SystemTools::AddTranslationPath(const char * a, const char * b) if( SystemTools::FileIsDirectory( path_a.c_str() ) ) { // 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("..") == kwsys_stl::string::npos ) { @@ -2605,6 +2607,9 @@ kwsys_stl::string SystemTools::CollapseFullPath(const char* in_path, // Split the input path components. kwsys_stl::vector 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(path_components[0].length() == 0) { @@ -2640,11 +2645,36 @@ kwsys_stl::string SystemTools::CollapseFullPath(const char* in_path, path_components.begin(), path_components.end()); - // Transform the path back to a string. - kwsys_stl::string newPath = SystemTools::JoinPath(out_components); + // remove any . components as they do nothing + kwsys_stl::vector clean_components; + kwsys_stl::vector::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); #ifdef _WIN32 newPath = SystemTools::GetActualCaseForPath(newPath.c_str());