From 2e7b0ac87536f081ed9252fa47435555ff91574b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ram=C3=B3n=20S=C3=A1nchez=20Morales?= Date: Tue, 27 Jun 2023 19:58:53 +0200 Subject: [PATCH] fix(mac_brew_pkg): avoid using cmd.run on 'None' executable path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Sindicate fetching os brew path for use also on __virtual__ method without running an extra command at this moment Signed-off-by: Antonio Ramón Sánchez Morales --- salt/modules/mac_brew_pkg.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/salt/modules/mac_brew_pkg.py b/salt/modules/mac_brew_pkg.py index dd45b4ab8cf..b90791c5dd0 100644 --- a/salt/modules/mac_brew_pkg.py +++ b/salt/modules/mac_brew_pkg.py @@ -31,7 +31,7 @@ def __virtual__(): """ if __grains__["os"] != "MacOS": return False, "brew module is macos specific" - if not _homebrew_bin(): + if not _homebrew_os_bin(): return False, "The 'brew' binary was not found" return __virtualname__ @@ -93,16 +93,26 @@ def _tap(tap, runas=None): return True +def _homebrew_os_bin(): + """ + Fetch PATH binary brew full path eg: /usr/local/bin/brew (symbolic link) + """ + return salt.utils.path.which("brew") + + def _homebrew_bin(): """ - Returns the full path to the homebrew binary in the PATH + Returns the full path to the homebrew binary in the homebrew installation folder """ - # Fetch PATH binary brew full path eg: /usr/local/bin/brew (symbolic link) - brew = salt.utils.path.which("brew") - # Fetch and ret brew installation folder full path eg: /opt/homebrew/bin/brew - ret = __salt__["cmd.run"](f"{brew} --prefix", output_loglevel="trace") - ret += "/bin/brew" - return ret + brew = _homebrew_os_bin() + if not brew: + # Return None in case we don't have brew installed, so we prevent calling cmd.run for 'None' executable path + return None + else: + # Fetch and ret brew installation folder full path eg: /opt/homebrew/bin/brew + ret = __salt__["cmd.run"](f"{brew} --prefix", output_loglevel="trace") + ret += "/bin/brew" + return ret def _call_brew(*cmd, failhard=True):