feat: Add trans_add_pkg_by_name and trans_remove_pkg_by_name #63
+94
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These convenience methods perform database lookups internally, avoiding borrow checker conflicts when holding
&Packagereferences across transaction operations liketrans_prepare().trans_remove_pkg_by_namelooks up package in localdb;trans_add_pkg_by_namesearches all registered sync databases.For extra context, I was working on adding orphan cleanup features to cockpit-pacman and notice that when removing packages, the typical pattern hits a borrow checker conflict like e.g.:
The
&Packagereferences borrow from the handle, preventingtrans_prepare(&mut self). Users must work around this by collecting package names as owned strings first.These new methods encapsulate the lookup, so no
&Packageescapes:I thought it would make sense to upstream this, maybe. Looking forward to hearing your thoughts.