MCPcopy Create free account
hub / github.com/Tencent/MMKV / walkInDir

Function walkInDir

Core/MemoryFile.cpp:633–677  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

631#endif // !defined(MMKV_APPLE)
632
633void walkInDir(const MMKVPath_t &dirPath, WalkType type, const function<void(const MMKVPath_t&, WalkType)> &walker) {
634 auto folderPathStr = dirPath.data();
635 DIR *dir = opendir(folderPathStr);
636 if (!dir) {
637 MMKVError("opendir failed: %d(%s), %s", errno, strerror(errno), dirPath.c_str());
638 return;
639 }
640
641 char childPath[PATH_MAX];
642 size_t folderPathLength = dirPath.size();
643 strncpy(childPath, folderPathStr, folderPathLength + 1);
644 if (folderPathStr[folderPathLength - 1] != '/') {
645 childPath[folderPathLength] = '/';
646 folderPathLength++;
647 }
648
649 while (auto child = readdir(dir)) {
650 if ((child->d_type & DT_REG) && (type & WalkFile)) {
651#if defined(_DIRENT_HAVE_D_NAMLEN) || defined(__APPLE__)
652 stpcpy(childPath + folderPathLength, child->d_name);
653 childPath[folderPathLength + child->d_namlen] = 0;
654#else
655 strcpy(childPath + folderPathLength, child->d_name);
656#endif
657 walker(childPath, WalkFile);
658 } else if ((child->d_type & DT_DIR) && (type & WalkFolder)) {
659#if defined(_DIRENT_HAVE_D_NAMLEN) || defined(__APPLE__)
660 if ((child->d_namlen == 1 && child->d_name[0] == '.') ||
661 (child->d_namlen == 2 && child->d_name[0] == '.' && child->d_name[1] == '.')) {
662 continue;
663 }
664 stpcpy(childPath + folderPathLength, child->d_name);
665 childPath[folderPathLength + child->d_namlen] = 0;
666#else
667 if (strcmp(child->d_name, ".") == 0 || strcmp(child->d_name, "..") == 0) {
668 continue;
669 }
670 strcpy(childPath + folderPathLength, child->d_name);
671#endif
672 walker(childPath, WalkFolder);
673 }
674 }
675
676 closedir(dir);
677}
678
679bool deleteFile(const MMKVPath_t &path) {
680 auto filename = path.c_str();

Callers 2

backupAllToDirectoryMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected