Author: chaoren Date: Sat Jun 27 18:11:34 2015 New Revision: 240895 URL: http://llvm.org/viewvc/llvm-project?rev=240895&view=rev Log: Replace `rm -rf` with more portable implementation.
Reviewers: clayborg, vharron Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D10787 Modified: lldb/trunk/source/Host/posix/FileSystem.cpp Modified: lldb/trunk/source/Host/posix/FileSystem.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/FileSystem.cpp?rev=240895&r1=240894&r2=240895&view=diff ============================================================================== --- lldb/trunk/source/Host/posix/FileSystem.cpp (original) +++ lldb/trunk/source/Host/posix/FileSystem.cpp Sat Jun 27 18:11:34 2015 @@ -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 FileSp { 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 { _______________________________________________ lldb-commits mailing list lldb-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits