RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
Public Types | Public Member Functions | Static Public Member Functions | List of all members
rstudio::launcher_plugins::system::FilePath Class Reference

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...
 

Detailed Description

Class which represents a path on the system. May be any type of file (e.g. directory, symlink, regular file, etc.)

Member Typedef Documentation

◆ RecursiveIterationFunction

Function which recursively iterates over FilePath objects.

Parameters
intThe depth of the iteration.
FilePathThe current FilePath object in the recursive iteration.
Returns
True if the computation can continue; false otherwise.

Member Enumeration Documentation

◆ MoveType

Enum which represents the type of move to perform.

Enumerator
MoveDirect 

Attempt to perform an ordinary move

MoveCrossDevice 

Perform an ordinary move, but fallback to copy/delete on cross-device errors

Constructor & Destructor Documentation

◆ FilePath() [1/2]

rstudio::launcher_plugins::system::FilePath::FilePath ( const std::string &  in_absolutePath)
explicit

Constructor.

Parameters
in_absolutePathThe string representation of the path.

◆ FilePath() [2/2]

rstudio::launcher_plugins::system::FilePath::FilePath ( const char *  in_absolutePath)
explicit

Constructor.

Parameters
in_absolutePathThe string representation of the path.

Member Function Documentation

◆ changeFileMode() [1/2]

Error rstudio::launcher_plugins::system::FilePath::changeFileMode ( const std::string &  in_fileModeStr) const

Changes the file mode to the specified file mode.

Parameters
in_fileModeStrThe posix file mode string. e.g. rwxr-xr-x.
Returns
Success if the file mode could be changed; Error otherwise.

◆ changeFileMode() [2/2]

Error rstudio::launcher_plugins::system::FilePath::changeFileMode ( FileMode  in_fileMode,
bool  in_setStickyBit = false 
) const

Changes the file mode to the specified file mode.

Parameters
in_fileModeThe new file mode.
in_setStickyBitWhether to set the sticky bit on this file.
Returns
Success if the file mode could be changed; Error otherwise.

◆ changeOwnership()

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.

Parameters
in_newUserThe user who should own the file.
in_recursiveIf this FilePath is a directory, whether to recursively change ownership on all files and directories within this directory.
in_shouldChownA 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.
Returns
Success if the file, and optionally all nested files and directories, had their ownership changed; Error otherwise.

◆ completeChildPath() [1/2]

FilePath rstudio::launcher_plugins::system::FilePath::completeChildPath ( const std::string &  in_filePath) const

Gets the provided relative path as a child of this path.

Parameters
in_filePathThe path to get as a child of this path. Must be a relative path.
Returns
The completed child path, or this path if the provided path was not relative or another error occurred.

◆ completeChildPath() [2/2]

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.

Parameters
in_filePathThe 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_childPathThe completed child path. Not valid if an error is returned.
Returns
Success if the child path could be completed; Error otherwise.

◆ completePath()

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.

Parameters
in_filePathin_filePathThe path to complete.
Returns
The completed path if the provided path was relative, or the provided path if it was not relative.

◆ copy()

Error rstudio::launcher_plugins::system::FilePath::copy ( const FilePath in_targetPath,
bool  overwrite = false 
) const

Copies this file path to the specified location.

Parameters
in_targetPathThe location to copy this file path to.
overwriteWhether to overwrite the file if one exists in target path.
Returns
Success if the copy could be completed; Error otherwise.

◆ copyDirectoryRecursive()

Error rstudio::launcher_plugins::system::FilePath::copyDirectoryRecursive ( const FilePath in_targetPath,
bool  overwrite = false 
) const

Copies this directory recursively to the specified location.

Parameters
in_targetPathThe location to which to copy this directory and its contents.
overwriteWhether to overwrite the file if one exists in target path.
Returns
Success if the copy could be completed; Error otherwise.

◆ createAliasedPath()

static std::string rstudio::launcher_plugins::system::FilePath::createAliasedPath ( const FilePath in_filePath,
const FilePath in_userHomePath 
)
static

Creates a path in which the user home path will be replaced by the ~ alias.

Parameters
in_filePathThe path to convert to an aliased path.
in_userHomePathThe user home path.
Returns
If the path is within the user home path, an aliased path; the original path otherwise.

◆ createDirectory()

Error rstudio::launcher_plugins::system::FilePath::createDirectory ( const std::string &  in_filePath) const

Creates the specified directory.

Parameters
in_filePathThe directory to create, relative to this directory.
Returns
Success if the directory could be created; Error if it could not be created for any reason.

◆ ensureDirectory()

Error rstudio::launcher_plugins::system::FilePath::ensureDirectory ( ) const

Creates this directory, if it does not exist.

Returns
Success if the directory could be created or it exists already; Error otherwise.

◆ ensureFile()

Error rstudio::launcher_plugins::system::FilePath::ensureFile ( ) const

Creates this file, if it does not exist.

Returns
Success if the file could be created or it exists already; Error otherwise.

◆ exists() [1/2]

bool rstudio::launcher_plugins::system::FilePath::exists ( ) const

Checks whether this file path exists in the file system.

Returns
True if this file path exists; false otherwise.

◆ exists() [2/2]

static bool rstudio::launcher_plugins::system::FilePath::exists ( const std::string &  in_filePath)
static

Checks whether the specified path exists.

Parameters
in_filePathThe path to check.
Returns
True if the specified path exists; false otherwise.

◆ getAbsolutePath()

std::string rstudio::launcher_plugins::system::FilePath::getAbsolutePath ( ) const

Gets the full absolute representation of this file path.

Returns
The absolute representation of this file path.

◆ getAbsolutePathNative()

std::string rstudio::launcher_plugins::system::FilePath::getAbsolutePathNative ( ) const

Gets the full absolute representation of this file path in native format.

Returns
The absolute representation of this file path in native format.

◆ getCanonicalPath()

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.

Returns
The canonical representation of this file path.

◆ getChildren()

Error rstudio::launcher_plugins::system::FilePath::getChildren ( std::vector< FilePath > &  out_filePaths) const

Gets the children of this directory. Sub-directories will not be traversed.

Parameters
out_filePathsThe children of this directory.
Returns
Success if the children could be retrieved; Error otherwise (e.g. if this path does not exist).

◆ getChildrenRecursive()

Error rstudio::launcher_plugins::system::FilePath::getChildrenRecursive ( const RecursiveIterationFunction in_iterationFunction) const

Gets the children of this directory recursively. Sub-directories will be traversed.

Parameters
in_iterationFunctionThe function to perform for each child of this directory.
Returns
Success if the children could be iterated; Error otherwise (e.g. if tis path does not exist).

◆ getExtension()

std::string rstudio::launcher_plugins::system::FilePath::getExtension ( ) const

Gets the extension of the file, including the leading '.'.

Returns
The extension of the file.

◆ getExtensionLowerCase()

std::string rstudio::launcher_plugins::system::FilePath::getExtensionLowerCase ( ) const

Gets the extension of the file in lower case, including the leading '.'.

Returns
The extension of the file in lower case.

◆ getFileMode()

Error rstudio::launcher_plugins::system::FilePath::getFileMode ( FileMode &  out_fileMode) const

Gets the posix file mode of this file or directory.

Parameters
out_fileModeThe file mode of this file or directory. Invalid if an error is returned.
Returns
Success if the file mode could be retrieved; Error otherwise.

◆ getFilename()

std::string rstudio::launcher_plugins::system::FilePath::getFilename ( ) const

Gets only the name of the file, including the extension.

Returns
The name of the file, including the extension.

◆ getLastWriteTime()

std::time_t rstudio::launcher_plugins::system::FilePath::getLastWriteTime ( ) const

Get the last time this file path was written.

Returns
The time of the last write.

◆ getLexicallyNormalPath()

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.

Returns
The lexically normal representation of this file path.

◆ getMimeContentType()

std::string rstudio::launcher_plugins::system::FilePath::getMimeContentType ( const std::string &  in_defaultType = "text/plain") const

Gets the mime content type of this file.

Parameters
in_defaultTypeThe default mime content type to return if this file does not have a mime content type. Default: "text/plain".
Returns
The mime content type of this file, or the default type if the file does not have a mime content type.

◆ getParent()

FilePath rstudio::launcher_plugins::system::FilePath::getParent ( ) const

Gets the parent directory of this file path.

Returns
The parent directory of this file path.

◆ getRelativePath()

std::string rstudio::launcher_plugins::system::FilePath::getRelativePath ( const FilePath in_parentPath) const

Gets the representation of this path, relative to the provided path.

Parameters
in_parentPathThe parent of this path.
Returns
The representation of this path, relative to the provided parent, or empty if this path is not within the provided parent.

◆ getSize()

uintmax_t rstudio::launcher_plugins::system::FilePath::getSize ( ) const

Gets the size of this file path in bytes.

Returns
The size of this file path in bytes.

◆ getSizeRecursive()

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.

Returns
The size of this file path and all sub-directories and files in it, in bytes.

◆ getStem()

std::string rstudio::launcher_plugins::system::FilePath::getStem ( ) const

Gets only the name of the file, excluding the extension.

Returns
The name of the file, excluding the extension.

◆ hasExtension()

bool rstudio::launcher_plugins::system::FilePath::hasExtension ( const std::string &  in_extension) const

Checks whether this file has the specified extension.

Parameters
in_extensionThe extension to check this file for.
Returns
True if the extension of this file matches the specified extension; false otherwise.

◆ hasExtensionLowerCase()

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.

Parameters
in_extensionThe extension to check this file for.
Returns
True if the lower case extension of this file matches the specified extension; false otherwise.

◆ hasTextMimeType()

bool rstudio::launcher_plugins::system::FilePath::hasTextMimeType ( ) const

Checks whether this file has a text mime content type.

Returns
True if this file has a text mime content type; false otherwise.

◆ isDirectory()

bool rstudio::launcher_plugins::system::FilePath::isDirectory ( ) const

Checks whether this file path is a directory.

Returns
True if this file path is a directory; false otherwise.

◆ isEmpty()

bool rstudio::launcher_plugins::system::FilePath::isEmpty ( ) const

Checks whether this file path contains a path or not.

Returns
True if this file path does not contain a path; false otherwise.

◆ isEqualCaseInsensitive()

static bool rstudio::launcher_plugins::system::FilePath::isEqualCaseInsensitive ( const FilePath in_filePath1,
const FilePath in_filePath2 
)
static

Checks whether the two provided files are equal, ignoring case. Two files are equal if their absolute paths are equal.

Parameters
in_filePath1The first file to compare.
in_filePath2The second file to compare.
Returns
True if the absolute representations of the paths are equal, case insensitively; false otherwise.

◆ isEquivalentTo()

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.

Parameters
in_otherThe file path to which to compare this file path to.
Returns
True if this file path points to the same location in the filesystem as the specified file path; false otherwise.

◆ isHidden()

bool rstudio::launcher_plugins::system::FilePath::isHidden ( ) const

Checks whether this file path is a hidden file or directory.

Returns
True if this file path is a hidden file or directory; false otherwise.

◆ isReadable()

Error rstudio::launcher_plugins::system::FilePath::isReadable ( bool &  out_readable) const

Checks whether this file path is readable.

Parameters
out_readableTrue if this file path is readable by the current effective user; false if it is not. Invalid if this method returns an error.
Returns
Success if the readability of this file could be checked; Error otherwise. (e.g. EACCES).

◆ isRegularFile()

bool rstudio::launcher_plugins::system::FilePath::isRegularFile ( ) const

Checks whether this file path is a regular file.

Returns
True if this file path is a regular file; false otherwise.

◆ isRootPath()

static bool rstudio::launcher_plugins::system::FilePath::isRootPath ( const std::string &  in_filePath)
static

Checks whether the specified path is a root path or a relative path.

Parameters
in_filePathThe path to check.
Returns
True if the path is a root path; false if the path is a relative path.

◆ isSymlink()

bool rstudio::launcher_plugins::system::FilePath::isSymlink ( ) const

Checks whether this file path is a symbolic link.

Returns
True if this file path is a symbolic link; false otherwise.

◆ isWithin()

bool rstudio::launcher_plugins::system::FilePath::isWithin ( const FilePath in_scopePath) const

Checks whether this file path is within the specified file path.

Parameters
in_scopePathThe potential parent path.
Returns
True if this file path is within the specified path, or if the two paths are equal; false otherwise.

◆ isWriteable()

Error rstudio::launcher_plugins::system::FilePath::isWriteable ( bool &  out_writeable) const

Checks whether this file path is writeable.

Parameters
out_writeableTrue if this file path is writeable by the current effective user; false if it is not. Invalid if this method returns an error.
Returns
Success if the writeability of this file could be checked; Error otherwise. (e.g. EACCES).

◆ makeCurrent()

static Error rstudio::launcher_plugins::system::FilePath::makeCurrent ( const std::string &  in_filePath)
static

Changes the current working directory to the specified path.

Parameters
in_filePathThe path to which to change the current working directory.
Returns
Success if in_path exists and can be moved to; Error otherwise.

◆ makeCurrentPath()

Error rstudio::launcher_plugins::system::FilePath::makeCurrentPath ( bool  in_autoCreate = false) const

Changes the current working directory to location represented by this file path.

Parameters
in_autoCreateControls whether to create the location represented by this file path if it does not exist. Default: false.
Returns
Success if the working directory was changed; Error otherwise.

◆ move()

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.

Parameters
in_targetPathThe location to which to move this directory.
in_typeThe type of move to perform, direct or cross device. See MoveType for more details. Default: MoveCrossDevice.
overwriteWhether to overwrite the file if one exists in target path.
Returns
Success if this directory could be moved to the target; Error otherwise.

◆ moveIndirect()

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.

Parameters
in_targetPathThe location to which to move this directory.
overwriteWhether to overwrite the file if one exists in target path.
Returns
Success if this directory could be moved to the target; Error otherwise.

◆ openForRead()

Error rstudio::launcher_plugins::system::FilePath::openForRead ( std::shared_ptr< std::istream > &  out_stream) const

Opens this file for read.

Parameters
out_streamThe input stream for this open file.
Returns
Success if the file was opened; system error otherwise (e.g. EPERM, ENOENT, etc.)

◆ openForWrite()

Error rstudio::launcher_plugins::system::FilePath::openForWrite ( std::shared_ptr< std::ostream > &  out_stream,
bool  in_truncate = true 
) const

Opens this file for write.

Parameters
out_streamThe output stream for this open file.
in_truncateWhether to truncate the existing contents of the file. Default: true.
Returns
Success if the file was opened; system error otherwise (e.g. EPERM, ENOENT, etc.)

◆ operator!=()

bool rstudio::launcher_plugins::system::FilePath::operator!= ( const FilePath in_other) const

Comparison operator. File paths are equal if their absolute representations are equal.

Parameters
in_otherThe file path to compare with this file path.
Returns
True if the file paths are not equal; false otherwise.

◆ operator<()

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.

Parameters
in_otherThe path to which to compare this path.
Returns
True if the absolute representation of this path is less, alphabetically, than the absolute representation of the other path; false otherwise.

◆ operator==()

bool rstudio::launcher_plugins::system::FilePath::operator== ( const FilePath in_other) const

Comparison operator. File paths are equal if their absolute representations are equal.

Parameters
in_otherThe file path to compare with this file path.
Returns
True if the file paths are equal; false otherwise.

◆ remove()

Error rstudio::launcher_plugins::system::FilePath::remove ( ) const

Removes this file or directory from the filesystem.

Returns
Success if the file or directory was removed; Error otherwise.

◆ removeIfExists()

Error rstudio::launcher_plugins::system::FilePath::removeIfExists ( ) const

Removes this file or directory from the filesystem, if it exists.

Returns
Success if the file or directory was removed, or if the file did not exist; Error otherwise.

◆ resetDirectory()

Error rstudio::launcher_plugins::system::FilePath::resetDirectory ( ) const

Removes the directory represented by this FilePath, if it exists, and recreates it.

Returns
Success if the directory was able to be created freshly; Error otherwise.

◆ resolveAliasedPath()

static FilePath rstudio::launcher_plugins::system::FilePath::resolveAliasedPath ( const std::string &  in_aliasedPath,
const FilePath in_userHomePath 
)
static

Resolves the '~' alias within the path to the user's home path.

Parameters
in_aliasedPathThe aliased path to resolve.
in_userHomePathThe user's home path.
Returns
The resolved path.

◆ resolveSymlink()

FilePath rstudio::launcher_plugins::system::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.

Returns
The resolved symbolic link, or this path if it is not a symbolic link.

◆ safeCurrentPath()

static FilePath rstudio::launcher_plugins::system::FilePath::safeCurrentPath ( const FilePath in_revertToPath)
static

Checks whether the current working directory exists. If it does not, moves the current working directory to the specified path.

Parameters
in_revertToPathThe path to revert to if the current working directory no longer exists.
Returns
The current working directory.

◆ setLastWriteTime()

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.

Parameters
in_timeThe time to which to set the last write time of this file. Default: now.

◆ tempFilePath() [1/2]

static Error rstudio::launcher_plugins::system::FilePath::tempFilePath ( const std::string &  in_extension,
FilePath out_filePath 
)
static

Creates a randomly named file with the specified extension in the temp directory.

Parameters
in_extensionThe extension with which to create the file. The extension should include the leading '.', e.g. '.zip'.
out_filePathThe absolute path of the newly created file, or an empty file path if the file could not be created.
Returns
Success if the file could be created; Error otherwise.

◆ tempFilePath() [2/2]

static Error rstudio::launcher_plugins::system::FilePath::tempFilePath ( FilePath out_filePath)
static

Creates a randomly named file in the temp directory.

Parameters
out_filePathThe absolute path of the newly created file, or an empty file path if the file could not be created.
Returns
Success if the file could be created; Error otherwise.

◆ testWritePermissions()

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.

Returns
Success if file can be written to; system error otherwise (e.g. EPERM, ENOENT, etc.)

◆ uniqueFilePath() [1/2]

static Error rstudio::launcher_plugins::system::FilePath::uniqueFilePath ( const std::string &  in_basePath,
const std::string &  in_extension,
FilePath out_filePath 
)
static

Creates a file with a random name and the specified extension in the specified directory.

Parameters
in_basePathThe path at which to create the file.
in_extensionThe extension with which to create the file. The extension should include the leading '.', e.g. '.zip'.
out_filePathThe absolute path of the newly created file, or an empty file path if the file could not be created.
Returns
Success if the file could be created; Error otherwise.

◆ uniqueFilePath() [2/2]

static Error rstudio::launcher_plugins::system::FilePath::uniqueFilePath ( const std::string &  in_basePath,
FilePath out_filePath 
)
static

Creates a file with a random name in the specified directory.

Parameters
in_basePathThe path at which to create the file.
out_filePathThe absolute path of the newly created file, or an empty file path if the file could not be created.
Returns
Success if the file could be created; Error otherwise.

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