Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass delete on skipped versions #286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions lib/arc/actions/delete.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Arc.Actions.Delete do
defmacro __using__(_) do
quote do
def delete(args), do: Arc.Actions.Delete.delete(__MODULE__, args)

defoverridable [{:delete, 1}]
end
end
Expand Down Expand Up @@ -40,6 +40,11 @@ defmodule Arc.Actions.Delete do
end

defp delete_version(definition, version, {file, scope}) do
definition.__storage.delete(definition, version, {file, scope})
conversion = definition.transform(version, {file, scope})
if conversion == :skip do
:ok
else
definition.__storage.delete(definition, version, {file, scope})
end
end
end
9 changes: 6 additions & 3 deletions test/storage/local_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ defmodule ArcTest.Storage.Local do


defmodule DummyDefinition do
use Arc.Actions.Store
use Arc.Definition.Storage
use Arc.Actions.Url
use Arc.Definition

@acl :public_read
def transform(:thumb, _), do: {:convert, "-strip -thumbnail 10x10"}
Expand Down Expand Up @@ -44,6 +42,11 @@ defmodule ArcTest.Storage.Local do
refute File.exists?("arctest/uploads/1/thumb-image.png")
end

test "deleting when there's a skipped version" do
DummyDefinition.store(@img)
assert :ok = DummyDefinition.delete(@img)
end

test "save binary" do
Arc.Storage.Local.put(DummyDefinition, :original, {Arc.File.new(%{binary: "binary", filename: "binary.png"}), nil})
assert true == File.exists?("arctest/uploads/binary.png")
Expand Down