MySQL 9.0.0
Source Code Documentation
mysql_harness::Path Class Reference

Class representing a path in a file system. More...

#include <filesystem.h>

Inheritance diagram for mysql_harness::Path:
[legend]

Public Types

enum class  FileType {
  STATUS_ERROR , EMPTY_PATH , FILE_NOT_FOUND , REGULAR_FILE ,
  DIRECTORY_FILE , SYMLINK_FILE , BLOCK_FILE , CHARACTER_FILE ,
  FIFO_FILE , SOCKET_FILE , TYPE_UNKNOWN
}
 Enum used to identify file types. More...
 

Public Member Functions

 Path () noexcept
 
 Path (std::string path)
 Construct a path. More...
 
 Path (std::string_view path)
 
 Path (const char *path)
 
bool operator== (const Path &rhs) const
 
bool operator!= (const Path &rhs) const
 
bool operator< (const Path &rhs) const
 Path ordering operator. More...
 
FileType type (bool refresh=false) const
 Get the file type. More...
 
bool is_directory () const
 Check if the file is a directory. More...
 
bool is_regular () const
 Check if the file is a regular file. More...
 
bool is_absolute () const
 Check if the path is absolute or not. More...
 
bool exists () const
 Check if path exists. More...
 
bool is_readable () const
 
Path dirname () const
 Get the directory name of the path. More...
 
Path basename () const
 Get the basename of the path. More...
 
void append (const Path &other)
 Append a path component to the current path. More...
 
Path join (const Path &other) const
 Join two path components to form a new path. More...
 
Path real_path () const
 Returns the canonical form of the path, resolving relative paths. More...
 
const char * c_str () const
 Get a C-string representation to the path. More...
 
const std::string & str () const noexcept
 Get a string representation of the path. More...
 
bool is_set () const noexcept
 Test if path is set. More...
 
 operator bool () const noexcept
 

Static Public Member Functions

static Path make_path (const Path &directory, const std::string &basename, const std::string &extension)
 Create a path from directory, basename, and extension. More...
 

Static Public Attributes

static const char *const directory_separator = "/"
 Directory separator string. More...
 
static const char *const root_directory = "/"
 Root directory string. More...
 

Private Member Functions

void validate_non_empty_path () const
 

Private Attributes

std::string path_
 
FileType type_
 

Friends

std::ostream & operator<< (std::ostream &out, const Path &path)
 
HARNESS_EXPORT std::ostream & operator<< (std::ostream &out, FileType type)
 

Detailed Description

Class representing a path in a file system.

Paths are used to access files in the file system and can be either relative or absolute. Absolute paths have a slash (/) first in the path, otherwise, the path is relative.

Member Enumeration Documentation

◆ FileType

enum class mysql_harness::Path::FileType
strong

Enum used to identify file types.

Enumerator
STATUS_ERROR 

An error occurred when trying to get file type, but it is not that the file was not found.

EMPTY_PATH 

Empty path was given.

FILE_NOT_FOUND 

The file was not found.

REGULAR_FILE 

The file is a regular file.

DIRECTORY_FILE 

The file is a directory.

SYMLINK_FILE 

The file is a symbolic link.

BLOCK_FILE 

The file is a block device.

CHARACTER_FILE 

The file is a character device.

FIFO_FILE 

The file is a FIFO.

SOCKET_FILE 

The file is a UNIX socket.

TYPE_UNKNOWN 

The type of the file is unknown, either because it was not fetched yet or because stat(2) reported something else than the above.

Constructor & Destructor Documentation

◆ Path() [1/4]

Path::Path ( )
noexcept

◆ Path() [2/4]

Path::Path ( std::string  path)

Construct a path.

Parameters
pathNon-empty string denoting the path.
Exceptions
std::invalid_argument

◆ Path() [3/4]

mysql_harness::Path::Path ( std::string_view  path)
inline

◆ Path() [4/4]

mysql_harness::Path::Path ( const char *  path)
inline

Member Function Documentation

◆ append()

void Path::append ( const Path other)

Append a path component to the current path.

This function will append a path component to the path using the appropriate directory separator.

Parameters
otherPath component to append to the path.

◆ basename()

Path Path::basename ( ) const

Get the basename of the path.

Return the basename of the path: the path without the directory portion.

Note
No checking of the components are done, this is just simple path manipulation.
Returns
A new path object representing the basename of the path. the path.

◆ c_str()

const char * mysql_harness::Path::c_str ( ) const
inline

Get a C-string representation to the path.

Note
This will return a pointer to the internal representation of the path and hence will become a dangling pointer when the Path object is destroyed.
Returns
Pointer to a null-terminated C-string.

◆ dirname()

Path Path::dirname ( ) const

Get the directory name of the path.

This will strip the last component of a path, assuming that the what remains is a directory name. If the path is a relative path that do not contain any directory separators, a dot will be returned (denoting the current directory).

Note
No checking of the components are done, this is just simple path manipulation.
Returns
A new path object representing the directory portion of the path.

◆ exists()

bool Path::exists ( ) const

Check if path exists.

◆ is_absolute()

bool Path::is_absolute ( ) const

Check if the path is absolute or not.

The path is considered absolute if it starts with one of: Unix: '/' Windows: '/' or '\' or '.:' (where . is any character) else: it's considered relative (empty path is also relative in such respect)

◆ is_directory()

bool Path::is_directory ( ) const

Check if the file is a directory.

◆ is_readable()

bool Path::is_readable ( ) const

◆ is_regular()

bool Path::is_regular ( ) const

Check if the file is a regular file.

◆ is_set()

bool mysql_harness::Path::is_set ( ) const
inlinenoexcept

Test if path is set.

Returns
Test result

◆ join()

Path Path::join ( const Path other) const

Join two path components to form a new path.

This function will join the two path components using a directory separator.

Note
This will return a new Path object. If you want to modify the existing path object, you should use append instead.
Parameters
otherPath component to be appended to the path

◆ make_path()

Path Path::make_path ( const Path directory,
const std::string &  basename,
const std::string &  extension 
)
static

Create a path from directory, basename, and extension.

◆ operator bool()

mysql_harness::Path::operator bool ( ) const
inlinenoexcept

◆ operator!=()

bool mysql_harness::Path::operator!= ( const Path rhs) const
inline

◆ operator<()

bool Path::operator< ( const Path rhs) const

Path ordering operator.

This is mainly used for ordered containers. The paths are ordered lexicographically.

◆ operator==()

bool Path::operator== ( const Path rhs) const

◆ real_path()

Path Path::real_path ( ) const

Returns the canonical form of the path, resolving relative paths.

◆ str()

const std::string & mysql_harness::Path::str ( ) const
inlinenoexcept

Get a string representation of the path.

Returns
Instance of std::string containing the path.

◆ type()

Path::FileType Path::type ( bool  refresh = false) const

Get the file type.

The file type is normally cached so if the file type under a path changes it is necessary to force a refresh.

Parameters
refreshSet to true if the file type should be refreshed, default to false.
Returns
The type of the file.

◆ validate_non_empty_path()

void Path::validate_non_empty_path ( ) const
private

Friends And Related Function Documentation

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream &  out,
const Path path 
)
friend

◆ operator<< [2/2]

HARNESS_EXPORT std::ostream & operator<< ( std::ostream &  out,
Path::FileType  type 
)
friend

Member Data Documentation

◆ directory_separator

const char *const Path::directory_separator = "/"
static

Directory separator string.

Note
This is platform-dependent and defined in the appropriate source file.

◆ path_

std::string mysql_harness::Path::path_
private

◆ root_directory

const char *const Path::root_directory = "/"
static

Root directory string.

Note
This is platform-dependent and defined in the appropriate source file.

◆ type_

FileType mysql_harness::Path::type_
mutableprivate

The documentation for this class was generated from the following files: