File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 1616 * limitations under the License.
1717 */
1818
19+ #include < sys/stat.h>
1920#include < fstream>
2021#include < list>
2122#include < unordered_map>
@@ -216,6 +217,16 @@ std::string GetParentDirectory(const std::string& path) {
216217 return path.substr (0 , pos + 1 );
217218}
218219
220+ bool isRegularFile (const std::string& path) {
221+ struct stat info;
222+
223+ if (stat (path.c_str (), &info) != 0 )
224+ return false ;
225+
226+ // Check if it's a directory
227+ return (info.st_mode & S_IFMT) == S_IFREG;
228+ }
229+
219230} // namespace
220231
221232Config::Config () : internal(new ConfigInternal()) {}
@@ -241,6 +252,8 @@ ConverterPtr Config::NewFromFile(const std::string& fileName,
241252 impl->paths .push_back (PACKAGE_DATA_DIRECTORY);
242253 }
243254 std::string prefixedFileName = impl->FindConfigFile (fileName);
255+ if (!isRegularFile (prefixedFileName))
256+ throw FileNotFound (prefixedFileName);
244257 std::ifstream ifs (UTF8Util::GetPlatformString (prefixedFileName));
245258 std::string content (std::istreambuf_iterator<char >(ifs),
246259 (std::istreambuf_iterator<char >()));
You can’t perform that action at this time.
0 commit comments