ENH: Add code for setting and getting permissions

This commit is contained in:
Andy Cedilnik 2004-01-26 14:55:57 -05:00
parent 0217af3b58
commit 7527fbccc2
2 changed files with 41 additions and 1 deletions

View File

@ -42,6 +42,8 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <sys/stat.h>
bool cmSystemTools::s_RunCommandHideConsole = false; bool cmSystemTools::s_RunCommandHideConsole = false;
bool cmSystemTools::s_DisableRunCommandOutput = false; bool cmSystemTools::s_DisableRunCommandOutput = false;
@ -1205,3 +1207,37 @@ bool cmSystemTools::PutEnv(const char* value)
localEnvironment.push_back(envVar); localEnvironment.push_back(envVar);
return ret == 0; return ret == 0;
} }
bool cmSystemTools::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 cmSystemTools::SetPermissions(const char* file, mode_t mode)
{
if ( !file )
{
return false;
}
if ( !cmSystemTools::FileExists(file) )
{
return false;
}
if ( chmod(file, mode) < 0 )
{
return false;
}
return true;
}

View File

@ -259,7 +259,11 @@ public:
/** put a string into the environment /** put a string into the environment
of the form var=value */ of the form var=value */
static bool PutEnv(const char* value); static bool PutEnv(const char* value);
///! Get permissions of the file
static bool GetPermissions(const char* file, mode_t& mode);
static bool SetPermissions(const char* file, mode_t mode);
private: private:
static bool s_ForceUnixPaths; static bool s_ForceUnixPaths;
static bool s_RunCommandHideConsole; static bool s_RunCommandHideConsole;