File tree 1 file changed +5
-1
lines changed
1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change 64
64
#endif
65
65
66
66
#include " rcutils/env.h"
67
+ #include " rcpputils/scope_exit.hpp"
67
68
#include " rcpputils/split.hpp"
68
69
69
70
namespace rcpputils
@@ -474,6 +475,10 @@ bool remove_all(const path & p)
474
475
return 0 == ret && false == file_options.fAnyOperationsAborted ;
475
476
#else
476
477
DIR * dir = opendir (p.string ().c_str ());
478
+ if (dir == nullptr ) {
479
+ return false ;
480
+ }
481
+ RCPPUTILS_SCOPE_EXIT (closedir (dir));
477
482
struct dirent * directory_entry;
478
483
while ((directory_entry = readdir (dir)) != nullptr ) {
479
484
// Make sure to not call ".." or "." entries in directory (might delete everything)
@@ -488,7 +493,6 @@ bool remove_all(const path & p)
488
493
}
489
494
}
490
495
}
491
- closedir (dir);
492
496
// directory is empty now, call remove
493
497
rcpputils::fs::remove (p);
494
498
return !rcpputils::fs::exists (p);
You can’t perform that action at this time.
0 commit comments