Just validate command is in PATH; forking a shell is wasteful
authorMark Felder <feld@feld.me>
Thu, 14 Jan 2021 22:58:18 +0000 (16:58 -0600)
committerMark Felder <feld@feld.me>
Thu, 14 Jan 2021 23:19:02 +0000 (17:19 -0600)
lib/pleroma/utils.ex

index fa75a8c9930426ae7f5473d7dc3c0ce0b2f3db9f..fae7657d9714fafa6ae23d9715c6e399a121f3bd 100644 (file)
@@ -30,7 +30,10 @@ defmodule Pleroma.Utils do
   """
   @spec command_available?(String.t()) :: boolean()
   def command_available?(command) do
-    match?({_output, 0}, System.cmd("sh", ["-c", "command -v #{command}"]))
+    case :os.find_executable(String.to_charlist(command)) do
+      false -> false
+      _ -> true
+    end
   end
 
   @doc "creates the uniq temporary directory"