RStudio Launcher Plugin SDK
1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
|
24 #ifndef LAUNCHER_PLUGINS_FILE_PATH_HPP
25 #define LAUNCHER_PLUGINS_FILE_PATH_HPP
27 #include <Noncopyable.hpp>
43 namespace launcher_plugins {
53 namespace launcher_plugins {
63 USER_READ_WRITE_EXECUTE,
64 USER_READ_WRITE_GROUP_READ,
65 USER_READ_WRITE_ALL_READ,
66 USER_READ_WRITE_EXECUTE_ALL_READ_EXECUTE,
67 USER_READ_WRITE_EXECUTE_GROUP_READ_WRITE_EXECUTE_ALL_READ_EXECUTE,
70 ALL_READ_WRITE_EXECUTE
112 explicit FilePath(
const std::string& in_absolutePath);
119 explicit FilePath(
const char* in_absolutePath);
167 static bool exists(
const std::string& in_filePath);
187 static bool isRootPath(
const std::string& in_filePath);
298 bool in_recursive =
false,
475 std::string
getMimeContentType(
const std::string& in_defaultType =
"text/plain")
const;
522 bool hasExtension(
const std::string& in_extension)
const;
663 Error openForWrite(std::shared_ptr<std::ostream>& out_stream,
bool in_truncate =
true)
const;
715 PRIVATE_IMPL_SHARED(m_impl);
721 struct PathScopeImpl;
756 std::unique_ptr<PathScopeImpl, PathScopeImplDeleter> m_impl;
781 std::unique_ptr<PathScopeImpl, PathScopeImplDeleter> m_impl;
792 std::ostream& operator<<(std::ostream& io_ostream,
const FilePath& in_filePath);
820 bool isFileNotFoundError(
const Error& in_error);
839 Error fileNotFoundError(
const std::string& in_filePath,
const ErrorLocation& in_location);
858 bool isPathNotFoundError(
const Error& error);
877 Error pathNotFoundError(
const std::string& in_filePath,
const ErrorLocation& in_location);
886 bool isNotFoundError(
const Error& in_error);
Error remove() const
Removes this file or directory from the filesystem.
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.
bool isEquivalentTo(const FilePath &in_other) const
Checks whether this file path points to the same location in the filesystem as the specified file pat...
Struct which implements the deleter for PathScopeImpl.
Definition: FilePath.hpp:726
std::time_t getLastWriteTime() const
Get the last time this file path was written.
bool isHidden() const
Checks whether this file path is a hidden file or directory.
static FilePath resolveAliasedPath(const std::string &in_aliasedPath, const FilePath &in_userHomePath)
Resolves the '~' alias within the path to the user's home path.
static Error uniqueFilePath(const std::string &in_basePath, FilePath &out_filePath)
Creates a file with a random name in the specified directory.
uintmax_t getSizeRecursive() const
Gets the size of this file path and all sub-directories and files in it, in bytes.
FilePath resolveSymlink() const
Resolves this symbolic link to the location to which it is pointing. If this FilePath is not a symbol...
Class which represents a path on the system. May be any type of file (e.g. directory,...
Definition: FilePath.hpp:77
uintmax_t getSize() const
Gets the size of this file path in bytes.
Class which represents the location of an error.
Definition: Error.hpp:74
Error makeCurrentPath(bool in_autoCreate=false) const
Changes the current working directory to location represented by this file path.
Error ensureDirectory() const
Creates this directory, if it does not exist.
Definition: FilePath.hpp:86
RemoveOnExitScope(FilePath in_restorePath, ErrorLocation in_location)
Constructor.
bool isDirectory() const
Checks whether this file path is a directory.
Class which represents a system user.
Definition: User.hpp:55
RAII class for restoring the current working directory.
Definition: FilePath.hpp:737
Error ensureFile() const
Creates this file, if it does not exist.
virtual ~RemoveOnExitScope()
Destructor. Removes the path that was provided in the constructor from the filesystem.
std::string getAbsolutePathNative() const
Gets the full absolute representation of this file path in native format.
Error changeFileMode(const std::string &in_fileModeStr) const
Changes the file mode to the specified file mode.
RestoreCurrentPathScope(FilePath in_restorePath, ErrorLocation in_location)
Constructor.
bool isWithin(const FilePath &in_scopePath) const
Checks whether this file path is within the specified file path.
std::string getCanonicalPath() const
Gets the canonical representation of this file path. The path must exist so that its canonical locati...
std::string getLexicallyNormalPath() const
Gets the lexically normal representation of this file path, with . and .. components resolved and/or ...
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.
Error resetDirectory() const
Removes the directory represented by this FilePath, if it exists, and recreates it.
std::function< bool(int, const FilePath &)> RecursiveIterationFunction
Function which recursively iterates over FilePath objects.
Definition: FilePath.hpp:100
Error isReadable(bool &out_readable) const
Checks whether this file path is readable.
bool operator<(const FilePath &in_other) const
Less-than operator to establish natural order. The natural order is based on the absolute representat...
FilePath completeChildPath(const std::string &in_filePath) const
Gets the provided relative path as a child of this path.
bool isSymlink() const
Checks whether this file path is a symbolic link.
MoveType
Enum which represents the type of move to perform.
Definition: FilePath.hpp:83
Error openForRead(std::shared_ptr< std::istream > &out_stream) const
Opens this file for read.
bool isEmpty() const
Checks whether this file path contains a path or not.
static FilePath safeCurrentPath(const FilePath &in_revertToPath)
Checks whether the current working directory exists. If it does not, moves the current working direct...
bool operator!=(const FilePath &in_other) const
Comparison operator. File paths are equal if their absolute representations are equal.
Error getChildren(std::vector< FilePath > &out_filePaths) const
Gets the children of this directory. Sub-directories will not be traversed.
virtual ~RestoreCurrentPathScope()
Destructor. Returns the working directory to the original path.
static Error tempFilePath(FilePath &out_filePath)
Creates a randomly named file in the temp directory.
RAII class for restoring the current working directory.
Definition: FilePath.hpp:762
std::string getRelativePath(const FilePath &in_parentPath) const
Gets the representation of this path, relative to the provided path.
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.
std::string getAbsolutePath() const
Gets the full absolute representation of this file path.
bool hasTextMimeType() const
Checks whether this file has a text mime content type.
static bool isRootPath(const std::string &in_filePath)
Checks whether the specified path is a root path or a relative path.
Error openForWrite(std::shared_ptr< std::ostream > &out_stream, bool in_truncate=true) const
Opens this file for write.
bool hasExtensionLowerCase(const std::string &in_extension) const
Checks whether this file has the specified extension when it is converted to lower case.
void operator()(PathScopeImpl *)
Deletion operator.
Definition: FilePath.hpp:89
Error getFileMode(FileMode &out_fileMode) const
Gets the posix file mode of this file or directory.
FilePath completePath(const std::string &in_filePath) const
Completes the provided path relative to this path. If the provided path is not relative,...
Error removeIfExists() const
Removes this file or directory from the filesystem, if it exists.
Class which represents an error.
Definition: Error.hpp:174
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...
Error isWriteable(bool &out_writeable) const
Checks whether this file path is writeable.
Error createDirectory(const std::string &in_filePath) const
Creates the specified directory.
std::string getFilename() const
Gets only the name of the file, including the extension.
FilePath getParent() const
Gets the parent directory of this file path.
bool hasExtension(const std::string &in_extension) const
Checks whether this file has the specified extension.
std::string getExtensionLowerCase() const
Gets the extension of the file in lower case, including the leading '.'.
void setLastWriteTime(std::time_t in_time=::time(nullptr)) const
Sets the last time that this file was modified to the specified time.
std::string getStem() const
Gets only the name of the file, excluding the extension.
Class which can be inherited from to disallow copying of its child classes.
Definition: Noncopyable.hpp:34
Error copyDirectoryRecursive(const FilePath &in_targetPath, bool overwrite=false) const
Copies this directory recursively to the specified location.
bool operator==(const FilePath &in_other) const
Comparison operator. File paths are equal if their absolute representations are equal.
Error copy(const FilePath &in_targetPath, bool overwrite=false) const
Copies this file path to the specified location.
std::string getMimeContentType(const std::string &in_defaultType="text/plain") const
Gets the mime content type of this file.
bool exists() const
Checks whether this file path exists in the file system.
std::string getExtension() const
Gets the extension of the file, including the leading '.'.
FilePath()
Default constructor.
static Error makeCurrent(const std::string &in_filePath)
Changes the current working directory to the specified path.
Error testWritePermissions() const
Checks if a file can be written to by opening the file.
Error getChildrenRecursive(const RecursiveIterationFunction &in_iterationFunction) const
Gets the children of this directory recursively. Sub-directories will be traversed.
Error move(const FilePath &in_targetPath, MoveType in_type=MoveCrossDevice, bool overwrite=false) const
Moves the current directory to the specified directory.
bool isRegularFile() const
Checks whether this file path is a regular file.