Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute remove action before install actions #3424

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 23 additions & 45 deletions libmamba/src/core/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,59 +398,37 @@ namespace mamba

TransactionRollback rollback;

const auto execute_action = [&](const auto& act)
const auto link = [&](const specs::PackageInfo& pkg)
{
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>)
if (is_sig_interrupted())
{
Console::stream() << "Linking " << act.install.str();
link(act.install);
return util::LoopControl::Break;
}
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;
};

for (const auto& action : m_solution.actions)
const auto unlink = [&](const specs::PackageInfo& pkg)
{
if (is_sig_interrupted())
{
break;
return util::LoopControl::Break;
}
std::visit(execute_action, action);
}
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())
{
Expand Down
Loading