7#ifndef KEA_UTIL_FILESYSTEM_H
8#define KEA_UTIL_FILESYSTEM_H
12#include <boost/shared_ptr.hpp>
33exists(
const std::string& path);
58isDir(
const std::string& path);
67isFile(
const std::string& path);
87 Path(std::string
const& path);
94 std::string
str()
const;
116 std::string
stem()
const;
161 std::string parent_path_;
167 std::string extension_;
175 std::string dir_name_;
189 PathChecker(
const std::string default_path,
const std::string env_name =
"");
209 std::string
getPath(
bool reset =
false,
const std::string explicit_path =
"");
226 std::string
validatePath(
const std::string input_path_str,
261 return (default_path_);
282 std::string default_path_;
285 std::string env_name_;
291 bool default_overridden_;
294 static bool enforce_security_;
std::string getPath(bool reset=false, const std::string explicit_path="")
Fetches the supported path.
static bool shouldEnforceSecurity()
Indicates security checks should be enforced.
PathChecker(const std::string default_path, const std::string env_name="")
Constructor.
virtual ~PathChecker()
Destructor.
std::string getDefaultPath() const
Fetches the default path.
bool isDefaultOverridden()
Indicates if the default path has been overridden.
static void enableEnforcement(bool enable)
Enables or disables security enforcment checks.
std::string validateDirectory(const std::string input_path_str, bool enforce_path=shouldEnforceSecurity()) const
Validates a directory against a supported path.
bool pathHasPermissions(mode_t permissions, bool enforce_perms=shouldEnforceSecurity()) const
Check if the path has expected permissions.
std::string validatePath(const std::string input_path_str, bool enforce_path=shouldEnforceSecurity()) const
Validates a file path against a supported path.
std::string getEnvName() const
Fetches the environment variable name.
boost::shared_ptr< PathChecker > PathCheckerPtr
Defines a pointer to a PathChecker.
bool isSocket(string const &path)
Check if there is a socket at the given path.
string getContent(string const &file_name)
Get the content of a regular file.
bool isFile(string const &path)
Check if there is a file at the given path.
bool exists(string const &path)
Check if there is a file or directory at the given path.
bool isDir(string const &path)
Check if there is a directory at the given path.
mode_t getPermissions(const std::string path)
Fetches the file permissions mask.
bool hasPermissions(const std::string path, const mode_t &permissions)
Check if there if file or directory has the given permissions.
void setUmask()
Set umask (at least 0027 i.e. no group write and no other access).
Defines the logger used by the top-level component of kea-lfc.
Path(std::string const &path)
Constructor.
Path & replaceParentPath(std::string const &replacement=std::string())
Trims {replacement} and replaces this instance's parent path with it.
std::string parentDirectory() const
Get the parent directory.
std::string extension() const
Get the extension of the file.
Path & replaceExtension(std::string const &replacement=std::string())
Identifies the extension in {replacement}, trims it, and replaces this instance's extension with it.
std::string stem() const
Get the base name of the file without the extension.
std::string parentPath() const
Get the parent path.
std::string filename() const
Get the name of the file, extension included.
std::string str() const
Get the path in textual format.