Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
See inlined comments for needed changes.
lldb/trunk/source/Host/posix/FileSystem.cpp | ||
---|---|---|
85–103 | Please fix the following things: 1 - use FileSpec::EnumerateDirectory(...) instead of using opendir(), readdir(), closedir() directly Extra credit for possibly making a new version of FileSpec::EnumerateDirectory(...) that uses a lambda instead of a callback. Something like: typedef std::function < FileSpec::EnumerateDirectoryResult(FileType file_type, const FileSpec &spec)> FileCallback; FileSpec::EnumerateDirectoryResult bool find_directories, bool find_files, bool find_other, FileCallback const& callback); |
I implemented my suggestions with:
% svn commit Sending include/lldb/Host/FileSpec.h Sending source/Host/common/FileSpec.cpp Sending source/Host/posix/FileSystem.cpp Transmitting file data ... Committed revision 240978.
Please fix the following things:
1 - use FileSpec::EnumerateDirectory(...) instead of using opendir(), readdir(), closedir() directly
2 - Save the directories up in a std::vector and process them _after_ the call the FileSpec::EnumerateDirectory(...) has completed iterating through the current directory so we don't run out of file descriptors when we try to delete a directory that has 1000000 entries inside of it. Each opendir()/closedir() takes up a file descriptor and if you recursively call this function you will run out of fds. You want to avoid the recursive nature here and only use 1 file descriptor at a time for the recursion by just saving the list of directories to delete, then iterating through those directories and calling FileSystem::DeleteDirectory() with each item.
Extra credit for possibly making a new version of FileSpec::EnumerateDirectory(...) that uses a lambda instead of a callback. Something like:
typedef std::function < FileSpec::EnumerateDirectoryResult(FileType file_type, const FileSpec &spec)> FileCallback;
FileSpec::EnumerateDirectoryResult
FileSpec::ForEachDirectory (const char *dir_path,