wibble  0.1.28
Classes | Functions
wibble::sys::fs Namespace Reference

Classes

struct  FileLock
 RAII fcntl advisory file lock. More...
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.
void writeFile (const std::string &file, const std::string &data)
 Write data to file, replacing existing contents if it already exists.
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)
void rmtree (const std::string &dir)
 Delete the directory dir and all its content.
std::auto_ptr< struct statstat (const std::string &pathname)
 stat() the given file and return the struct stat with the results.
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.
void mkdirIfMissing (const std::string &dir, mode_t mode)
 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.
bool isdir (const std::string &pathname)
 Returns true if the given pathname is a directory, else false.
bool isDirectory (const std::string &pathname) __attribute__((deprecated))
 same as isdir, but with a legacy clumsy name

Function Documentation

std::string wibble::sys::fs::abspath ( const std::string &  pathname)

Get the absolute path of a file.

bool wibble::sys::fs::access ( const std::string &  s,
int  m 
)
bool wibble::sys::fs::deleteIfExists ( const std::string &  file)

Delete a file if it exists.

If it does not exist, do nothing.

Returns:
true if the file was deleted, false if it did not exist

References unlink().

Referenced by TestFs::_deleteIfExists().

bool wibble::sys::fs::exists ( const std::string &  s)

Same as access(s, F_OK);.

bool wibble::sys::fs::isdir ( const std::string &  pathname)

Returns true if the given pathname is a directory, else false.

It also returns false if the pathname does not exist.

bool wibble::sys::fs::isDirectory ( const std::string &  pathname)

same as isdir, but with a legacy clumsy name

Referenced by TestFs::_isDirectory().

void wibble::sys::fs::mkdirIfMissing ( const std::string &  dir,
mode_t  mode 
)

Create the given directory, if it does not already exists.

It will complain if the given pathname already exists but is not a directory.

void wibble::sys::fs::mkFilePath ( const std::string &  file)

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().

void wibble::sys::fs::mkpath ( const std::string &  dir)

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.

References wibble::list::end().

void wibble::sys::fs::renameIfExists ( const std::string &  src,
const std::string &  dst 
)

Move src to dst, without raising exception if src does not exist.

void wibble::sys::fs::rmdir ( const std::string &  dirname)

Remove the directory using rmdir(2)

Referenced by rmtree().

void wibble::sys::fs::rmtree ( const std::string &  dir)
std::auto_ptr<struct stat> wibble::sys::fs::stat ( const std::string &  pathname)

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 wibble::sys::fs::Directory::isdir().

void wibble::sys::fs::unlink ( const std::string &  fname)

Delete the file.

Referenced by deleteIfExists(), and rmtree().

void wibble::sys::fs::writeFile ( const std::string &  file,
const std::string &  data 
)

Write data to file, replacing existing contents if it already exists.