emoji api error on not writable dir
authorAlexander Strizhakov <alex.strizhakov@gmail.com>
Wed, 29 Jan 2020 10:51:17 +0000 (13:51 +0300)
committerAlexander Strizhakov <alex.strizhakov@gmail.com>
Wed, 29 Jan 2020 12:31:34 +0000 (15:31 +0300)
lib/pleroma/web/pleroma_api/controllers/emoji_api_controller.ex
test/web/pleroma_api/controllers/emoji_api_controller_test.exs

index 0bbf84fd3706d2dc9c904af8a0ae86afc5442eda..42f62d97a1ee3d511148a32434cd1790e00e8210 100644 (file)
@@ -573,11 +573,14 @@ keeping it in cache for #{div(cache_ms, 1000)}s")
   assumed to be emojis and stored in the new `pack.json` file.
   """
   def import_from_fs(conn, _params) do
-    with {:ok, results} <- File.ls(emoji_dir_path()) do
+    emoji_path = emoji_dir_path()
+
+    with {:ok, %{access: :read_write}} <- File.stat(emoji_path),
+         {:ok, results} <- File.ls(emoji_path) do
       imported_pack_names =
         results
         |> Enum.filter(fn file ->
-          dir_path = Path.join(emoji_dir_path(), file)
+          dir_path = Path.join(emoji_path, file)
           # Find the directories that do NOT have pack.json
           File.dir?(dir_path) and not File.exists?(Path.join(dir_path, "pack.json"))
         end)
@@ -585,6 +588,11 @@ keeping it in cache for #{div(cache_ms, 1000)}s")
 
       json(conn, imported_pack_names)
     else
+      {:ok, %{access: _}} ->
+        conn
+        |> put_status(:internal_server_error)
+        |> json(%{error: "Error emoji pack directory must be writable and readable"})
+
       {:error, _} ->
         conn
         |> put_status(:internal_server_error)
index 8e76f2f3dbc5cff90a3102b2ee11136b57ba1218..6f1ea78eced1631c1f74be53ab6ad5950fb799d1 100644 (file)
@@ -6,7 +6,6 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
   use Pleroma.Web.ConnCase
 
   import Tesla.Mock
-
   import Pleroma.Factory
 
   @emoji_dir_path Path.join(