in include/poac/subcmd/uninstall.hpp [58:113]
void create_uninstall_list(
InputIterator first,
InputIterator last,
std::string_view target_name,
Backtracked& uninstall_list)
{
namespace cli = io::cli;
// 同じ名前で複数のバージョンは存在しないことが,
// resolved_deps = lock_to_resolved(*locked_deps);
// と,
// const resolver::Deps deps = _install::resolve_packages(deps_node);
// resolved_deps = resolver::resolve(deps);
// の両方で保証されているため,同一の名前を検索するだけでパッケージを一意に特定できる.(versionの比較が不要)
const auto target = std::find_if(first, last, [&](auto x){ return x.name == target_name; });
if (target == last) { // 同じパッケージ名を二つ以上いれた
return;
}
// 他に依存されているパッケージは削除しない
if (!target->deps.empty()) {
for (auto itr = first; itr != last; ++itr) {
// uninstall_listに入ってない
const auto found1 = std::find_if(uninstall_list.begin(), uninstall_list.end(),
[&](auto x){ return x.first == itr->name; });
// targetのdepsに入っていない
const auto found2 = std::find_if(target->deps.begin(), target->deps.end(),
[&](auto x) { return x.name == itr->name; });
if (found1 == uninstall_list.end() && found2 == target->deps.end()) {
for (const auto& deps : itr->deps) {
// 他のパッケージに依存されている
if (target->name == deps.name) {
const auto warn = deps.name + ": " + deps.version +
" can not be deleted because " +
itr->name + ": " + itr->version +
" depends on it";
cli::echo(cli::to_warning(warn));
return;
}
}
}
}
}
// 循環していないかチェック
const auto cycle_check = std::find_if(uninstall_list.begin(), uninstall_list.end(),
[&](auto x){ return x.first == target->name; });
if (cycle_check == uninstall_list.end()) {
// ここまでたどり着いたなら,他に依存されていないということなので,削除リストに加える
uninstall_list[target->name] = { {target->version}, {target->source} };
// さらにそれの依存も,削除リストに加える
for (const auto& td : target->deps) {
create_uninstall_list(first, last, td.name, uninstall_list);
}
}
}