[Lldb-commits] [PATCH] Replace `rm -rf` with more portable implementation.

Chaoren Lin chaorenl at google.com
Fri Jun 26 18:06:09 PDT 2015


Hi vharron, clayborg,

http://reviews.llvm.org/D10787

Files:
  source/Host/posix/FileSystem.cpp

Index: source/Host/posix/FileSystem.cpp
===================================================================
--- source/Host/posix/FileSystem.cpp
+++ 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 @@
     {
         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
         {

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10787.28615.patch
Type: text/x-patch
Size: 1453 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150627/9ec9a051/attachment.bin>


More information about the lldb-commits mailing list