summaryrefslogtreecommitdiff
path: root/lib/pleroma/utils.ex
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2020-11-12 12:34:48 +0000
committerrinpatch <rinpatch@sdf.org>2020-11-12 12:34:48 +0000
commit1172844ed18d94d84724dc6f11c6e9f72e0ba6ec (patch)
tree7d48a259e08856ab6db0eba255f20c0c19410463 /lib/pleroma/utils.ex
parenta0f5e8b27edbe2224d9c2c3997ad5b8ea484244b (diff)
parentb4c6b262d6dc12362f0014a864e8aed6c727c39c (diff)
Merge branch 'release/2.2.0' into 'stable'v2.2.0
Release/2.2.0 See merge request pleroma/secteam/pleroma!19
Diffstat (limited to 'lib/pleroma/utils.ex')
-rw-r--r--lib/pleroma/utils.ex20
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