7#ifndef KEA_UTIL_FILESYSTEM_H
8#define KEA_UTIL_FILESYSTEM_H
13#include <boost/noncopyable.hpp>
14#include <boost/shared_ptr.hpp>
54exists(
const std::string& path);
80isDir(
const std::string& path);
89isFile(
const std::string& path);
130 Path(std::string
const& path);
137 std::string
str()
const;
159 std::string
stem()
const;
204 std::string parent_path_;
210 std::string extension_;
218 std::string dir_name_;
232 PathChecker(
const std::string default_path,
const std::string env_name =
"");
252 std::string
getPath(
bool reset =
false,
const std::string explicit_path =
"");
270 std::string
validatePath(
const std::string input_path_str,
305 return (default_path_);
326 std::string default_path_;
329 std::string env_name_;
335 bool default_overridden_;
338 static bool enforce_security_;
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
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 enforcement 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.
SecurityError(const char *file, size_t line, const char *what)
SecurityWarn(const char *file, size_t line, const char *what)
bool amRunningAsRoot()
Indicates if current user is root.
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.