summaryrefslogtreecommitdiffstats
path: root/Source/cmFileCommand.cxx
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2005-03-07 18:51:18 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2005-03-07 18:51:18 (GMT)
commit04bb427d1f067a4f1820a7cc0c81250f9ccfd7c6 (patch)
tree432e6a613be033a190368364f63cda68f438ee87 /Source/cmFileCommand.cxx
parent14890b6ad43c25cb709b5368acaed9a4a3c28307 (diff)
downloadCMake-04bb427d1f067a4f1820a7cc0c81250f9ccfd7c6.zip
CMake-04bb427d1f067a4f1820a7cc0c81250f9ccfd7c6.tar.gz
CMake-04bb427d1f067a4f1820a7cc0c81250f9ccfd7c6.tar.bz2
BUG: Handle restrictive permissions
Diffstat (limited to 'Source/cmFileCommand.cxx')
-rw-r--r--Source/cmFileCommand.cxx26
1 files changed, 26 insertions, 0 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 0bc515c..e66ac08 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -89,6 +89,31 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
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
+ S_IRUSR | S_IWUSR |
+ S_IRGRP |
+ S_IROTH
+#endif
+ ;
+
+ // 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
+#else
+ S_IRUSR | S_IWUSR
+#endif
+ );
+ }
+ // If GetPermissions fails, pretend like it is ok. File open will fail if
+ // the file is not writable
std::ofstream file(fileName.c_str(), append?std::ios::app: std::ios::out);
if ( !file )
{
@@ -100,6 +125,7 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
}
file << message;
file.close();
+ cmSystemTools::SetPermissions(fileName.c_str(), mode);
m_Makefile->AddWrittenFile(fileName.c_str());
return true;
}