MCPcopy Create free account
hub / github.com/bloomberg/pystack / DirectoryReader

Class DirectoryReader

src/pystack/_pystack/process.cpp:30–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28static const std::string PERM_MESSAGE = "Operation not permitted";
29
30class 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
64namespace pystack {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected