X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=inline;f=lib%2Fpleroma%2Futils.ex;h=bc0c953322338b347316b5414f4d3f36b78cfffb;hb=49741961f234816c1fff278adca397e9ff7cabe7;hp=e95766223d86e9965fbcfdc9f5595e98a5505461;hpb=436d1a3c41fc92183efffb81cc041ca270025d02;p=akkoma
diff --git a/lib/pleroma/utils.ex b/lib/pleroma/utils.ex
index e95766223..bc0c95332 100644
--- a/lib/pleroma/utils.ex
+++ b/lib/pleroma/utils.ex
@@ -1,8 +1,16 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Utils do
+ @posix_error_codes ~w(
+ eacces eagain ebadf ebadmsg ebusy edeadlk edeadlock edquot eexist efault
+ efbig eftype eintr einval eio eisdir eloop emfile emlink emultihop
+ enametoolong enfile enobufs enodev enolck enolink enoent enomem enospc
+ enosr enostr enosys enotblk enotdir enotsup enxio eopnotsupp eoverflow
+ eperm epipe erange erofs espipe esrch estale etxtbsy exdev
+ )a
+
def compile_dir(dir) when is_binary(dir) do
dir
|> File.ls!()
@@ -22,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"
@@ -44,4 +55,12 @@ defmodule Pleroma.Utils do
error -> error
end
end
+
+ @spec posix_error_message(atom()) :: binary()
+ def posix_error_message(code) when code in @posix_error_codes do
+ error_message = Gettext.dgettext(Pleroma.Web.Gettext, "posix_errors", "#{code}")
+ "(POSIX error: #{error_message})"
+ end
+
+ def posix_error_message(_), do: ""
end