Execute remove action before install actions (#3424)

This commit is contained in:
Sylvain Corlay 2024-08-31 00:30:24 +02:00 committed by GitHub
parent 3bc31adbf0
commit d51cd0e451
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 27 additions and 49 deletions

View File

@ -398,59 +398,37 @@ namespace mamba
TransactionRollback rollback;
const auto execute_action = [&](const auto& act)
{
using Action = std::decay_t<decltype(act)>;
const auto link = [&](const specs::PackageInfo& pkg)
{
const fs::u8path cache_path(m_multi_cache.get_extracted_dir_path(pkg, false));
LinkPackage lp(pkg, cache_path, &m_transaction_context);
lp.execute();
rollback.record(lp);
m_history_entry.link_dists.push_back(pkg.long_str());
};
const auto unlink = [&](const specs::PackageInfo& pkg)
{
const fs::u8path cache_path(m_multi_cache.get_extracted_dir_path(pkg));
UnlinkPackage up(pkg, cache_path, &m_transaction_context);
up.execute();
rollback.record(up);
m_history_entry.unlink_dists.push_back(pkg.long_str());
};
if constexpr (std::is_same_v<Action, Solution::Reinstall>)
{
Console::stream() << "Reinstalling " << act.what.str();
unlink(act.what);
link(act.what);
}
else if constexpr (Solution::has_remove_v<Action> && Solution::has_install_v<Action>)
{
Console::stream() << "Changing " << act.remove.str() << " ==> " << act.install.str();
unlink(act.remove);
link(act.install);
}
else if constexpr (Solution::has_remove_v<Action>)
{
Console::stream() << "Unlinking " << act.remove.str();
unlink(act.remove);
}
else if constexpr (Solution::has_install_v<Action>)
{
Console::stream() << "Linking " << act.install.str();
link(act.install);
}
};
for (const auto& action : m_solution.actions)
const auto link = [&](const specs::PackageInfo& pkg)
{
if (is_sig_interrupted())
{
break;
return util::LoopControl::Break;
}
std::visit(execute_action, action);
}
Console::stream() << "Linking " << pkg.str();
const fs::u8path cache_path(m_multi_cache.get_extracted_dir_path(pkg, false));
LinkPackage lp(pkg, cache_path, &m_transaction_context);
lp.execute();
rollback.record(lp);
m_history_entry.link_dists.push_back(pkg.long_str());
return util::LoopControl::Continue;
};
const auto unlink = [&](const specs::PackageInfo& pkg)
{
if (is_sig_interrupted())
{
return util::LoopControl::Break;
}
Console::stream() << "Unlinking " << pkg.str();
const fs::u8path cache_path(m_multi_cache.get_extracted_dir_path(pkg));
UnlinkPackage up(pkg, cache_path, &m_transaction_context);
up.execute();
rollback.record(up);
m_history_entry.unlink_dists.push_back(pkg.long_str());
return util::LoopControl::Continue;
};
for_each_to_remove(m_solution.actions, unlink);
for_each_to_install(m_solution.actions, link);
if (is_sig_interrupted())
{