Skip to content

Commit

Permalink
add: config sub_directory
Browse files Browse the repository at this point in the history
  • Loading branch information
mad42 committed Jun 9, 2021
1 parent 25942fb commit 14c6479
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ following Mix config:
```elixir
config :briefly,
directory: [{:system, "TMPDIR"}, {:system, "TMP"}, {:system, "TEMP"}, "/tmp"],
sub_directory: "briefly",
default_prefix: "briefly",
default_extname: ""
```
Expand Down
2 changes: 2 additions & 0 deletions lib/briefly/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule Briefly.Config do

def directory, do: get(:directory)

def sub_directory, do: get(:sub_directory)

def default_prefix, do: get(:default_prefix)

def default_extname, do: get(:default_extname)
Expand Down
6 changes: 4 additions & 2 deletions lib/briefly/entry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ defmodule Briefly.Entry do

def init(_init_arg) do
tmp = Briefly.Config.directory()
sub = Briefly.Config.sub_directory()
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
Expand Down Expand Up @@ -68,7 +69,8 @@ defmodule Briefly.Entry do

defp ensure_tmp_dir(tmps) do
{mega, _, _} = :os.timestamp()
subdir = "briefly-" <> i(mega)
[_tmp, _cwd, sub] = tmps
subdir = sub <> "-" <> i(mega)
Enum.find_value(tmps, &write_tmp_dir(&1 <> subdir))
end

Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ defmodule Briefly.Mixfile do
defp default_env do
[
directory: [{:system, "TMPDIR"}, {:system, "TMP"}, {:system, "TEMP"}, "/tmp"],
sub_directory: "briefly",
default_prefix: "briefly",
default_extname: ""
]
Expand Down

0 comments on commit 14c6479

Please sign in to comment.