E-MailRelay
|
A simple static class for dealing with files. More...
#include <gfile.h>
Classes | |
class | Append |
An overload discriminator for G::File::open(). More... | |
struct | CreateExclusive |
An overload discriminator for G::File::open(). More... | |
struct | Stat |
A portable 'struct stat'. More... | |
class | Text |
An overload discriminator for G::File::open(). More... | |
Public Types | |
enum class | InOut { In , Out } |
enum class | InOutAppend { In , Out , Append , OutNoCreate } |
enum class | Seek { Start , Current , End } |
Static Public Member Functions | |
static bool | remove (const Path &path, std::nothrow_t) noexcept |
Deletes the file or directory. Returns false on error. More... | |
static void | remove (const Path &path) |
Deletes the file or directory. Throws an exception on error. More... | |
static bool | cleanup (const Cleanup::Arg &path_arg) noexcept |
Deletes the file. More... | |
static bool | rename (const Path &from, const Path &to, std::nothrow_t) noexcept |
Renames the file. More... | |
static void | rename (const Path &from, const Path &to, bool ignore_missing=false) |
Renames the file. More... | |
static bool | renameOnto (const Path &from, const Path &to, std::nothrow_t) noexcept |
Renames the file, deleting 'to' first if necessary. More... | |
static bool | copy (const Path &from, const Path &to, std::nothrow_t) |
Copies a file. Returns false on error. More... | |
static void | copy (const Path &from, const Path &to) |
Copies a file. More... | |
static void | copy (std::istream &from, std::ostream &to, std::streamsize limit=0U, std::size_t block=0U) |
Copies a stream with an optional size limit. More... | |
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. More... | |
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. More... | |
static bool | mkdirs (const Path &dir, std::nothrow_t, int=100) |
Creates a directory and all necessary parents. More... | |
static void | mkdirs (const Path &dir, int=100) |
Creates a directory and all necessary parents. More... | |
static bool | mkdir (const Path &dir, std::nothrow_t) |
Creates a directory. More... | |
static void | mkdir (const Path &dir) |
Creates a directory. More... | |
static bool | isEmpty (const Path &file, std::nothrow_t) |
Returns true if the file size is zero. More... | |
static std::string | sizeString (const Path &file) |
Returns the file's size in string format. More... | |
static bool | exists (const Path &file) |
Returns true if the file (directory, device etc.) exists. More... | |
static bool | exists (const Path &file, std::nothrow_t) |
Returns true if the file (directory, device etc.) exists. More... | |
static bool | isExecutable (const Path &, std::nothrow_t) |
Returns true if the path is probably executable by the calling process. More... | |
static bool | isLink (const Path &path, std::nothrow_t) |
Returns true if the path is an existing symlink. More... | |
static bool | isDirectory (const Path &path, std::nothrow_t) |
Returns true if the path exists() and is a directory. More... | |
static Stat | stat (const Path &path, bool symlink_nofollow=false) |
Returns a file status structure. More... | |
static SystemTime | time (const Path &file) |
Returns the file's timestamp. Throws on error. More... | |
static SystemTime | time (const Path &file, std::nothrow_t) |
Returns the file's timestamp. More... | |
static void | chmodx (const Path &file) |
Makes the file executable. Throws on error. More... | |
static bool | chmodx (const Path &file, std::nothrow_t) |
Makes the file executable. More... | |
static void | chmod (const Path &file, const std::string &spec) |
Sets the file permissions. More... | |
static void | chgrp (const Path &file, const std::string &group) |
Sets the file group ownership. Throws on error. More... | |
static bool | chgrp (const Path &file, const std::string &group, std::nothrow_t) |
Sets the file group ownership. Returns false on error. More... | |
static bool | chgrp (const Path &file, gid_t group_id, std::nothrow_t) |
Sets the file group ownership. Returns false on error. More... | |
static G::Path | readlink (const Path &link) |
Reads a symlink. Throws on error. More... | |
static G::Path | readlink (const Path &link, std::nothrow_t) |
Reads a symlink. Returns the empty path on error. More... | |
static void | link (const Path &target, const Path &new_link) |
Creates a symlink. More... | |
static bool | link (const Path &target, const Path &new_link, std::nothrow_t) |
Creates a symlink. Returns false on error. More... | |
static bool | hardlink (const Path &src, const Path &dst, std::nothrow_t) |
Creates a hard link. More... | |
static void | create (const Path &) |
Creates the file if it does not exist. More... | |
static int | compare (const Path &, const Path &, bool ignore_whitespace=false) |
Compares the contents of the two files. Returns 0, 1 or -1. More... | |
static void | open (std::ofstream &, const Path &) |
Calls open() on the given output file stream. More... | |
static void | open (std::ofstream &, const Path &, Append) |
Calls open() on the given output file stream. More... | |
static void | open (std::ofstream &, const Path &, Text) |
Calls open() on the given output file stream. More... | |
static void | open (std::ifstream &, const Path &) |
Calls open() on the given input file stream. More... | |
static void | open (std::ifstream &, const Path &, Text) |
Calls open() on the given input file stream. More... | |
static std::filebuf * | open (std::filebuf &, const Path &, InOut) |
Calls open() on the given filebuf. More... | |
static int | open (const Path &, InOutAppend, bool windows_inherit=false) noexcept |
Opens a file descriptor. More... | |
static int | open (const Path &, CreateExclusive) noexcept |
Creates a file and returns a writable file descriptor. More... | |
static std::FILE * | fopen (const Path &, const char *mode) noexcept |
Calls std::fopen(). More... | |
static bool | probe (const Path &) noexcept |
Creates and deletes a temporary probe file. More... | |
static ssize_t | read (int fd, char *, std::size_t) noexcept |
Calls read() or equivalent. More... | |
static ssize_t | write (int fd, const char *, std::size_t) noexcept |
Calls ::write() or equivalent. More... | |
static void | close (int fd) noexcept |
Calls ::close() or equivalent. More... | |
static std::streamoff | seek (int fd, std::streamoff offset, Seek) noexcept |
Does ::lseek() or equivalent. More... | |
static void | setNonBlocking (int fd) noexcept |
Sets the file descriptor to non-blocking mode. More... | |
static bool | remove (const char *, std::nothrow_t)=delete |
static bool | remove (const std::string &, std::nothrow_t)=delete |
static bool | rename (const char *, const Path &, std::nothrow_t)=delete |
static bool | rename (const std::string &, const Path &, std::nothrow_t)=delete |
static bool | rename (const char *, const char *, std::nothrow_t)=delete |
static bool | rename (const std::string &, const std::string &, std::nothrow_t)=delete |
static bool | renameOnto (const char *, const char *, std::nothrow_t)=delete |
static bool | renameOnto (const std::string &, const std::string &, std::nothrow_t)=delete |
static int | open (const char *, InOutAppend)=delete |
static int | open (const std::string &, InOutAppend)=delete |
static int | open (const char *, CreateExclusive)=delete |
static int | open (const std::string &, CreateExclusive)=delete |
static std::FILE * | fopen (const char *, const char *mode)=delete |
static std::FILE * | fopen (const std::string &, const char *mode)=delete |
static bool | probe (const char *)=delete |
static bool | probe (const std::string &)=delete |
A simple static class for dealing with files.
|
static |
Sets the file group ownership. Throws on error.
Definition at line 370 of file gfile_unix.cpp.
|
static |
Sets the file group ownership. Returns false on error.
Definition at line 379 of file gfile_unix.cpp.
|
static |
Sets the file group ownership. Returns false on error.
Definition at line 385 of file gfile_unix.cpp.
|
static |
Sets the file permissions.
Throws on error. The spec is a simplified sub-set of the /bin/chmod command syntax. The umask is ignored.
Definition at line 272 of file gfile_unix.cpp.
|
static |
|
static |
|
staticnoexcept |
Deletes the file.
Returns false on error. Used in G::Cleanup handlers:
Definition at line 172 of file gfile_unix.cpp.
|
staticnoexcept |
Calls ::close() or equivalent.
Definition at line 159 of file gfile_unix.cpp.
|
static |
|
static |
Creates the file if it does not exist.
Leaves it alone if it does. Throws on error.
Definition at line 135 of file gfile_unix.cpp.
|
static |
|
static |
|
staticnoexcept |
Calls std::fopen().
Definition at line 114 of file gfile_unix.cpp.
Creates a hard link.
Returns false on error or if not implemented.
Definition at line 390 of file gfile_unix.cpp.
|
static |
|
static |
|
static |
|
static |
Creates a symlink.
If the link already exists but is not not pointing at the correct target then the link is deleted and recreated. Throws on error.
Definition at line 396 of file gfile_unix.cpp.
Creates a symlink. Returns false on error.
Definition at line 416 of file gfile_unix.cpp.
|
static |
|
static |
|
static |
|
static |
Creates a directory and all necessary parents.
Returns false on error, but EEXIST is not an error and chmod errors are also ignored.
Note that the EEXIST result is ignored even if the target path already exists as a non-directory. This is a feature not a bug because it can avoid races.
|
staticnoexcept |
Creates a file and returns a writable file descriptor.
Fails if the file already exists. Returns -1 on error. Uses SH_DENYNO and O_BINARY on windows.
Definition at line 106 of file gfile_unix.cpp.
|
staticnoexcept |
Opens a file descriptor.
Returns -1 on error. Uses SH_DENYNO, O_BINARY and optionally O_NOINHERIT on windows. The inherit flag is ignored on unix.
Definition at line 91 of file gfile_unix.cpp.
|
static |
Calls open() on the given filebuf.
Returns the address of the given filebuf, or nullptr on failure. Uses SH_DENYNO and O_BINARY on windows.
Definition at line 83 of file gfile_unix.cpp.
|
static |
Calls open() on the given input file stream.
Uses SH_DENYNO and O_BINARY on windows.
Definition at line 71 of file gfile_unix.cpp.
Calls open() on the given input file stream.
This overload is for native end-of-line conversion. Uses SH_DENYNO and O_BINARY on windows.
Definition at line 77 of file gfile_unix.cpp.
|
static |
Calls open() on the given output file stream.
Uses SH_DENYNO and O_BINARY on windows.
Definition at line 56 of file gfile_unix.cpp.
Calls open() on the given output file stream.
This overload is for append-on-every-write mode. Uses SH_DENYNO and O_BINARY on windows.
Definition at line 66 of file gfile_unix.cpp.
Calls open() on the given output file stream.
This overload is for native end-of-line conversion. Uses SH_DENYNO and O_BINARY on windows.
Definition at line 61 of file gfile_unix.cpp.
|
staticnoexcept |
Creates and deletes a temporary probe file.
Fails if the file already exists. Returns false on error.
Definition at line 120 of file gfile_unix.cpp.
|
staticnoexcept |
Calls read() or equivalent.
Definition at line 149 of file gfile_unix.cpp.
Reads a symlink. Throws on error.
Definition at line 436 of file gfile_unix.cpp.
Reads a symlink. Returns the empty path on error.
Definition at line 445 of file gfile_unix.cpp.
|
static |
Deletes the file or directory. Throws an exception on error.
Definition at line 183 of file gfile_unix.cpp.
|
staticnoexcept |
Deletes the file or directory. Returns false on error.
Definition at line 177 of file gfile_unix.cpp.
Renames the file.
Whether it fails if 'to' already exists depends on the o/s (see also renameOnto()). Returns false on error.
Renames the file, deleting 'to' first if necessary.
Returns false on error.
Definition at line 144 of file gfile_unix.cpp.
|
staticnoexcept |
Does ::lseek() or equivalent.
Definition at line 472 of file gfile_unix.cpp.
|
staticnoexcept |
Sets the file descriptor to non-blocking mode.
Definition at line 480 of file gfile_unix.cpp.
|
static |
|
static |
|
static |
|
static |
|
staticnoexcept |
Calls ::write() or equivalent.
Definition at line 154 of file gfile_unix.cpp.