CPack handle symlinks in CPACK_INSTALLED_DIRECTORIES fix for bug5430

The proposed solution is to avoid to CopyIfDifferent any links
found in CPACK_INSTALLED_DIRECTORIES but memorize them instead
then at the end of the processing for each dir do re-create the
link in the installed tree.
Current patch should work if the link are "local" to the directory.
This commit is contained in:
Eric NOULARD 2010-08-28 16:50:06 +02:00
parent 216aa24d92
commit 013e0039ee
1 changed files with 43 additions and 1 deletions

View File

@ -329,6 +329,7 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories(
it != installDirectoriesVector.end();
++it )
{
std::list<std::pair<std::string,std::string> > symlinkedFiles;
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
cmsys::Glob gl;
std::string top = it->c_str();
@ -372,7 +373,18 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories(
+ cmSystemTools::RelativePath(top.c_str(), gfit->c_str());
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy file: "
<< inFile.c_str() << " -> " << filePath.c_str() << std::endl);
if ( !cmSystemTools::CopyFileIfDifferent(inFile.c_str(),
/* If the file is a symlink we will have to re-create it */
if ( cmSystemTools::FileIsSymlink(inFile.c_str()))
{
std::string targetFile;
std::string inFileRelative =
cmSystemTools::RelativePath(top.c_str(),inFile.c_str());
cmSystemTools::ReadSymlink(inFile.c_str(),targetFile);
symlinkedFiles.push_back(std::pair<std::string,
std::string>(targetFile,inFileRelative));
}
/* If it is not a symlink then do a plain copy */
else if ( !cmSystemTools::CopyFileIfDifferent(inFile.c_str(),
filePath.c_str()) )
{
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying file: "
@ -380,6 +392,36 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories(
return 0;
}
}
/* rebuild symlinks in the installed tree */
if (symlinkedFiles.size()>0)
{
std::list< std::pair<std::string,std::string> >::iterator symlinkedIt;
std::string curDir = cmSystemTools::GetCurrentWorkingDirectory();
std::string goToDir = tempDir;
goToDir += "/"+subdir;
cmCPackLogger(cmCPackLog::LOG_DEBUG,
"Change dir to: " << goToDir <<std::endl);
cmSystemTools::ChangeDirectory(goToDir.c_str());
for (symlinkedIt=symlinkedFiles.begin();
symlinkedIt != symlinkedFiles.end();
++symlinkedIt)
{
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Will create a symlink: "
<< symlinkedIt->second << "--> "
<< symlinkedIt->first << std::endl);
if (!cmSystemTools::CreateSymlink((symlinkedIt->first).c_str(),
(symlinkedIt->second).c_str()))
{
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot create symlink: "
<< symlinkedIt->second << "--> "
<< symlinkedIt->first << std::endl);
return 0;
}
}
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Going back to: "
<< curDir <<std::endl);
cmSystemTools::ChangeDirectory(curDir.c_str());
}
}
}
return 1;