diff options
author | Chaoren Lin <chaorenl@google.com> | 2015-06-27 23:11:34 +0000 |
---|---|---|
committer | Chaoren Lin <chaorenl@google.com> | 2015-06-27 23:11:34 +0000 |
commit | 226937eb15385a81144da725239127097acd3bc2 (patch) | |
tree | 52484145778df21284fd8d5916d4a185fbafc0c5 /lldb/source/Host/posix/FileSystem.cpp | |
parent | ccc06b36c1ce9a87a08431b184ce458e6bb3008a (diff) | |
download | bcm5719-llvm-226937eb15385a81144da725239127097acd3bc2.tar.gz bcm5719-llvm-226937eb15385a81144da725239127097acd3bc2.zip |
Replace `rm -rf` with more portable implementation.
Reviewers: clayborg, vharron
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D10787
llvm-svn: 240895
Diffstat (limited to 'lldb/source/Host/posix/FileSystem.cpp')
-rw-r--r-- | lldb/source/Host/posix/FileSystem.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/lldb/source/Host/posix/FileSystem.cpp b/lldb/source/Host/posix/FileSystem.cpp index 626c37dae94..1ec53e2cc66 100644 --- a/lldb/source/Host/posix/FileSystem.cpp +++ b/lldb/source/Host/posix/FileSystem.cpp @@ -10,6 +10,7 @@ #include "lldb/Host/FileSystem.h" // C includes +#include <dirent.h> #include <sys/mount.h> #include <sys/param.h> #include <sys/stat.h> @@ -81,11 +82,25 @@ FileSystem::DeleteDirectory(const FileSpec &file_spec, bool recurse) { if (recurse) { - StreamString command; - command.Printf("rm -rf \"%s\"", file_spec.GetCString()); - int status = ::system(command.GetString().c_str()); - if (status != 0) - error.SetError(status, eErrorTypeGeneric); + DIR *dirp = opendir(file_spec.GetCString()); + if (!dirp) + { + error.SetErrorToErrno(); + return error; + } + struct dirent *direntp; + while (error.Success() && (direntp = readdir(dirp))) + { + if (direntp->d_type == DT_DIR) + error = DeleteDirectory(FileSpec{direntp->d_name, false}, true); + else if (::unlink(direntp->d_name) != 0) + error.SetErrorToErrno(); + } + if (closedir(dirp) != 0) + error.SetErrorToErrno(); + if (error.Fail()) + return error; + return DeleteDirectory(file_spec, false); } else { |