diff options
author | ADAM David Alan Martin <adam.martin@10gen.com> | 2019-03-18 18:06:05 -0400 |
---|---|---|
committer | ADAM David Alan Martin <adam.martin@10gen.com> | 2019-03-18 18:41:32 -0400 |
commit | 159eba44d7aad44e49c688820b1b0331230236bf (patch) | |
tree | f6a43efe06d6de381bdad19d03f47cc7c6573ce9 /src/mongo/shell/dbshell.cpp | |
parent | d9952e5baca401fd1b8f375016cd26b156f06e1a (diff) | |
download | mongo-159eba44d7aad44e49c688820b1b0331230236bf.tar.gz |
SERVER-39195 Make shell history file placement more correct.
Shell history file placement should rely upon more than just the
`$HOME` environment variable.
Resolves: #1294
Diffstat (limited to 'src/mongo/shell/dbshell.cpp')
-rw-r--r-- | src/mongo/shell/dbshell.cpp | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp index 91359c8b94d..46cf674fea5 100644 --- a/src/mongo/shell/dbshell.cpp +++ b/src/mongo/shell/dbshell.cpp @@ -84,7 +84,6 @@ using namespace std::literals::string_literals; using namespace mongo; -std::string historyFile; bool gotInterrupted = false; bool inMultiLine = false; static AtomicWord<bool> atPrompt(false); // can eval before getting to prompt @@ -199,14 +198,7 @@ void completionHook(const char* text, linenoiseCompletions* lc) { } void shellHistoryInit() { - std::stringstream ss; - const char* h = shell_utils::getUserDir(); - if (h) - ss << h << "/"; - ss << ".dbshell"; - historyFile = ss.str(); - - Status res = linenoiseHistoryLoad(historyFile.c_str()); + Status res = linenoiseHistoryLoad(shell_utils::getHistoryFilePath().string().c_str()); if (!res.isOK()) { error() << "Error loading history file: " << res; } @@ -214,7 +206,7 @@ void shellHistoryInit() { } void shellHistoryDone() { - Status res = linenoiseHistorySave(historyFile.c_str()); + Status res = linenoiseHistorySave(shell_utils::getHistoryFilePath().string().c_str()); if (!res.isOK()) { error() << "Error saving history file: " << res; } @@ -865,14 +857,14 @@ int _main(int argc, char* argv[], char** envp) { std::stringstream ss; ss << "DB.prototype._defaultAuthenticationMechanism = \"" << escape(authMechanisms.get()) << "\";" << std::endl; - mongo::shell_utils::_dbConnect += ss.str(); + mongo::shell_utils::dbConnect += ss.str(); } if (const auto gssapiServiveName = parsedURI.getOption("gssapiServiceName")) { std::stringstream ss; ss << "DB.prototype._defaultGssapiServiceName = \"" << escape(gssapiServiveName.get()) << "\";" << std::endl; - mongo::shell_utils::_dbConnect += ss.str(); + mongo::shell_utils::dbConnect += ss.str(); } if (!shellGlobalParams.nodb) { // connect to db @@ -909,7 +901,7 @@ int _main(int argc, char* argv[], char** envp) { ss << "db = db.getMongo().startSession().getDatabase(db.getName());" << std::endl; } - mongo::shell_utils::_dbConnect += ss.str(); + mongo::shell_utils::dbConnect += ss.str(); } mongo::ScriptEngine::setConnectCallback(mongo::shell_utils::onConnect); |