[Lldb-commits] [PATCH] D62216: [EditLine] Rewrite GetHistoryFilePath

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue May 21 14:51:04 PDT 2019


JDevlieghere updated this revision to Diff 200592.
JDevlieghere added a comment.

Jim's feedback


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62216/new/

https://reviews.llvm.org/D62216

Files:
  lldb/source/Host/common/Editline.cpp


Index: lldb/source/Host/common/Editline.cpp
===================================================================
--- lldb/source/Host/common/Editline.cpp
+++ lldb/source/Host/common/Editline.cpp
@@ -171,23 +171,25 @@
   }
 
   const char *GetHistoryFilePath() {
+    // Compute the history path lazily.
     if (m_path.empty() && m_history && !m_prefix.empty()) {
-      FileSpec parent_path("~/.lldb");
-      FileSystem::Instance().Resolve(parent_path);
-      char history_path[PATH_MAX];
-      if (!llvm::sys::fs::create_directory(parent_path.GetPath())) {
-        snprintf(history_path, sizeof(history_path), "~/.lldb/%s-history",
-                 m_prefix.c_str());
-      } else {
-        snprintf(history_path, sizeof(history_path), "~/%s-widehistory",
-                 m_prefix.c_str());
+      llvm::SmallString<128> lldb_history_file;
+      llvm::sys::path::home_directory(lldb_history_file);
+      llvm::sys::path::append(lldb_history_file, ".lldb");
+      if (!llvm::sys::fs::create_directory(lldb_history_file)) {
+#if LLDB_EDITLINE_USE_WCHAR
+        std::string filename = m_prefix + "-widehistory";
+#else
+        std::string filename = m_prefix + "-history";
+#endif
+        llvm::sys::path::append(lldb_history_file, filename);
+        m_path = lldb_history_file.str();
       }
-      auto file_spec = FileSpec(history_path);
-      FileSystem::Instance().Resolve(file_spec);
-      m_path = file_spec.GetPath();
     }
+
     if (m_path.empty())
-      return NULL;
+      return nullptr;
+
     return m_path.c_str();
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62216.200592.patch
Type: text/x-patch
Size: 1557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190521/0797cc85/attachment.bin>


More information about the lldb-commits mailing list