File, Directory Permissions

- Added default and override permissions for files and directories.
This commit is contained in:
Paul Beckingham 2013-07-07 13:04:19 -04:00
parent 061bf4882e
commit 82c4b05fe4
6 changed files with 50 additions and 10 deletions

View file

@ -85,9 +85,9 @@ Directory& Directory::operator= (const Directory& other)
}
////////////////////////////////////////////////////////////////////////////////
bool Directory::create ()
bool Directory::create (int mode /* = 0755 */)
{
return mkdir (_data.c_str (), 0755) == 0 ? true : false;
return mkdir (_data.c_str (), mode) == 0 ? true : false;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -42,7 +42,7 @@ public:
Directory& operator= (const Directory&);
virtual bool create ();
virtual bool create (int mode = 0755);
virtual bool remove () const;
std::vector <std::string> list ();

View file

@ -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;
}

View file

@ -45,7 +45,7 @@ public:
File& operator= (const File&);
virtual bool create ();
virtual bool create (int mode = 0640);
virtual bool remove () const;
bool open ();
@ -72,7 +72,7 @@ public:
virtual time_t ctime () const;
virtual time_t btime () const;
static bool create (const std::string&);
static bool create (const std::string&, int mode = 0640);
static std::string read (const std::string&);
static bool read (const std::string&, std::string&);
static bool read (const std::string&, std::vector <std::string>&);