mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 05:37:59 +01:00
Fix Dialyzer (#265)
* Fix post-Elixir 1.16 divergence in File.stream! * Add exclusion for PhilomenaWeb.Config compile-time variance * Add missing Autocomplete.t
This commit is contained in:
parent
9d20b9c465
commit
80f9fa9352
3 changed files with 25 additions and 3 deletions
|
@ -2,6 +2,8 @@ defmodule Philomena.Autocomplete.Autocomplete do
|
|||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
@type t :: %__MODULE__{}
|
||||
|
||||
@primary_key false
|
||||
schema "autocomplete" do
|
||||
field :content, :binary
|
||||
|
|
|
@ -1,11 +1,27 @@
|
|||
defmodule Philomena.Sha512 do
|
||||
@spec file(String.t()) :: String.t()
|
||||
def file(file) do
|
||||
@chunk_size 10_485_760
|
||||
|
||||
@spec file(Path.t()) :: String.t()
|
||||
def file(path) do
|
||||
hash_ref = :crypto.hash_init(:sha512)
|
||||
|
||||
File.stream!(file, [], 10_485_760)
|
||||
path
|
||||
|> stream_file()
|
||||
|> Enum.reduce(hash_ref, &:crypto.hash_update(&2, &1))
|
||||
|> :crypto.hash_final()
|
||||
|> Base.encode16(case: :lower)
|
||||
end
|
||||
|
||||
if Version.match?(System.version(), ">= 1.16.0") do
|
||||
# `stream!/2` was added in Elixir 1.16 to accept a shortened form,
|
||||
# where we only need to specify the size of each stream chunk
|
||||
defp stream_file(file) do
|
||||
File.stream!(file, @chunk_size)
|
||||
end
|
||||
else
|
||||
# Use legacy stream/3 for older Elixir versions
|
||||
defp stream_file(file) do
|
||||
File.stream!(file, [], @chunk_size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
defmodule PhilomenaWeb.Config do
|
||||
# Dialyzer only analyzes beam files directly and cannot see the compile-time variance in
|
||||
# the associated values, so it flags a false positive here.
|
||||
@dialyzer [:no_match]
|
||||
|
||||
@reload_enabled Application.compile_env(:philomena, :vite_reload, false)
|
||||
@csp_relaxed Application.compile_env(:philomena, :csp_relaxed, false)
|
||||
|
||||
|
|
Loading…
Reference in a new issue