Various refactoring and typespec improvements

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-09-24 16:46:42 +02:00
parent d235653876
commit 1893d9f55b
142 changed files with 1854 additions and 1297 deletions

View File

@@ -21,8 +21,8 @@ defmodule Mobilizon.Web.Upload.Uploader.Local do
@impl true
@spec put_file(Upload.t()) ::
:ok | {:ok, {:file, String.t()}} | {:error, :tempfile_no_longer_exists}
def put_file(%Upload{path: path, tempfile: tempfile}) do
{path, file} = local_path(path)
def put_file(%Upload{path: initial_path, tempfile: tempfile}) do
{path, file} = local_path(initial_path)
result_file = Path.join(path, file)
if File.exists?(result_file) do
@@ -31,23 +31,11 @@ defmodule Mobilizon.Web.Upload.Uploader.Local do
else
if File.exists?(tempfile) do
File.cp!(tempfile, result_file)
{:ok, {:file, result_file}}
{:ok, {:file, initial_path}}
else
{:error, :tempfile_no_longer_exists}
end
end
with {:result_exists, false} <- {:result_exists, File.exists?(result_file)},
{:temp_file_exists, true} <- {:temp_file_exists, File.exists?(tempfile)} do
File.cp!(tempfile, result_file)
else
{:result_exists, _} ->
# If the resulting file already exists, it's because of the Dedupe filter
:ok
{:temp_file_exists, _} ->
{:error, "Temporary file no longer exists"}
end
end
@impl true