Skip to content

Commit

Permalink
Warn if fetching registry without outer checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmj committed Feb 4, 2020
1 parent 13de420 commit 8d3af62
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
9 changes: 9 additions & 0 deletions lib/hex/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ defmodule Hex.Repo do
else
case :mix_hex_registry.decode_package(body, repo, package) do
{:ok, releases} ->
outer_checksum? = Enum.all?(releases, &Map.has_key?(&1, :outer_checksum))

if not outer_checksum? and Hex.Server.should_warn_registry_version?() do
Hex.Shell.warn(
"Fetched old registry record version from repo #{repo}. The" <>
"repository you are using should update to include the new :outer_checksum field"
)
end

releases

{:error, :unverified} ->
Expand Down
23 changes: 19 additions & 4 deletions lib/hex/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ defmodule Hex.Server do
GenServer.call(@name, :should_warn_lock_version?)
end

def should_warn_registry_version?() do
GenServer.call(@name, :should_warn_registry_version?)
end

def init([]) do
{:ok, state()}
end
Expand All @@ -26,15 +30,26 @@ defmodule Hex.Server do
{:reply, :ok, state()}
end

def handle_call(:should_warn_lock_version?, _from, %{warned_tuple_size: false} = state) do
{:reply, true, %{state | warned_tuple_size: true}}
def handle_call(:should_warn_lock_version?, _from, %{warned_lock_version: false} = state) do
{:reply, true, %{state | warned_lock_version: true}}
end

def handle_call(:should_warn_lock_version?, _from, %{warned_lock_version: true} = state) do
{:reply, false, state}
end

def handle_call(:should_warn_registry_version?, _from, %{warned_registry_size: false} = state) do
{:reply, true, %{state | warned_registry_size: true}}
end

def handle_call(:should_warn_lock_version?, _from, %{warned_tuple_size: true} = state) do
def handle_call(:should_warn_registry_version?, _from, %{warned_registry_size: true} = state) do
{:reply, false, state}
end

defp state() do
%{warned_tuple_size: false}
%{
warned_lock_version: false,
warned_registry_version: false
}
end
end

0 comments on commit 8d3af62

Please sign in to comment.