|
RStudio Launcher Plugin SDK
1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
|
Class which represents a path on the system. May be any type of file (e.g. directory, symlink, regular file, etc.) More...
#include <FilePath.hpp>
Public Types | |
| enum | MoveType { MoveDirect, MoveCrossDevice } |
| Enum which represents the type of move to perform. More... | |
| typedef std::function< bool(int, const FilePath &)> | RecursiveIterationFunction |
| Function which recursively iterates over FilePath objects. More... | |
Public Member Functions | |
| FilePath () | |
| Default constructor. | |
| FilePath (const std::string &in_absolutePath) | |
| Constructor. More... | |
| FilePath (const char *in_absolutePath) | |
| Constructor. More... | |
| bool | operator== (const FilePath &in_other) const |
| Comparison operator. File paths are equal if their absolute representations are equal. More... | |
| bool | operator!= (const FilePath &in_other) const |
| Comparison operator. File paths are equal if their absolute representations are equal. More... | |
| bool | operator< (const FilePath &in_other) const |
| Less-than operator to establish natural order. The natural order is based on the absolute representation of the paths. More... | |
| Error | changeFileMode (const std::string &in_fileModeStr) const |
| Changes the file mode to the specified file mode. More... | |
| Error | changeFileMode (FileMode in_fileMode, bool in_setStickyBit=false) const |
| Changes the file mode to the specified file mode. More... | |
| Error | changeOwnership (const system::User &in_newUser, bool in_recursive=false, const RecursiveIterationFunction &in_shouldChown=RecursiveIterationFunction()) const |
| Changes the ownership of the file or directory to the specified user. More... | |
| FilePath | completeChildPath (const std::string &in_filePath) const |
| Gets the provided relative path as a child of this path. More... | |
| Error | completeChildPath (const std::string &in_filePath, FilePath &out_childPath) const |
| Gets the provided relative path as a child of this path. More... | |
| FilePath | completePath (const std::string &in_filePath) const |
| Completes the provided path relative to this path. If the provided path is not relative, it will be returned as is. Relative paths such as ".." are permitted. More... | |
| Error | copy (const FilePath &in_targetPath, bool overwrite=false) const |
| Copies this file path to the specified location. More... | |
| Error | copyDirectoryRecursive (const FilePath &in_targetPath, bool overwrite=false) const |
| Copies this directory recursively to the specified location. More... | |
| Error | createDirectory (const std::string &in_filePath) const |
| Creates the specified directory. More... | |
| Error | ensureDirectory () const |
| Creates this directory, if it does not exist. More... | |
| Error | ensureFile () const |
| Creates this file, if it does not exist. More... | |
| bool | exists () const |
| Checks whether this file path exists in the file system. More... | |
| std::string | getAbsolutePath () const |
| Gets the full absolute representation of this file path. More... | |
| std::string | getAbsolutePathNative () const |
| Gets the full absolute representation of this file path in native format. More... | |
| std::string | getCanonicalPath () const |
| Gets the canonical representation of this file path. The path must exist so that its canonical location on disk can be obtained. More... | |
| Error | getChildren (std::vector< FilePath > &out_filePaths) const |
| Gets the children of this directory. Sub-directories will not be traversed. More... | |
| Error | getChildrenRecursive (const RecursiveIterationFunction &in_iterationFunction) const |
| Gets the children of this directory recursively. Sub-directories will be traversed. More... | |
| std::string | getExtension () const |
| Gets the extension of the file, including the leading '.'. More... | |
| std::string | getExtensionLowerCase () const |
| Gets the extension of the file in lower case, including the leading '.'. More... | |
| Error | getFileMode (FileMode &out_fileMode) const |
| Gets the posix file mode of this file or directory. More... | |
| std::string | getFilename () const |
| Gets only the name of the file, including the extension. More... | |
| std::time_t | getLastWriteTime () const |
| Get the last time this file path was written. More... | |
| std::string | getLexicallyNormalPath () const |
| Gets the lexically normal representation of this file path, with . and .. components resolved and/or removed. More... | |
| std::string | getMimeContentType (const std::string &in_defaultType="text/plain") const |
| Gets the mime content type of this file. More... | |
| FilePath | getParent () const |
| Gets the parent directory of this file path. More... | |
| std::string | getRelativePath (const FilePath &in_parentPath) const |
| Gets the representation of this path, relative to the provided path. More... | |
| uintmax_t | getSize () const |
| Gets the size of this file path in bytes. More... | |
| uintmax_t | getSizeRecursive () const |
| Gets the size of this file path and all sub-directories and files in it, in bytes. More... | |
| std::string | getStem () const |
| Gets only the name of the file, excluding the extension. More... | |
| bool | hasExtension (const std::string &in_extension) const |
| Checks whether this file has the specified extension. More... | |
| bool | hasExtensionLowerCase (const std::string &in_extension) const |
| Checks whether this file has the specified extension when it is converted to lower case. More... | |
| bool | hasTextMimeType () const |
| Checks whether this file has a text mime content type. More... | |
| bool | isDirectory () const |
| Checks whether this file path is a directory. More... | |
| bool | isEmpty () const |
| Checks whether this file path contains a path or not. More... | |
| bool | isEquivalentTo (const FilePath &in_other) const |
| Checks whether this file path points to the same location in the filesystem as the specified file path. More... | |
| bool | isHidden () const |
| Checks whether this file path is a hidden file or directory. More... | |
| Error | isReadable (bool &out_readable) const |
| Checks whether this file path is readable. More... | |
| bool | isRegularFile () const |
| Checks whether this file path is a regular file. More... | |
| bool | isSymlink () const |
| Checks whether this file path is a symbolic link. More... | |
| bool | isWithin (const FilePath &in_scopePath) const |
| Checks whether this file path is within the specified file path. More... | |
| Error | isWriteable (bool &out_writeable) const |
| Checks whether this file path is writeable. More... | |
| Error | makeCurrentPath (bool in_autoCreate=false) const |
| Changes the current working directory to location represented by this file path. More... | |
| Error | move (const FilePath &in_targetPath, MoveType in_type=MoveCrossDevice, bool overwrite=false) const |
| Moves the current directory to the specified directory. More... | |
| Error | moveIndirect (const FilePath &in_targetPath, bool overwrite=false) const |
| Performs an indirect move by copying this directory to the target and then deleting this directory. More... | |
| Error | openForRead (std::shared_ptr< std::istream > &out_stream) const |
| Opens this file for read. More... | |
| Error | openForWrite (std::shared_ptr< std::ostream > &out_stream, bool in_truncate=true) const |
| Opens this file for write. More... | |
| Error | remove () const |
| Removes this file or directory from the filesystem. More... | |
| Error | removeIfExists () const |
| Removes this file or directory from the filesystem, if it exists. More... | |
| Error | resetDirectory () const |
| Removes the directory represented by this FilePath, if it exists, and recreates it. More... | |
| FilePath | resolveSymlink () const |
| Resolves this symbolic link to the location to which it is pointing. If this FilePath is not a symbolic link, the original FilePath is returned. More... | |
| void | setLastWriteTime (std::time_t in_time=::time(nullptr)) const |
| Sets the last time that this file was modified to the specified time. More... | |
| Error | testWritePermissions () const |
| Checks if a file can be written to by opening the file. More... | |
Static Public Member Functions | |
| static std::string | createAliasedPath (const FilePath &in_filePath, const FilePath &in_userHomePath) |
| Creates a path in which the user home path will be replaced by the ~ alias. More... | |
| static bool | exists (const std::string &in_filePath) |
| Checks whether the specified path exists. More... | |
| static bool | isEqualCaseInsensitive (const FilePath &in_filePath1, const FilePath &in_filePath2) |
| Checks whether the two provided files are equal, ignoring case. Two files are equal if their absolute paths are equal. More... | |
| static bool | isRootPath (const std::string &in_filePath) |
| Checks whether the specified path is a root path or a relative path. More... | |
| static Error | makeCurrent (const std::string &in_filePath) |
| Changes the current working directory to the specified path. More... | |
| static FilePath | resolveAliasedPath (const std::string &in_aliasedPath, const FilePath &in_userHomePath) |
| Resolves the '~' alias within the path to the user's home path. More... | |
| static FilePath | safeCurrentPath (const FilePath &in_revertToPath) |
| Checks whether the current working directory exists. If it does not, moves the current working directory to the specified path. More... | |
| static Error | tempFilePath (FilePath &out_filePath) |
| Creates a randomly named file in the temp directory. More... | |
| static Error | tempFilePath (const std::string &in_extension, FilePath &out_filePath) |
| Creates a randomly named file with the specified extension in the temp directory. More... | |
| static Error | uniqueFilePath (const std::string &in_basePath, FilePath &out_filePath) |
| Creates a file with a random name in the specified directory. More... | |
| static Error | uniqueFilePath (const std::string &in_basePath, const std::string &in_extension, FilePath &out_filePath) |
| Creates a file with a random name and the specified extension in the specified directory. More... | |
Class which represents a path on the system. May be any type of file (e.g. directory, symlink, regular file, etc.)
| typedef std::function<bool(int, const FilePath&)> rstudio::launcher_plugins::system::FilePath::RecursiveIterationFunction |
|
explicit |
Constructor.
| in_absolutePath | The string representation of the path. |
|
explicit |
Constructor.
| in_absolutePath | The string representation of the path. |
| Error rstudio::launcher_plugins::system::FilePath::changeFileMode | ( | const std::string & | in_fileModeStr | ) | const |
| Error rstudio::launcher_plugins::system::FilePath::changeFileMode | ( | FileMode | in_fileMode, |
| bool | in_setStickyBit = false |
||
| ) | const |
| Error rstudio::launcher_plugins::system::FilePath::changeOwnership | ( | const system::User & | in_newUser, |
| bool | in_recursive = false, |
||
| const RecursiveIterationFunction & | in_shouldChown = RecursiveIterationFunction() |
||
| ) | const |
Changes the ownership of the file or directory to the specified user.
| in_newUser | The user who should own the file. |
| in_recursive | If this FilePath is a directory, whether to recursively change ownership on all files and directories within this directory. |
| in_shouldChown | A recursive iteration function which allows the caller to filter files and directories. If a file or directory should have its ownership changed, this function should return true. |
| FilePath rstudio::launcher_plugins::system::FilePath::completeChildPath | ( | const std::string & | in_filePath | ) | const |
Gets the provided relative path as a child of this path.
| in_filePath | The path to get as a child of this path. Must be a relative path. |
| Error rstudio::launcher_plugins::system::FilePath::completeChildPath | ( | const std::string & | in_filePath, |
| FilePath & | out_childPath | ||
| ) | const |
Gets the provided relative path as a child of this path.
| in_filePath | The path to get as a child of this path. Must be a relative path that refers to a path strictly within this one (i.e. ".." isn't allowed) |
| out_childPath | The completed child path. Not valid if an error is returned. |
| FilePath rstudio::launcher_plugins::system::FilePath::completePath | ( | const std::string & | in_filePath | ) | const |
Completes the provided path relative to this path. If the provided path is not relative, it will be returned as is. Relative paths such as ".." are permitted.
| in_filePath | in_filePathThe path to complete. |
|
static |
Creates a path in which the user home path will be replaced by the ~ alias.
| in_filePath | The path to convert to an aliased path. |
| in_userHomePath | The user home path. |
| Error rstudio::launcher_plugins::system::FilePath::createDirectory | ( | const std::string & | in_filePath | ) | const |
| Error rstudio::launcher_plugins::system::FilePath::ensureDirectory | ( | ) | const |
| Error rstudio::launcher_plugins::system::FilePath::ensureFile | ( | ) | const |
| bool rstudio::launcher_plugins::system::FilePath::exists | ( | ) | const |
Checks whether this file path exists in the file system.
|
static |
Checks whether the specified path exists.
| in_filePath | The path to check. |
| std::string rstudio::launcher_plugins::system::FilePath::getAbsolutePath | ( | ) | const |
Gets the full absolute representation of this file path.
| std::string rstudio::launcher_plugins::system::FilePath::getAbsolutePathNative | ( | ) | const |
Gets the full absolute representation of this file path in native format.
| std::string rstudio::launcher_plugins::system::FilePath::getCanonicalPath | ( | ) | const |
Gets the canonical representation of this file path. The path must exist so that its canonical location on disk can be obtained.
| Error rstudio::launcher_plugins::system::FilePath::getChildrenRecursive | ( | const RecursiveIterationFunction & | in_iterationFunction | ) | const |
| std::string rstudio::launcher_plugins::system::FilePath::getExtension | ( | ) | const |
Gets the extension of the file, including the leading '.'.
| std::string rstudio::launcher_plugins::system::FilePath::getExtensionLowerCase | ( | ) | const |
Gets the extension of the file in lower case, including the leading '.'.
| Error rstudio::launcher_plugins::system::FilePath::getFileMode | ( | FileMode & | out_fileMode | ) | const |
| std::string rstudio::launcher_plugins::system::FilePath::getFilename | ( | ) | const |
Gets only the name of the file, including the extension.
| std::time_t rstudio::launcher_plugins::system::FilePath::getLastWriteTime | ( | ) | const |
Get the last time this file path was written.
| std::string rstudio::launcher_plugins::system::FilePath::getLexicallyNormalPath | ( | ) | const |
Gets the lexically normal representation of this file path, with . and .. components resolved and/or removed.
| std::string rstudio::launcher_plugins::system::FilePath::getMimeContentType | ( | const std::string & | in_defaultType = "text/plain" | ) | const |
Gets the mime content type of this file.
| in_defaultType | The default mime content type to return if this file does not have a mime content type. Default: "text/plain". |
| FilePath rstudio::launcher_plugins::system::FilePath::getParent | ( | ) | const |
Gets the parent directory of this file path.
| std::string rstudio::launcher_plugins::system::FilePath::getRelativePath | ( | const FilePath & | in_parentPath | ) | const |
Gets the representation of this path, relative to the provided path.
| in_parentPath | The parent of this path. |
| uintmax_t rstudio::launcher_plugins::system::FilePath::getSize | ( | ) | const |
Gets the size of this file path in bytes.
| uintmax_t rstudio::launcher_plugins::system::FilePath::getSizeRecursive | ( | ) | const |
Gets the size of this file path and all sub-directories and files in it, in bytes.
| std::string rstudio::launcher_plugins::system::FilePath::getStem | ( | ) | const |
Gets only the name of the file, excluding the extension.
| bool rstudio::launcher_plugins::system::FilePath::hasExtension | ( | const std::string & | in_extension | ) | const |
Checks whether this file has the specified extension.
| in_extension | The extension to check this file for. |
| bool rstudio::launcher_plugins::system::FilePath::hasExtensionLowerCase | ( | const std::string & | in_extension | ) | const |
Checks whether this file has the specified extension when it is converted to lower case.
| in_extension | The extension to check this file for. |
| bool rstudio::launcher_plugins::system::FilePath::hasTextMimeType | ( | ) | const |
Checks whether this file has a text mime content type.
| bool rstudio::launcher_plugins::system::FilePath::isDirectory | ( | ) | const |
Checks whether this file path is a directory.
| bool rstudio::launcher_plugins::system::FilePath::isEmpty | ( | ) | const |
Checks whether this file path contains a path or not.
|
static |
Checks whether the two provided files are equal, ignoring case. Two files are equal if their absolute paths are equal.
| in_filePath1 | The first file to compare. |
| in_filePath2 | The second file to compare. |
| bool rstudio::launcher_plugins::system::FilePath::isEquivalentTo | ( | const FilePath & | in_other | ) | const |
Checks whether this file path points to the same location in the filesystem as the specified file path.
| in_other | The file path to which to compare this file path to. |
| bool rstudio::launcher_plugins::system::FilePath::isHidden | ( | ) | const |
Checks whether this file path is a hidden file or directory.
| Error rstudio::launcher_plugins::system::FilePath::isReadable | ( | bool & | out_readable | ) | const |
| bool rstudio::launcher_plugins::system::FilePath::isRegularFile | ( | ) | const |
Checks whether this file path is a regular file.
|
static |
Checks whether the specified path is a root path or a relative path.
| in_filePath | The path to check. |
| bool rstudio::launcher_plugins::system::FilePath::isSymlink | ( | ) | const |
Checks whether this file path is a symbolic link.
| bool rstudio::launcher_plugins::system::FilePath::isWithin | ( | const FilePath & | in_scopePath | ) | const |
Checks whether this file path is within the specified file path.
| in_scopePath | The potential parent path. |
| Error rstudio::launcher_plugins::system::FilePath::isWriteable | ( | bool & | out_writeable | ) | const |
|
static |
| Error rstudio::launcher_plugins::system::FilePath::makeCurrentPath | ( | bool | in_autoCreate = false | ) | const |
| Error rstudio::launcher_plugins::system::FilePath::move | ( | const FilePath & | in_targetPath, |
| MoveType | in_type = MoveCrossDevice, |
||
| bool | overwrite = false |
||
| ) | const |
Moves the current directory to the specified directory.
| in_targetPath | The location to which to move this directory. |
| in_type | The type of move to perform, direct or cross device. See MoveType for more details. Default: MoveCrossDevice. |
| overwrite | Whether to overwrite the file if one exists in target path. |
| Error rstudio::launcher_plugins::system::FilePath::moveIndirect | ( | const FilePath & | in_targetPath, |
| bool | overwrite = false |
||
| ) | const |
Performs an indirect move by copying this directory to the target and then deleting this directory.
| in_targetPath | The location to which to move this directory. |
| overwrite | Whether to overwrite the file if one exists in target path. |
| Error rstudio::launcher_plugins::system::FilePath::openForRead | ( | std::shared_ptr< std::istream > & | out_stream | ) | const |
Opens this file for read.
| out_stream | The input stream for this open file. |
| Error rstudio::launcher_plugins::system::FilePath::openForWrite | ( | std::shared_ptr< std::ostream > & | out_stream, |
| bool | in_truncate = true |
||
| ) | const |
Opens this file for write.
| out_stream | The output stream for this open file. |
| in_truncate | Whether to truncate the existing contents of the file. Default: true. |
| bool rstudio::launcher_plugins::system::FilePath::operator!= | ( | const FilePath & | in_other | ) | const |
Comparison operator. File paths are equal if their absolute representations are equal.
| in_other | The file path to compare with this file path. |
| bool rstudio::launcher_plugins::system::FilePath::operator< | ( | const FilePath & | in_other | ) | const |
Less-than operator to establish natural order. The natural order is based on the absolute representation of the paths.
| in_other | The path to which to compare this path. |
| bool rstudio::launcher_plugins::system::FilePath::operator== | ( | const FilePath & | in_other | ) | const |
Comparison operator. File paths are equal if their absolute representations are equal.
| in_other | The file path to compare with this file path. |
| Error rstudio::launcher_plugins::system::FilePath::remove | ( | ) | const |
| Error rstudio::launcher_plugins::system::FilePath::removeIfExists | ( | ) | const |
| Error rstudio::launcher_plugins::system::FilePath::resetDirectory | ( | ) | const |
|
static |
Resolves the '~' alias within the path to the user's home path.
| in_aliasedPath | The aliased path to resolve. |
| in_userHomePath | The user's home path. |
| FilePath rstudio::launcher_plugins::system::FilePath::resolveSymlink | ( | ) | const |
|
static |
Checks whether the current working directory exists. If it does not, moves the current working directory to the specified path.
| in_revertToPath | The path to revert to if the current working directory no longer exists. |
| void rstudio::launcher_plugins::system::FilePath::setLastWriteTime | ( | std::time_t | in_time = ::time(nullptr) | ) | const |
Sets the last time that this file was modified to the specified time.
| in_time | The time to which to set the last write time of this file. Default: now. |
|
static |
Creates a randomly named file with the specified extension in the temp directory.
| in_extension | The extension with which to create the file. The extension should include the leading '.', e.g. '.zip'. |
| out_filePath | The absolute path of the newly created file, or an empty file path if the file could not be created. |
| Error rstudio::launcher_plugins::system::FilePath::testWritePermissions | ( | ) | const |
Checks if a file can be written to by opening the file.
To be successful, the file must be a regular file (not a directory, etc.) and already exist on the system.
If write access is not absolutely necessary, use isWriteable instead.
|
static |
Creates a file with a random name and the specified extension in the specified directory.
| in_basePath | The path at which to create the file. |
| in_extension | The extension with which to create the file. The extension should include the leading '.', e.g. '.zip'. |
| out_filePath | The absolute path of the newly created file, or an empty file path if the file could not be created. |
1.8.16