File, Directory Permissions
- Added default and override permissions for files and directories.
This commit is contained in:
10
src/File.cpp
10
src/File.cpp
@@ -28,6 +28,7 @@
|
||||
#include <cmake.h>
|
||||
#include <fstream>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/file.h>
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
@@ -90,10 +91,11 @@ File& File::operator= (const File& other)
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool File::create ()
|
||||
bool File::create (int mode /* = 0640 */)
|
||||
{
|
||||
if (open ())
|
||||
{
|
||||
fchmod (_h, mode);
|
||||
close ();
|
||||
return true;
|
||||
}
|
||||
@@ -361,12 +363,14 @@ time_t File::btime () const
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool File::create (const std::string& name)
|
||||
bool File::create (const std::string& name, int mode /* = 0640 */)
|
||||
{
|
||||
std::ofstream out (expand (name).c_str ());
|
||||
std::string full_name = expand (name);
|
||||
std::ofstream out (full_name.c_str ());
|
||||
if (out.good ())
|
||||
{
|
||||
out.close ();
|
||||
chmod (full_name.c_str (), mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user