Skip to content

Commit 8c3f302

Browse files
committed
First release: finish testing and fix bugs
1 parent 969775b commit 8c3f302

File tree

7 files changed

+330
-56
lines changed

7 files changed

+330
-56
lines changed

lib/file_cache.ex

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defmodule FileCache do
1414
alias FileCache.Utils
1515
alias FileCache.Config
1616

17-
namespace_single_type = {:or, [{:in, [nil, :host]}, {:fun, 0}, :mfa]}
17+
namespace_single_type = {:or, [{:in, [nil, :host]}, :string, {:fun, 0}, :mfa]}
1818
namespace_type = {:or, [namespace_single_type, {:list, namespace_single_type}]}
1919

2020
@init_options_schema NimbleOptions.new!(
@@ -99,10 +99,6 @@ defmodule FileCache do
9999
ttl: [
100100
type: :pos_integer
101101
]
102-
# TODO: do we need it? what's the usecase?
103-
# owner: [
104-
# type: :pid
105-
# ]
106102
)
107103

108104
defp validate_op_options!(opts) do

lib/file_cache/cleaner.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ defmodule FileCache.Cleaner do
1313
@optional_callbacks name: 1
1414

1515
defmacro __using__(opts) do
16-
kind = opts[:kind]
16+
kind = Keyword.fetch!(opts, :kind)
1717

1818
quote do
1919
use GenServer

lib/file_cache/common.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ defmodule FileCache.Common do
66
alias FileCache.Config
77
alias FileCache.Utils
88

9-
def calculate_namespace(nil), do: ""
10-
11-
def calculate_namespace(many) when is_list(many) do
12-
many
13-
|> Enum.map(&do_calculate_namespace/1)
9+
def calculate_namespace(namespace) do
10+
namespace
11+
|> List.wrap()
12+
|> Enum.map(fn part -> validate_namespace_part(do_calculate_namespace(part)) end)
13+
|> List.insert_at(0, "")
1414
|> Path.join()
1515
end
1616

17-
def calculate_namespace(other), do: do_calculate_namespace(other)
17+
defp do_calculate_namespace(str) when is_binary(str), do: str
1818

1919
defp do_calculate_namespace(:host) do
2020
{:ok, host} = :inet.gethostname()
21-
host
21+
IO.chardata_to_string(host)
2222
end
2323

2424
defp do_calculate_namespace({m, f, a}), do: apply(m, f, a)

lib/file_cache/stale_cleaner.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule FileCache.StaleCleaner do
22
@moduledoc false
33

4-
use FileCache.Cleaner
4+
use FileCache.Cleaner, kind: :stale
55

66
alias FileCache.Config
77
alias FileCache.Perm

lib/file_cache/temp.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule FileCache.Temp do
1616
owner = Access.get(opts, :owner, self())
1717

1818
filename =
19-
"#{filename_prefix()}#{@sep}#{Utils.pid_to_string(owner)}#{@sep}#{:erlang.unique_integer()}_#{id}"
19+
"#{filename_prefix()}#{@sep}#{Utils.pid_to_string(owner)}#{@sep}#{:erlang.unique_integer()}#{@sep}#{id}"
2020

2121
Path.join(full_dir_path(cache_name), filename)
2222
end
@@ -76,7 +76,7 @@ defmodule FileCache.Temp do
7676
end
7777

7878
defp parse_pid(pid_str) do
79-
:erlang.list_to_pid('<#{pid_str}>')
79+
{:ok, :erlang.list_to_pid('<#{pid_str}>')}
8080
rescue
8181
ArgumentError ->
8282
{:error, :bad_pid}

0 commit comments

Comments
 (0)