diff --git a/README.md b/README.md index d06533c..c344e17 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ following Mix config: ```elixir config :briefly, directory: [{:system, "TMPDIR"}, {:system, "TMP"}, {:system, "TEMP"}, "/tmp"], + sub_directory_prefix: "briefly", default_prefix: "briefly", default_extname: "" ``` diff --git a/lib/briefly/config.ex b/lib/briefly/config.ex index 7b7d0d2..3724e37 100644 --- a/lib/briefly/config.ex +++ b/lib/briefly/config.ex @@ -3,6 +3,8 @@ defmodule Briefly.Config do def directory, do: get(:directory) + def sub_directory_prefix, do: get(:sub_directory_prefix) + def default_prefix, do: get(:default_prefix) def default_extname, do: get(:default_extname) diff --git a/lib/briefly/entry.ex b/lib/briefly/entry.ex index 211d717..8b27e86 100644 --- a/lib/briefly/entry.ex +++ b/lib/briefly/entry.ex @@ -18,9 +18,10 @@ defmodule Briefly.Entry do def init(_init_arg) do tmp = Briefly.Config.directory() + sub = Briefly.Config.sub_directory_prefix() cwd = Path.join(File.cwd!(), "tmp") ets = :ets.new(:briefly, [:private]) - {:ok, {[tmp, cwd], ets}} + {:ok, {[tmp, cwd, sub], ets}} end def handle_call({:create, opts}, {caller_pid, _ref}, {tmps, ets} = state) do @@ -68,8 +69,9 @@ defmodule Briefly.Entry do defp ensure_tmp_dir(tmps) do {mega, _, _} = :os.timestamp() - subdir = "briefly-" <> i(mega) - Enum.find_value(tmps, &write_tmp_dir(&1 <> subdir)) + [_tmp, _cwd, sub] = tmps + subdir = "#{sub}-#{mega}" + Enum.find_value(tmps, &write_tmp_dir(Path.join(&1, subdir))) end defp write_tmp_dir(path) do @@ -110,9 +112,6 @@ defmodule Briefly.Entry do {:too_many_attempts, tmp, attempts} end - @compile {:inline, i: 1} - defp i(integer), do: Integer.to_string(integer) - defp path(options, tmp) do time = :erlang.monotonic_time() |> to_string |> String.trim("-") diff --git a/mix.exs b/mix.exs index 6cfbdf7..6279ca9 100644 --- a/mix.exs +++ b/mix.exs @@ -49,6 +49,7 @@ defmodule Briefly.Mixfile do defp default_env do [ directory: [{:system, "TMPDIR"}, {:system, "TMP"}, {:system, "TEMP"}, "/tmp"], + sub_directory_prefix: "briefly", default_prefix: "briefly", default_extname: "" ]