From 4ea25c647ccde3297453d603d4e6a435e0d2bf66 Mon Sep 17 00:00:00 2001 From: as51340 Date: Fri, 24 Jul 2026 15:49:12 +0200 Subject: [PATCH] feat: Avoid checking history if --no-history arg is provided --- src/interactive.cpp | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/interactive.cpp b/src/interactive.cpp index c5d411f2..ec7737a7 100644 --- a/src/interactive.cpp +++ b/src/interactive.cpp @@ -115,27 +115,32 @@ int Run(utils::bolt::Config &bolt_config, const std::string &history, bool no_hi console::SetStdinEcho(true); } - fs::path history_dir = history; - if (history == (constants::kDefaultHistoryBaseDir + "/" + constants::kDefaultHistoryMemgraphDir)) { - // Fetch home dir for user. - history_dir = utils::GetUserHomeDir() / constants::kDefaultHistoryMemgraphDir; - } - if (!utils::EnsureDir(history_dir)) { - console::EchoFailure("History directory doesn't exist", history_dir.string()); - // Should program exit here or just continue with warning message? - cleanup_resources(); - return 1; - } - fs::path history_file = history_dir / constants::kHistoryFilename; - // Read history file. - if (fs::exists(history_file)) { - auto ret = replxx_history_load(replxx_instance, history_file.string().c_str()); - if (ret != 0) { - console::EchoFailure("Unable to read history file", history_file.string()); + // When history is disabled, skip touching the filesystem entirely: don't + // resolve/create the history directory and don't read the history file. + fs::path history_file; + if (!no_history) { + fs::path history_dir = history; + if (history == (constants::kDefaultHistoryBaseDir + "/" + constants::kDefaultHistoryMemgraphDir)) { + // Fetch home dir for user. + history_dir = utils::GetUserHomeDir() / constants::kDefaultHistoryMemgraphDir; + } + if (!utils::EnsureDir(history_dir)) { + console::EchoFailure("History directory doesn't exist", history_dir.string()); // Should program exit here or just continue with warning message? cleanup_resources(); return 1; } + history_file = history_dir / constants::kHistoryFilename; + // Read history file. + if (fs::exists(history_file)) { + auto ret = replxx_history_load(replxx_instance, history_file.string().c_str()); + if (ret != 0) { + console::EchoFailure("Unable to read history file", history_file.string()); + // Should program exit here or just continue with warning message? + cleanup_resources(); + return 1; + } + } } // Save history function. Used to save replxx history after each query.