[Lldb-commits] [lldb] r298203 - Remove FileSystem::MakeDirectory.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Sat Mar 18 22:48:48 PDT 2017


Author: zturner
Date: Sun Mar 19 00:48:47 2017
New Revision: 298203

URL: http://llvm.org/viewvc/llvm-project?rev=298203&view=rev
Log:
Remove FileSystem::MakeDirectory.

Have callers use llvm::sys::fs::create_directory() instead.

Differential Revision: https://reviews.llvm.org/D31086

Modified:
    lldb/trunk/include/lldb/Host/FileSystem.h
    lldb/trunk/source/Host/common/Editline.cpp
    lldb/trunk/source/Host/common/HostInfoBase.cpp
    lldb/trunk/source/Host/posix/FileSystem.cpp
    lldb/trunk/source/Host/windows/FileSystem.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
    lldb/trunk/source/Target/Platform.cpp
    lldb/trunk/tools/lldb-server/lldb-platform.cpp

Modified: lldb/trunk/include/lldb/Host/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSystem.h?rev=298203&r1=298202&r2=298203&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSystem.h (original)
+++ lldb/trunk/include/lldb/Host/FileSystem.h Sun Mar 19 00:48:47 2017
@@ -28,8 +28,6 @@ public:
 
   static FileSpec::PathSyntax GetNativePathSyntax();
 
-  static Error MakeDirectory(const FileSpec &file_spec, uint32_t mode);
-
   static Error GetFilePermissions(const FileSpec &file_spec,
                                   uint32_t &file_permissions);
   static Error SetFilePermissions(const FileSpec &file_spec,

Modified: lldb/trunk/source/Host/common/Editline.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Editline.cpp?rev=298203&r1=298202&r2=298203&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Editline.cpp (original)
+++ lldb/trunk/source/Host/common/Editline.cpp Sun Mar 19 00:48:47 2017
@@ -15,13 +15,13 @@
 #include "lldb/Host/ConnectionFileDescriptor.h"
 #include "lldb/Host/Editline.h"
 #include "lldb/Host/FileSpec.h"
-#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Utility/Error.h"
 #include "lldb/Utility/LLDBAssert.h"
 #include "lldb/Utility/SelectHelper.h"
 #include "lldb/Utility/StreamString.h"
 
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Threading.h"
 
 using namespace lldb_private;
@@ -178,9 +178,7 @@ private:
     if (m_path.empty() && m_history && !m_prefix.empty()) {
       FileSpec parent_path{"~/.lldb", true};
       char history_path[PATH_MAX];
-      if (FileSystem::MakeDirectory(parent_path,
-                                    lldb::eFilePermissionsDirectoryDefault)
-              .Success()) {
+      if (!llvm::sys::fs::create_directory(parent_path.GetPath()) {
         snprintf(history_path, sizeof(history_path), "~/.lldb/%s-history",
                  m_prefix.c_str());
       } else {

Modified: lldb/trunk/source/Host/common/HostInfoBase.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/HostInfoBase.cpp?rev=298203&r1=298202&r2=298203&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/HostInfoBase.cpp (original)
+++ lldb/trunk/source/Host/common/HostInfoBase.cpp Sun Mar 19 00:48:47 2017
@@ -314,9 +314,7 @@ bool HostInfoBase::ComputeProcessTempFil
 
   std::string pid_str{llvm::to_string(Host::GetCurrentProcessID())};
   temp_file_spec.AppendPathComponent(pid_str);
-  if (!FileSystem::MakeDirectory(temp_file_spec,
-                                 eFilePermissionsDirectoryDefault)
-           .Success())
+  if (llvm::sys::fs::create_directory(temp_file_spec.GetPath()))
     return false;
 
   file_spec.GetDirectory().SetCString(temp_file_spec.GetCString());
@@ -338,9 +336,7 @@ bool HostInfoBase::ComputeGlobalTempFile
     return false;
 
   temp_file_spec.AppendPathComponent("lldb");
-  if (!FileSystem::MakeDirectory(temp_file_spec,
-                                 eFilePermissionsDirectoryDefault)
-           .Success())
+  if (llvm::sys::fs::create_directory(temp_file_spec.GetPath()))
     return false;
 
   file_spec.GetDirectory().SetCString(temp_file_spec.GetCString());

Modified: lldb/trunk/source/Host/posix/FileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/FileSystem.cpp?rev=298203&r1=298202&r2=298203&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/FileSystem.cpp (original)
+++ lldb/trunk/source/Host/posix/FileSystem.cpp Sun Mar 19 00:48:47 2017
@@ -40,39 +40,6 @@ FileSpec::PathSyntax FileSystem::GetNati
   return FileSpec::ePathSyntaxPosix;
 }
 
-Error FileSystem::MakeDirectory(const FileSpec &file_spec,
-                                uint32_t file_permissions) {
-  if (file_spec) {
-    Error error;
-    if (::mkdir(file_spec.GetCString(), file_permissions) == -1) {
-      error.SetErrorToErrno();
-      errno = 0;
-      switch (error.GetError()) {
-      case ENOENT: {
-        // Parent directory doesn't exist, so lets make it if we can
-        // Make the parent directory and try again
-        FileSpec parent_file_spec{file_spec.GetDirectory().GetCString(), false};
-        error = MakeDirectory(parent_file_spec, file_permissions);
-        if (error.Fail())
-          return error;
-        // Try and make the directory again now that the parent directory was
-        // made successfully
-        if (::mkdir(file_spec.GetCString(), file_permissions) == -1) {
-          error.SetErrorToErrno();
-        }
-        return error;
-      } break;
-      case EEXIST: {
-        if (llvm::sys::fs::is_directory(file_spec.GetPath()))
-          return Error(); // It is a directory and it already exists
-      } break;
-      }
-    }
-    return error;
-  }
-  return Error("empty path");
-}
-
 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=298203&r1=298202&r2=298203&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/FileSystem.cpp (original)
+++ lldb/trunk/source/Host/windows/FileSystem.cpp Sun Mar 19 00:48:47 2017
@@ -30,21 +30,6 @@ FileSpec::PathSyntax FileSystem::GetNati
   return FileSpec::ePathSyntaxWindows;
 }
 
-Error FileSystem::MakeDirectory(const FileSpec &file_spec,
-                                uint32_t file_permissions) {
-  // On Win32, the mode parameter is ignored, as Windows files and directories
-  // support a
-  // different permission model than POSIX.
-  Error error;
-  const auto err_code =
-      llvm::sys::fs::create_directories(file_spec.GetPath(), true);
-  if (err_code) {
-    error.SetErrorString(err_code.message().c_str());
-  }
-
-  return error;
-}
-
 Error FileSystem::GetFilePermissions(const FileSpec &file_spec,
                                      uint32_t &file_permissions) {
   Error error;

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=298203&r1=298202&r2=298203&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Sun Mar 19 00:48:47 2017
@@ -225,8 +225,7 @@ static lldb_private::Error
 MakeCacheFolderForFile(const FileSpec &module_cache_spec) {
   FileSpec module_cache_folder =
       module_cache_spec.CopyByRemovingLastPathComponent();
-  return FileSystem::MakeDirectory(module_cache_folder,
-                                   eFilePermissionsDirectoryDefault);
+  return llvm::sys::fs::create_directory(module_cache_folder.GetPath());
 }
 
 static lldb_private::Error

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp?rev=298203&r1=298202&r2=298203&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp Sun Mar 19 00:48:47 2017
@@ -22,7 +22,6 @@
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Host/FileSpec.h"
-#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/ObjectFile.h"
@@ -279,8 +278,7 @@ PlatformMacOSX::GetFileWithUUID(const ll
       FileSpec module_cache_folder =
           module_cache_spec.CopyByRemovingLastPathComponent();
       // try to make the local directory first
-      Error err = FileSystem::MakeDirectory(module_cache_folder,
-                                            eFilePermissionsDirectoryDefault);
+      Error err(llvm::sys::fs::create_directory(module_cache_folder.GetPath()));
       if (err.Fail())
         return err;
       err = GetFile(platform_file, module_cache_spec);

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp?rev=298203&r1=298202&r2=298203&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp Sun Mar 19 00:48:47 2017
@@ -794,7 +794,7 @@ GDBRemoteCommunicationServerCommon::Hand
   if (packet.GetChar() == ',') {
     std::string path;
     packet.GetHexByteString(path);
-    Error error = FileSystem::MakeDirectory(FileSpec{path, false}, mode);
+    Error error(llvm::sys::fs::create_directory(path, mode));
 
     StreamGDBRemote response;
     response.Printf("F%u", error.GetError());

Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=298203&r1=298202&r2=298203&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Sun Mar 19 00:48:47 2017
@@ -761,7 +761,7 @@ bool Platform::SetWorkingDirectory(const
 
 Error Platform::MakeDirectory(const FileSpec &file_spec, uint32_t permissions) {
   if (IsHost())
-    return FileSystem::MakeDirectory(file_spec, permissions);
+    return llvm::sys::fs::create_directory(file_spec.GetPath(), permissions);
   else {
     Error error;
     error.SetErrorStringWithFormat("remote platform %s doesn't support %s",

Modified: lldb/trunk/tools/lldb-server/lldb-platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-server/lldb-platform.cpp?rev=298203&r1=298202&r2=298203&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-server/lldb-platform.cpp (original)
+++ lldb/trunk/tools/lldb-server/lldb-platform.cpp Sun Mar 19 00:48:47 2017
@@ -32,7 +32,6 @@
 #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
 #include "lldb/Host/ConnectionFileDescriptor.h"
 #include "lldb/Host/FileSpec.h"
-#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostGetOpt.h"
 #include "lldb/Host/OptionParser.h"
 #include "lldb/Host/common/TCPSocket.h"
@@ -102,8 +101,7 @@ static void display_usage(const char *pr
 static Error save_socket_id_to_file(const std::string &socket_id,
                                     const FileSpec &file_spec) {
   FileSpec temp_file_spec(file_spec.GetDirectory().AsCString(), false);
-  auto error = FileSystem::MakeDirectory(temp_file_spec,
-                                         eFilePermissionsDirectoryDefault);
+  Error error(llvm::sys::fs::create_directory(temp_file_spec.GetPath()));
   if (error.Fail())
     return Error("Failed to create directory %s: %s",
                  temp_file_spec.GetCString(), error.AsCString());




More information about the lldb-commits mailing list