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

macOS: Fix issue when Homebrew casks's tap is null #62793

Merged
merged 8 commits into from
Oct 3, 2022

Conversation

cdalvaro
Copy link
Contributor

@cdalvaro cdalvaro commented Oct 1, 2022

This PR fixes an issue when the tap from a Homebrew cask is null.

This can happen when the cask source is: homebrew/cask. For other official formulae, such as fonts, the tap field is filled with homebrew/cask-fonts, for example.

We append the tap value to the package name when full name and short name of a package are the same. We do this for backward compatibility with formulas that install packages as: homebre/cask/firefox.

A typical response from the brew interface is:

brew info --json=v2 --installed | jq '.casks | map(select(.token == "firefox"))'
[
  {
    "token": "firefox",
    "full_token": "firefox",
    "tap": null,
    "name": [
      "Mozilla Firefox"
    ],
    "desc": "Web browser",
    "homepage": "https://www.mozilla.org/firefox/",
    "url": "https://download-installer.cdn.mozilla.net/pub/firefox/releases/105.0.1/mac/en-US/Firefox%20105.0.1.dmg",
    "appcast": null,
    # More stuffs
  }
]

This PR also recovers some tests that were tabulated so they weren't executed.

Related issue: #59439

Previous Behavior

Before this patch, salt fails to check wether a homebrew cask has been installed with the following error:

    Function: pkg.installed
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/opt/homebrew/Cellar/salt/3005_1/libexec/lib/python3.10/site-packages/salt/state.py", line 2276, in call
                  ret = self.states[cdata["full"]](
                File "/opt/homebrew/Cellar/salt/3005_1/libexec/lib/python3.10/site-packages/salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/opt/homebrew/Cellar/salt/3005_1/libexec/lib/python3.10/site-packages/salt/loader/lazy.py", line 1228, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/opt/homebrew/Cellar/salt/3005_1/libexec/lib/python3.10/site-packages/salt/loader/lazy.py", line 1243, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/opt/homebrew/Cellar/salt/3005_1/libexec/lib/python3.10/site-packages/salt/loader/lazy.py", line 1276, in wrapper
                  return f(*args, **kwargs)
                File "/opt/homebrew/Cellar/salt/3005_1/libexec/lib/python3.10/site-packages/salt/states/pkg.py", line 1698, in installed
                  result = _find_install_targets(
                File "/opt/homebrew/Cellar/salt/3005_1/libexec/lib/python3.10/site-packages/salt/states/pkg.py", line 567, in _find_install_targets
                  cur_pkgs = __salt__["pkg.list_pkgs"](versions_as_list=True, **kwargs)
                File "/opt/homebrew/Cellar/salt/3005_1/libexec/lib/python3.10/site-packages/salt/loader/lazy.py", line 149, in __call__
                  return self.loader.run(run_func, *args, **kwargs)
                File "/opt/homebrew/Cellar/salt/3005_1/libexec/lib/python3.10/site-packages/salt/loader/lazy.py", line 1228, in run
                  return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                File "/opt/homebrew/Cellar/salt/3005_1/libexec/lib/python3.10/site-packages/salt/loader/lazy.py", line 1243, in _run_as
                  return _func_or_method(*args, **kwargs)
                File "/var/cache/salt/minion/extmods/modules/mac_brew_pkg.py", line 188, in list_pkgs
                  names.add("/".join([package["tap"], package["token"]]))
              TypeError: sequence item 0: expected str instance, NoneType found
     Started: 15:27:09.666115
    Duration: 4169.847 ms
     Changes:

New Behavior

With the patch applied, packages are successfully installed.

Merge requirements satisfied?

Commits signed with GPG?

Yes

@cdalvaro cdalvaro requested a review from a team as a code owner October 1, 2022 14:31
@cdalvaro cdalvaro requested review from whytewolf and removed request for a team October 1, 2022 14:31
@cdalvaro cdalvaro force-pushed the bugfix/mac_brew_pkg_null_taps branch from 3a76111 to 6ba4ab7 Compare October 2, 2022 10:39
@Ch3LL Ch3LL merged commit 96902c3 into saltstack:master Oct 3, 2022
@cdalvaro cdalvaro changed the title macOS: Fix issue when Homebrew casks's tap ir null macOS: Fix issue when Homebrew casks's tap is null Oct 4, 2022
@cdalvaro cdalvaro deleted the bugfix/mac_brew_pkg_null_taps branch October 4, 2022 05:24
@cdalvaro
Copy link
Contributor Author

cdalvaro commented Oct 4, 2022

Thank you, @Ch3LL!

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.

2 participants