diff options
author | Mark Felder <feld@FreeBSD.org> | 2020-10-09 11:26:10 -0500 |
---|---|---|
committer | Mark Felder <feld@FreeBSD.org> | 2020-10-09 11:26:10 -0500 |
commit | 04b514c567aa664d2606313d17be69e665a7f1af (patch) | |
tree | 13f46fd39d8a90837b031b1081b7e20696d6823a /lib/pleroma/utils.ex | |
parent | 55562ca9362d66553ea3638c91174bbeb6c637f1 (diff) | |
parent | d239bd3ca4348d38c12ab54c7e2e9cb2b825cc3c (diff) | |
download | pleroma-04b514c567aa664d2606313d17be69e665a7f1af.tar.gz |
Merge branch 'develop' into feature/gen-magic
Diffstat (limited to 'lib/pleroma/utils.ex')
-rw-r--r-- | lib/pleroma/utils.ex | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/pleroma/utils.ex b/lib/pleroma/utils.ex index 21d1159be..e95766223 100644 --- a/lib/pleroma/utils.ex +++ b/lib/pleroma/utils.ex @@ -24,4 +24,24 @@ defmodule Pleroma.Utils do def command_available?(command) do match?({_output, 0}, System.cmd("sh", ["-c", "command -v #{command}"])) end + + @doc "creates the uniq temporary directory" + @spec tmp_dir(String.t()) :: {:ok, String.t()} | {:error, :file.posix()} + def tmp_dir(prefix \\ "") do + sub_dir = + [ + prefix, + Timex.to_unix(Timex.now()), + :os.getpid(), + String.downcase(Integer.to_string(:rand.uniform(0x100000000), 36)) + ] + |> Enum.join("-") + + tmp_dir = Path.join(System.tmp_dir!(), sub_dir) + + case File.mkdir(tmp_dir) do + :ok -> {:ok, tmp_dir} + error -> error + end + end end |