MCPcopy Create free account
hub / github.com/apple/foundationdb / eraseDirectoryRecursive

Function eraseDirectoryRecursive

flow/Platform.actor.cpp:3212–3240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3210int __eraseDirectoryRecurseiveCount;
3211
3212int eraseDirectoryRecursive(std::string const& dir) {
3213 __eraseDirectoryRecurseiveCount = 0;
3214#ifdef _WIN32
3215 system(("rd /s /q \"" + dir + "\"").c_str());
3216#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
3217 int error = nftw(
3218 dir.c_str(),
3219 [](const char* fpath, const struct stat* sb, int typeflag, struct FTW* ftwbuf) -> int {
3220 int r = remove(fpath);
3221 if (r == 0)
3222 ++__eraseDirectoryRecurseiveCount;
3223 return r;
3224 },
3225 64,
3226 FTW_DEPTH | FTW_PHYS);
3227 /* Looks like calling code expects this to continue silently if
3228 the directory we're deleting doesn't exist in the first
3229 place */
3230 if (error && errno != ENOENT) {
3231 Error e = systemErrorCodeToError();
3232 TraceEvent(SevError, "EraseDirectoryRecursiveError").error(e).detail("Directory", dir).GetLastError();
3233 throw e;
3234 }
3235#else
3236#error Port me!
3237#endif
3238 // INJECT_FAULT( platform_error, "eraseDirectoryRecursive" );
3239 return __eraseDirectoryRecurseiveCount;
3240}
3241
3242TmpFile::TmpFile() : filename("") {
3243 createTmpFile(boost::filesystem::temp_directory_path().string(), TmpFile::defaultPrefix);

Callers 12

deleteCheckpointMethod · 0.85
actionMethod · 0.85
mainFunction · 0.85
setupMethod · 0.85
runUnitTestsMethod · 0.85
_startMethod · 0.85
deleteContainerMethod · 0.85

Calls 6

systemErrorCodeToErrorFunction · 0.85
TraceEventClass · 0.85
detailMethod · 0.80
removeFunction · 0.50
c_strMethod · 0.45
errorMethod · 0.45

Tested by 5

setupMethod · 0.68
runUnitTestsMethod · 0.68
_startMethod · 0.68