| 90 | } |
| 91 | |
| 92 | int scandir( |
| 93 | const std::string& path, |
| 94 | std::vector<dirent>& outList, |
| 95 | ScandirFilter filterMethod, |
| 96 | ScandirSort sortMethod |
| 97 | ) { |
| 98 | auto lock = getLock(path)->asScopedLock(); |
| 99 | lock.lock(); |
| 100 | |
| 101 | LOGGER.info("scandir start"); |
| 102 | DIR* dir = opendir(path.c_str()); |
| 103 | if (dir == nullptr) { |
| 104 | LOGGER.error("Failed to open dir {}", path); |
| 105 | return -1; |
| 106 | } |
| 107 | |
| 108 | dirent* current_entry; |
| 109 | while ((current_entry = readdir(dir)) != nullptr) { |
| 110 | if (filterMethod == nullptr || filterMethod(current_entry) == 0) { |
| 111 | outList.push_back(*current_entry); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | closedir(dir); |
| 116 | |
| 117 | if (sortMethod != nullptr) { |
| 118 | std::ranges::sort(outList, sortMethod); |
| 119 | } |
| 120 | |
| 121 | LOGGER.info("scandir finish"); |
| 122 | return outList.size(); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | long getSize(FILE* file) { |
no test coverage detected