wibble 1.1
|
Classes | |
class | Directory |
Nicely wrap access to directories. More... | |
struct | Lockfile |
RAII lock file. More... | |
Functions | |
std::string | readFile (const std::string &file) |
Read whole file into memory. Throws exceptions on failure. | |
std::string | readFile (std::istream &file, const std::string &filename) |
Read the entire contents of a file into a string. | |
void | writeFile (const std::string &file, const std::string &data) |
Write data to file, replacing existing contents if it already exists. | |
void | writeFileAtomically (const std::string &file, const std::string &data) |
Write data to file, replacing existing contents if it already exists. | |
std::string | findExecutable (const std::string &name) |
Compute the absolute path of an executable. | |
bool | deleteIfExists (const std::string &file) |
Delete a file if it exists. | |
void | renameIfExists (const std::string &src, const std::string &dst) |
Move src to dst, without raising exception if src does not exist. | |
void | unlink (const std::string &fname) |
Delete the file. | |
void | rmdir (const std::string &dirname) |
Remove the directory using rmdir(2) | |
time_t | timestamp (const std::string &file) |
File mtime. | |
time_t | timestamp (const std::string &file, time_t def) |
File mtime (or def if the file does not exist) | |
size_t | size (const std::string &file) |
File size. | |
size_t | size (const std::string &file, size_t def) |
File size (or def if the file does not exist) | |
ino_t | inode (const std::string &file) |
File inode number. | |
ino_t | inode (const std::string &file, ino_t def) |
File inode number (or 0 if the file does not exist) | |
std::auto_ptr< struct stat > | stat (const std::string &pathname) |
stat() the given file and return the struct stat with the results. | |
void | stat (const std::string &pathname, struct stat &st) |
stat() the given file filling in the given structure. | |
bool | access (const std::string &s, int m) |
access() a filename | |
bool | exists (const std::string &s) |
Same as access(s, F_OK);. | |
std::string | abspath (const std::string &pathname) |
Get the absolute path of a file. | |
std::string | mkdtemp (std::string templ) |
void | mkdirIfMissing (const std::string &dir, mode_t mode=0777) |
Create the given directory, if it does not already exists. | |
void | mkpath (const std::string &dir) |
Create all the component of the given directory, including the directory itself. | |
void | mkFilePath (const std::string &file) |
Ensure that the path to the given file exists, creating it if it does not. | |
void | rmtree (const std::string &dir) |
Delete the directory dir and all its content. | |
bool | isdir (const std::string &pathname) |
Returns true if the given pathname is a directory, else false. | |
bool | isblk (const std::string &pathname) |
Same as isdir but checks for block devices. | |
bool | ischr (const std::string &pathname) |
Same as isdir but checks for character devices. | |
bool | isfifo (const std::string &pathname) |
Same as isdir but checks for FIFOs. | |
bool | islnk (const std::string &pathname) |
Same as isdir but checks for symbolic links. | |
bool | isreg (const std::string &pathname) |
Same as isdir but checks for regular files. | |
bool | issock (const std::string &pathname) |
Same as isdir but checks for sockets. | |
std::string wibble::sys::fs::abspath | ( | const std::string & | pathname | ) |
Get the absolute path of a file.
Referenced by findExecutable().
access() a filename
Referenced by TestFs::_mkdirIfMissing(), TestFs::_mkFilePath(), TestFs::_mkPath2(), and findExecutable().
Delete a file if it exists.
If it does not exist, do nothing.
References unlink().
Referenced by TestFs::_deleteIfExists().
Same as access(s, F_OK);.
Referenced by wibble::tests::TestFileExists::check(), wibble::tests::test_assert_file_exists(), and wibble::tests::test_assert_not_file_exists().
std::string wibble::sys::fs::findExecutable | ( | const std::string & | name | ) |
Compute the absolute path of an executable.
If name is specified as a partial path, it ensures it is made absolute. If name is not specified as a path, it looks for the executable in $PATH and return its absolute pathname.
References abspath(), access(), and wibble::str::joinpath().
File inode number (or 0 if the file does not exist)
References stat().
Same as isdir but checks for block devices.
Same as isdir but checks for character devices.
Returns true if the given pathname is a directory, else false.
It also returns false if the pathname does not exist.
Referenced by TestFs::_isdir().
Same as isdir but checks for symbolic links.
Same as isdir but checks for regular files.
Create the given directory, if it does not already exists.
It will complain if the given pathname already exists but is not a directory.
Referenced by TestFs::_mkdirIfMissing().
std::string wibble::sys::fs::mkdtemp | ( | std::string | templ | ) |
Ensure that the path to the given file exists, creating it if it does not.
The file itself will not get created.
Referenced by TestFs::_mkFilePath().
Create all the component of the given directory, including the directory itself.
Referenced by TestFs::_mkPath(), and TestFs::_mkPath2().
std::string wibble::sys::fs::readFile | ( | const std::string & | file | ) |
Read whole file into memory. Throws exceptions on failure.
Referenced by TestFs::writeFileAtomically().
std::string wibble::sys::fs::readFile | ( | std::istream & | file, |
const std::string & | filename | ||
) |
Read the entire contents of a file into a string.
filename | name or description of the stream we are reading. Used only for error messages. |
Move src to dst, without raising exception if src does not exist.
Delete the directory dir and all its content.
File size (or def if the file does not exist)
References stat().
stat() the given file and return the struct stat with the results.
If the file does not exist, return NULL. Raises exceptions in case of errors.
Referenced by inode(), inode(), size(), size(), timestamp(), and timestamp().
stat() the given file filling in the given structure.
Raises exceptions in case of errors, including if the file does not exist.
File mtime (or def if the file does not exist)
References stat().
Delete the file.
References unlink().
Referenced by deleteIfExists(), TestFs::timestamp(), and unlink().
Write data to file, replacing existing contents if it already exists.
Referenced by TestFs::timestamp().
Write data to file, replacing existing contents if it already exists.
Data is written to a temporary file, then moved to its final destination, to ensure an atomic operation.
References wibble::str::fmtf().