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

This commit is contained in:
Andy Cedilnik 2004-09-29 12:20:52 -04:00
parent cf8d34040e
commit 3fc7dc5e70
4 changed files with 56 additions and 46 deletions

View File

@ -858,19 +858,13 @@ bool cmSystemTools::DoesFileExistWithExtensions(
bool cmSystemTools::cmCopyFile(const char* source, const char* destination) bool cmSystemTools::cmCopyFile(const char* source, const char* destination)
{ {
mode_t perm = 0; return Superclass::CopyFileAlways(source, destination);
return cmSystemTools::GetPermissions(source, perm) &&
Superclass::CopyFileAlways(source, destination) &&
cmSystemTools::SetPermissions(destination, perm);
} }
bool cmSystemTools::CopyFileIfDifferent(const char* source, bool cmSystemTools::CopyFileIfDifferent(const char* source,
const char* destination) const char* destination)
{ {
mode_t perm = 0; return Superclass::CopyFileIfDifferent(source, destination);
return cmSystemTools::GetPermissions(source, perm) &&
Superclass::CopyFileIfDifferent(source, destination) &&
cmSystemTools::SetPermissions(destination, perm);
} }
void cmSystemTools::Glob(const char *directory, const char *regexp, void cmSystemTools::Glob(const char *directory, const char *regexp,
@ -1283,36 +1277,3 @@ bool cmSystemTools::PutEnv(const char* value)
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

@ -20,7 +20,6 @@
#include "cmStandardIncludes.h" #include "cmStandardIncludes.h"
#include <cmsys/SystemTools.hxx> #include <cmsys/SystemTools.hxx>
#include <sys/types.h>
/** \class cmSystemTools /** \class cmSystemTools
* \brief A collection of useful functions for CMake. * \brief A collection of useful functions for CMake.
@ -278,10 +277,6 @@ public:
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;

View File

@ -930,6 +930,10 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination)
{ {
return true; return true;
} }
mode_t perm = 0;
bool perms = SystemTools::GetPermissions(source, perm);
const int bufferSize = 4096; const int bufferSize = 4096;
char buffer[bufferSize]; char buffer[bufferSize];
@ -1022,6 +1026,13 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination)
{ {
return false; return false;
} }
if ( perms )
{
if ( !SystemTools::SetPermissions(destination, perm) )
{
return false;
}
}
return true; return true;
} }
@ -1886,6 +1897,40 @@ int SystemTools::GetTerminalWidth()
#endif #endif
return width; 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 } // namespace KWSYS_NAMESPACE
#if defined(_MSC_VER) && defined(_DEBUG) #if defined(_MSC_VER) && defined(_DEBUG)

View File

@ -20,6 +20,8 @@
#include <@KWSYS_NAMESPACE@/Configure.h> #include <@KWSYS_NAMESPACE@/Configure.h>
#include <sys/types.h>
/* Define these macros temporarily to keep the code readable. */ /* Define these macros temporarily to keep the code readable. */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS #if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define kwsys_stl @KWSYS_NAMESPACE@_stl # define kwsys_stl @KWSYS_NAMESPACE@_stl
@ -284,6 +286,12 @@ public:
*/ */
static int GetTerminalWidth(); static int GetTerminalWidth();
/**
* Get and set permissions of the file.
*/
static bool GetPermissions(const char* file, mode_t& mode);
static bool SetPermissions(const char* file, mode_t mode);
protected: protected:
// these two functions can be called from ConvertToOutputPath // these two functions can be called from ConvertToOutputPath
/** /**
@ -299,6 +307,7 @@ protected:
* if there are spaces in the string it is double quoted. * if there are spaces in the string it is double quoted.
*/ */
static kwsys_stl::string ConvertToWindowsOutputPath(const char*); static kwsys_stl::string ConvertToWindowsOutputPath(const char*);
}; };
} // namespace @KWSYS_NAMESPACE@ } // namespace @KWSYS_NAMESPACE@