[Lldb-commits] [lldb] r297360 - Remove LLDB's recursive directory deletion function.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 8 21:12:36 PST 2017


Author: zturner
Date: Wed Mar  8 23:12:36 2017
New Revision: 297360

URL: http://llvm.org/viewvc/llvm-project?rev=297360&view=rev
Log:
Remove LLDB's recursive directory deletion function.

LLVM now has such a function, so we use that instead.

Modified:
    lldb/trunk/include/lldb/Host/FileSystem.h
    lldb/trunk/source/Host/common/HostInfoBase.cpp
    lldb/trunk/source/Host/posix/FileSystem.cpp
    lldb/trunk/source/Host/windows/FileSystem.cpp
    lldb/trunk/source/Target/ModuleCache.cpp

Modified: lldb/trunk/include/lldb/Host/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSystem.h?rev=297360&r1=297359&r2=297360&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSystem.h (original)
+++ lldb/trunk/include/lldb/Host/FileSystem.h Wed Mar  8 23:12:36 2017
@@ -29,7 +29,6 @@ public:
   static FileSpec::PathSyntax GetNativePathSyntax();
 
   static Error MakeDirectory(const FileSpec &file_spec, uint32_t mode);
-  static Error DeleteDirectory(const FileSpec &file_spec, bool recurse);
 
   static Error GetFilePermissions(const FileSpec &file_spec,
                                   uint32_t &file_permissions);

Modified: lldb/trunk/source/Host/common/HostInfoBase.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/HostInfoBase.cpp?rev=297360&r1=297359&r2=297360&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/HostInfoBase.cpp (original)
+++ lldb/trunk/source/Host/common/HostInfoBase.cpp Wed Mar  8 23:12:36 2017
@@ -46,7 +46,7 @@ struct HostInfoBaseFields {
       // Remove the LLDB temporary directory if we have one. Set "recurse" to
       // true to all files that were created for the LLDB process can be cleaned
       // up.
-      FileSystem::DeleteDirectory(m_lldb_process_tmp_dir, true);
+      llvm::sys::fs::remove_directories(m_lldb_process_tmp_dir.GetPath());
     }
   }
 

Modified: lldb/trunk/source/Host/posix/FileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/FileSystem.cpp?rev=297360&r1=297359&r2=297360&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/FileSystem.cpp (original)
+++ lldb/trunk/source/Host/posix/FileSystem.cpp Wed Mar  8 23:12:36 2017
@@ -73,58 +73,6 @@ Error FileSystem::MakeDirectory(const Fi
   return Error("empty path");
 }
 
-Error FileSystem::DeleteDirectory(const FileSpec &file_spec, bool recurse) {
-  Error error;
-  if (file_spec) {
-    if (recurse) {
-      // Save all sub directories in a list so we don't recursively call this
-      // function
-      // and possibly run out of file descriptors if the directory is too deep.
-      std::vector<FileSpec> sub_directories;
-
-      FileSpec::ForEachItemInDirectory(
-          file_spec.GetCString(),
-          [&error, &sub_directories](
-              llvm::sys::fs::file_type ft,
-              const FileSpec &spec) -> FileSpec::EnumerateDirectoryResult {
-            if (ft == llvm::sys::fs::file_type::directory_file) {
-              // Save all directorires and process them after iterating through
-              // this directory
-              sub_directories.push_back(spec);
-            } else {
-              // Update sub_spec to point to the current file and delete it
-              error = FileSystem::Unlink(spec);
-            }
-            // If anything went wrong, stop iterating, else process the next
-            // file
-            if (error.Fail())
-              return FileSpec::eEnumerateDirectoryResultQuit;
-            else
-              return FileSpec::eEnumerateDirectoryResultNext;
-          });
-
-      if (error.Success()) {
-        // Now delete all sub directories with separate calls that aren't
-        // recursively calling into this function _while_ this function is
-        // iterating through the current directory.
-        for (const auto &sub_directory : sub_directories) {
-          error = DeleteDirectory(sub_directory, recurse);
-          if (error.Fail())
-            break;
-        }
-      }
-    }
-
-    if (error.Success()) {
-      if (::rmdir(file_spec.GetCString()) != 0)
-        error.SetErrorToErrno();
-    }
-  } else {
-    error.SetErrorString("empty path");
-  }
-  return error;
-}
-
 Error FileSystem::GetFilePermissions(const FileSpec &file_spec,
                                      uint32_t &file_permissions) {
   Error error;

Modified: lldb/trunk/source/Host/windows/FileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/FileSystem.cpp?rev=297360&r1=297359&r2=297360&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/FileSystem.cpp (original)
+++ lldb/trunk/source/Host/windows/FileSystem.cpp Wed Mar  8 23:12:36 2017
@@ -45,40 +45,6 @@ Error FileSystem::MakeDirectory(const Fi
   return error;
 }
 
-Error FileSystem::DeleteDirectory(const FileSpec &file_spec, bool recurse) {
-  Error error;
-  std::wstring path_buffer;
-  if (!llvm::ConvertUTF8toWide(file_spec.GetPath(), path_buffer)) {
-    error.SetErrorString(PATH_CONVERSION_ERROR);
-    return error;
-  }
-  if (!recurse) {
-    BOOL result = ::RemoveDirectoryW(path_buffer.c_str());
-    if (!result)
-      error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
-  } else {
-    // SHFileOperation() accepts a list of paths, and so must be
-    // double-null-terminated to
-    // indicate the end of the list. The first null terminator is there only in
-    // the backing
-    // store but not the actual vector contents, and so we need to push twice.
-    path_buffer.push_back(0);
-    path_buffer.push_back(0);
-
-    SHFILEOPSTRUCTW shfos = {};
-    shfos.wFunc = FO_DELETE;
-    shfos.pFrom = (LPCWSTR)path_buffer.data();
-    shfos.fFlags = FOF_NO_UI;
-
-    int result = ::SHFileOperationW(&shfos);
-    // TODO(zturner): Correctly handle the intricacies of SHFileOperation return
-    // values.
-    if (result != 0)
-      error.SetErrorStringWithFormat("SHFileOperation failed");
-  }
-  return error;
-}
-
 Error FileSystem::GetFilePermissions(const FileSpec &file_spec,
                                      uint32_t &file_permissions) {
   Error error;

Modified: lldb/trunk/source/Target/ModuleCache.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ModuleCache.cpp?rev=297360&r1=297359&r2=297360&view=diff
==============================================================================
--- lldb/trunk/source/Target/ModuleCache.cpp (original)
+++ lldb/trunk/source/Target/ModuleCache.cpp Wed Mar  8 23:12:36 2017
@@ -109,7 +109,7 @@ void DeleteExistingModule(const FileSpec
     return;
 
   const auto module_spec_dir = GetModuleDirectory(root_dir_spec, module_uuid);
-  FileSystem::DeleteDirectory(module_spec_dir, true);
+  llvm::sys::fs::remove_directories(module_spec_dir.GetPath());
   lock.Delete();
 }
 




More information about the lldb-commits mailing list