BUG: Automatic pwd/cwd path translation must check that the generated logical-to-physical mapping is correct by using realpath.
This commit is contained in:
parent
b0d05cf020
commit
93efb1cf5b
@ -3672,37 +3672,35 @@ void SystemTools::ClassInitialize()
|
|||||||
char buf[2048];
|
char buf[2048];
|
||||||
if(const char* cwd = Getcwd(buf, 2048))
|
if(const char* cwd = Getcwd(buf, 2048))
|
||||||
{
|
{
|
||||||
|
// The current working directory may be a logical path. Find
|
||||||
|
// the shortest logical path that still produces the correct
|
||||||
|
// physical path.
|
||||||
|
kwsys_stl::string cwd_changed;
|
||||||
|
kwsys_stl::string pwd_changed;
|
||||||
|
|
||||||
|
// Test progressively shorter logical-to-physical mappings.
|
||||||
|
kwsys_stl::string pwd_str = pwd;
|
||||||
|
kwsys_stl::string cwd_str = cwd;
|
||||||
kwsys_stl::string pwd_path;
|
kwsys_stl::string pwd_path;
|
||||||
Realpath(pwd, pwd_path);
|
Realpath(pwd, pwd_path);
|
||||||
if(cwd == pwd_path && strcmp(cwd, pwd) != 0)
|
while(cwd_str == pwd_path && cwd_str != pwd_str)
|
||||||
{
|
{
|
||||||
// The current working directory is a logical path. Split
|
// The current pair of paths is a working logical mapping.
|
||||||
// both the logical and physical paths into their components.
|
cwd_changed = cwd_str;
|
||||||
kwsys_stl::vector<kwsys_stl::string> cwd_components;
|
pwd_changed = pwd_str;
|
||||||
kwsys_stl::vector<kwsys_stl::string> pwd_components;
|
|
||||||
SystemTools::SplitPath(cwd, cwd_components);
|
|
||||||
SystemTools::SplitPath(pwd, pwd_components);
|
|
||||||
|
|
||||||
// Remove the common ending of the paths to leave only the
|
// Strip off one directory level and see if the logical
|
||||||
// part that changes under the logical mapping.
|
// mapping still works.
|
||||||
kwsys_stl::vector<kwsys_stl::string>::iterator ic = cwd_components.end();
|
pwd_str = SystemTools::GetFilenamePath(pwd_str.c_str());
|
||||||
kwsys_stl::vector<kwsys_stl::string>::iterator ip = pwd_components.end();
|
cwd_str = SystemTools::GetFilenamePath(cwd_str.c_str());
|
||||||
for(;ip != pwd_components.begin() && ic != cwd_components.begin() &&
|
Realpath(pwd_str.c_str(), pwd_path);
|
||||||
*(ip-1) == *(ic-1); --ip,--ic);
|
}
|
||||||
cwd_components.erase(ic, cwd_components.end());
|
|
||||||
pwd_components.erase(ip, pwd_components.end());
|
|
||||||
|
|
||||||
// Reconstruct the string versions of the part of the path
|
// Add the translation to keep the logical path name.
|
||||||
// that changed.
|
if(!cwd_changed.empty() && !pwd_changed.empty())
|
||||||
kwsys_stl::string cwd_changed = SystemTools::JoinPath(cwd_components);
|
{
|
||||||
kwsys_stl::string pwd_changed = SystemTools::JoinPath(pwd_components);
|
SystemTools::AddTranslationPath(cwd_changed.c_str(),
|
||||||
|
pwd_changed.c_str());
|
||||||
// Add the translation to keep the logical path name.
|
|
||||||
if(!cwd_changed.empty() && !pwd_changed.empty())
|
|
||||||
{
|
|
||||||
SystemTools::AddTranslationPath(cwd_changed.c_str(),
|
|
||||||
pwd_changed.c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user