Skip to content

Commit cc988f2

Browse files
committedAug 22, 2020
Added exception handling with directory_iterator when the constructed path is not a directory
1 parent d5cdaef commit cc988f2

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed
 

‎source/glob.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,21 @@ std::vector<fs::path> iter_directory(const fs::path &dirname, bool dironly) {
184184
}
185185

186186
if (fs::exists(current_directory)) {
187-
for (auto &entry : fs::directory_iterator(
188-
current_directory, fs::directory_options::follow_directory_symlink |
189-
fs::directory_options::skip_permission_denied)) {
190-
if (!dironly || entry.is_directory()) {
191-
if (dirname.is_absolute()) {
192-
result.push_back(entry.path());
193-
} else {
194-
result.push_back(fs::relative(entry.path()));
187+
try {
188+
for (auto &entry : fs::directory_iterator(
189+
current_directory, fs::directory_options::follow_directory_symlink |
190+
fs::directory_options::skip_permission_denied)) {
191+
if (!dironly || entry.is_directory()) {
192+
if (dirname.is_absolute()) {
193+
result.push_back(entry.path());
194+
} else {
195+
result.push_back(fs::relative(entry.path()));
196+
}
195197
}
196198
}
199+
} catch (std::exception& e) {
200+
// not a directory
201+
// do nothing
197202
}
198203
}
199204

0 commit comments

Comments
 (0)
Please sign in to comment.