| 3210 | int __eraseDirectoryRecurseiveCount; |
| 3211 | |
| 3212 | int 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 | |
| 3242 | TmpFile::TmpFile() : filename("") { |
| 3243 | createTmpFile(boost::filesystem::temp_directory_path().string(), TmpFile::defaultPrefix); |