35 class DirectoryIteratorImp ;
45 G_EXCEPTION( StatError ,
"cannot access file" ) ;
46 G_EXCEPTION( CannotRemove ,
"cannot delete file" ) ;
47 G_EXCEPTION( CannotRename ,
"cannot rename file" ) ;
48 G_EXCEPTION( CannotCopy ,
"cannot copy file" ) ;
49 G_EXCEPTION( CannotMkdir ,
"cannot create directory" ) ;
50 G_EXCEPTION( CannotChmod ,
"cannot chmod file" ) ;
51 G_EXCEPTION( CannotChgrp ,
"cannot chgrp file" ) ;
52 G_EXCEPTION( CannotLink ,
"cannot create symlink" ) ;
53 G_EXCEPTION( CannotCreate ,
"cannot create file" ) ;
54 G_EXCEPTION( CannotReadLink ,
"cannot read symlink" ) ;
55 G_EXCEPTION( SizeOverflow ,
"file size overflow" ) ;
56 G_EXCEPTION( TimeError ,
"cannot get file modification time" ) ;
57 enum class InOut { In , Out } ;
58 enum class InOutAppend { In , Out ,
Append } ;
67 bool eaccess {
false} ;
69 bool is_link {
false} ;
70 bool is_executable {
false} ;
71 bool is_empty {
false} ;
72 std::time_t mtime_s {0} ;
73 unsigned int mtime_us {0} ;
74 unsigned long mode {0} ;
75 unsigned long long size {0} ;
76 unsigned long long blocks {0} ;
79 static bool remove(
const Path & path , std::nothrow_t ) noexcept ;
85 static bool rename(
const Path & from ,
const Path & to , std::nothrow_t ) noexcept ;
89 static void rename(
const Path & from ,
const Path & to ,
bool ignore_missing =
false ) ;
94 static bool copy(
const Path & from ,
const Path & to , std::nothrow_t ) ;
97 static void copy(
const Path & from ,
const Path & to ) ;
100 static void copy( std::istream & from , std::ostream & to ,
101 std::streamsize limit = 0U , std::string::size_type block = 0U ) ;
104 static bool copyInto(
const Path & from ,
const Path & to_dir , std::nothrow_t ) ;
108 static bool mkdirs(
const Path & dir , std::nothrow_t ,
int = 100 ) ;
119 static void mkdirs(
const Path & dir ,
int = 100 ) ;
125 static bool mkdir(
const Path & dir , std::nothrow_t ) ;
133 static bool isEmpty(
const Path & file , std::nothrow_t ) ;
146 static bool exists(
const Path & file , std::nothrow_t ) ;
157 static bool isLink(
const Path & path , std::nothrow_t ) ;
175 static bool chmodx(
const Path & file , std::nothrow_t ) ;
178 static void chmod(
const Path & file ,
const std::string & spec ) ;
183 static void chgrp(
const Path & file ,
const std::string & group ) ;
186 static bool chgrp(
const Path & file ,
const std::string & group , std::nothrow_t ) ;
195 static void link(
const Path & target ,
const Path & new_link ) ;
200 static bool link(
const Path & target ,
const Path & new_link , std::nothrow_t ) ;
207 static int compare(
const Path & ,
const Path & ,
bool ignore_whitespace =
false ) ;
210 static void open( std::ofstream & ,
const Path & ) ;
219 static void open( std::ofstream & ,
const Path & ,
Text ) ;
224 static void open( std::ifstream & ,
const Path & ) ;
228 static void open( std::ifstream & ,
const Path & ,
Text ) ;
233 static std::filebuf *
open( std::filebuf & ,
const Path & , InOut ) ;
238 static int open(
const char * , InOutAppend ) noexcept ;
242 static bool probe(
const char * ) noexcept ;
246 static ssize_t
read(
int fd ,
char * , std::size_t ) noexcept ;
249 static ssize_t
write(
int fd ,
const char * , std::size_t ) noexcept ;
252 static void close(
int fd ) noexcept ;
259 static const int rdonly = 1<<0 ;
260 static const int wronly = 1<<1 ;
261 static const int rdwr = 1<<2 ;
262 static const int trunc = 1<<3 ;
263 static const int creat = 1<<4 ;
264 static const int append = 1<<5 ;
266 static std::string
copy(
const Path & ,
const Path & ,
int ) ;
267 static bool exists(
const Path & ,
bool ,
bool ) ;
268 static bool existsImp(
const char * ,
bool & ,
bool & ) noexcept ;
269 static Stat statImp(
const char * ,
bool =
false ) noexcept ;
270 static
bool rename( const
char * , const
char * to ,
bool & enoent ) noexcept ;
271 static
bool chmodx( const
Path & file ,
bool ) ;
272 static
int linkImp( const
char * , const
char * ) ;
273 static
bool linked( const
Path & , const
Path & ) ;
274 static
int mkdirImp( const
Path & dir ) noexcept ;
275 static
bool mkdirsr(
int * , const
Path & dir ,
int ) ;
276 static
bool chmod( const
Path & , const std::
string & , std::nothrow_t ) ;
A pimple-pattern implementation class for DirectoryIterator using opendir()/readdir().
An overload discriminator for G::File::open().
An overload discriminator for G::File::open().
A simple static class for dealing with files.
static bool probe(const char *) noexcept
Creates and deletes a temporary probe file.
static void open(std::ofstream &, const Path &)
Calls open() on the given output file stream.
static bool isExecutable(const Path &, std::nothrow_t)
Returns true if the path is probably executable by the calling process.
static void close(int fd) noexcept
Calls ::close() or equivalent.
static SystemTime time(const Path &file)
Returns the file's timestamp. Throws on error.
static bool isEmpty(const Path &file, std::nothrow_t)
Returns true if the file size is zero.
static void link(const Path &target, const Path &new_link)
Creates a symlink.
static bool isDirectory(const Path &path, std::nothrow_t)
Returns true if the path exists() and is a directory.
static std::string sizeString(const Path &file)
Returns the file's size in string format.
static bool rename(const Path &from, const Path &to, std::nothrow_t) noexcept
Renames the file.
static ssize_t write(int fd, const char *, std::size_t) noexcept
Calls ::write() or equivalent.
static void chmod(const Path &file, const std::string &spec)
Sets the file permissions.
static bool remove(const Path &path, std::nothrow_t) noexcept
Deletes the file or directory. Returns false on error.
static bool exists(const Path &file)
Returns true if the file (directory, device etc.) exists.
static void chmodx(const Path &file)
Makes the file executable. Throws on error.
static bool isLink(const Path &path, std::nothrow_t)
Returns true if the path is an existing symlink.
static ssize_t read(int fd, char *, std::size_t) noexcept
Calls ::read() or equivalent.
static bool mkdirs(const Path &dir, std::nothrow_t, int=100)
Creates a directory and all necessary parents.
static bool copy(const Path &from, const Path &to, std::nothrow_t)
Copies a file. Returns false on error.
static bool copyInto(const Path &from, const Path &to_dir, std::nothrow_t)
Copies a file into a directory and does a chmodx() if necessary.
static bool mkdir(const Path &dir, std::nothrow_t)
Creates a directory.
static void create(const Path &)
Creates the file if it does not exist.
static G::Path readlink(const Path &link)
Reads a symlink. Throws on error.
static int compare(const Path &, const Path &, bool ignore_whitespace=false)
Compares the contents of the two files. Returns 0, 1 or -1.
static void chgrp(const Path &file, const std::string &group)
Sets the file group ownership. Throws on error.
A Path object represents a file system path.
Represents a unix-epoch time with microsecond resolution.
A portable 'struct stat'.