Page MenuHomePhabricator

Replace `rm -rf` with more portable implementation.
ClosedPublic

Authored by chaoren on Jun 26 2015, 6:06 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

chaoren retitled this revision from to Replace `rm -rf` with more portable implementation..
chaoren updated this object.
chaoren edited the test plan for this revision. (Show Details)
chaoren added reviewers: vharron, clayborg.
chaoren added a subscriber: Unknown Object (MLST).
This revision was automatically updated to reflect the committed changes.
clayborg edited edge metadata.Jun 29 2015, 10:35 AM

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
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,

bool find_directories,
bool find_files,
bool find_other,
FileCallback const& callback);

Ah, I missed that this was committed. I will fix this.

Please let me fix this. I need to redeem myself.

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.

Sorry I didn't see this email before I fixed it.

It's okay, it was my fault to begin with.