MySQL 9.1.0
Source Code Documentation
|
Wrapper for a path to a directory that may or may not exist. More...
#include <fil0fil.h>
Public Types | |
enum | path_type { absolute , relative , file_name_only , invalid } |
Various types of file paths. More... | |
Public Member Functions | |
Fil_path () | |
Default constructor. More... | |
Fil_path (const char *path, size_t len, bool normalize_path=false) | |
Constructor. More... | |
Fil_path (const char *path, bool normalize_path=false) | |
Constructor. More... | |
Fil_path (const std::string &path, bool normalize_path=false) | |
Constructor. More... | |
operator const char * () const | |
Implicit type conversion. More... | |
const char * | operator() () const |
Explicit type conversion. More... | |
const std::string & | path () const |
size_t | len () const |
const std::string | abs_path () const |
Return the absolute path by value. More... | |
size_t | abs_len () const |
bool | operator== (const Fil_path &other) const |
Determine if this path is equal to the other path. More... | |
bool | is_same_as (const Fil_path &other) const |
Check if m_path is the same as this other path. More... | |
bool | is_same_as (const std::string &other) const |
Check if this path is the same as the other path. More... | |
Fil_path | get_abs_directory () const |
Get the absolute directory of this path. More... | |
bool | is_dir_same_as (const Fil_path &other) const |
Check if the directory to path is same as directory as the other path. More... | |
bool | is_ancestor (const Fil_path &other) const |
Check if m_path is the parent of the other path. More... | |
bool | is_ancestor (const std::string &other) const |
Check if this Fil_path is an ancestor of the other path. More... | |
bool | is_file_and_exists () const |
bool | is_directory_and_exists () const |
bool | is_valid () const |
This validation is only for ':'. More... | |
bool | is_circular () const |
Determine if m_path contains a circular section like "/anydir/../" Fil_path::normalize() must be run before this. More... | |
bool | is_absolute_path () const |
Static Public Member Functions | |
static bool | is_same_as (const std::string &first, const std::string &second) |
Check if two path strings are equal. More... | |
static std::pair< std::string, std::string > | split (const std::string &path) |
Splits the path into directory and file name parts. More... | |
static bool | is_ancestor (const std::string &first, const std::string &second) |
Check if the first path is an ancestor of the second. More... | |
static bool | is_hidden (std::string path) |
Determine if the file or directory is considered HIDDEN. More... | |
static std::string | remove_quotes (const char *pathspec) |
Remove quotes e.g., 'a;b' or "a;b" -> a;b. More... | |
static bool | is_relative_path (const std::string &path) |
Determine if a path is a relative path or not. More... | |
static bool | is_absolute_path (const std::string &path) |
Determine if a path is an absolute path or not. More... | |
static path_type | type_of_path (const std::string &path) |
Determine what type of path is provided. More... | |
static bool | has_prefix (const std::string &path, const std::string prefix) |
static void | normalize (std::string &path) |
Normalize a directory path for the current OS: On Windows, we convert '/' to '\', else we convert '\' to '/'. More... | |
static void | normalize (char *path) |
Normalize a directory path for the current OS: On Windows, we convert '/' to '\', else we convert '\' to '/'. More... | |
static void | to_lower (std::string &path) |
Convert a path string to lower case using the CHARSET my_charset_filename. More... | |
static os_file_type_t | get_file_type (const std::string &path) |
static const char * | get_file_type_string (const std::string &path) |
Return a string to display the file type of a path. More... | |
static const char * | get_file_type_string (os_file_type_t type) |
Return a string to display the file type of a path. More... | |
static std::string | get_real_path (const std::string &path, bool force=true) |
Get the real path for a directory or a file name. More... | |
static std::string | get_basename (const std::string &filepath) |
Get the basename of the file path. More... | |
static std::string | get_existing_path (const std::string &path, std::string &ghost) |
Separate the portion of a directory path that exists and the portion that does not exist. More... | |
static bool | is_undo_tablespace_name (const std::string &name) |
Check if the name is an undo tablespace name. More... | |
static bool | has_suffix (ib_file_suffix sfx, const std::string &path) |
Check if the file has the the specified suffix. More... | |
static bool | truncate_suffix (ib_file_suffix sfx, std::string &path) |
Check if the file has the the specified suffix and truncate. More... | |
static bool | is_separator (char c) |
Check if a character is a path separator ('\' or '/') More... | |
static void | trim_separator (std::string &path) |
If the last character of a directory path is a separator ('\' or '/') trim it off the string. More... | |
static void | append_separator (std::string &path) |
If the last character of a directory path is NOT a separator, append a separator to the path. More... | |
static char * | make (const std::string &path_in, const std::string &name_in, ib_file_suffix ext, bool trim=false) |
Allocate and build a file name from a path, a table or tablespace name and a suffix. More... | |
static char * | make_cfg (const std::string &path_in) |
Allocate and build a CFG file name from a path. More... | |
static char * | make_cfp (const std::string &path_in) |
Allocate and build a CFP file name from a path. More... | |
static char * | make_ibd (const std::string &path_in, const std::string &name_in) |
Allocate and build a file name from a path, a table or tablespace name and a suffix. More... | |
static char * | make_ibd_from_table_name (const std::string &name_in) |
Allocate and build a file name from a path, a table or tablespace name and a suffix. More... | |
static std::string | make_new_path (const std::string &path_in, const std::string &name_in, ib_file_suffix extn) |
Create an IBD path name after replacing the basename in an old path with a new basename. More... | |
static bool | parse_file_path (const std::string &file_path, ib_file_suffix extn, std::string &dict_name) |
Parse file-per-table file name and build Innodb dictionary table name. More... | |
static void | make_data_dir_path (char *data_dir_path) |
This function reduces a null-terminated full remote path name into the path that is sent by MySQL for DATA DIRECTORY clause. More... | |
static bool | is_valid_location (const char *space_name, space_id_t space_id, uint32_t fsp_flags, const std::string &path) |
Check if the filepath provided is in a valid placement. More... | |
static bool | is_valid_location_within_db (const char *space_name, const std::string &path) |
Check if the implicit filepath is immediately within a dir named for the schema. More... | |
static void | convert_to_filename_charset (std::string &name) |
Convert filename to the file system charset format. More... | |
static void | convert_to_lower_case (std::string &path) |
Convert to lower case using the file system charset. More... | |
Static Public Attributes | |
static constexpr auto | DB_SEPARATOR = '/' |
schema '/' table separator More... | |
static constexpr auto | OS_SEPARATOR = OS_PATH_SEPARATOR |
OS specific path separator. More... | |
static constexpr auto | SEPARATOR = "\\/" |
Directory separators that are supported. More... | |
static constexpr auto | DOT_SLASH = "./" |
static constexpr auto | DOT_DOT_SLASH = "../" |
static constexpr auto | SLASH_DOT_DOT_SLASH = "/../" |
Protected Attributes | |
std::string | m_path |
Path to a file or directory. More... | |
std::string | m_abs_path |
A full absolute path to the same file. More... | |
Wrapper for a path to a directory that may or may not exist.
enum Fil_path::path_type |
Fil_path::Fil_path | ( | ) |
Default constructor.
Defaults to MySQL_datadir_path.
|
explicit |
Constructor.
[in] | path | Path, not necessarily NUL terminated |
[in] | len | Length of path |
[in] | normalize_path | If false, it's the callers responsibility to ensure that the path is normalized. |
|
explicit |
Constructor.
[in] | path | Path, not necessarily NUL terminated |
[in] | normalize_path | If false, it's the callers responsibility to ensure that the path is normalized. |
|
explicit |
Constructor.
[in] | path | pathname (may also include the file basename) |
[in] | normalize_path | If false, it's the callers responsibility to ensure that the path is normalized. |
|
inline |
|
inline |
Return the absolute path by value.
If m_abs_path is null, calculate it and return it by value without trying to reset this const object. m_abs_path can be empty if the path did not exist when this object was constructed.
|
inlinestatic |
If the last character of a directory path is NOT a separator, append a separator to the path.
NOTE: We leave it up to the caller to assure that the path is a directory and not a file since if that directory does not yet exist, this function cannot tell the difference.
[in] | path | file system path |
|
static |
Convert filename to the file system charset format.
[in,out] | name | Filename to convert |
|
static |
Convert to lower case using the file system charset.
[in,out] | path | Filepath to convert |
Fil_path Fil_path::get_abs_directory | ( | ) | const |
Get the absolute directory of this path.
|
static |
Get the basename of the file path.
This is the file name without any directory separators. In other words, the file name after the last separator.
[in] | filepath | The name of a file, optionally with a path. |
|
static |
Separate the portion of a directory path that exists and the portion that does not exist.
[in] | path | Path to evaluate |
[in,out] | ghost | The portion of the path that does not exist. |
|
static |
|
static |
Return a string to display the file type of a path.
[in] | path | path name |
|
static |
Return a string to display the file type of a path.
[in] | type | OS file type |
|
static |
Get the real path for a directory or a file name.
This path can be used to compare with another absolute path. It will be converted to lower case on case insensitive file systems and if it is a directory, it will end with a directory separator. The call to my_realpath() may fail on non-Windows platforms if the path does not exist. If so, the parameter 'force' determines what to return.
[in] | path | directory or filename to convert to a real path |
[in] | force | if true and my_realpath() fails, use the path provided. if false and my_realpath() fails, return a null string. |
|
inlinestatic |
|
inlinestatic |
Check if the file has the the specified suffix.
[in] | sfx | suffix to look for |
[in] | path | Filename to check |
|
inline |
|
inlinestatic |
Determine if a path is an absolute path or not.
[in] | path | OS directory or file path to evaluate |
true | if the path is absolute |
false | if the path is relative or file_name_only |
bool Fil_path::is_ancestor | ( | const Fil_path & | other | ) | const |
Check if m_path is the parent of the other path.
[in] | other | path to compare to |
|
inlinestatic |
Check if the first path is an ancestor of the second.
Do not assume that these paths have been converted to real paths and are ready to compare. If the two paths are the same we will return false.
[in] | first | Parent path to check |
[in] | second | Descendent path to check |
bool Fil_path::is_ancestor | ( | const std::string & | other | ) | const |
Check if this Fil_path is an ancestor of the other path.
[in] | other | path to compare to |
bool Fil_path::is_circular | ( | ) | const |
Determine if m_path contains a circular section like "/anydir/../" Fil_path::normalize() must be run before this.
bool Fil_path::is_dir_same_as | ( | const Fil_path & | other | ) | const |
Check if the directory to path is same as directory as the other path.
[in] | other | directory path to compare to |
bool Fil_path::is_directory_and_exists | ( | ) | const |
bool Fil_path::is_file_and_exists | ( | ) | const |
|
static |
Determine if the file or directory is considered HIDDEN.
Most file systems identify the HIDDEN attribute by a '.' preceding the basename. On Windows, a HIDDEN path is identified by a file attribute. We will use the preceding '.' to indicate a HIDDEN attribute on ALL file systems so that InnoDB tablespaces and their directory structure remain portable.
[in] | path | The full or relative path of a file or directory. |
|
inlinestatic |
Determine if a path is a relative path or not.
[in] | path | OS directory or file path to evaluate |
true | if the path is relative |
false | if the path is absolute or file_name_only |
bool Fil_path::is_same_as | ( | const Fil_path & | other | ) | const |
Check if m_path is the same as this other path.
[in] | other | directory path to compare to |
|
inlinestatic |
Check if two path strings are equal.
Put them into Fil_path objects so that they can be compared correctly.
[in] | first | first path to check |
[in] | second | socond path to check |
bool Fil_path::is_same_as | ( | const std::string & | other | ) | const |
Check if this path is the same as the other path.
[in] | other | directory path to compare to |
|
inlinestatic |
Check if a character is a path separator ('\' or '/')
[in] | c | Character to check |
|
static |
Check if the name is an undo tablespace name.
Check if the basename of a filepath is an undo tablespace name.
[in] | name | Tablespace name |
bool Fil_path::is_valid | ( | void | ) | const |
This validation is only for ':'.
|
static |
Check if the filepath provided is in a valid placement.
This routine is run during file discovery at startup. 1) File-per-table must be in a dir named for the schema. 2) File-per-table must not be in the datadir. 3) General tablespace must not be under the datadir.
[in] | space_name | tablespace name |
[in] | space_id | tablespace ID |
[in] | fsp_flags | tablespace flags |
[in] | path | scanned realpath to an existing file to validate |
true | if the filepath is a valid datafile location |
|
static |
Check if the implicit filepath is immediately within a dir named for the schema.
[in] | space_name | tablespace name |
[in] | path | scanned realpath to an existing file to validate |
true | if the filepath is valid |
|
inline |
|
static |
Allocate and build a file name from a path, a table or tablespace name and a suffix.
[in] | path_in | nullptr or the directory path or the full path and filename |
[in] | name_in | nullptr if path is full, or Table/Tablespace name |
[in] | ext | the file extension to use |
[in] | trim | whether last name on the path should be trimmed |
|
inlinestatic |
Allocate and build a CFG file name from a path.
[in] | path_in | Full path to the filename |
|
inlinestatic |
Allocate and build a CFP file name from a path.
[in] | path_in | Full path to the filename |
|
static |
This function reduces a null-terminated full remote path name into the path that is sent by MySQL for DATA DIRECTORY clause.
It replaces the 'databasename/tablename.ibd' found at the end of the path with just 'tablename'.
Since the result is always smaller than the path sent in, no new memory is allocated. The caller should allocate memory for the path sent in. This function manipulates that path in place. If the path format is not as expected, set data_dir_path to "" and return.
The result is used to inform a SHOW CREATE TABLE command.
[in,out] | data_dir_path | Full path/data_dir_path |
|
inlinestatic |
Allocate and build a file name from a path, a table or tablespace name and a suffix.
[in] | path_in | nullptr or the directory path or the full path and filename |
[in] | name_in | nullptr if path is full, or Table/Tablespace name |
|
inlinestatic |
Allocate and build a file name from a path, a table or tablespace name and a suffix.
[in] | name_in | Table/Tablespace name |
|
static |
Create an IBD path name after replacing the basename in an old path with a new basename.
The old_path is a full path name including the extension. The tablename is in the normal form "schema/tablename".
[in] | path_in | Pathname |
[in] | name_in | Contains new base name |
[in] | extn | File extension |
|
inlinestatic |
Normalize a directory path for the current OS: On Windows, we convert '/' to '\', else we convert '\' to '/'.
[in,out] | path | A NUL terminated path |
|
inlinestatic |
Normalize a directory path for the current OS: On Windows, we convert '/' to '\', else we convert '\' to '/'.
[in,out] | path | Directory and file path |
|
inline |
Implicit type conversion.
|
inline |
Explicit type conversion.
|
inline |
Determine if this path is equal to the other path.
[in] | other | path to compare to |
|
static |
Parse file-per-table file name and build Innodb dictionary table name.
[in] | file_path | File name with complete path |
[in] | extn | File extension |
[out] | dict_name | Innodb dictionary table name |
|
inline |
|
inlinestatic |
Remove quotes e.g., 'a;b' or "a;b" -> a;b.
This will only remove the quotes if they are matching on the whole string. This will not work if each delimited string is quoted since this is called before the string is parsed.
|
static |
Splits the path into directory and file name parts.
[in] | path | path to split |
|
inlinestatic |
Convert a path string to lower case using the CHARSET my_charset_filename.
[in,out] | path | Directory and file path |
|
inlinestatic |
If the last character of a directory path is a separator ('\' or '/') trim it off the string.
[in] | path | file system path |
|
inlinestatic |
Check if the file has the the specified suffix and truncate.
[in] | sfx | suffix to look for |
[in,out] | path | Filename to check |
|
inlinestatic |
Determine what type of path is provided.
[in] | path | OS directory or file path to evaluate |
|
staticconstexpr |
schema '/' table separator
|
staticconstexpr |
|
staticconstexpr |
|
protected |
A full absolute path to the same file.
|
protected |
Path to a file or directory.
|
staticconstexpr |
OS specific path separator.
|
staticconstexpr |
Directory separators that are supported.
|
staticconstexpr |