Add Pleroma.Utils.command_available?/1 and use where appropriate
This commit is contained in:
parent
11dd29ef3f
commit
aedbbec88a
4 changed files with 28 additions and 4 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue