35 class DirectoryIteratorImp ;
45 G_EXCEPTION( StatError ,
tx(
"cannot access file") ) ;
46 G_EXCEPTION( CannotRemove ,
tx(
"cannot delete file") ) ;
47 G_EXCEPTION( CannotRename ,
tx(
"cannot rename file") ) ;
48 G_EXCEPTION( CannotCopy ,
tx(
"cannot copy file") ) ;
49 G_EXCEPTION( CannotMkdir ,
tx(
"cannot create directory") ) ;
50 G_EXCEPTION( CannotChmod ,
tx(
"cannot chmod file") ) ;
51 G_EXCEPTION( CannotChgrp ,
tx(
"cannot chgrp file") ) ;
52 G_EXCEPTION( CannotLink ,
tx(
"cannot create symlink") ) ;
53 G_EXCEPTION( CannotCreate ,
tx(
"cannot create file") ) ;
54 G_EXCEPTION( CannotReadLink ,
tx(
"cannot read symlink") ) ;
55 G_EXCEPTION( SizeOverflow ,
tx(
"file size overflow") ) ;
56 G_EXCEPTION( TimeError ,
tx(
"cannot get file modification time") ) ;
57 enum class InOut { In , Out } ;
58 enum class InOutAppend { In , Out ,
Append } ;
59 enum class Seek { Start , Current , End } ;
70 bool eaccess {
false} ;
72 bool is_link {
false} ;
73 bool is_executable {
false} ;
74 bool is_empty {
false} ;
75 std::time_t mtime_s {0} ;
76 unsigned int mtime_us {0} ;
77 unsigned long mode {0} ;
78 unsigned long long size {0} ;
79 unsigned long long blocks {0} ;
82 bool inherit {
false} ;
85 static bool remove(
const Path & path , std::nothrow_t ) noexcept ;
91 static bool rename(
const Path & from ,
const Path & to , std::nothrow_t ) noexcept ;
96 static void rename(
const Path & from ,
const Path & to ,
bool ignore_missing =
false ) ;
101 static bool renameOnto(
const Path & from ,
const Path & to , std::nothrow_t ) noexcept ;
105 static bool copy(
const Path & from ,
const Path & to , std::nothrow_t ) ;
108 static void copy(
const Path & from ,
const Path & to ) ;
111 static void copy( std::istream & from , std::ostream & to ,
112 std::streamsize limit = 0U , std::size_t block = 0U ) ;
115 static bool copyInto(
const Path & from ,
const Path & to_dir , std::nothrow_t ) ;
119 static bool mkdirs(
const Path & dir , std::nothrow_t ,
int = 100 ) ;
129 static void mkdirs(
const Path & dir ,
int = 100 ) ;
133 static bool mkdir(
const Path & dir , std::nothrow_t ) ;
141 static bool isEmpty(
const Path & file , std::nothrow_t ) ;
154 static bool exists(
const Path & file , std::nothrow_t ) ;
165 static bool isLink(
const Path & path , std::nothrow_t ) ;
173 static Stat stat(
const Path & path ,
bool read_symlink =
false ) ;
188 static bool chmodx(
const Path & file , std::nothrow_t ) ;
191 static void chmod(
const Path & file ,
const std::string & spec ) ;
196 static void chgrp(
const Path & file ,
const std::string & group ) ;
199 static bool chgrp(
const Path & file ,
const std::string & group , std::nothrow_t ) ;
202 static bool chgrp(
const Path & file , gid_t group_id , std::nothrow_t ) ;
211 static void link(
const Path & target ,
const Path & new_link ) ;
216 static bool link(
const Path & target ,
const Path & new_link , std::nothrow_t ) ;
219 static bool hardlink(
const Path & src ,
const Path & dst , std::nothrow_t ) ;
227 static int compare(
const Path & ,
const Path & ,
bool ignore_whitespace =
false ) ;
230 static void open( std::ofstream & ,
const Path & ) ;
239 static void open( std::ofstream & ,
const Path & ,
Text ) ;
244 static void open( std::ifstream & ,
const Path & ) ;
248 static void open( std::ifstream & ,
const Path & ,
Text ) ;
253 static std::filebuf *
open( std::filebuf & ,
const Path & , InOut ) ;
258 static int open(
const char * , InOutAppend ) noexcept ;
267 static std::FILE *
fopen(
const char * ,
const char * mode ) noexcept ;
270 static bool probe(
const char * ) noexcept ;
274 static ssize_t
read(
int fd ,
char * , std::size_t ) noexcept ;
277 static ssize_t
write(
int fd ,
const char * , std::size_t ) noexcept ;
280 static void close(
int fd ) noexcept ;
283 static std::streamoff
seek(
int fd , std::streamoff offset , Seek ) noexcept ;
293 static const int rdonly = 1<<0 ;
294 static const int wronly = 1<<1 ;
295 static const int rdwr = 1<<2 ;
296 static const int trunc = 1<<3 ;
297 static const int creat = 1<<4 ;
298 static const int append = 1<<5 ;
299 friend class G::DirectoryIteratorImp ;
300 static std::string
copy(
const Path & ,
const Path & ,
int ) ;
301 static bool exists(
const Path & ,
bool ,
bool ) ;
302 static bool existsImp(
const char * ,
bool & ,
bool & ) noexcept ;
303 static Stat statImp(
const char * ,
bool =
false ) noexcept ;
304 static
bool rename( const
char * , const
char * to ,
bool & enoent ) noexcept ;
305 static
bool chmodx( const
Path & file ,
bool ) ;
306 static
int linkImp( const
char * , const
char * ) ;
307 static
bool linked( const
Path & , const
Path & ) ;
308 static
int mkdirImp( const
Path & dir ) noexcept ;
309 static
bool mkdirsr( const
Path & dir ,
int & ,
int & ) ;
310 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 std::FILE * fopen(const char *, const char *mode) noexcept
Calls std::fopen().
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 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 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 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 Stat stat(const Path &path, bool read_symlink=false)
Returns a file status structure.
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 bool hardlink(const Path &src, const Path &dst, std::nothrow_t)
Creates a hard link.
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.
constexpr const char * tx(const char *p)
A briefer alternative to G::gettext_noop().
An overload discriminator for G::File::open().
A portable 'struct stat'.