Skip to content

Commit

Permalink
Small libsolv improvments and make static keys a member (#2399)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv authored Mar 29, 2023
1 parent 967ca0b commit 1d7fb17
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
4 changes: 4 additions & 0 deletions libmamba/include/mamba/core/repo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ namespace mamba

MRepo(MPool& pool, const std::string& name, const std::vector<PackageInfo>& uris);

void init(MPool& pool);

bool read_file(const fs::u8path& filename);

fs::u8path m_json_file, m_solv_file;
Expand All @@ -146,6 +148,8 @@ namespace mamba
RepoMetadata m_metadata;

Repo* m_repo;
::Id m_real_repo_key = 0;
::Id m_noarch_repo_key = 0;
const Channel* p_channel = nullptr;
};

Expand Down
50 changes: 28 additions & 22 deletions libmamba/src/core/repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <solv/repo.h>
#include <solv/repo_solv.h>
#include <solv/repo_write.h>
#include <solv/solvable.h>
extern "C" // Incomplete header
{
#include <solv/conda.h>
Expand Down Expand Up @@ -44,28 +45,28 @@ namespace mamba
const RepoMetadata& metadata,
const Channel& channel
)
: m_metadata(metadata)
: m_url(rsplit(metadata.url, "/", 1)[0])
, m_metadata(metadata)
{
m_url = rsplit(metadata.url, "/", 1)[0];
m_repo = repo_create(pool, m_url.c_str());
m_repo->appdata = this;
init(pool);
read_file(index);
p_channel = &channel;
}

MRepo::MRepo(MPool& pool, const std::string& name, const std::string& index, const std::string& url)
: m_url(url)
, m_repo(repo_create(pool, name.c_str()))
{
m_repo = repo_create(pool, name.c_str());
m_repo->appdata = this;
read_file(index);
p_channel = &ChannelBuilder::make_cached_channel(url);
p_channel = &ChannelBuilder::make_cached_channel(m_url);
init(pool);
}

MRepo::MRepo(MPool& pool, const std::string& name, const std::vector<PackageInfo>& package_infos)
: m_repo(repo_create(pool, name.c_str()))
{
m_repo = repo_create(pool, name.c_str());
m_repo->appdata = this;
init(pool);
int flags = 0;
Repodata* data;
data = repo_add_repodata(m_repo, flags);
Expand All @@ -77,9 +78,9 @@ namespace mamba
}

MRepo::MRepo(MPool& pool, const PrefixData& prefix_data)
: m_repo(repo_create(pool, "installed"))
{
m_repo = repo_create(pool, "installed");
m_repo->appdata = this;
init(pool);
int flags = 0;
Repodata* data;
data = repo_add_repodata(m_repo, flags);
Expand All @@ -98,6 +99,13 @@ namespace mamba
set_installed();
}

void MRepo::init(MPool& pool)
{
m_repo->appdata = this;
m_real_repo_key = pool_str2id(pool, "solvable:real_repo_url", 1);
m_noarch_repo_key = pool_str2id(pool, "solvable:noarch_type", 1);
}

MRepo::~MRepo()
{
if (m_repo)
Expand Down Expand Up @@ -154,27 +162,25 @@ namespace mamba
LOG_INFO << "Adding package record to repo " << info.name;
Pool* pool = m_repo->pool;

static Id real_repo_key = pool_str2id(pool, "solvable:real_repo_url", 1);
static Id noarch_repo_key = pool_str2id(pool, "solvable:noarch_type", 1);

Id handle = repo_add_solvable(m_repo);
Solvable* s = pool_id2solvable(pool, handle);
repodata_set_str(data, handle, SOLVABLE_BUILDVERSION, std::to_string(info.build_number).c_str());
repodata_add_poolstr_array(data, handle, SOLVABLE_BUILDFLAVOR, info.build_string.c_str());
s->name = pool_str2id(pool, info.name.c_str(), 1);
s->evr = pool_str2id(pool, info.version.c_str(), 1);
repodata_set_num(data, handle, SOLVABLE_DOWNLOADSIZE, info.size);
solvable_set_str(s, SOLVABLE_BUILDVERSION, std::to_string(info.build_number).c_str());
solvable_add_poolstr_array(s, SOLVABLE_BUILDFLAVOR, info.build_string.c_str());
solvable_set_str(s, SOLVABLE_NAME, info.name.c_str());
solvable_set_str(s, SOLVABLE_EVR, info.version.c_str());
solvable_set_num(s, SOLVABLE_DOWNLOADSIZE, info.size);
// No ``solvable_xxx`` equivalent
repodata_set_checksum(data, handle, SOLVABLE_PKGID, REPOKEY_TYPE_MD5, info.md5.c_str());

solvable_set_str(s, real_repo_key, info.url.c_str());
solvable_set_str(s, m_real_repo_key, info.url.c_str());

if (!info.noarch.empty())
{
solvable_set_str(s, noarch_repo_key, info.noarch.c_str());
solvable_set_str(s, m_noarch_repo_key, info.noarch.c_str());
}

// No ``solvable_xxx`` equivalent
repodata_set_location(data, handle, 0, info.subdir.c_str(), info.fn.c_str());

repodata_set_checksum(data, handle, SOLVABLE_CHECKSUM, REPOKEY_TYPE_SHA256, info.sha256.c_str());

if (!info.depends.empty())
Expand All @@ -196,7 +202,7 @@ namespace mamba
Id constrains_id = pool_conda_matchspec(pool, cst.c_str());
if (constrains_id)
{
repodata_add_idarray(data, handle, SOLVABLE_CONSTRAINS, constrains_id);
solvable_add_idarray(s, SOLVABLE_CONSTRAINS, constrains_id);
}
}
}
Expand Down

0 comments on commit 1d7fb17

Please sign in to comment.