Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

#include <sys/stat.h>
#include <fstream>
#include <list>
#include <unordered_map>
Expand Down Expand Up @@ -216,6 +217,16 @@ std::string GetParentDirectory(const std::string& path) {
return path.substr(0, pos + 1);
}

bool isRegularFile(const std::string& path) {
struct stat info;

if (stat(path.c_str(), &info) != 0)
return false;

// Check if it's a regular file
return (info.st_mode & S_IFMT) == S_IFREG;
}

} // namespace

Config::Config() : internal(new ConfigInternal()) {}
Expand All @@ -241,6 +252,8 @@ ConverterPtr Config::NewFromFile(const std::string& fileName,
impl->paths.push_back(PACKAGE_DATA_DIRECTORY);
}
std::string prefixedFileName = impl->FindConfigFile(fileName);
if (!isRegularFile(prefixedFileName))
throw FileNotFound(prefixedFileName);
std::ifstream ifs(UTF8Util::GetPlatformString(prefixedFileName));
std::string content(std::istreambuf_iterator<char>(ifs),
(std::istreambuf_iterator<char>()));
Expand Down