blocxx
Enumerations | Functions

BLOCXX_NAMESPACE::FileSystem::Path Namespace Reference

Enumerations

enum  ESecurity { E_INSECURE, E_SECURE_DIR, E_SECURE_FILE }

Functions

BLOCXX_COMMON_API String realPath (const String &path)
BLOCXX_COMMON_API std::pair
< ESecurity, String
security (String const &path, UserId uid)
BLOCXX_COMMON_API std::pair
< ESecurity, String
security (String const &path)
 Equivalent to security(path, uid), where uid is the effective user ID of the process.
BLOCXX_COMMON_API std::pair
< ESecurity, String
security (String const &base_dir, String const &rel_path, UserId uid)
 A variant of security() that is more efficient if some ancestor directory of the path is already known to be secure and in canonical form.
BLOCXX_COMMON_API std::pair
< ESecurity, String
security (String const &base_dir, String const &rel_path)
 Equivalent to security(base_dir, rel_path, uid), where uid is the effective user ID of the process.
BLOCXX_COMMON_API String dirname (const String &filename)
 Take a string that contains a pathname, and return a string that is a pathname of the parent directory of that file.
BLOCXX_COMMON_API String basename (const String &filename)
 Take a string that contains a pathname, and return a string that is the filename with the path removed.
BLOCXX_COMMON_API String getCurrentWorkingDirectory ()
 Get the process's current working directory.

Enumeration Type Documentation

Enumerator:
E_INSECURE 
E_SECURE_DIR 
E_SECURE_FILE 

Definition at line 341 of file FileSystem.hpp.


Function Documentation

String BLOCXX_NAMESPACE::FileSystem::Path::basename ( const String filename)

Take a string that contains a pathname, and return a string that is the filename with the path removed.

Parameters:
filenameThe file pathname
Returns:
The filename with the path removed

Definition at line 1171 of file PosixFileSystem.cpp.

References BLOCXX_FILENAME_SEPARATOR, BLOCXX_FILENAME_SEPARATOR_C, BLOCXX_NAMESPACE::FileSystem::g_fileSystemMockObject, BLOCXX_NAMESPACE::String::lastIndexOf(), BLOCXX_NAMESPACE::String::length(), BLOCXX_NAMESPACE::String::npos, and BLOCXX_NAMESPACE::String::substring().

String BLOCXX_NAMESPACE::FileSystem::Path::dirname ( const String filename)

Take a string that contains a pathname, and return a string that is a pathname of the parent directory of that file.

Trailing '/' characters in the path are not counted as part of the path. If path does not contain a '/', then dirname() shall return the string ".". If path an empty string, dirname() shall return the string ".".

Parameters:
filenameThe file pathname
Returns:
The pathname of the parent directory of filename.

Definition at line 1132 of file PosixFileSystem.cpp.

References BLOCXX_FILENAME_SEPARATOR, BLOCXX_FILENAME_SEPARATOR_C, BLOCXX_NAMESPACE::FileSystem::g_fileSystemMockObject, BLOCXX_NAMESPACE::String::lastIndexOf(), BLOCXX_NAMESPACE::String::length(), BLOCXX_NAMESPACE::String::npos, and BLOCXX_NAMESPACE::String::substring().

String BLOCXX_NAMESPACE::FileSystem::Path::getCurrentWorkingDirectory ( )

Get the process's current working directory.

Calls to chdir() or fchdir() will modify this. Multi-threaded applications must exercise caution changing the current working directory.

Exceptions:
FileSystemException,:ENOENT-The current working directory has been unlinked.

Definition at line 1209 of file PosixFileSystem.cpp.

References BLOCXX_THROW_ERRNO, BLOCXX_NAMESPACE::FileSystem::g_fileSystemMockObject, and MAXPATHLEN.

Referenced by realPath().

String BLOCXX_NAMESPACE::FileSystem::Path::realPath ( const String path)
Returns:
The canonical path specifying the same directory or file as path. A path is in canonical form iff
  • it is an absolute path,
  • no component is ".", "..", nor a symbolic link,
  • it does not contain repeated '/' characters, and
  • the last character is not '/' unless the entire path is "/".

If path is relative, it will be interpreted relative to the current working directory. This function is similar to the SuSv3 function, however it's easier to use and thread safe.

Parameters:
pathThe path to canonicalize.
Precondition:
No path component examined in the course of resolving path to its canonical form is renamed, deleted, or (for symbolic links) reassigned by some other thread or process while the function executes.
Exceptions:
FileSystemExceptionEACCESS, EIO, ELOOP, ENOENT, ENOTDIR

Definition at line 1080 of file PosixFileSystem.cpp.

References BLOCXX_THROW, BLOCXX_NAMESPACE::String::c_str(), BLOCXX_NAMESPACE::FileSystem::g_fileSystemMockObject, getCurrentWorkingDirectory(), security(), and BLOCXX_NAMESPACE::String::startsWith().

Referenced by BLOCXX_NAMESPACE::FileSystem::readSymbolicLink().

std::pair< ESecurity, String > BLOCXX_NAMESPACE::FileSystem::Path::security ( String const &  base_dir,
String const &  rel_path 
)

Equivalent to security(base_dir, rel_path, uid), where uid is the effective user ID of the process.

Definition at line 544 of file PathSecurity.cpp.

References security().

std::pair< ESecurity, String > BLOCXX_NAMESPACE::FileSystem::Path::security ( String const &  path,
UserId  uid 
)
Returns:
A pair (sec, rpath), as follows:
  • rpath = realpath(path).
  • If path names a directory, and no user other than root or user uid can change the contents of this directory or make path refer to some other file or directory, then sec = E_SECURE_DIR.
  • If path names a regular file, and no user other than root or user uid can change the contents of this file or make path refer to some other file or directory, then sec = E_SECURE_FILE.
  • If any user other than root or user uid can change what path refers to, or change the contents of the file or directory it refers to, then sec = E_INSECURE.
Precondition:
No path component examined in the course of resolving path to its canonical form is renamed, deleted, or (for symbolic links) reassigned by root or user uid while the function executes.
Exceptions:
FileSystemExceptionEACCESS, EIO, ELOOP, ENOENT, ENOTDIR

Definition at line 524 of file PathSecurity.cpp.

Referenced by realPath(), and security().

std::pair< ESecurity, String > BLOCXX_NAMESPACE::FileSystem::Path::security ( String const &  path)

Equivalent to security(path, uid), where uid is the effective user ID of the process.

Definition at line 538 of file PathSecurity.cpp.

std::pair< ESecurity, String > BLOCXX_NAMESPACE::FileSystem::Path::security ( String const &  base_dir,
String const &  rel_path,
UserId  uid 
)

A variant of security() that is more efficient if some ancestor directory of the path is already known to be secure and in canonical form.

Precondition:
base_dir is a path in canonical form, as described for realPath(), and rel_path is a relative path.
Returns:
security(path, uid), where path is the catenation of base_dir, "/", and rel_path, under the assumption that base_dir is a secure directory.

Definition at line 531 of file PathSecurity.cpp.

References BLOCXX_NAMESPACE::String::c_str().