summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/SystemTools.cxx
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2004-09-29 16:20:52 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2004-09-29 16:20:52 (GMT)
commit3fc7dc5e70cd444731dd3adcc4599f9750e4936c (patch)
tree99f891a85d30981fa83a68c09ab33922356ec2fc /Source/kwsys/SystemTools.cxx
parentcf8d34040e66e2ffb13b4f6598024b38e298633d (diff)
downloadCMake-3fc7dc5e70cd444731dd3adcc4599f9750e4936c.zip
CMake-3fc7dc5e70cd444731dd3adcc4599f9750e4936c.tar.gz
CMake-3fc7dc5e70cd444731dd3adcc4599f9750e4936c.tar.bz2
ENH: Move permissions code to kwsys so that copyfile can use it. Fixes Bug #1133 - cmake -E copy file dir sets the wrong permissions on the destination directory
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r--Source/kwsys/SystemTools.cxx45
1 files changed, 45 insertions, 0 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index f909312..f08a50f 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -930,6 +930,10 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination)
{
return true;
}
+
+ mode_t perm = 0;
+ bool perms = SystemTools::GetPermissions(source, perm);
+
const int bufferSize = 4096;
char buffer[bufferSize];
@@ -1022,6 +1026,13 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination)
{
return false;
}
+ if ( perms )
+ {
+ if ( !SystemTools::SetPermissions(destination, perm) )
+ {
+ return false;
+ }
+ }
return true;
}
@@ -1886,6 +1897,40 @@ int SystemTools::GetTerminalWidth()
#endif
return width;
}
+
+bool SystemTools::GetPermissions(const char* file, mode_t& mode)
+{
+ if ( !file )
+ {
+ return false;
+ }
+
+ struct stat st;
+ if ( stat(file, &st) < 0 )
+ {
+ return false;
+ }
+ mode = st.st_mode;
+ return true;
+}
+
+bool SystemTools::SetPermissions(const char* file, mode_t mode)
+{
+ if ( !file )
+ {
+ return false;
+ }
+ if ( !SystemTools::FileExists(file) )
+ {
+ return false;
+ }
+ if ( chmod(file, mode) < 0 )
+ {
+ return false;
+ }
+
+ return true;
+}
} // namespace KWSYS_NAMESPACE
#if defined(_MSC_VER) && defined(_DEBUG)