mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-07 22:58:34 +02:00
File, Directory Permissions
- Added default and override permissions for files and directories.
This commit is contained in:
parent
061bf4882e
commit
82c4b05fe4
6 changed files with 50 additions and 10 deletions
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue