Skip to content

Commit

Permalink
Remove fake_signatures in favor of optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Hind-M committed Mar 8, 2024
1 parent a41a387 commit c3c9785
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 37 deletions.
52 changes: 16 additions & 36 deletions libmamba/src/solver/libsolv/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,38 +147,32 @@ namespace mamba::solver::libsolv
return util::lstrip_if_parts(tail, [&](char c) { return !is_sep(c); });
}

void
get_fake_signatures(simdjson::dom::parser& fake_parser, simdjson::dom::object& fake_signatures)
{
// Getting a fake simdjson::dom::object to simulate empty signatures
// A valid empty simdjson::dom::object is not handled in simdjson
const auto fake_signatures_json = R"( { "fake_signatures": "val" } )"_padded;
fake_signatures = fake_parser.parse(fake_signatures_json).get_object().value();
}

void set_solv_signatures(
solv::ObjSolvableView solv,
const std::string& filename,
const simdjson::dom::object& signatures
const std::optional<simdjson::dom::object>& signatures
)
{
// NOTE We need to use an intermediate nlohmann::json object to store signatures
// as simdjson objects are not conceived to be modified smoothly
// and we need an equivalent structure to how libsolv is storing the signatures
nlohmann::json glob_sigs, nested_sigs;
if (auto sigs = signatures[filename].get_object(); !sigs.error())
if (signatures)
{
for (auto dict : sigs)
if (auto sigs = signatures.value()[filename].get_object(); !sigs.error())
{
for (auto nested_dict : dict.value.get_object())
for (auto dict : sigs)
{
nested_sigs[dict.key]["signature"] = nested_dict.value;
}
glob_sigs["signatures"] = nested_sigs;
for (auto nested_dict : dict.value.get_object())
{
nested_sigs[dict.key]["signature"] = nested_dict.value;
}
glob_sigs["signatures"] = nested_sigs;

solv.set_signatures(glob_sigs.dump());
LOG_INFO << "Signatures for '" << filename
<< "' are set in corresponding solvable.";
solv.set_signatures(glob_sigs.dump());
LOG_INFO << "Signatures for '" << filename
<< "' are set in corresponding solvable.";
}
}
}
else
Expand All @@ -196,7 +190,7 @@ namespace mamba::solver::libsolv
solv::ObjSolvableView solv,
const std::string& filename,
const simdjson::dom::element& pkg,
const simdjson::dom::object& signatures,
const std::optional<simdjson::dom::object>& signatures,
const std::string& default_subdir
) -> bool
{
Expand Down Expand Up @@ -372,7 +366,7 @@ namespace mamba::solver::libsolv
const std::string& channel_id,
const std::string& default_subdir,
const simdjson::dom::object& packages,
const simdjson::dom::object& signatures
const std::optional<simdjson::dom::object>& signatures
)
{
std::string filename = {};
Expand Down Expand Up @@ -429,21 +423,7 @@ namespace mamba::solver::libsolv
}
else
{
// NOTE We need to create a fake signatures json doc to get a valid
// simdjson::dom::object (otherwise we get a segfault because constructor yields to
// an invalid simdjson::dom::object)
simdjson::dom::parser fake_parser;
simdjson::dom::object fake_signatures;
get_fake_signatures(fake_parser, fake_signatures);
set_repo_solvables(
pool,
repo,
parsed_url,
channel_id,
default_subdir,
packages,
fake_signatures
);
set_repo_solvables(pool, repo, parsed_url, channel_id, default_subdir, packages, std::nullopt);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/specs/package_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ namespace mamba::specs
{
j["sha256"] = pkg.sha256;
}
if (!pkg.signatures.empty())
if (!pkg.signatures.empty())
{
j["signatures"] = pkg.signatures;
}
Expand Down

0 comments on commit c3c9785

Please sign in to comment.