summaryrefslogtreecommitdiffstats
path: root/Source/cmWriteFileCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2010-06-03 14:46:38 (GMT)
committerBrad King <brad.king@kitware.com>2010-06-03 14:50:30 (GMT)
commit85cbdaade22c7ba6dac7a806c0b88ebc32caa4c1 (patch)
tree5ff368fb26f5e6244601dffe8661aa30abe3e5d4 /Source/cmWriteFileCommand.cxx
parent3ac3dea6f0eb1ce68b321020ecdd336b3db8a0fe (diff)
downloadCMake-85cbdaade22c7ba6dac7a806c0b88ebc32caa4c1.zip
CMake-85cbdaade22c7ba6dac7a806c0b88ebc32caa4c1.tar.gz
CMake-85cbdaade22c7ba6dac7a806c0b88ebc32caa4c1.tar.bz2
Really trust umask in file(WRITE) command (#10789, #10126)
Commit 8d0161c8 (Trust umask for file permissions, 2010-01-12) taught these commands to set permissions to 0666 explicitly. The intention was to let the open() call inside ofstream handle permsisions so that umask would be honored. Now we set permissions only when we need to preserve those on an existing file. New files will be created with umask-based permissions.
Diffstat (limited to 'Source/cmWriteFileCommand.cxx')
-rw-r--r--Source/cmWriteFileCommand.cxx19
1 files changed, 7 insertions, 12 deletions
diff --git a/Source/cmWriteFileCommand.cxx b/Source/cmWriteFileCommand.cxx
index f46b87f..ec558b6 100644
--- a/Source/cmWriteFileCommand.cxx
+++ b/Source/cmWriteFileCommand.cxx
@@ -54,24 +54,16 @@ bool cmWriteFileCommand
std::string dir = cmSystemTools::GetFilenamePath(fileName);
cmSystemTools::MakeDirectory(dir.c_str());
- mode_t mode =
-#if defined( _MSC_VER ) || defined( __MINGW32__ )
- S_IREAD | S_IWRITE
-#elif defined( __BORLANDC__ )
- S_IRUSR | S_IWUSR
-#else
- 0666
-#endif
- ;
+ mode_t mode = 0;
// Set permissions to writable
if ( cmSystemTools::GetPermissions(fileName.c_str(), mode) )
{
cmSystemTools::SetPermissions(fileName.c_str(),
#if defined( _MSC_VER ) || defined( __MINGW32__ )
- S_IREAD | S_IWRITE
+ mode | S_IWRITE
#else
- 0666
+ mode | S_IWUSR | S_IWGRP
#endif
);
}
@@ -89,7 +81,10 @@ bool cmWriteFileCommand
}
file << message << std::endl;
file.close();
- cmSystemTools::SetPermissions(fileName.c_str(), mode);
+ if(mode)
+ {
+ cmSystemTools::SetPermissions(fileName.c_str(), mode);
+ }
return true;
}