Fix: prevent Console from reinstantiate itself while being destroyed.

This commit is contained in:
Joël Lamotte (Klaim) 2022-05-06 12:46:46 +02:00
parent 35276cee6f
commit f3da147cd1
13 changed files with 26 additions and 28 deletions

View File

@ -109,9 +109,7 @@ namespace mamba
Console& operator=(Console&&) = delete;
static Console& instance();
static ConsoleStream stream();
static void print(const std::string_view& str, bool force_print = false);
static bool prompt(const std::string_view& message, char fallback = '_');
static bool prompt(const std::string_view& message,
char fallback,
@ -126,6 +124,7 @@ namespace mamba
static std::string hide_secrets(const std::string_view& str);
void print(const std::string_view& str, bool force_print = false);
void json_write(const nlohmann::json& j);
void json_append(const std::string& value);
void json_append(const nlohmann::json& j);

View File

@ -199,7 +199,7 @@ namespace mamba
auto to_be_removed = collect_tarballs();
if (!ctx.dry_run)
{
Console::print("Cleaning tarballs..");
Console::instance().print("Cleaning tarballs..");
if (to_be_removed.size() == 0)
{
@ -277,7 +277,7 @@ namespace mamba
auto to_be_removed = collect_package_folders();
if (!ctx.dry_run)
{
Console::print("Cleaning packages..");
Console::instance().print("Cleaning packages..");
if (to_be_removed.size() == 0)
{

View File

@ -1657,7 +1657,7 @@ namespace mamba
CONFIG_DEBUGGING;
if (at("show_banner").value<bool>())
Console::print(banner());
Console::instance().print(banner());
auto& ctx = Context::instance();
ctx.set_log_level(ctx.logging_level);

View File

@ -340,7 +340,7 @@ namespace mamba
}
else
{
Console::print("Nothing to do.");
Console::instance().print("Nothing to do.");
}
config.operation_teardown();
@ -458,7 +458,7 @@ namespace mamba
std::vector<std::string> pinned_str;
for (auto& ms : solver.pinned_specs())
pinned_str.push_back(" - " + ms.conda_build_form() + "\n");
Console::print("\nPinned packages:\n" + join("", pinned_str));
Console::instance().print("\nPinned packages:\n" + join("", pinned_str));
}
bool success = solver.solve();
@ -471,7 +471,7 @@ namespace mamba
return install_specs(specs, create_env, solver_flag, is_retry | RETRY_SOLVE_ERROR);
}
if (freeze_installed)
Console::print("Possible hints:\n - 'freeze_installed' is turned on\n");
Console::instance().print("Possible hints:\n - 'freeze_installed' is turned on\n");
if (ctx.json)
{
@ -567,7 +567,7 @@ namespace mamba
{
detail::create_target_directory(prefix);
Console::print(join(
Console::instance().print(join(
"", std::vector<std::string>({ "Empty environment created at prefix: ", prefix })));
Console::instance().json_write({ { "success", true } });
}

View File

@ -55,7 +55,7 @@ namespace mamba
}
else
{
Console::print("Nothing to do.");
Console::instance().print("Nothing to do.");
}
config.operation_teardown();

View File

@ -105,7 +105,7 @@ namespace mamba
std::vector<std::string> pinned_str;
for (auto& ms : solver.pinned_specs())
pinned_str.push_back(" - " + ms.conda_build_form() + "\n");
Console::print("\nPinned packages:\n" + join("", pinned_str));
Console::instance().print("\nPinned packages:\n" + join("", pinned_str));
}
solver.solve();

View File

@ -912,7 +912,7 @@ namespace mamba
if (is_sig_interrupted())
{
Console::print("Download interrupted");
Console::instance().print("Download interrupted");
curl_multi_cleanup(m_handle);
return false;
}

View File

@ -437,7 +437,7 @@ namespace mamba
}
else
{
Console::print(msg);
Console::instance().print(msg);
}
if (ec)

View File

@ -314,12 +314,11 @@ namespace mamba
{
if (force_print || !(Context::instance().quiet || Context::instance().json))
{
auto& data = instance().p_data;
const std::lock_guard<std::mutex> lock(data->m_mutex);
const std::lock_guard<std::mutex> lock(p_data->m_mutex);
if (data->p_progress_bar_manager && data->p_progress_bar_manager->started())
if (p_data->p_progress_bar_manager && p_data->p_progress_bar_manager->started())
{
data->m_buffer.push_back(hide_secrets(str));
p_data->m_buffer.push_back(hide_secrets(str));
}
else
{
@ -384,7 +383,7 @@ namespace mamba
if (response.compare("no") == 0 || response.compare("No") == 0
|| response.compare("n") == 0 || response.compare("N") == 0)
{
Console::print("Aborted.");
Console::instance().print("Aborted.");
return false;
}
}

View File

@ -1289,7 +1289,7 @@ namespace mamba
if (Context::instance().json)
return;
Console::print("Transaction\n");
Console::instance().print("Transaction\n");
Console::stream() << " Prefix: " << Context::instance().target_prefix.string() << "\n";
// check size of transaction
@ -1297,18 +1297,18 @@ namespace mamba
{
if (m_history_entry.update.size())
{
Console::print(" All requested packages already installed\n");
Console::instance().print(" All requested packages already installed\n");
}
else
{
Console::print(" Nothing to do\n");
Console::instance().print(" Nothing to do\n");
}
return;
}
if (m_history_entry.update.size())
{
Console::print(" Updating specs:\n");
Console::instance().print(" Updating specs:\n");
for (auto& s : m_history_entry.update)
{
Console::stream() << " - " << s;
@ -1317,7 +1317,7 @@ namespace mamba
if (m_history_entry.remove.size())
{
Console::print(" Removing specs:\n");
Console::instance().print(" Removing specs:\n");
for (auto& s : m_history_entry.remove)
{
Console::stream() << " - " << s;
@ -1326,7 +1326,7 @@ namespace mamba
Console::stream() << "\n";
if (m_history_entry.update.empty() && m_history_entry.remove.empty())
{
Console::print(" No specs added or removed.\n");
Console::instance().print(" No specs added or removed.\n");
}
printers::Table t({ "Package", "Version", "Build", "Channel", "Size" });

View File

@ -39,7 +39,7 @@ main(int argc, char** argv)
if (app.get_subcommands().size() == 0)
{
Configuration::instance().load();
Console::print(app.help());
Console::instance().print(app.help());
}
return 0;

View File

@ -81,13 +81,13 @@ main(int argc, char** argv)
if (app.get_subcommands().size() == 0)
{
Configuration::instance().load();
Console::print(app.help());
Console::instance().print(app.help());
}
if (app.got_subcommand("config")
&& app.get_subcommand("config")->get_subcommands().size() == 0)
{
Configuration::instance().load();
Console::print(app.get_subcommand("config")->help());
Console::instance().print(app.get_subcommand("config")->help());
}
}
catch (const std::exception& e)

View File

@ -302,7 +302,7 @@ set_ps_command(CLI::App* subcom)
}
if (procs.empty())
{
Console::print("Did not find any matching process.");
Console::instance().print("Did not find any matching process.");
return -1;
}
return 0;