1 #ifndef WIBBLE_SYS_DIRECTORY_H 2 #define WIBBLE_SYS_DIRECTORY_H 22 std::auto_ptr<struct stat>
stat(
const std::string& pathname);
28 void stat(
const std::string& pathname,
struct stat& st);
31 bool access(
const std::string& s,
int m);
34 bool exists(
const std::string& s);
39 std::string
abspath(
const std::string& pathname);
42 std::string
mkdtemp( std::string templ );
51 void mkpath(
const std::string& dir);
58 std::string
readFile(
const std::string &file);
67 std::string
readFile(std::istream& file,
const std::string& filename);
70 void writeFile(
const std::string &file,
const std::string &data);
97 void renameIfExists(
const std::string& src,
const std::string& dst);
100 void unlink(
const std::string& fname);
106 void rmtree(
const std::string& dir);
113 bool isdir(
const std::string& pathname);
116 bool isblk(
const std::string& pathname);
119 bool ischr(
const std::string& pathname);
122 bool isfifo(
const std::string& pathname);
125 bool islnk(
const std::string& pathname);
128 bool isreg(
const std::string& pathname);
131 bool issock(
const std::string& pathname);
134 time_t
timestamp(
const std::string& file);
137 time_t
timestamp(
const std::string& file, time_t def);
140 size_t size(
const std::string& file);
143 size_t size(
const std::string& file,
size_t def);
146 ino_t
inode(
const std::string& file);
149 ino_t
inode(
const std::string& file, ino_t def);
167 struct dirent* direntbuf;
void mkdirIfMissing(const std::string &dir, mode_t mode=0777)
Create the given directory, if it does not already exists.
bool ischr(const std::string &pathname)
Same as isdir but checks for character devices.
std::string findExecutable(const std::string &name)
Compute the absolute path of an executable.
Definition: fs.cpp:223
ino_t inode(const std::string &file)
File inode number.
Definition: fs.cpp:300
void writeFileAtomically(const std::string &file, const std::string &data)
Write data to file, replacing existing contents if it already exists.
Definition: fs.cpp:206
bool isblk(const std::string &pathname)
Same as isdir but checks for block devices.
bool exists(const std::string &s)
Same as access(s, F_OK);.
void rmtree(const std::string &dir)
Delete the directory dir and all its content.
std::string abspath(const std::string &pathname)
Get the absolute path of a file.
const std::string & path() const
Pathname of the directory.
Definition: fs.h:216
std::string m_path
Directory pathname.
Definition: fs.h:157
const_iterator & operator=(const const_iterator &i)
void unlink(const std::string &fname)
Delete the file.
Definition: fs.cpp:262
bool isfifo(const std::string &pathname)
Same as isdir but checks for FIFOs.
void mkpath(const std::string &dir)
Create all the component of the given directory, including the directory itself.
std::string mkdtemp(std::string templ)
void writeFile(const std::string &file, const std::string &data)
Write data to file, replacing existing contents if it already exists.
Definition: fs.cpp:198
bool deleteIfExists(const std::string &file)
Delete a file if it exists.
Definition: fs.cpp:244
Directory(const std::string &path)
bool access(const std::string &s, int m)
access() a filename
bool operator!=(const const_iterator &iter) const
bool isreg(const std::string &pathname)
Same as isdir but checks for regular files.
const_iterator end() const
End iterator.
void rmdir(const std::string &dirname)
Remove the directory using rmdir(2)
Definition: fs.cpp:268
time_t timestamp(const std::string &file)
File mtime.
Definition: fs.cpp:274
bool islnk(const std::string &pathname)
Same as isdir but checks for symbolic links.
const_iterator begin() const
Begin iterator.
size_t size(const std::string &file)
File size.
Definition: fs.cpp:287
std::string readFile(const std::string &file)
Read whole file into memory. Throws exceptions on failure.
Definition: fs.cpp:164
Nicely wrap access to directories.
Definition: fs.h:153
bool operator==(const const_iterator &iter) const
bool issock(const std::string &pathname)
Same as isdir but checks for sockets.
void mkFilePath(const std::string &file)
Ensure that the path to the given file exists, creating it if it does not.
std::string dirname(const std::string &pathname)
Given a pathname, return the directory name without the file name.
Definition: string.h:134
bool isdir(const std::string &pathname)
Returns true if the given pathname is a directory, else false.
std::auto_ptr< struct stat > stat(const std::string &pathname)
stat() the given file and return the struct stat with the results.
std::string operator*() const
bool exists() const
Check if the directory exists.
const_iterator & operator++()
Move to the next directory entry.
void renameIfExists(const std::string &src, const std::string &dst)
Move src to dst, without raising exception if src does not exist.
Definition: fs.cpp:255