36 ifstream file(file_name, ios::in);
37 if (!file.is_open()) {
48 return (::stat(path.c_str(), &statbuf) == 0);
54 if (::stat(path.c_str(), &statbuf) < 0) {
57 return ((statbuf.st_mode & S_IFMT) == S_IFDIR);
63 if (::stat(path.c_str(), &statbuf) < 0) {
66 return ((statbuf.st_mode & S_IFMT) == S_IFREG);
70 umask(orig_umask_ | mask);
80 if (::stat(path.c_str(), &statbuf) < 0) {
83 return ((statbuf.st_mode & S_IFMT) == S_IFSOCK);
87 if (!full_name.empty()) {
88 bool dir_present =
false;
90 size_t last_slash = full_name.find_last_of(
'/');
91 if (last_slash != string::npos) {
94 parent_path_ = full_name.substr(0, last_slash);
95 if (last_slash == full_name.size()) {
106 size_t last_dot = full_name.find_last_of(
'.');
107 if ((last_dot == string::npos) || (dir_present && (last_dot < last_slash))) {
112 stem_ = full_name.substr(last_slash + 1);
118 extension_ = full_name.substr(last_dot);
121 if ((last_dot - last_slash) > 1) {
122 stem_ = full_name.substr(last_slash + 1, last_dot - last_slash - 1);
129 return (parent_path_ + ((parent_path_.empty() || parent_path_ ==
"/") ?
string() :
"/") + stem_ + extension_);
134 return (parent_path_);
149 return (stem_ + extension_);
154 string const trimmed_replacement(
trim(replacement));
155 if (trimmed_replacement.empty()) {
156 extension_ = string();
158 size_t const last_dot(trimmed_replacement.find_last_of(
'.'));
159 if (last_dot == string::npos) {
160 extension_ =
"." + trimmed_replacement;
162 extension_ = trimmed_replacement.substr(last_dot);
170 string const trimmed_replacement(
trim(replacement));
171 if (trimmed_replacement.empty()) {
172 parent_path_ = string();
173 }
else if (trimmed_replacement ==
"/") {
174 parent_path_ = trimmed_replacement;
175 }
else if (trimmed_replacement.at(trimmed_replacement.size() - 1) ==
'/') {
176 parent_path_ = trimmed_replacement.substr(0, trimmed_replacement.size() - 1);
178 parent_path_ = trimmed_replacement;
184 char dir[](
"/tmp/kea-tmpdir-XXXXXX");
185 char const* dir_name = mkdtemp(dir);
189 dir_name_ = string(dir_name);
193 DIR *dir(opendir(dir_name_.c_str()));
200 while ((i = readdir(dir))) {
201 if (strcmp(i->d_name,
".") == 0 || strcmp(i->d_name,
"..") == 0) {
205 filepath = dir_name_ +
'/' + i->d_name;
206 remove(filepath.c_str());
209 rmdir(dir_name_.c_str());
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown when an unexpected error condition occurs.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
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 isSocket(string const &path)
bool isDir(string const &path)
Check if there is a directory at the given path.
string trim(const string &input)
Trim leading and trailing spaces.
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 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.
Umask(mode_t mask)
Constructor.