Safe id2pkginfo

This commit is contained in:
AntoinePrv 2022-07-26 10:11:36 +02:00
parent 13a6a4c086
commit cabd3bf640
3 changed files with 16 additions and 4 deletions

View File

@ -8,7 +8,9 @@
#define MAMBA_CORE_POOL_HPP #define MAMBA_CORE_POOL_HPP
#include <list> #include <list>
#include <optional>
#include "repo.hpp" #include "repo.hpp"
#include "package_info.hpp"
extern "C" extern "C"
{ {
@ -39,6 +41,8 @@ namespace mamba
std::vector<Id> select_solvables(Id id); std::vector<Id> select_solvables(Id id);
Id matchspec2id(const std::string& ms); Id matchspec2id(const std::string& ms);
std::optional<PackageInfo> id2pkginfo(Id id);
operator Pool*(); operator Pool*();
MRepo& add_repo(MRepo&& repo); MRepo& add_repo(MRepo&& repo);

View File

@ -98,6 +98,15 @@ namespace mamba
return id; return id;
} }
std::optional<PackageInfo> MPool::id2pkginfo(Id id)
{
if (id == 0 || id >= m_pool->nsolvables)
{
return std::nullopt;
}
return pool_id2solvable(m_pool, id);
}
MRepo& MPool::add_repo(MRepo&& repo) MRepo& MPool::add_repo(MRepo&& repo)
{ {
m_repo_list.push_back(std::move(repo)); m_repo_list.push_back(std::move(repo));

View File

@ -67,10 +67,9 @@ PYBIND11_MODULE(bindings, m)
.def(py::init<>()) .def(py::init<>())
.def("set_debuglevel", &MPool::set_debuglevel) .def("set_debuglevel", &MPool::set_debuglevel)
.def("create_whatprovides", &MPool::create_whatprovides) .def("create_whatprovides", &MPool::create_whatprovides)
.def("select_solvables", &MPool::select_solvables) .def("select_solvables", &MPool::select_solvables, py::arg("id"))
.def("matchspec2id", &MPool::matchspec2id) .def("matchspec2id", &MPool::matchspec2id, py::arg("ms"))
.def("id2pkginfo", .def("id2pkginfo", &MPool::id2pkginfo, py::arg("id"));
[](MPool& self, Id id) { return PackageInfo(pool_id2solvable(self, id)); });
py::class_<MultiPackageCache>(m, "MultiPackageCache") py::class_<MultiPackageCache>(m, "MultiPackageCache")
.def(py::init<std::vector<fs::path>>()) .def(py::init<std::vector<fs::path>>())