From 09421a261c188763d3acfc7155d49c1c6fabc3ae Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Mon, 26 Jan 2004 15:50:38 -0500 Subject: ENH: Preserve permissions when copying files --- Source/cmConfigureFileCommand.cxx | 3 +++ Source/cmSystemTools.cxx | 14 +++++++++++++- Source/cmSystemTools.h | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Source/cmConfigureFileCommand.cxx b/Source/cmConfigureFileCommand.cxx index d2a6443..3bf97c8 100644 --- a/Source/cmConfigureFileCommand.cxx +++ b/Source/cmConfigureFileCommand.cxx @@ -74,6 +74,8 @@ void cmConfigureFileCommand::ConfigureFile() { m_Makefile->AddCMakeDependFile(m_InputFile.c_str()); cmSystemTools::ConvertToUnixSlashes(m_OuputFile); + mode_t perm = 0; + cmSystemTools::GetPermissions(m_InputFile.c_str(), perm); std::string::size_type pos = m_OuputFile.rfind('/'); if(pos != std::string::npos) { @@ -142,6 +144,7 @@ void cmConfigureFileCommand::ConfigureFile() cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(), m_OuputFile.c_str()); cmSystemTools::RemoveFile(tempOutputFile.c_str()); + cmSystemTools::SetPermissions(m_OuputFile.c_str(), perm); } } diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index dae4124..e3a9028 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -810,7 +810,19 @@ bool cmSystemTools::DoesFileExistWithExtensions( bool cmSystemTools::cmCopyFile(const char* source, const char* destination) { - return Superclass::CopyFileAlways(source, destination); + mode_t perm = 0; + return cmSystemTools::GetPermissions(source, perm) && + Superclass::CopyFileAlways(source, destination) && + cmSystemTools::SetPermissions(destination, perm); +} + +bool cmSystemTools::CopyFileIfDifferent(const char* source, + const char* destination) +{ + mode_t perm = 0; + return cmSystemTools::GetPermissions(source, perm) && + Superclass::CopyFileIfDifferent(source, destination) && + cmSystemTools::SetPermissions(destination, perm); } void cmSystemTools::Glob(const char *directory, const char *regexp, diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 9099844..d183cae 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -150,6 +150,8 @@ public: ///! Copy a file. static bool cmCopyFile(const char* source, const char* destination); + static bool CopyFileIfDifferent(const char* source, + const char* destination); /** * Run an executable command and put the stdout in output. -- cgit v0.12