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

Enable pkg.installed to detect packages by their origin name on FreeBSD #67127

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

amendlik
Copy link
Contributor

@amendlik amendlik commented Jan 3, 2025

What does this PR do?

Enable pkg.installed to detect packages by their origin name on FreeBSD

What issues does this PR fix or reference?

Fixes #67126

Previous Behavior

pkg.installed would not detect packages installed by their origin name when run in test mode

New Behavior

pkg.installed correctly detects packages installed by their origin name when run in test mode and reports no changes.

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

@amendlik amendlik requested a review from a team as a code owner January 3, 2025 17:18
cver = cur_pkgs.get(package_name, [])

# FreeBSD pkg supports `openjdk` and `java/openjdk7` package names
origin = bool(re.search('/', package_name))
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need a regex to check if a substring is in a string; it can just be has_origin = '/' in package_name. However we might want to use a regex in order to not match cases like /package_name and package_name/

origin = bool(re.search('/', package_name))

if __grains__['os'] == 'FreeBSD' and origin:
cver = [k for k, v in cur_pkgs.items() if v['origin'] == package_name]
Copy link
Contributor

Choose a reason for hiding this comment

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

There are often hundreds or thousands of packages installed on a system. If someone is attempting to install many of these packages that have a / in the name then iterating over all the packages every time (O(n*m) might not be as performant as one would desire; although it could be an acceptable since there are probably not millions or hundreds of thousands of packages.

Copy link
Contributor

Choose a reason for hiding this comment

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

It appears there is a orgins dict stored in the context (

def version(*names, **kwargs):
); perhaps that could be utilized.

@amendlik
Copy link
Contributor Author

@bdrx312 I appreciate the review and agree with your recommendations, but my approach was just to copy the pattern used elsewhere in the file to the area where it was omitted. Is that sufficient for this fix, or do we need to go back and address the original implementation?

@bdrx312
Copy link
Contributor

bdrx312 commented Jan 14, 2025

@bdrx312 I appreciate the review and agree with your recommendations, but my approach was just to copy the pattern used elsewhere in the file to the area where it was omitted. Is that sufficient for this fix, or do we need to go back and address the original implementation?

I am just a contributor that uses the tool, so I try to review pull requests when I have time and try to make improvements to the code so I don't have any authority to say whether a change is sufficient or not. With that said, since your changes seem to be the existing pattern used in other places in this file I think your change should be sufficient for a fix. Ideally someone can improve this in the future though. I would think ideally any places where there are conditional checks for the os should be contained in the os specific module like the pkgng.py for freebsd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] pkg.installed fails to detect packages by their origin name on FreeBSD
3 participants