[cmake-commits] king committed cmFileCommand.cxx 1.74 1.75
cmake-commits at cmake.org
cmake-commits at cmake.org
Mon Mar 12 13:15:27 EST 2007
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv22961
Modified Files:
cmFileCommand.cxx
Log Message:
BUG: Preserve symlinks during installation. This addresses bug#4384.
Index: cmFileCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileCommand.cxx,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- cmFileCommand.cxx 2 Mar 2007 15:48:58 -0000 1.74
+++ cmFileCommand.cxx 12 Mar 2007 18:15:25 -0000 1.75
@@ -474,9 +474,65 @@
}
return true;
}
+
+private:
+ bool InstallSymlink(const char* fromFile, const char* toFile, bool always);
};
//----------------------------------------------------------------------------
+bool cmFileInstaller::InstallSymlink(const char* fromFile, const char* toFile,
+ bool always)
+{
+ // Inform the user about this file installation.
+ std::string message = "Installing ";
+ message += toFile;
+ this->Makefile->DisplayStatus(message.c_str(), -1);
+
+ // Read the original symlink.
+ std::string symlinkTarget;
+ if(!cmSystemTools::ReadSymlink(fromFile, symlinkTarget))
+ {
+ cmOStringStream e;
+ e << "INSTALL cannot read symlink \"" << fromFile
+ << "\" to duplicate at \"" << toFile << "\".";
+ this->FileCommand->SetError(e.str().c_str());
+ return false;
+ }
+
+ // Compare the symlink value to that at the destination if not
+ // always installing.
+ if(!always)
+ {
+ std::string oldSymlinkTarget;
+ if(cmSystemTools::ReadSymlink(toFile, oldSymlinkTarget))
+ {
+ if(symlinkTarget == oldSymlinkTarget)
+ {
+ return true;
+ }
+ }
+ }
+
+ // Remove the destination file so we can always create the symlink.
+ cmSystemTools::RemoveFile(toFile);
+
+ // Create the symlink.
+ if(!cmSystemTools::CreateSymlink(symlinkTarget.c_str(), toFile))
+ {
+ cmOStringStream e;
+ e << "INSTALL cannot duplicate symlink \"" << fromFile
+ << "\" at \"" << toFile << "\".";
+ this->FileCommand->SetError(e.str().c_str());
+ return false;
+ }
+
+ // Add the file to the manifest.
+ this->ManifestAppend(toFile);
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
bool cmFileInstaller::InstallFile(const char* fromFile, const char* toFile,
bool always)
{
@@ -489,6 +545,12 @@
return true;
}
+ // Short-circuit for symbolic links.
+ if(cmSystemTools::FileIsSymlink(fromFile))
+ {
+ return this->InstallSymlink(fromFile, toFile, always);
+ }
+
// Inform the user about this file installation.
std::string message = "Installing ";
message += toFile;
@@ -541,6 +603,12 @@
return true;
}
+ // Short-circuit for symbolic links.
+ if(cmSystemTools::FileIsSymlink(source))
+ {
+ return this->InstallSymlink(source, destination, always);
+ }
+
// Inform the user about this directory installation.
std::string message = "Installing ";
message += destination;
More information about the Cmake-commits
mailing list