"""
@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
|> 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
defp version(version) do
identifier_filter = ~r/[^0-9a-z\-]+/i
- {_cmdgit, cmdgit_err} = System.cmd("sh", ["-c", "command -v git"])
+ git_available? = Pleroma.Utils.command_available?("git")
git_pre_release =
- if cmdgit_err == 0 do
+ if git_available? do
{tag, tag_err} =
System.cmd("git", ["describe", "--tags", "--abbrev=0"], stderr_to_stdout: true)
# Branch name as pre-release version component, denoted with a dot
branch_name =
- with 0 <- cmdgit_err,
+ with true <- git_available?,
{branch_name, 0} <- System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"]),
branch_name <- String.trim(branch_name),
branch_name <- System.get_env("PLEROMA_BUILD_BRANCH") || branch_name,
alias Pleroma.Upload.Filter
test "apply exiftool filter" do
+ assert Pleroma.Utils.command_available?("exiftool")
+
File.cp!(
"test/fixtures/DSCN0010.jpg",
"test/fixtures/DSCN0010_tmp.jpg"