From f2fbac3ccb4960c4a3d057f641c28dba10ebf799 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 14 Oct 2013 01:06:03 +0300 Subject: [PATCH] Throw an exception in list_files if the directory can't be opened --- source/fs/dir.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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; } -- 2.45.2