diff options
author | Roman Chvanikov <chvanikoff@pm.me> | 2020-07-11 15:48:45 +0300 |
---|---|---|
committer | Roman Chvanikov <chvanikoff@pm.me> | 2020-07-11 15:48:45 +0300 |
commit | aedbbec88aa0a9a38e588eabfbecb8058652002b (patch) | |
tree | b3203d2efedaf60e199040ae70d7be1212fba763 /lib | |
parent | 11dd29ef3f9bb5b0b3109eb572c3d5ae2c830ea3 (diff) | |
download | pleroma-aedbbec88aa0a9a38e588eabfbecb8058652002b.tar.gz |
Add Pleroma.Utils.command_available?/1 and use where appropriate
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/upload/filter/exiftool.ex | 9 | ||||
-rw-r--r-- | lib/pleroma/utils.ex | 15 |
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/pleroma/upload/filter/exiftool.ex b/lib/pleroma/upload/filter/exiftool.ex index c7fb6aefa..94622acd0 100644 --- a/lib/pleroma/upload/filter/exiftool.ex +++ b/lib/pleroma/upload/filter/exiftool.ex @@ -9,8 +9,15 @@ defmodule Pleroma.Upload.Filter.Exiftool do """ @behaviour Pleroma.Upload.Filter + require Logger + def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do - System.cmd("exiftool", ["-overwrite_original", "-gps:all=", file], parallelism: true) + if Pleroma.Utils.command_available?("exiftool") do + System.cmd("exiftool", ["-overwrite_original", "-gps:all=", file], parallelism: true) + else + Logger.warn("exiftool is not available, filter #{__MODULE__} skipped") + end + :ok end diff --git a/lib/pleroma/utils.ex b/lib/pleroma/utils.ex index 6b8e3accf..21d1159be 100644 --- a/lib/pleroma/utils.ex +++ b/lib/pleroma/utils.ex @@ -9,4 +9,19 @@ defmodule Pleroma.Utils do |> Enum.map(&Path.join(dir, &1)) |> Kernel.ParallelCompiler.compile() end + + @doc """ + POSIX-compliant check if command is available in the system + + ## Examples + iex> command_available?("git") + true + iex> command_available?("wrongcmd") + false + + """ + @spec command_available?(String.t()) :: boolean() + def command_available?(command) do + match?({_output, 0}, System.cmd("sh", ["-c", "command -v #{command}"])) + end end |