36 class DirectoryIteratorImp ;
46 G_EXCEPTION( StatError ,
tx(
"cannot access file") )
47 G_EXCEPTION( CannotRemove ,
tx(
"cannot delete file") )
48 G_EXCEPTION( CannotRename ,
tx(
"cannot rename file") )
49 G_EXCEPTION( CannotCopy ,
tx(
"cannot copy file") )
50 G_EXCEPTION( CannotMkdir ,
tx(
"cannot create directory") )
51 G_EXCEPTION( CannotChmod ,
tx(
"cannot chmod file") )
52 G_EXCEPTION( CannotChgrp ,
tx(
"cannot chgrp file") )
53 G_EXCEPTION( CannotLink ,
tx(
"cannot create symlink") )
54 G_EXCEPTION( CannotCreate ,
tx(
"cannot create file") )
55 G_EXCEPTION( CannotReadLink ,
tx(
"cannot read symlink") )
56 G_EXCEPTION( SizeOverflow ,
tx(
"file size overflow") )
57 G_EXCEPTION( TimeError ,
tx(
"cannot get file modification time") )
58 enum class InOut { In , Out } ;
59 enum class InOutAppend { In , Out ,
Append , OutNoCreate } ;
60 enum class Seek { Start , Current , End } ;
71 bool eaccess {
false} ;
73 bool is_link {
false} ;
74 bool is_executable {
false} ;
75 bool is_empty {
false} ;
76 std::time_t mtime_s {0} ;
77 unsigned int mtime_us {0} ;
78 unsigned long mode {0} ;
79 unsigned long long size {0} ;
80 unsigned long long blocks {0} ;
83 bool inherit {
false} ;
86 static bool remove(
const Path & path , std::nothrow_t ) noexcept ;
96 static bool rename(
const Path & from ,
const Path & to , std::nothrow_t ) noexcept ;
101 static void rename(
const Path & from ,
const Path & to ,
bool ignore_missing =
false ) ;
106 static bool renameOnto(
const Path & from ,
const Path & to , std::nothrow_t ) noexcept ;
110 static bool copy(
const Path & from ,
const Path & to , std::nothrow_t ) ;
113 static void copy(
const Path & from ,
const Path & to ) ;
116 static void copy( std::istream & from , std::ostream & to ,
117 std::streamsize limit = 0U , std::size_t block = 0U ) ;
125 static bool copyInto(
const Path & from ,
const Path & to_dir , std::nothrow_t ) ;
129 static bool mkdirs(
const Path & dir , std::nothrow_t ,
int = 100 ) ;
139 static void mkdirs(
const Path & dir ,
int = 100 ) ;
143 static bool mkdir(
const Path & dir , std::nothrow_t ) ;
151 static bool isEmpty(
const Path & file , std::nothrow_t ) ;
164 static bool exists(
const Path & file , std::nothrow_t ) ;
175 static bool isLink(
const Path & path , std::nothrow_t ) ;
183 static Stat stat(
const Path & path ,
bool symlink_nofollow =
false ) ;
198 static bool chmodx(
const Path & file , std::nothrow_t ) ;
201 static void chmod(
const Path & file ,
const std::string & spec ) ;
206 static void chgrp(
const Path & file ,
const std::string & group ) ;
209 static bool chgrp(
const Path & file ,
const std::string & group , std::nothrow_t ) ;
212 static bool chgrp(
const Path & file , gid_t group_id , std::nothrow_t ) ;
221 static void link(
const Path & target ,
const Path & new_link ) ;
226 static bool link(
const Path & target ,
const Path & new_link , std::nothrow_t ) ;
229 static bool hardlink(
const Path & src ,
const Path & dst , std::nothrow_t ) ;
237 static int compare(
const Path & ,
const Path & ,
bool ignore_whitespace =
false ) ;
240 static void open( std::ofstream & ,
const Path & ) ;
249 static void open( std::ofstream & ,
const Path & ,
Text ) ;
254 static void open( std::ifstream & ,
const Path & ) ;
258 static void open( std::ifstream & ,
const Path & ,
Text ) ;
263 static std::filebuf *
open( std::filebuf & ,
const Path & , InOut ) ;
268 static int open(
const Path & , InOutAppend ,
bool windows_inherit =
false ) noexcept ;
278 static
std::FILE *
fopen( const
Path & , const
char * mode ) noexcept ;
281 static
bool probe( const
Path & ) noexcept ;
285 static ssize_t
read(
int fd ,
char * ,
std::
size_t ) noexcept ;
288 static ssize_t
write(
int fd , const
char * ,
std::
size_t ) noexcept ;
291 static
void close(
int fd ) noexcept ;
294 static
std::streamoff
seek(
int fd ,
std::streamoff offset , Seek ) noexcept ;
303 static
bool remove( const
char * ,
std::nothrow_t ) = delete ;
304 static
bool remove( const
std::
string & ,
std::nothrow_t ) = delete ;
305 static
bool rename( const
char * , const
Path & ,
std::nothrow_t ) = delete ;
306 static
bool rename( const
std::
string & , const
Path & ,
std::nothrow_t ) = delete ;
307 static
bool rename( const
char * , const
char * ,
std::nothrow_t ) = delete ;
308 static
bool rename( const
std::
string & , const
std::
string & ,
std::nothrow_t ) = delete ;
309 static
bool renameOnto( const
char * , const
char * ,
std::nothrow_t ) = delete ;
310 static
bool renameOnto( const
std::
string & , const
std::
string & ,
std::nothrow_t ) = delete ;
311 static
int open( const
char * , InOutAppend ) = delete ;
312 static
int open( const
std::
string & , InOutAppend ) = delete ;
315 static
std::FILE *
fopen( const
char * , const
char * mode ) = delete ;
316 static
std::FILE *
fopen( const
std::
string & , const
char * mode ) = delete ;
317 static
bool probe( const
char * ) = delete ;
318 static
bool probe( const
std::
string & ) = delete ;
321 static const
int rdonly = 1<<0 ;
322 static const
int wronly = 1<<1 ;
323 static const
int rdwr = 1<<2 ;
324 static const
int trunc = 1<<3 ;
325 static const
int creat = 1<<4 ;
326 static const
int append = 1<<5 ;
327 friend class
G::DirectoryIteratorImp ;
329 static
bool exists( const
Path & ,
bool ,
bool ) ;
330 static
bool existsImp( const
char * ,
bool & ,
bool & ) noexcept ;
331 static
Stat statImp( const
char * ,
bool = false ) noexcept ;
332 static
bool renameImp( const
char * , const
char * ,
int * ) noexcept ;
333 static
bool chmodx( const
Path & file ,
bool ) ;
334 static
int linkImp( const
char * , const
char * ) ;
335 static
bool linked( const
Path & , const
Path & ) ;
336 static
int mkdirImp( const
Path & dir ) noexcept ;
337 static
bool mkdirsImp( const
Path & dir ,
int & ,
int ) ;
338 static
bool chmod( const
Path & , const
std::
string & ,
std::nothrow_t ) ;
An overload discriminator for G::File::open().
An overload discriminator for G::File::open().
A simple static class for dealing with files.
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 std::streamoff seek(int fd, std::streamoff offset, Seek) noexcept
Does ::lseek() or equivalent.
static void setNonBlocking(int fd) noexcept
Sets the file descriptor to non-blocking mode.
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 Stat stat(const Path &path, bool symlink_nofollow=false)
Returns a file status structure.
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 Path backup(const Path &from, std::nothrow_t)
Creates a backup copy of the given file in the same directory and with a lightly-mangled filename.
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 renameOnto(const Path &from, const Path &to, std::nothrow_t) noexcept
Renames the file, deleting 'to' first if necessary.
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 std::FILE * fopen(const Path &, const char *mode) noexcept
Calls std::fopen().
static bool hardlink(const Path &src, const Path &dst, std::nothrow_t)
Creates a hard link.
static bool probe(const Path &) noexcept
Creates and deletes a temporary probe file.
static int compare(const Path &, const Path &, bool ignore_whitespace=false)
Compares the contents of the two files. Returns 0, 1 or -1.
static bool cleanup(const Cleanup::Arg &path_arg) noexcept
Deletes the file.
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.
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().
Opaque leaky string pointer wrapper created by G::Cleanup::arg().
An overload discriminator for G::File::open().
A portable 'struct stat'.