| 46 | |
| 47 | namespace { |
| 48 | void DeleteTree(const std::string& path) |
| 49 | { |
| 50 | // fts_open wants a char* const, not a const char*; therefore, we need |
| 51 | // a mutable pointer to path. fts promises not to modify it. |
| 52 | std::vector<char> pathchars(path.begin(), path.end()); |
| 53 | pathchars.push_back(0); |
| 54 | |
| 55 | std::array<char*, 2> paths{pathchars.data(), nullptr}; |
| 56 | |
| 57 | FTS* tree = fts_open(paths.data(), FTS_PHYSICAL | FTS_NOCHDIR, nullptr); |
| 58 | if (!tree) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | while (FTSENT* f = fts_read(tree)) { |
| 63 | switch (f->fts_info) { |
| 64 | case FTS_D: |
| 65 | // skip pre-order directory traversal because it's potentially |
| 66 | // not empty yet |
| 67 | break; |
| 68 | |
| 69 | default: |
| 70 | // attempt to delete anything else and ignore errors |
| 71 | remove(f->fts_accpath); |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | fts_close(tree); |
| 77 | } |
| 78 | |
| 79 | } // namespace |
| 80 |
no test coverage detected