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

RepoSack: New API to reload system repo #1702

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion include/libdnf5/repo/repo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,16 @@ class LIBDNF_API Repo {
friend class PackageDownloader;
friend class solv::Pool;

/// Loads the repository objects into sacks.
/// Loads the repository objects into sacks. Only the first call actually loads the repo.
///
/// Also writes the libsolv's solv/solvx cache files.
LIBDNF_LOCAL void load();

/// Empties currently loaded repo and loads it again.
LIBDNF_LOCAL void reload();

LIBDNF_LOCAL void _load();

/// Downloads repository metadata.
// @replaces libdnf:repo/Repo.hpp:method:Repo.downloadMetadata(const std::string & destdir)
LIBDNF_LOCAL void download_metadata(const std::string & destdir);
Expand Down
3 changes: 3 additions & 0 deletions include/libdnf5/repo/repo_sack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class LIBDNF_API RepoSack : public sack::Sack<Repo> {
/// @return The system repository.
libdnf5::repo::RepoWeakPtr get_system_repo();

/// Reloads the system repository. If the system repository has not been created yet, it will create and load it.
void reload_system_repo();

/// Add given paths to comdline repository.
/// @param paths Vector of paths to rpm files to be inserted to cmdline repo. Can contain paths to local files or URLs of remote rpm files. Specifications that are neither file paths, nor URLs are ignored.
/// @param calculate_checksum Whether libsolv should calculate and store checksum of added packages. Setting to true significantly reduces performance.
Expand Down
22 changes: 16 additions & 6 deletions libdnf5/repo/repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,7 @@ void Repo::download_metadata(const std::string & destdir) {
p_impl->downloader->download_metadata(destdir);
}

void Repo::load() {
// Each repository can only be loaded once. This one has already loaded, so just return instantly
if (is_loaded()) {
return;
}

void Repo::_load() {
make_solv_repo();

if (p_impl->type == Type::AVAILABLE) {
Expand All @@ -234,6 +229,21 @@ void Repo::load() {
p_impl->base->get_rpm_package_sack()->p_impl->invalidate_provides();
}

void Repo::load() {
// Each repository can only be loaded once. This one has already loaded, so just return instantly
if (is_loaded()) {
return;
}
_load();
}

void Repo::reload() {
if (p_impl->solv_repo) {
p_impl->solv_repo->empty();
}
_load();
}

void Repo::add_libsolv_testcase(const std::string & path) {
make_solv_repo();

Expand Down
4 changes: 4 additions & 0 deletions libdnf5/repo/repo_sack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ RepoWeakPtr RepoSack::get_system_repo() {
return p_impl->system_repo->get_weak_ptr();
}

void RepoSack::reload_system_repo() {
get_system_repo()->reload();
}

/**
*
* @param repos Set of repositories to load
Expand Down
5 changes: 5 additions & 0 deletions libdnf5/repo/solv_repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,4 +792,9 @@ void SolvRepo::create_environment_solvable(
repodata_internalize(data);
}

void SolvRepo::empty() {
// TODO(mblaha): is resuseid=true safe enough?
Copy link
Contributor

@jrohel jrohel Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code from libsolv:

  if (reuseids && repo->end == pool->nsolvables)
    {
      /* it's ok to reuse the ids. As this is the last repo, we can
         just shrink the solvable array */

It looks like reuseids works only when the repo is last. DNF places the system repo first. Behind it are available repos. The system repo is last only if it is the only one (we don't have available repos loaded).

Note:
OK. Maybe after the first reload the system repository will be the last one.

repo_empty(repo, true);
}

} // namespace libdnf5::repo
4 changes: 4 additions & 0 deletions libdnf5/repo/solv_repo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ class SolvRepo {
/// @return True if the group was successfully read.
bool read_group_solvable_from_xml(const std::string & path);

/// Free all solvables in the repository. The repository will be empty
/// after this call.
void empty();

private:
// "type_name == nullptr" means load "primary" cache (.solv file)
bool load_solv_cache(solv::Pool & pool, const char * type_name, int flags);
Expand Down
Loading