Throw an exception in list_files if the directory can't be opened
authorMikko Rasa <tdb@tdb.fi>
Sun, 13 Oct 2013 22:06:03 +0000 (01:06 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 13 Oct 2013 22:06:03 +0000 (01:06 +0300)
source/fs/dir.cpp

index f77584708bb20a94d01496da33465dd0ffec40c7..2ae5122e63768492f54274a7b7062e861445a094 100644 (file)
@@ -103,18 +103,18 @@ list<string> list_filtered(const Path &path, const string &filter)
 
        list<string> 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;
 }