|
BuildCache
|
File utility functions and classes. More...
Classes | |
| class | exe_path_t |
| Path to an executable file. More... | |
| class | file_info_t |
| Information about a file. More... | |
| class | file_lock_t |
| A scoped exclusive global lock class. More... | |
| class | scoped_work_dir_t |
| A helper class for temporarily changing the current working dir (CWD). More... | |
| class | tmp_file_t |
| A helper class for handling temporary files and directories. More... | |
Functions | |
| std::string | canonicalize_path (const std::string &path) |
| Get the canonical form of a path. More... | |
| std::string | get_extension (const std::string &path) |
| Get the file extension of a path. More... | |
| std::string | change_extension (const std::string &path, const std::string &new_ext) |
| Change the file extension of a path. More... | |
| std::string | get_file_part (const std::string &path, const bool include_ext=true) |
| Get the file name part of a path. More... | |
| std::string | get_dir_part (const std::string &path) |
| Get the directory part of a path. More... | |
| std::string | get_temp_dir () |
| Get a temporary directory for this user and process. More... | |
| std::string | get_user_home_dir () |
| Get the user home directory. More... | |
| std::string | get_cwd () |
| Get the current working directory. More... | |
| void | set_cwd (const std::string &path) |
| Set the current working directory. More... | |
| std::string | resolve_path (const std::string &path) |
| Resolve a path. More... | |
| exe_path_t | find_executable (const std::string &program, const std::string &exclude=std::string()) |
| Find the true path to an executable file. More... | |
| void | create_dir (const std::string &path) |
| Create a directory. More... | |
| void | create_dir_with_parents (const std::string &path) |
| Create a directory and its parent directories. More... | |
| void | remove_file (const std::string &path, const bool ignore_errors=false) |
| Remove an existing file. More... | |
| void | remove_dir (const std::string &path, const bool ignore_errors=false) |
| Remove a directory and all its contents (recursively). More... | |
| bool | dir_exists (const std::string &path) |
| Check if a directory exists. More... | |
| bool | file_exists (const std::string &path) |
| Check if a file exists. More... | |
| void | move (const std::string &from_path, const std::string &to_path) |
| Move a file from an old location to a new location. More... | |
| void | copy (const std::string &from_path, const std::string &to_path) |
| Make a full copy of a file. More... | |
| void | link_or_copy (const std::string &from_path, const std::string &to_path) |
| Make a hard link or a full copy of a file. More... | |
| void | touch (const std::string &path) |
| Touch the file to update the modification time. More... | |
| std::string | read (const std::string &path) |
| Read a file into a string. More... | |
| void | write (const std::string &data, const std::string &path) |
| Write a string to a file. More... | |
| void | write_atomic (const std::string &data, const std::string &path) |
| Write a string to a file in an atomic fashion. More... | |
| void | append (const std::string &data, const std::string &path) |
| Append a string to a file. More... | |
| file_info_t | get_file_info (const std::string &path) |
| Get file information about a single file or directory. More... | |
| std::string | human_readable_size (const int64_t byte_size) |
| Convert a size to a human readable string. More... | |
| std::vector< file_info_t > | walk_directory (const std::string &path) |
| Walk a directory and its subdirectories. More... | |
| std::string | get_unique_id () |
| Create a unique ID string. More... | |
File utility functions and classes.
| void bcache::file::append | ( | const std::string & | data, |
| const std::string & | path | ||
| ) |
Append a string to a file.
| data | The data string to write. |
| path | The path to the file. |
| runtime_error | if the operation could not be completed. |
| std::string bcache::file::append_path | ( | const std::string & | path, |
| const std::string & | append | ||
| ) |
Append two paths.
| path | The base path. |
| append | The path to be appended (e.g. a file name). |
path is empty or append is empty, the result will not contain any path separator. | std::string bcache::file::canonicalize_path | ( | const std::string & | path | ) |
Get the canonical form of a path.
The returned path is absolute, and free of relative operators ("." and "..").
| path | The path to canonicalize. |
| std::string bcache::file::change_extension | ( | const std::string & | path, |
| const std::string & | new_ext | ||
| ) |
Change the file extension of a path.
| path | The path to a file. |
| new_ext | The new file extension (including the leading period) for the file. |
| void bcache::file::copy | ( | const std::string & | from_path, |
| const std::string & | to_path | ||
| ) |
Make a full copy of a file.
| from_path | The source file. |
| to_path | The destination file. |
| runtime_error | if the operation could not be completed. |
| void bcache::file::create_dir | ( | const std::string & | path | ) |
Create a directory.
| path | The path to the directory. |
| runtime_error | if the directory could not be created. |
| void bcache::file::create_dir_with_parents | ( | const std::string & | path | ) |
Create a directory and its parent directories.
This function will create parent directories if required (similar to mkdir -p), and if the specified directory does not already exist, it is created (unlike create_dir, which will always try to create the directory).
| path | The path to the directory. |
| runtime_error | if the directory could not be created. |
| bool bcache::file::dir_exists | ( | const std::string & | path | ) |
Check if a directory exists.
| path | The path to the directory. |
| bool bcache::file::file_exists | ( | const std::string & | path | ) |
Check if a file exists.
| path | The path to the file. |
| exe_path_t bcache::file::find_executable | ( | const std::string & | program, |
| const std::string & | exclude = std::string() |
||
| ) |
Find the true path to an executable file.
| program | The file to find. |
| exclude | A file name to exclude (excluding the file extension). |
| runtime_error | if the executable file could not be found. |
| std::string bcache::file::get_cwd | ( | ) |
Get the current working directory.
| runtime_error | if the current working directory could not be determined. |
| std::string bcache::file::get_dir_part | ( | const std::string & | path | ) |
Get the directory part of a path.
| path | The path to a file. |
| std::string bcache::file::get_extension | ( | const std::string & | path | ) |
Get the file extension of a path.
| path | The path to a file. |
| file_info_t bcache::file::get_file_info | ( | const std::string & | path | ) |
Get file information about a single file or directory.
| path | The path to the file (or directory). |
| std::string bcache::file::get_file_part | ( | const std::string & | path, |
| const bool | include_ext = true |
||
| ) |
Get the file name part of a path.
| path | The path to a file. |
| include_ext | Include the file extension in the file name. |
| std::string bcache::file::get_temp_dir | ( | ) |
Get a temporary directory for this user and process.
| std::string bcache::file::get_unique_id | ( | ) |
Create a unique ID string.
| std::string bcache::file::get_user_home_dir | ( | ) |
Get the user home directory.
| std::string bcache::file::human_readable_size | ( | const int64_t | byte_size | ) |
Convert a size to a human readable string.
| byte_size | The size (number of bytes). |
| void bcache::file::link_or_copy | ( | const std::string & | from_path, |
| const std::string & | to_path | ||
| ) |
Make a hard link or a full copy of a file.
A hard link will be performed if possible. Otherwise a full copy will be made.
| from_path | The source file. |
| to_path | The destination file. |
| runtime_error | if the operation could not be completed. |
| void bcache::file::move | ( | const std::string & | from_path, |
| const std::string & | to_path | ||
| ) |
Move a file from an old location to a new location.
| from_path | The source file. |
| to_path | The destination file. |
| runtime_error | if the operation could not be completed. |
| std::string bcache::file::read | ( | const std::string & | path | ) |
Read a file into a string.
| path | The path to the file. |
| runtime_error | if the operation could not be completed. |
| void bcache::file::remove_dir | ( | const std::string & | path, |
| const bool | ignore_errors = false |
||
| ) |
Remove a directory and all its contents (recursively).
| path | The path to the dir. |
| ignore_errors | Set this to true to ignore errors related to removing files. |
| runtime_error | if the dir could not be removed. |
| void bcache::file::remove_file | ( | const std::string & | path, |
| const bool | ignore_errors = false |
||
| ) |
Remove an existing file.
| path | The path to the file. |
| ignore_errors | Set this to true to ignore errors related to removing files. |
| runtime_error | if the file could not be removed. |
| std::string bcache::file::resolve_path | ( | const std::string & | path | ) |
Resolve a path.
Relative paths are converted into absolute paths, and symbolic links are resolved.
| path | The path to resolve. |
| void bcache::file::set_cwd | ( | const std::string & | path | ) |
Set the current working directory.
| path | the path to the new working directory. |
| runtime_error | if the current working directory could not be changed. |
| void bcache::file::touch | ( | const std::string & | path | ) |
Touch the file to update the modification time.
| path | The path to the file. |
| runtime_error | if the operation could not be completed. |
| std::vector< file_info_t > bcache::file::walk_directory | ( | const std::string & | path | ) |
Walk a directory and its subdirectories.
| path | The path to the directory. |
| void bcache::file::write | ( | const std::string & | data, |
| const std::string & | path | ||
| ) |
Write a string to a file.
| data | The data string to write. |
| path | The path to the file. |
| runtime_error | if the operation could not be completed. |
| void bcache::file::write_atomic | ( | const std::string & | data, |
| const std::string & | path | ||
| ) |
Write a string to a file in an atomic fashion.
The target file will either be written in whole, or the function will fail.
| data | The data string to write. |
| path | The path to the file. |
| runtime_error | if the operation could not be completed. |
1.8.17