libcamgm
Classes | Functions
ca_mgm::path Namespace Reference

The LiMaL path utility namespace. More...

Classes

class  PathInfo
 Wrapper class for ::stat/::lstat and other file/directory related operations. More...
 
class  PathName
 PathName manipulation class. More...
 

Functions

bool operator== (const PathName &lname, const PathName &rname)
 
bool operator!= (const PathName &lname, const PathName &rname)
 
PathName operator+ (const PathName &lname, const PathName &rname)
 
std::ostream & operator<< (std::ostream &ostr, const PathName &path)
 
int createDir (const PathName &path, mode_t mode=0755)
 Create a directory. More...
 
int createDirRecursive (const PathName &path, mode_t mode=0755)
 
int removeDir (const PathName &path)
 Remove a directory. More...
 
int removeDirRecursive (const PathName &path)
 Remove a directory recursively. More...
 
int copyDir (const PathName &srcPath, const PathName &destPath)
 
int readDir (std::list< std::string > &retlist, const PathName &path, bool dots)
 
int removeFile (const PathName &path)
 
int moveFile (const PathName &oldPath, const PathName &newPath)
 
int copyFile (const PathName &file, const PathName &dest)
 
int symLink (const PathName &oldPath, const PathName &newPath)
 
int changeMode (const PathName &path, mode_t mode)
 

Detailed Description

The LiMaL path utility namespace.

Function Documentation

int ca_mgm::path::changeMode ( const PathName path,
mode_t  mode 
)

Like '::chmod'. The mode of the file given by path is changed.

Returns
0 on success, errno on failure
int ca_mgm::path::copyDir ( const PathName srcPath,
const PathName destPath 
)

Like 'cp -a srcPath destPath'. Copy directory tree. srcpath/destpath must be directories. 'basename srcpath' must not exist in destpath.

Returns
0 on success, ENOTDIR if srcpath/destpath is not a directory, EEXIST if 'basename srcpath' exists in destpath, otherwise the commands return value.
Todo:
Rewrite not to execute shell command 'cp -a <srcPath> <destPath>'
int ca_mgm::path::copyFile ( const PathName file,
const PathName dest 
)

Like 'cp file dest'. Copy file to destination file.

Returns
0 on success, EINVAL if file is not a file, EISDIR if destiantion is a directory, otherwise the commands return value.
int ca_mgm::path::createDir ( const PathName path,
mode_t  mode = 0755 
)

Create a directory.

Like '::mkdir'. Attempt to create a new directory with name 'path'. The parameter 'mode' specifies the permissions bits to use. It is modified by the process's umask in the usual way.

The directory's user ID is set to the process' effective user ID, the group ID to the effective group ID of the process or inherited from the parent directory if the set group ID bit is set or if specified by mount options.

Parameters
pathThe path name of the new directory.
modeThe permissions bits of the new directory.
Returns
0 on success, errno value on failure
int ca_mgm::path::createDirRecursive ( const PathName path,
mode_t  mode = 0755 
)

Create a directory with parent directories as needed.

Like 'mkdir -p'. Attempt to create a new directory with name 'path' and all parent directories as needed. The parameter 'mode' specifies the permissions bits to use. It is modified by the process's umask in the usual way. No error is reported if the directory already exists.

Parameters
pathThe path name of the new directory.
modeThe permissions bits of the new directory.
Returns
0 on success, errno value on failure
int ca_mgm::path::moveFile ( const PathName oldPath,
const PathName newPath 
)

Like '::rename'. Renames a file, moving it between directories if required.

Returns
0 on success, errno on failure
bool ca_mgm::path::operator!= ( const PathName lname,
const PathName rname 
)
inline
PathName ca_mgm::path::operator+ ( const PathName lname,
const PathName rname 
)
inline

References operator<<().

std::ostream& ca_mgm::path::operator<< ( std::ostream &  ostr,
const PathName path 
)
bool ca_mgm::path::operator== ( const PathName lname,
const PathName rname 
)
inline
int ca_mgm::path::readDir ( std::list< std::string > &  retlist,
const PathName path,
bool  dots 
)

Return content of directory via retlist. If dots is false entries starting with '.' are not reported. "." and ".." are never reported.

Returns
0 on success, errno on failure.
int ca_mgm::path::removeDir ( const PathName path)

Remove a directory.

Like '::rmdir'. Delete a directory, which must be empty.

Parameters
pathThe path to the directory.
Returns
0 on success, errno value on failure
int ca_mgm::path::removeDirRecursive ( const PathName path)

Remove a directory recursively.

Like 'rm -r path'. Delete a directory, recursively removing its contents.

Parameters
pathThe path to the directory.
Returns
0 on success, ENOTDIR if the specified path is not a directory, otherwise the commands return value.
Todo:
Rewrite not to execute shell command 'rm -rf –preserve-root – <path>'.
int ca_mgm::path::removeFile ( const PathName path)

Like '::unlink'. Delete a file (symbolic link, socket, fifo or device).

Returns
0 on success, errno on failure
int ca_mgm::path::symLink ( const PathName oldPath,
const PathName newPath 
)

Like '::symlink'. Creates a symbolic link named newpath which contains the string oldpath. If newpath exists it will not be overwritten.

Returns
0 on success, errno on failure.