Emoji.Pack: Implement empty name and directory creation failure handling
This commit is contained in:
parent
4eeb9c1f2d
commit
80e0f07240
1 changed files with 9 additions and 1 deletions
|
|
@ -230,15 +230,23 @@ defmodule Pleroma.Emoji.Pack do
|
||||||
:ok <- validate_new_pack(name),
|
:ok <- validate_new_pack(name),
|
||||||
{:ok, archive_data} <- fetch_archive_data(opts),
|
{:ok, archive_data} <- fetch_archive_data(opts),
|
||||||
pack_path <- path_join_name_safe(emoji_path(), name),
|
pack_path <- path_join_name_safe(emoji_path(), name),
|
||||||
:ok <- File.mkdir_p(pack_path),
|
:ok <- create_pack_dir(pack_path),
|
||||||
:ok <- safe_unzip(archive_data, pack_path) do
|
:ok <- safe_unzip(archive_data, pack_path) do
|
||||||
ensure_pack_json(pack_path, archive_data, opts)
|
ensure_pack_json(pack_path, archive_data, opts)
|
||||||
else
|
else
|
||||||
|
{:error, :empty_values} -> {:error, "Pack name cannot be empty"}
|
||||||
{:error, reason} when is_binary(reason) -> {:error, reason}
|
{:error, reason} when is_binary(reason) -> {:error, reason}
|
||||||
_ -> {:error, "Could not process pack"}
|
_ -> {:error, "Could not process pack"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp create_pack_dir(pack_path) do
|
||||||
|
case File.mkdir_p(pack_path) do
|
||||||
|
:ok -> :ok
|
||||||
|
{:error, _} -> {:error, "Could not create the pack directory"}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp safe_unzip(archive_data, pack_path) do
|
defp safe_unzip(archive_data, pack_path) do
|
||||||
case SafeZip.unzip_data(archive_data, pack_path) do
|
case SafeZip.unzip_data(archive_data, pack_path) do
|
||||||
{:ok, _} -> :ok
|
{:ok, _} -> :ok
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue