summaryrefslogtreecommitdiff
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorRahul Gottipati <rahul.blr97@gmail.com>2020-06-25 19:06:25 +0530
committerBrad King <brad.king@kitware.com>2020-06-30 11:20:41 -0400
commit27b03281e2028d8239c3f7e43ea67f30a70dc42b (patch)
tree932b13ea34f2256e7d3400d5264cbf39b28f7096 /Source/cmMakefile.cxx
parentf2b84d24cfccf49b6332cf3f2ca164fd71ae023e (diff)
downloadcmake-27b03281e2028d8239c3f7e43ea67f30a70dc42b.tar.gz
configure_file: Add option to control file permissions transfer to copy
Issue: #20866
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx17
1 files changed, 16 insertions, 1 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index d34259f3f5..283f57d3b1 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -34,6 +34,7 @@
#include "cmExecutionStatus.h"
#include "cmExpandedCommandArgument.h" // IWYU pragma: keep
#include "cmExportBuildFileGenerator.h"
+#include "cmFSPermissions.h"
#include "cmFileLockPool.h"
#include "cmFunctionBlocker.h"
#include "cmGeneratedFileStream.h"
@@ -69,6 +70,8 @@
class cmMessenger;
+using namespace cmFSPermissions;
+
cmDirectoryId::cmDirectoryId(std::string s)
: String(std::move(s))
{
@@ -3997,6 +4000,7 @@ void cmMakefile::ConfigureString(const std::string& input, std::string& output,
int cmMakefile::ConfigureFile(const std::string& infile,
const std::string& outfile, bool copyonly,
bool atOnly, bool escapeQuotes,
+ bool use_source_permissions,
cmNewLineStyle newLine)
{
int res = 1;
@@ -4020,7 +4024,13 @@ int cmMakefile::ConfigureFile(const std::string& infile,
this->AddCMakeOutputFile(soutfile);
mode_t perm = 0;
- cmSystemTools::GetPermissions(sinfile, perm);
+ if (!use_source_permissions) {
+ perm = perm | mode_owner_read | mode_owner_write | mode_group_read |
+ mode_world_read;
+ } else {
+ cmSystemTools::GetPermissions(sinfile, perm);
+ }
+
std::string::size_type pos = soutfile.rfind('/');
if (pos != std::string::npos) {
std::string path = soutfile.substr(0, pos);
@@ -4033,6 +4043,11 @@ int cmMakefile::ConfigureFile(const std::string& infile,
cmSystemTools::GetLastSystemError());
return 0;
}
+ if (!cmSystemTools::SetPermissions(soutfile, perm)) {
+ this->IssueMessage(MessageType::FATAL_ERROR,
+ cmSystemTools::GetLastSystemError());
+ return 0;
+ }
} else {
std::string newLineCharacters;
std::ios::openmode omode = std::ios::out | std::ios::trunc;