| 28 | static const std::string PERM_MESSAGE = "Operation not permitted"; |
| 29 | |
| 30 | class DirectoryReader |
| 31 | { |
| 32 | public: |
| 33 | explicit DirectoryReader(const std::string& path) |
| 34 | : dir_(opendir(path.c_str())) |
| 35 | { |
| 36 | if (!dir_) { |
| 37 | throw std::runtime_error("Could not read the contents of " + path); |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | ~DirectoryReader() |
| 42 | { |
| 43 | closedir(dir_); |
| 44 | }; |
| 45 | |
| 46 | std::vector<std::string> files() const |
| 47 | { |
| 48 | std::vector<std::string> files; |
| 49 | struct dirent* ent; |
| 50 | while ((ent = readdir(dir_)) != nullptr) { |
| 51 | if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) { |
| 52 | continue; |
| 53 | } |
| 54 | files.emplace_back(ent->d_name); |
| 55 | } |
| 56 | return files; |
| 57 | } |
| 58 | |
| 59 | private: |
| 60 | DIR* dir_; |
| 61 | }; |
| 62 | |
| 63 | } // namespace |
| 64 | namespace pystack { |
nothing calls this directly
no outgoing calls
no test coverage detected