MCPcopy Create free account
hub / github.com/facebook/CacheLib / removePath

Function removePath

cachelib/common/Utils.cpp:310–339  ·  view source on GitHub ↗

throws error on any failure. */

Source from the content-addressed store, hash-verified

308
309/* throws error on any failure. */
310void removePath(const std::string& name) {
311 if (!pathExists(name)) {
312 return;
313 }
314
315 if (isDir(name)) {
316 auto dir = opendir(name.c_str());
317 if (!dir) {
318 throwSystemError(errno, fmt::format("Err removing path={}", name));
319 }
320 SCOPE_EXIT { closedir(dir); };
321 struct dirent* entry;
322 while ((entry = readdir(dir))) {
323 if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
324 continue;
325 }
326 std::string path = name + "/" + std::string(entry->d_name);
327 removePath(path);
328 }
329 auto err = rmdir(name.c_str());
330 if (err) {
331 throwSystemError(errno, fmt::format("Err removing path={}", name));
332 }
333 } else {
334 auto err = unlink(name.c_str());
335 if (err) {
336 throwSystemError(errno, fmt::format("Err removing path={}", name));
337 }
338 }
339}
340
341std::string getUniqueTempDir(folly::StringPiece prefix) {
342 const char* dir = getenv("TMPDIR");

Callers 15

~TempShmMappingMethod · 0.85
createShmManagerMethod · 0.85
createShmMappingMethod · 0.85
~NvmCacheStateTestMethod · 0.85
~AllocatorTestMethod · 0.85
~NvmCacheTestMethod · 0.85
TEST_FFunction · 0.85
TESTFunction · 0.85
ShmManagerMethod · 0.85
SetUpMethod · 0.85
TearDownMethod · 0.85

Calls 3

pathExistsFunction · 0.85
isDirFunction · 0.85
throwSystemErrorFunction · 0.85

Tested by 15

~NvmCacheStateTestMethod · 0.68
~AllocatorTestMethod · 0.68
~NvmCacheTestMethod · 0.68
TEST_FFunction · 0.68
TESTFunction · 0.68
SetUpMethod · 0.68
TearDownMethod · 0.68
testMetaFileDeletionMethod · 0.68
testDropFileMethod · 0.68
testInvalidCachedDirMethod · 0.68