diff options
author | lain <lain@soykaf.club> | 2020-09-23 10:49:29 +0000 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-09-23 10:49:29 +0000 |
commit | a5e1c400e49e7979e70f2c9dd4887ae144dca44c (patch) | |
tree | 559fe96b7f65cd750a4bab5e9a117c43829c800f /lib/pleroma/utils.ex | |
parent | 34235bc02a88718b1d5a9d7fa2437784b91bb692 (diff) | |
parent | a6c14041c49df0dc850204723cfc1f242ded8aa2 (diff) | |
download | pleroma-a5e1c400e49e7979e70f2c9dd4887ae144dca44c.tar.gz |
Merge branch 'issue/1975' into 'develop'
[#1975] import emoji from a zip archive
Closes admin-fe#130
See merge request pleroma/pleroma!2911
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 |