Code cleanup in list_files

This commit is contained in:
Maxime Coste 2014-04-06 10:59:51 +01:00
parent b01ba59911
commit 0df088be20

View File

@ -275,15 +275,12 @@ std::vector<String> list_files(const String& prefix,
{ {
kak_assert(dirname.empty() or dirname.back() == '/'); kak_assert(dirname.empty() or dirname.back() == '/');
DIR* dir = opendir(dirname.empty() ? "./" : dirname.c_str()); DIR* dir = opendir(dirname.empty() ? "./" : dirname.c_str());
auto closeDir = on_scope_end([=]{ if (not dir)
if (dir != NULL) return {};
closedir(dir);
}); auto closeDir = on_scope_end([=]{ closedir(dir); });
std::vector<String> result; std::vector<String> result;
if (not dir)
return result;
std::vector<String> subseq_result; std::vector<String> subseq_result;
while (dirent* entry = readdir(dir)) while (dirent* entry = readdir(dir))
{ {
@ -309,8 +306,7 @@ std::vector<String> list_files(const String& prefix,
} }
} }
} }
auto& real_result = result.empty() ? subseq_result : result; return result.empty() ? subseq_result : result;
return real_result;
} }
std::vector<String> complete_filename(const String& prefix, std::vector<String> complete_filename(const String& prefix,