Skip to content

Commit

Permalink
Limit search pattern for remove command
Browse files Browse the repository at this point in the history
It prevents additional removal after succesful remove using the same spec.
Spec `foo`. The original code during the first run removes (dnf5 remove foo)
all packages with the name `foo`. In the next run (dnf5 remove foo) it
removes all packages providing `foo`. The next run will remove packages
providing binary `foo`. This behavior is inconsistent.

Resolves: https://issues.redhat.com/browse/RHEL-5747
  • Loading branch information
j-mracek committed Jan 4, 2024
1 parent 8a797b9 commit 55b0c1a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion dnf5/commands/remove/remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,16 @@ void RemoveCommand::configure() {

void RemoveCommand::run() {
auto goal = get_context().get_goal();

// Limit remove spec capabity to prevent multiple matches. Remove command should not match anything after performing
// a remove action with the same spec. NEVRA and filenames are the only types that have no overlaps.
libdnf5::GoalJobSettings settings;
settings.with_nevra = true;
settings.with_provides = false;
settings.with_filenames = true;
settings.with_binaries = false;
for (const auto & spec : pkg_specs) {
goal->add_remove(spec);
goal->add_remove(spec, settings);
}
// To enable removal of dependency packages it requires to use allow_erasing
goal->set_allow_erasing(true);
Expand Down
7 changes: 7 additions & 0 deletions dnf5daemon-server/services/rpm/rpm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,14 @@ sdbus::MethodReply Rpm::remove(sdbus::MethodCall & call) {

// fill the goal
auto & goal = session.get_goal();

// Limit remove spec capabity to prevent multiple matches. Remove command should not match anything after performing
// a remove action with the same spec. NEVRA and filenames are the only types that have no overlaps.
libdnf5::GoalJobSettings setting;
setting.with_nevra = true;
setting.with_provides = false;
setting.with_filenames = true;
setting.with_binaries = false;
for (const auto & spec : specs) {
goal.add_remove(spec, setting);
}
Expand Down

0 comments on commit 55b0c1a

Please sign in to comment.