Make Filesystem::is* functions handle nonexistent paths properly

If stat() failed, these functions could read from an uninitialized
stat struct and return "true" for paths that didn't exist.
develop
lethosor 2015-09-19 17:34:58 -04:00
parent 2fcf751a44
commit a56a427d12
1 changed files with 4 additions and 3 deletions

@ -128,18 +128,19 @@ bool Filesystem::exists (std::string path)
_filetype Filesystem::filetype (std::string path)
{
STAT_STRUCT info;
Filesystem::stat(path, info);
if (!Filesystem::stat(path, info))
return FILETYPE_NONE;
return mode2type(info.st_mode);
}
bool Filesystem::isfile (std::string path)
{
return Filesystem::filetype(path) == FILETYPE_FILE;
return Filesystem::exists(path) && Filesystem::filetype(path) == FILETYPE_FILE;
}
bool Filesystem::isdir (std::string path)
{
return Filesystem::filetype(path) == FILETYPE_DIRECTORY;
return Filesystem::exists(path) && Filesystem::filetype(path) == FILETYPE_DIRECTORY;
}
#define DEFINE_STAT_TIME_WRAPPER(attr) \