From: Mikko Rasa Date: Sun, 13 Oct 2013 22:06:03 +0000 (+0300) Subject: Throw an exception in list_files if the directory can't be opened X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f2fbac3ccb4960c4a3d057f641c28dba10ebf799;p=libs%2Fcore.git Throw an exception in list_files if the directory can't be opened --- diff --git a/source/fs/dir.cpp b/source/fs/dir.cpp index f775847..2ae5122 100644 --- a/source/fs/dir.cpp +++ b/source/fs/dir.cpp @@ -103,18 +103,18 @@ list list_filtered(const Path &path, const string &filter) list result; DIR *dir = opendir(path.str().c_str()); - if(dir) + if(!dir) + throw system_error("opendir"); + + while(dirent *de = readdir(dir)) { - while(dirent *de = readdir(dir)) - { - const char *fn = de->d_name; - if(fn[0]=='.' && (fn[1]==0 || (fn[1]=='.' && fn[2]==0))) - continue; - if(r_filter.match(fn)) - result.push_back(fn); - } - closedir(dir); + const char *fn = de->d_name; + if(fn[0]=='.' && (fn[1]==0 || (fn[1]=='.' && fn[2]==0))) + continue; + if(r_filter.match(fn)) + result.push_back(fn); } + closedir(dir); return result; }