Skip to content

Commit

Permalink
Fix :ets.foldl/3 usage on Plug.Upload.terminate/2, add test for it (#582
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cles authored and josevalim committed Jul 29, 2017
1 parent 1a10f7a commit 9c06cad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/plug/upload.ex
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ defmodule Plug.Upload do
end

def terminate(_reason, _state) do
:ets.foldl(@table, :ok, fn {_pid, _tmp, paths} ->
:ets.foldl(fn({_pid, _tmp, paths}, _) ->
delete_paths(paths)
end)
end, :ok, @table)
:ok
end

Expand Down
6 changes: 6 additions & 0 deletions test/plug/upload_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ defmodule Plug.UploadTest do
refute File.exists?(path)
end
end

test "terminate removes all files" do
{:ok, path} = Plug.Upload.random_file("sample")
:ok = Plug.Upload.terminate(:shutdown, [])
refute File.exists?(path)
end
end

0 comments on commit 9c06cad

Please sign in to comment.