Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/waffle/definition/storage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ defmodule Waffle.Definition.Storage do
This code would authenticate request only for specific domain. Otherwise, it would send
empty request headers.

## Temporary Directory

When processing files, Waffle creates temporary files for operations like downloading
remote files or applying transformations. By default, these files are stored in the
system's temporary directory (as returned by `System.tmp_dir/0`).

You can customize this location by setting the `:tmp_dir` configuration option:

config :waffle,
tmp_dir: "/path/to/custom/tmp"

Waffle may fail to remove temporary files if the process using them crashes.

"""
defmacro __using__(_) do
quote do
Expand Down
9 changes: 8 additions & 1 deletion lib/waffle/file.ex
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ defmodule Waffle.File do
|> Base.encode32()
|> Kernel.<>(string_extension)

Path.join(System.tmp_dir(), file_name)
Path.join(tmp_dir(), file_name)
end

defp tmp_dir do
case Application.get_env(:waffle, :tmp_dir) do
nil -> System.tmp_dir()
value -> value
end
end

defp write_binary(file) do
Expand Down
22 changes: 22 additions & 0 deletions test/file_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule WaffleTest.File do
use ExUnit.Case, async: false

@custom_tmp_dir System.tmp_dir() <> "/waffle_test_custom"

describe "generate_temporary_path/1" do
test "uses configured tmp_dir" do
File.mkdir_p!(@custom_tmp_dir)
Application.put_env(:waffle, :tmp_dir, @custom_tmp_dir)

assert Waffle.File.generate_temporary_path() |> String.starts_with?(@custom_tmp_dir)
on_exit fn ->
Application.delete_env(:waffle, :tmp_dir)
File.rm_rf!(@custom_tmp_dir)
end
end

test "uses system tmp_dir" do
assert Waffle.File.generate_temporary_path() |> String.starts_with?(System.tmp_dir())
end
end
end