#include <PathInfo.hpp>
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. | |
| PathInfo (const blocxx::String &path, Mode initial=E_STAT) | |
| Constructor to create a PathInfo object from a blocxx::String. Initial stat-mode defaults to E_STAT. | |
| 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. | |
| virtual | ~PathInfo () |
| Destructor. | |
| const PathName | path () const |
| Returns the PathName object this PathInfo object holds. | |
| blocxx::String | toString () const |
| Returns a blocxx::String formed from the PathName object this this PathInfo object holds. | |
| Mode | mode () const |
| Returns the stat mode which is currently set in this PathInfo object. | |
| int | error () const |
| Returns the internal error code. | |
| void | setPath (const PathName &path) |
| Set the path you want to explore to path. | |
| void | setMode (Mode mode) |
| Set the [l]stat mode to mode. | |
| bool | stat (const PathName &path) |
| Performs stat on path. | |
| bool | lstat (const PathName &path) |
| Performs lstat on path. | |
| bool | operator() (const PathName &path) |
| Sets the PathInfo object to path and performs (l)stat on on it. | |
| bool | stat () |
| Performs a stat operation on the path currently held by this PathInfo object. | |
| bool | lstat () |
| Performs a lstat operation on the path currently held by this PathInfo object. | |
| bool | operator() () |
| Performs (l)stat on current path. | |
| bool | exists () const |
| True if the path that this PathInfo object points to exists. | |
| nlink_t | nlink () const |
| Returns the number of hard links to the file the PathName object points to. | |
| uid_t | owner () const |
| Get the user ID of the file owner. | |
| gid_t | group () const |
| Get the group ID of the file owner. | |
| dev_t | dev () const |
| Returns the ID of the device that contains the file. | |
| dev_t | rdev () const |
| Returns the device ID of a special file. | |
| ino_t | ino () const |
| Returns the inode number of the file or directory this PathInfo object holds. | |
| ::off_t | size () const |
| Returns the size of the file. | |
| blksize_t | blksize () const |
| Returns the block size of the file. | |
| blkcnt_t | blocks () const |
| Returns the number of blocks used by the file. | |
File type functions. | |
| FileType | fileType () const |
| Returns the file type. | |
| bool | isFile () const |
| Check if the PathInfo object points to a regular file. | |
| bool | isDir () const |
| Check if the PathInfo object points to a directory. | |
| bool | isLink () const |
| Check if the PathInfo object points to a symbolic link. | |
| bool | isChr () const |
| Check if the PathInfo object points to a character device. | |
| bool | isBlk () const |
| Check if the PathInfo object points to a block device. | |
| bool | isFifo () const |
| Check if the PathInfo object points to a FIFO (named pipe). | |
| bool | isSock () const |
| Check if the PathInfo object points to a socket. | |
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. | |
| bool | isWUsr () const |
| Check if owner has write permission. | |
| bool | isXUsr () const |
| Check if owner has execute permission. | |
| bool | isR () const |
| bool | isW () const |
| bool | isX () const |
| bool | isRGrp () const |
| Check if group has read permission. | |
| bool | isWGrp () const |
| Check if group has write permission. | |
| bool | isXGrp () const |
| Check if group has execute permission. | |
| bool | isROth () const |
| Check if others have read permission. | |
| bool | isWOth () const |
| Check if others have write permission. | |
| bool | isXOth () const |
| Check if others have execute permission. | |
| bool | isUid () const |
| Check if 'set UID bit" is set. | |
| bool | isGid () const |
| Check if 'set GID bit" is set. | |
| bool | isVtx () const |
| Check if 'sticky bit" is set. | |
| mode_t | uperm () const |
| Get the file owner permissions. | |
| mode_t | gperm () const |
| Get the file group permissions. | |
| mode_t | operm () const |
| Get the file permissions for others. | |
| mode_t | perm () const |
| Get the complete file permissions. | |
| bool | isPerm (mode_t m) const |
| Check if file has given permissions. | |
| bool | hasPerm (mode_t m) const |
| Check if file has given permission flags set. | |
| mode_t | st_mode () const |
| Returns the mode (i.e. file access permissions) of the file. | |
| mode_t | userMay () const |
| Get permission according to current uid/gid. | |
| bool | userMayR () const |
| Check if the current User (as returned by getuid()) may read the file. | |
| bool | userMayW () const |
| Check if the current User (as returned by getuid()) may write to the file. | |
| bool | userMayX () const |
| Check if the current User (as returned by getuid()) may execute the file. | |
| bool | userMayRW () const |
| Check if the current User (as returned by getuid()) may read and write the file. | |
| bool | userMayRX () const |
| Check if the current User (as returned by getuid()) may read and execute the file. | |
| bool | userMayWX () const |
| Check if the current User (as returned by getuid()) may write and execute the file. | |
| bool | userMayRWX () const |
| Check if the current User (as returned by getuid()) may read, write and execute the file. | |
time functions | |
| time_t | atime () const |
| Get the access time of the file. | |
| time_t | mtime () const |
| Get the time of the last modification of the file. | |
| time_t | ctime () const |
| Get the last-change time of inode status of the file. | |
Private Attributes | |
| PathName | m_path |
| stat | m_statbuf_C |
| Mode | m_mode |
| int | m_error |
Friends | |
| std::ostream & | operator<< (std::ostream &str, FileType obj) |
| Overloaded << operator. | |
| std::ostream & | operator<< (std::ostream &str, const PathInfo &obj) |
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... | |
This wrapper class for stat/lstat can be used like in the following code fragment:
PathInfo pi1( "/foo/bar/some_file"); // new object from c-string PathInfo pi2( PathName( "/foo/bar/some_file"); // new object from PathName object PathInfo pi3( blocxx::String( "/foo/bar/some_file" ); // new object from blocxx::String std::cout << "File: \t\t" << pi1 << std::endl; std::cout << "Type: \t\t" << pi1.fileType() << std::endl; std::cout << "UID: \t\t" << pi1.owner() << std::endl; std::cout << "GID: \t\t" << pi1.group() << std::endl; std::cout << "#links: \t" << pi1.nlink() << std::endl; // Note the comment further down on the return value of size()! std::cout << "size: \t\t" << blocxx::String( pi1.size() ) << std::endl; std::cout << "blksize: \t" << pi1.blksize() << std::endl; std::cout << "blocks: \t" << pi1.blocks() << std::endl; std::cout << "dev: \t\t" << pi1.dev() << std::endl; std::cout << "ino: \t\t" << pi1.ino() << std::endl; // Using PathInfo::[a,c,m]time() time_t tmpTime = pi1.atime(); struct tm *timeStruct = localtime( &tmpTime ); char *timeFormat = "%d.%m.%Y - %X"; char timeBuf[256]; strftime( timeBuf, sizeof( timeBuf ), timeFormat, timeStruct ); std::cout << "atime: \t\t" << timeBuf << std::endll;
|
|
|
|
|
|
|
||||||||||||
|
Constructor to create a PathInfo object from an existing PathName object. Initial stat-mode defaults to E_STAT.
|
|
||||||||||||
|
Constructor to create a PathInfo object from a blocxx::String. Initial stat-mode defaults to E_STAT.
|
|
||||||||||||
|
Constructor to create a PathInfo object from a c-string. Initial stat-mode defaults to E_STAT.
|
|
|
Destructor.
|
|
|
Get the access time of the file.
|
|
|
Returns the block size of the file.
|
|
|
Returns the number of blocks used by the file.
|
|
|
Get the last-change time of inode status of the file.
|
|
|
Returns the ID of the device that contains the file.
|
|
|
Returns the internal error code. Returns '-1' if no (l)stat operations has been performed so far. This can be the case if:
|
|
|
True if the path that this PathInfo object points to exists.
|
|
|
Returns the file type.
|
|
|
Get the file group permissions. All other flags are masked out (masked to 0).
|
|
|
Get the group ID of the file owner.
|
|
|
Check if file has given permission flags set.
|
|
|
Returns the inode number of the file or directory this PathInfo object holds.
|
|
|
Check if the PathInfo object points to a block device.
|
|
|
Check if the PathInfo object points to a character device.
|
|
|
Check if the PathInfo object points to a directory.
|
|
|
Check if the PathInfo object points to a FIFO (named pipe).
|
|
|
Check if the PathInfo object points to a regular file.
|
|
|
Check if 'set GID bit" is set.
|
|
|
Check if the PathInfo object points to a symbolic link.
|
|
|
Check if file has given permissions.
|
|
|
|
|
|
Check if group has read permission.
|
|
|
Check if others have read permission.
|
|
|
Check if owner has read permission.
|
|
|
Check if the PathInfo object points to a socket.
|
|
|
Check if 'set UID bit" is set.
|
|
|
Check if 'sticky bit" is set.
|
|
|
|
|
|
Check if group has write permission.
|
|
|
Check if others have write permission.
|
|
|
Check if owner has write permission.
|
|
|
|
|
|
Check if group has execute permission.
|
|
|
Check if others have execute permission.
|
|
|
Check if owner has execute permission.
|
|
|
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'
|
|
|
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'.
|
|
|
Returns the stat mode which is currently set in this PathInfo object.
|
|
|
Get the time of the last modification of the file.
|
|
|
Returns the number of hard links to the file the PathName object points to.
|
|
|
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().
|
|
|
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().
|
|
|
Get the file permissions for others. All other flags are masked out (masked to 0).
|
|
|
Get the user ID of the file owner.
|
|
|
Returns the PathName object this PathInfo object holds.
|
|
|
Get the complete file permissions.
|
|
|
Returns the device ID of a special file.
|
|
|
Set the [l]stat mode to mode. When examining a link you get:
|
|
|
Set the path you want to explore to path.
|
|
|
Returns the size of the file.
|
|
|
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:
|
|
|
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'
|
|
|
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'.
|
|
|
Returns a blocxx::String formed from the PathName object this this PathInfo object holds.
|
|
|
Get the file owner permissions. All other flags are masked out (masked to 0).
|
|
|
Get permission according to current uid/gid.
|
|
|
Check if the current User (as returned by getuid()) may read the file.
|
|
|
Check if the current User (as returned by getuid()) may read and write the file.
|
|
|
Check if the current User (as returned by getuid()) may read, write and execute the file.
|
|
|
Check if the current User (as returned by getuid()) may read and execute the file.
|
|
|
Check if the current User (as returned by getuid()) may write to the file.
|
|
|
Check if the current User (as returned by getuid()) may write and execute the file.
|
|
|
Check if the current User (as returned by getuid()) may execute the file.
|
|
||||||||||||
|
|
|
||||||||||||
|
Overloaded << operator. The << operator is overloaded for FileType objects to produce the following output: PathInfo pi("./foo/bar/some_file"); std::cout << pi.fileType(); // =="./foo/bar/some_file{<st_mode> <uid>/<gid> [size <size>]"
|
|
|
|
|
|
|
|
|
|
|
|
|
1.4.6