[Lldb-commits] [lldb] r298205 - Remove FileSystem::Get/SetFilePermissions

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


Author: zturner
Date: Sun Mar 19 00:49:43 2017
New Revision: 298205

URL: http://llvm.org/viewvc/llvm-project?rev=298205&view=rev
Log:
Remove FileSystem::Get/SetFilePermissions

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

Modified:
    lldb/trunk/include/lldb/Host/FileSystem.h
    lldb/trunk/source/Host/posix/FileSystem.cpp
    lldb/trunk/source/Host/windows/FileSystem.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
    lldb/trunk/source/Target/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=298205&r1=298204&r2=298205&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSystem.h (original)
+++ lldb/trunk/include/lldb/Host/FileSystem.h Sun Mar 19 00:49:43 2017
@@ -28,10 +28,6 @@ public:
 
   static FileSpec::PathSyntax GetNativePathSyntax();
 
-  static Error GetFilePermissions(const FileSpec &file_spec,
-                                  uint32_t &file_permissions);
-  static Error SetFilePermissions(const FileSpec &file_spec,
-                                  uint32_t file_permissions);
   static lldb::user_id_t GetFileSize(const FileSpec &file_spec);
   static bool GetFileExists(const FileSpec &file_spec);
 

Modified: lldb/trunk/source/Host/posix/FileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/FileSystem.cpp?rev=298205&r1=298204&r2=298205&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/FileSystem.cpp (original)
+++ lldb/trunk/source/Host/posix/FileSystem.cpp Sun Mar 19 00:49:43 2017
@@ -40,28 +40,6 @@ FileSpec::PathSyntax FileSystem::GetNati
   return FileSpec::ePathSyntaxPosix;
 }
 
-Error FileSystem::GetFilePermissions(const FileSpec &file_spec,
-                                     uint32_t &file_permissions) {
-  Error error;
-  struct stat file_stats;
-  if (::stat(file_spec.GetCString(), &file_stats) == 0) {
-    // The bits in "st_mode" currently match the definitions
-    // for the file mode bits in unix.
-    file_permissions = file_stats.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
-  } else {
-    error.SetErrorToErrno();
-  }
-  return error;
-}
-
-Error FileSystem::SetFilePermissions(const FileSpec &file_spec,
-                                     uint32_t file_permissions) {
-  Error error;
-  if (::chmod(file_spec.GetCString(), file_permissions) != 0)
-    error.SetErrorToErrno();
-  return error;
-}
-
 lldb::user_id_t FileSystem::GetFileSize(const FileSpec &file_spec) {
   return file_spec.GetByteSize();
 }

Modified: lldb/trunk/source/Host/windows/FileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/FileSystem.cpp?rev=298205&r1=298204&r2=298205&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/FileSystem.cpp (original)
+++ lldb/trunk/source/Host/windows/FileSystem.cpp Sun Mar 19 00:49:43 2017
@@ -30,34 +30,6 @@ FileSpec::PathSyntax FileSystem::GetNati
   return FileSpec::ePathSyntaxWindows;
 }
 
-Error FileSystem::GetFilePermissions(const FileSpec &file_spec,
-                                     uint32_t &file_permissions) {
-  Error error;
-  // Beware that Windows's permission model is different from Unix's, and it's
-  // not clear if this API is supposed to check ACLs.  To match the caller's
-  // expectations as closely as possible, we'll use Microsoft's _stat, which
-  // attempts to emulate POSIX stat.  This should be good enough for basic
-  // checks like FileSpec::Readable.
-  struct _stat file_stats;
-  if (::_stat(file_spec.GetCString(), &file_stats) == 0) {
-    // The owner permission bits in "st_mode" currently match the definitions
-    // for the owner file mode bits.
-    file_permissions = file_stats.st_mode & (_S_IREAD | _S_IWRITE | _S_IEXEC);
-  } else {
-    error.SetErrorToErrno();
-  }
-
-  return error;
-}
-
-Error FileSystem::SetFilePermissions(const FileSpec &file_spec,
-                                     uint32_t file_permissions) {
-  Error error;
-  error.SetErrorStringWithFormat("%s is not supported on this host",
-                                 LLVM_PRETTY_FUNCTION);
-  return error;
-}
-
 lldb::user_id_t FileSystem::GetFileSize(const FileSpec &file_spec) {
   return file_spec.GetByteSize();
 }

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=298205&r1=298204&r2=298205&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:49:43 2017
@@ -809,11 +809,12 @@ GDBRemoteCommunicationServerCommon::Hand
     StringExtractorGDBRemote &packet) {
   packet.SetFilePos(::strlen("qPlatform_chmod:"));
 
-  mode_t mode = packet.GetHexMaxU32(false, UINT32_MAX);
+  auto perms =
+      static_cast<llvm::sys::fs::perms>(packet.GetHexMaxU32(false, UINT32_MAX));
   if (packet.GetChar() == ',') {
     std::string path;
     packet.GetHexByteString(path);
-    Error error = FileSystem::SetFilePermissions(FileSpec{path, true}, mode);
+    Error error(llvm::sys::fs::setPermissions(path, perms));
 
     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=298205&r1=298204&r2=298205&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Sun Mar 19 00:49:43 2017
@@ -773,9 +773,12 @@ Error Platform::MakeDirectory(const File
 
 Error Platform::GetFilePermissions(const FileSpec &file_spec,
                                    uint32_t &file_permissions) {
-  if (IsHost())
-    return FileSystem::GetFilePermissions(file_spec, file_permissions);
-  else {
+  if (IsHost()) {
+    auto Value = llvm::sys::fs::getPermissions(file_spec.GetPath());
+    if (Value)
+      file_permissions = Value.get();
+    return Error(Value.getError());
+  } else {
     Error error;
     error.SetErrorStringWithFormat("remote platform %s doesn't support %s",
                                    GetPluginName().GetCString(),
@@ -786,9 +789,10 @@ Error Platform::GetFilePermissions(const
 
 Error Platform::SetFilePermissions(const FileSpec &file_spec,
                                    uint32_t file_permissions) {
-  if (IsHost())
-    return FileSystem::SetFilePermissions(file_spec, file_permissions);
-  else {
+  if (IsHost()) {
+    auto Perms = static_cast<llvm::sys::fs::perms>(file_permissions);
+    return llvm::sys::fs::setPermissions(file_spec.GetPath(), Perms);
+  } else {
     Error error;
     error.SetErrorStringWithFormat("remote platform %s doesn't support %s",
                                    GetPluginName().GetCString(),




More information about the lldb-commits mailing list