libcamgm
|
Wrapper class for ::stat/::lstat and other file/directory related operations. More...
#include <PathInfo.hpp>
Classes | |
class | DevInoCache |
Simple cache remembering device/inode to detect hard links. More... | |
class | StatMode |
Wrapper class for mode_t values as derived from ::stat. More... | |
Public Types | |
enum | Mode { E_STAT, E_LSTAT } |
enum | FileType { NOT_AVAIL = 0x00, NOT_EXIST = 0x01, T_FILE = 0x02, T_DIR = 0x04, T_CHARDEV = 0x08, T_BLOCKDEV = 0x10, T_FIFO = 0x20, T_LINK = 0x40, T_SOCKET = 0x80 } |
Public Member Functions | |
PathInfo (const PathName &path="", Mode initial=E_STAT) | |
Constructor to create a PathInfo object from an existing PathName object. Initial stat-mode defaults to E_STAT. More... | |
PathInfo (const std::string &path, Mode initial=E_STAT) | |
Constructor to create a PathInfo object from a std::string. Initial stat-mode defaults to E_STAT. More... | |
PathInfo (const char *path, Mode initial=E_STAT) | |
Constructor to create a PathInfo object from a c-string. Initial stat-mode defaults to E_STAT. More... | |
virtual | ~PathInfo () |
Destructor. More... | |
const PathName | path () const |
Returns the PathName object this PathInfo object holds. More... | |
std::string | toString () const |
Returns a std::string formed from the PathName object this this PathInfo object holds. More... | |
Mode | mode () const |
Returns the stat mode which is currently set in this PathInfo object. More... | |
int | error () const |
Returns the internal error code. More... | |
void | setPath (const PathName &path) |
Set the path you want to explore to path. More... | |
void | setMode (Mode mode) |
Set the [l]stat mode to mode. More... | |
bool | stat (const PathName &path) |
Performs stat on path. More... | |
bool | lstat (const PathName &path) |
Performs lstat on path. More... | |
bool | operator() (const PathName &path) |
Sets the PathInfo object to path and performs (l)stat on on it. More... | |
bool | stat () |
Performs a stat operation on the path currently held by this PathInfo object. More... | |
bool | lstat () |
Performs a lstat operation on the path currently held by this PathInfo object. More... | |
bool | operator() () |
Performs (l)stat on current path. More... | |
bool | exists () const |
True if the path that this PathInfo object points to exists. More... | |
nlink_t | nlink () const |
Returns the number of hard links to the file the PathName object points to. More... | |
uid_t | owner () const |
Get the user ID of the file owner. More... | |
gid_t | group () const |
Get the group ID of the file owner. More... | |
dev_t | dev () const |
Returns the ID of the device that contains the file. More... | |
dev_t | rdev () const |
Returns the device ID of a special file. More... | |
ino_t | ino () const |
Returns the inode number of the file or directory this PathInfo object holds. More... | |
::off_t | size () const |
Returns the size of the file. More... | |
blksize_t | blksize () const |
Returns the block size of the file. More... | |
blkcnt_t | blocks () const |
Returns the number of blocks used by the file. More... | |
File type functions. | |
FileType | fileType () const |
Returns the file type. More... | |
bool | isFile () const |
Check if the PathInfo object points to a regular file. More... | |
bool | isDir () const |
Check if the PathInfo object points to a directory. More... | |
bool | isLink () const |
Check if the PathInfo object points to a symbolic link. More... | |
bool | isChr () const |
Check if the PathInfo object points to a character device. More... | |
bool | isBlk () const |
Check if the PathInfo object points to a block device. More... | |
bool | isFifo () const |
Check if the PathInfo object points to a FIFO (named pipe). More... | |
bool | isSock () const |
Check if the PathInfo object points to a socket. More... | |
Permissions | |
The following functions can be used to check for file permissions. Their functionality closely resembles the POSIX flags mentioned in 'man [l]stat'. | |
bool | isRUsr () const |
Check if owner has read permission. More... | |
bool | isWUsr () const |
Check if owner has write permission. More... | |
bool | isXUsr () const |
Check if owner has execute permission. More... | |
bool | isR () const |
bool | isW () const |
bool | isX () const |
bool | isRGrp () const |
Check if group has read permission. More... | |
bool | isWGrp () const |
Check if group has write permission. More... | |
bool | isXGrp () const |
Check if group has execute permission. More... | |
bool | isROth () const |
Check if others have read permission. More... | |
bool | isWOth () const |
Check if others have write permission. More... | |
bool | isXOth () const |
Check if others have execute permission. More... | |
bool | isUid () const |
Check if 'set UID bit" is set. More... | |
bool | isGid () const |
Check if 'set GID bit" is set. More... | |
bool | isVtx () const |
Check if 'sticky bit" is set. More... | |
mode_t | uperm () const |
Get the file owner permissions. More... | |
mode_t | gperm () const |
Get the file group permissions. More... | |
mode_t | operm () const |
Get the file permissions for others. More... | |
mode_t | perm () const |
Get the complete file permissions. More... | |
bool | isPerm (mode_t m) const |
Check if file has given permissions. More... | |
bool | hasPerm (mode_t m) const |
Check if file has given permission flags set. More... | |
mode_t | st_mode () const |
Returns the mode (i.e. file access permissions) of the file. More... | |
mode_t | userMay () const |
Get permission according to current uid/gid. More... | |
bool | userMayR () const |
Check if the current User (as returned by getuid()) may read the file. More... | |
bool | userMayW () const |
Check if the current User (as returned by getuid()) may write to the file. More... | |
bool | userMayX () const |
Check if the current User (as returned by getuid()) may execute the file. More... | |
bool | userMayRW () const |
Check if the current User (as returned by getuid()) may read and write the file. More... | |
bool | userMayRX () const |
Check if the current User (as returned by getuid()) may read and execute the file. More... | |
bool | userMayWX () const |
Check if the current User (as returned by getuid()) may write and execute the file. More... | |
bool | userMayRWX () const |
Check if the current User (as returned by getuid()) may read, write and execute the file. More... | |
time functions | |
time_t | atime () const |
Get the access time of the file. More... | |
time_t | mtime () const |
Get the time of the last modification of the file. More... | |
time_t | ctime () const |
Get the last-change time of inode status of the file. More... | |
Private Attributes | |
PathName | m_path |
struct stat | m_statbuf_C |
Mode | m_mode |
int | m_error |
Friends | |
std::ostream & | operator<< (std::ostream &str, FileType obj) |
Overloaded << operator. More... | |
std::ostream & | operator<< (std::ostream &str, const PathInfo &obj) |
Wrapper class for ::stat/::lstat and other file/directory related operations.
This wrapper class for ::stat/::lstat can be used like in the following code fragment:
|
virtual |
Destructor.
time_t ca_mgm::path::PathInfo::atime | ( | ) | const |
Get the access time of the file.
blksize_t ca_mgm::path::PathInfo::blksize | ( | ) | const |
Returns the block size of the file.
blkcnt_t ca_mgm::path::PathInfo::blocks | ( | ) | const |
Returns the number of blocks used by the file.
time_t ca_mgm::path::PathInfo::ctime | ( | ) | const |
Get the last-change time of inode status of the file.
dev_t ca_mgm::path::PathInfo::dev | ( | ) | const |
Returns the ID of the device that contains the file.
|
inline |
Returns the internal error code.
Returns '-1' if no (l)stat operations has been performed so far. This can be the case if:
|
inline |
True if the path that this PathInfo object points to exists.
FileType ca_mgm::path::PathInfo::fileType | ( | ) | const |
mode_t ca_mgm::path::PathInfo::gperm | ( | ) | const |
Get the file group permissions.
All other flags are masked out (masked to 0).
gid_t ca_mgm::path::PathInfo::group | ( | ) | const |
Get the group ID of the file owner.
bool ca_mgm::path::PathInfo::hasPerm | ( | mode_t | m | ) | const |
Check if file has given permission flags set.
m | The mode_t flags you want the file to be checked for. |
ino_t ca_mgm::path::PathInfo::ino | ( | ) | const |
Returns the inode number of the file or directory this PathInfo object holds.
bool ca_mgm::path::PathInfo::isBlk | ( | ) | const |
Check if the PathInfo object points to a block device.
bool ca_mgm::path::PathInfo::isChr | ( | ) | const |
Check if the PathInfo object points to a character device.
bool ca_mgm::path::PathInfo::isDir | ( | ) | const |
Check if the PathInfo object points to a directory.
bool ca_mgm::path::PathInfo::isFifo | ( | ) | const |
Check if the PathInfo object points to a FIFO (named pipe).
bool ca_mgm::path::PathInfo::isFile | ( | ) | const |
Check if the PathInfo object points to a regular file.
bool ca_mgm::path::PathInfo::isGid | ( | ) | const |
Check if 'set GID bit" is set.
bool ca_mgm::path::PathInfo::isLink | ( | ) | const |
Check if the PathInfo object points to a symbolic link.
bool ca_mgm::path::PathInfo::isPerm | ( | mode_t | m | ) | const |
Check if file has given permissions.
m | The mode_t you want the file to be checked for. |
bool ca_mgm::path::PathInfo::isR | ( | ) | const |
bool ca_mgm::path::PathInfo::isRGrp | ( | ) | const |
Check if group has read permission.
bool ca_mgm::path::PathInfo::isROth | ( | ) | const |
Check if others have read permission.
bool ca_mgm::path::PathInfo::isRUsr | ( | ) | const |
Check if owner has read permission.
bool ca_mgm::path::PathInfo::isSock | ( | ) | const |
Check if the PathInfo object points to a socket.
bool ca_mgm::path::PathInfo::isUid | ( | ) | const |
Check if 'set UID bit" is set.
bool ca_mgm::path::PathInfo::isVtx | ( | ) | const |
Check if 'sticky bit" is set.
bool ca_mgm::path::PathInfo::isW | ( | ) | const |
bool ca_mgm::path::PathInfo::isWGrp | ( | ) | const |
Check if group has write permission.
bool ca_mgm::path::PathInfo::isWOth | ( | ) | const |
Check if others have write permission.
bool ca_mgm::path::PathInfo::isWUsr | ( | ) | const |
Check if owner has write permission.
bool ca_mgm::path::PathInfo::isX | ( | ) | const |
bool ca_mgm::path::PathInfo::isXGrp | ( | ) | const |
Check if group has execute permission.
bool ca_mgm::path::PathInfo::isXOth | ( | ) | const |
Check if others have execute permission.
bool ca_mgm::path::PathInfo::isXUsr | ( | ) | const |
Check if owner has execute permission.
bool ca_mgm::path::PathInfo::lstat | ( | const PathName & | path | ) |
Performs lstat on path.
In case lstat fails errno is saved and can be acquired with PathInfo::error(). The stat mode remains set to 'E_LSTAT'.
path | A PathName object pointing to the path you want to investigate. |
bool ca_mgm::path::PathInfo::lstat | ( | ) |
Performs a lstat operation on the path currently held by this PathInfo object.
On error errno is saved an can be acquired via PathInfo::error(). The stat mode remains set to 'E_LSTAT'
|
inline |
Returns the stat mode which is currently set in this PathInfo object.
time_t ca_mgm::path::PathInfo::mtime | ( | ) | const |
Get the time of the last modification of the file.
nlink_t ca_mgm::path::PathInfo::nlink | ( | ) | const |
Returns the number of hard links to the file the PathName object points to.
bool ca_mgm::path::PathInfo::operator() | ( | const PathName & | path | ) |
Sets the PathInfo object to path and performs (l)stat on on it.
Which function is called depends on the current stat mode (default: E_STAT). On error errno is saved and can be acquired via PathInfo::error().
path | A PathName object point to the path you want to investigate. |
bool ca_mgm::path::PathInfo::operator() | ( | ) |
Performs (l)stat on current path.
Depending on the current stat mode this operator performs either stat, or lstat. On error errno is saved and can be acquired via PathInfo::error().
mode_t ca_mgm::path::PathInfo::operm | ( | ) | const |
Get the file permissions for others.
All other flags are masked out (masked to 0).
uid_t ca_mgm::path::PathInfo::owner | ( | ) | const |
Get the user ID of the file owner.
|
inline |
mode_t ca_mgm::path::PathInfo::perm | ( | ) | const |
Get the complete file permissions.
dev_t ca_mgm::path::PathInfo::rdev | ( | ) | const |
Returns the device ID of a special file.
void ca_mgm::path::PathInfo::setMode | ( | Mode | mode | ) |
Set the [l]stat mode to mode.
When examining a link you get:
mode | The mode you want to set. Can be PathInfo::E_STAT, or PathInfo::E_LSTAT |
void ca_mgm::path::PathInfo::setPath | ( | const PathName & | path | ) |
Set the path you want to explore to path.
path | The PathName object you want to investigate. |
::off_t ca_mgm::path::PathInfo::size | ( | ) | const |
Returns the size of the file.
mode_t ca_mgm::path::PathInfo::st_mode | ( | ) | const |
Returns the mode (i.e. file access permissions) of the file.
From the lstat man page: The following POSIX macros are defined to check the file type:
bool ca_mgm::path::PathInfo::stat | ( | const PathName & | path | ) |
Performs stat on path.
In case stat fails errno is saved and can be acquired with PathInfo::error(). The stat mode remains set to 'E_STAT'.
path | The PathName object pointing to the path you want to investigate. |
bool ca_mgm::path::PathInfo::stat | ( | ) |
Performs a stat operation on the path currently held by this PathInfo object.
On error errno is saved an can be acquired via PathInfo::error(). The stat mode remains set to 'E_STAT'
|
inline |
mode_t ca_mgm::path::PathInfo::uperm | ( | ) | const |
Get the file owner permissions.
All other flags are masked out (masked to 0).
mode_t ca_mgm::path::PathInfo::userMay | ( | ) | const |
Get permission according to current uid/gid.
bool ca_mgm::path::PathInfo::userMayR | ( | ) | const |
Check if the current User (as returned by getuid()) may read the file.
bool ca_mgm::path::PathInfo::userMayRW | ( | ) | const |
Check if the current User (as returned by getuid()) may read and write the file.
bool ca_mgm::path::PathInfo::userMayRWX | ( | ) | const |
Check if the current User (as returned by getuid()) may read, write and execute the file.
bool ca_mgm::path::PathInfo::userMayRX | ( | ) | const |
Check if the current User (as returned by getuid()) may read and execute the file.
bool ca_mgm::path::PathInfo::userMayW | ( | ) | const |
Check if the current User (as returned by getuid()) may write to the file.
bool ca_mgm::path::PathInfo::userMayWX | ( | ) | const |
Check if the current User (as returned by getuid()) may write and execute the file.
bool ca_mgm::path::PathInfo::userMayX | ( | ) | const |
Check if the current User (as returned by getuid()) may execute the file.
|
friend |
Overloaded << operator.
The << operator is overloaded for FileType objects to produce the following output:
str | The std::ostream we want to write to. |
obj | The FileType object we want to be written to the ostream. |
|
friend |
|
private |
|
private |
|
private |
|
private |