MCPcopy Create free account
hub / github.com/apple/coremltools / DeleteTree

Function DeleteTree

mlmodel/tests/MILBlob/AutoDeleteTempFile.cpp:48–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46
47namespace {
48void 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

Callers 1

~AutoDeleteTempFileMethod · 0.85

Calls 4

push_backMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected