Line data Source code
1 : #pragma once 2 : 3 : #include <dirent.h> 4 : 5 : #include "envoy/filesystem/filesystem.h" 6 : 7 : #include "source/common/api/os_sys_calls_impl.h" 8 : 9 : namespace Envoy { 10 : namespace Filesystem { 11 : 12 : class DirectoryIteratorImpl : public DirectoryIterator { 13 : public: 14 : DirectoryIteratorImpl(const std::string& directory_path); 15 37 : DirectoryIteratorImpl() : directory_path_(""), os_sys_calls_(Api::OsSysCallsSingleton::get()) {} 16 : 17 : ~DirectoryIteratorImpl() override; 18 : 19 : DirectoryIteratorImpl& operator++() override; 20 : 21 : // We don't want this iterator to be copied. If the copy gets destructed, 22 : // then it will close its copy of the DIR* pointer, which will cause the 23 : // original's to be invalid. While we could implement a deep copy constructor to 24 : // work around this, it is not needed the moment. 25 : DirectoryIteratorImpl(const DirectoryIteratorImpl&) = delete; 26 : DirectoryIteratorImpl(DirectoryIteratorImpl&&) = default; 27 : 28 : private: 29 : void nextEntry(); 30 : void openDirectory(); 31 : 32 : absl::StatusOr<DirectoryEntry> makeEntry(absl::string_view filename) const; 33 : 34 : std::string directory_path_; 35 : DIR* dir_{nullptr}; 36 : Api::OsSysCallsImpl& os_sys_calls_; 37 : 38 : friend class DirectoryTest_MakeEntryThrowsOnStatFailure_Test; 39 : }; 40 : 41 : } // namespace Filesystem 42 : } // namespace Envoy