Browse Source

Merge pull request #2421 from starbelly/update-hex-core-to-v0-7-0

Re-vendor hex_core in at 0.7.0
pull/2431/head
Fred Hebert 4 years ago
committed by GitHub
parent
commit
f9885c98d5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 165 additions and 62 deletions
  1. +12
    -4
      bootstrap
  2. +0
    -3
      src/r3_hex_core.hrl
  3. +1
    -1
      src/vendored/r3_hex_api.erl
  4. +1
    -1
      src/vendored/r3_hex_api_key.erl
  5. +1
    -1
      src/vendored/r3_hex_api_package.erl
  6. +1
    -1
      src/vendored/r3_hex_api_package_owner.erl
  7. +42
    -5
      src/vendored/r3_hex_api_release.erl
  8. +1
    -1
      src/vendored/r3_hex_api_user.erl
  9. +7
    -3
      src/vendored/r3_hex_core.erl
  10. +3
    -0
      src/vendored/r3_hex_core.hrl
  11. +13
    -3
      src/vendored/r3_hex_erl_tar.erl
  12. +1
    -1
      src/vendored/r3_hex_erl_tar.hrl
  13. +1
    -1
      src/vendored/r3_hex_filename.erl
  14. +1
    -1
      src/vendored/r3_hex_http.erl
  15. +2
    -3
      src/vendored/r3_hex_http_httpc.erl
  16. +1
    -1
      src/vendored/r3_hex_pb_names.erl
  17. +1
    -1
      src/vendored/r3_hex_pb_package.erl
  18. +1
    -1
      src/vendored/r3_hex_pb_signed.erl
  19. +1
    -1
      src/vendored/r3_hex_pb_versions.erl
  20. +1
    -1
      src/vendored/r3_hex_registry.erl
  21. +1
    -1
      src/vendored/r3_hex_repo.erl
  22. +70
    -25
      src/vendored/r3_hex_tarball.erl
  23. +1
    -1
      src/vendored/r3_safe_erl_term.xrl
  24. +1
    -1
      vendor_hex_core.sh

+ 12
- 4
bootstrap View File

@ -26,10 +26,10 @@ main(_) ->
rm_rf("_build/default/lib/rebar"), rm_rf("_build/default/lib/rebar"),
rm_rf("_build/test/lib/rebar"), rm_rf("_build/test/lib/rebar"),
%% We fetch a few deps from hex for boostraping,
%% so we must compile r3_safe_erl_term.xrl which
%% is part of hex_core.
compile_xrl_file("src/r3_safe_erl_term.xrl"),
filelib:ensure_dir("_build/bootstrap/lib/rebar/ebin/"),
os:putenv("REBAR_PROFILE", "bootstrap"),
compile_vendored(),
%% Fetch and build deps required to build rebar3 %% Fetch and build deps required to build rebar3
BaseDeps = [{providers, []} BaseDeps = [{providers, []}
@ -176,6 +176,14 @@ maybe_set_ipfamily({ok, _}, Family) ->
maybe_set_ipfamily(_, _Family) -> maybe_set_ipfamily(_, _Family) ->
ok. ok.
compile_vendored() ->
compile_xrl_file("src/vendored/r3_safe_erl_term.xrl"),
Sources = filelib:wildcard(filename:join(["src/vendored", "*.erl"])),
OutDir = filename:absname("_build/bootstrap/lib/rebar/ebin"),
code:add_patha(OutDir),
Opts = [debug_info,{outdir, OutDir}, return | additional_defines()],
[compile_erl_file(X, Opts) || X <- Sources].
compile(App, FirstFiles) -> compile(App, FirstFiles) ->
Dir = filename:join(filename:absname("_build/default/lib/"), App), Dir = filename:join(filename:absname("_build/default/lib/"), App),
filelib:ensure_dir(filename:join([Dir, "ebin", "dummy.beam"])), filelib:ensure_dir(filename:join([Dir, "ebin", "dummy.beam"])),

+ 0
- 3
src/r3_hex_core.hrl View File

@ -1,3 +0,0 @@
%% Vendored from hex_core v0.6.8, do not edit manually
-define(HEX_CORE_VERSION, "0.6.8").

src/r3_hex_api.erl → src/vendored/r3_hex_api.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
%% @hidden %% @hidden

src/r3_hex_api_key.erl → src/vendored/r3_hex_api_key.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
-module(r3_hex_api_key). -module(r3_hex_api_key).
-export([ -export([

src/r3_hex_api_package.erl → src/vendored/r3_hex_api_package.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
-module(r3_hex_api_package). -module(r3_hex_api_package).
-export([get/2, search/3]). -export([get/2, search/3]).

src/r3_hex_api_package_owner.erl → src/vendored/r3_hex_api_package_owner.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
-module(r3_hex_api_package_owner). -module(r3_hex_api_package_owner).
-export([ -export([

src/r3_hex_api_release.erl → src/vendored/r3_hex_api_release.erl View File

@ -1,15 +1,18 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
-module(r3_hex_api_release). -module(r3_hex_api_release).
-export([ -export([
delete/3, delete/3,
get/3, get/3,
publish/2, publish/2,
publish/3,
retire/4, retire/4,
unretire/3 unretire/3
]). ]).
-export_type([retirement_params/0, retirement_reason/0]).
-export_type([publish_params/0, retirement_params/0, retirement_reason/0]).
-type publish_params() :: [{replace, boolean()}].
-type retirement_reason() :: other | invalid | security | deprecated | renamed. -type retirement_reason() :: other | invalid | security | deprecated | renamed.
@ -74,12 +77,46 @@ get(Config, Name, Version) when is_map(Config) and is_binary(Name) and is_binary
%% ''' %% '''
%% @end %% @end
-spec publish(r3_hex_core:config(), binary()) -> r3_hex_api:response(). -spec publish(r3_hex_core:config(), binary()) -> r3_hex_api:response().
publish(Config, Tarball) when is_map(Config) and is_binary(Tarball) ->
Path = r3_hex_api:build_repository_path(Config, ["publish"]),
publish(Config, Tarball) -> publish(Config, Tarball, []).
%% @doc
%% Publishes a new package release with query parameters.
%%
%% Supported query params :
%% - replace : boolean
%%
%% Examples:
%%
%% ```
%% > r3_hex_api_release:publish(r3_hex_core:default_config(), Tarball, [{replace, true}]).
%% {ok, {201, ..., #{
%% <<"checksum">> => <<"540d210d81f56f17f64309a4896430e727972499b37bd59342dc08d61dff74d8">>,
%% <<"docs_html_url">> => <<"https://hexdocs.pm/package/1.0.0/">>,
%% <<"downloads">> => 740,<<"has_docs">> => true,
%% <<"html_url">> => <<"https://hex.pm/packages/package/1.0.0">>,
%% <<"inserted_at">> => <<"2014-12-09T18:32:03Z">>,
%% <<"meta">> =>
%% #{<<"app">> => <<"package">>,
%% <<"build_tools">> => [<<"mix">>]},
%% <<"package_url">> => <<"https://hex.pm/api/packages/package">>,
%% <<"publisher">> => nil,<<"requirements">> => #{},
%% <<"retirement">> => nil,
%% <<"updated_at">> => <<"2019-07-28T21:12:11Z">>,
%% <<"url">> => <<"https://hex.pm/api/packages/package/releases/1.0.0">>,
%% <<"version">> => <<"1.0.0">>
%% }}}
%% '''
%% @end
-spec publish(hexcore:config(), binary(), publish_params()) -> r3_hex_api:response().
publish(Config, Tarball, Params) when is_map(Config) andalso is_binary(Tarball) andalso is_list(Params)->
QueryString = r3_hex_api:encode_query_string([{replace, proplists:get_value(replace, Params, false)}]),
Path = r3_hex_api:join_path_segments(r3_hex_api:build_repository_path(Config, ["publish"])),
PathWithQuery = <<Path/binary, "?", QueryString/binary>>,
TarballContentType = "application/octet-stream", TarballContentType = "application/octet-stream",
Config2 = put_header(<<"content-length">>, integer_to_binary(byte_size(Tarball)), Config), Config2 = put_header(<<"content-length">>, integer_to_binary(byte_size(Tarball)), Config),
Body = {TarballContentType, Tarball}, Body = {TarballContentType, Tarball},
r3_hex_api:post(Config2, Path, Body).
r3_hex_api:post(Config2, PathWithQuery, Body).
%% @doc %% @doc
%% Deletes a package release. %% Deletes a package release.

src/r3_hex_api_user.erl → src/vendored/r3_hex_api_user.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
-module(r3_hex_api_user). -module(r3_hex_api_user).
-export([ -export([

src/r3_hex_core.erl → src/vendored/r3_hex_core.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
%% @doc %% @doc
%% hex_core entrypoint module. %% hex_core entrypoint module.
@ -69,7 +69,9 @@ J1i2xWFndWa6nfFnRxZmCStCOZWYYPlaxr+FZceFbpMwzTNs4g3d4tLNUcbKAIH4
repo_url => binary(), repo_url => binary(),
repo_organization => binary() | undefined, repo_organization => binary() | undefined,
repo_verify => boolean(), repo_verify => boolean(),
repo_verify_origin => boolean()
repo_verify_origin => boolean(),
tarball_max_size => pos_integer(),
tarball_max_uncompressed_size => pos_integer()
}. }.
-spec default_config() -> config(). -spec default_config() -> config().
@ -82,6 +84,7 @@ default_config() ->
http_adapter => r3_hex_http_httpc, http_adapter => r3_hex_http_httpc,
http_adapter_config => #{profile => default}, http_adapter_config => #{profile => default},
http_etag => undefined, http_etag => undefined,
http_headers => #{},
http_user_agent_fragment => <<"(httpc)">>, http_user_agent_fragment => <<"(httpc)">>,
repo_key => undefined, repo_key => undefined,
repo_name => <<"hexpm">>, repo_name => <<"hexpm">>,
@ -90,5 +93,6 @@ default_config() ->
repo_organization => undefined, repo_organization => undefined,
repo_verify => true, repo_verify => true,
repo_verify_origin => true, repo_verify_origin => true,
http_headers => #{}
tarball_max_size => 8 * 1024 * 1024,
tarball_max_uncompressed_size => 64 * 1024 * 1024
}. }.

+ 3
- 0
src/vendored/r3_hex_core.hrl View File

@ -0,0 +1,3 @@
%% Vendored from hex_core v0.7.0, do not edit manually
-define(HEX_CORE_VERSION, "0.7.0").

src/r3_hex_erl_tar.erl → src/vendored/r3_hex_erl_tar.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
%% @private %% @private
%% Copied from https://github.com/erlang/otp/blob/OTP-20.0.1/lib/stdlib/src/erl_tar.erl %% Copied from https://github.com/erlang/otp/blob/OTP-20.0.1/lib/stdlib/src/erl_tar.erl
@ -11,6 +11,7 @@
%% - Add safe_relative_path_links/2 to check directory traversal vulnerability when extracting files, %% - Add safe_relative_path_links/2 to check directory traversal vulnerability when extracting files,
%% it differs from OTP's current fix (2020-02-04) in that it checks regular files instead of %% it differs from OTP's current fix (2020-02-04) in that it checks regular files instead of
%% symlink targets. This allows creating symlinks with relative path targets such as `../tmp/log` %% symlink targets. This allows creating symlinks with relative path targets such as `../tmp/log`
%% - Remove ram_file usage (backported from OTP master)
%% %%
%% %CopyrightBegin% %% %CopyrightBegin%
@ -335,10 +336,19 @@ do_open(Name, Mode) when is_list(Mode) ->
{error, {Name, Reason}} {error, {Name, Reason}}
end. end.
open1({binary,Bin}, read, _Raw, Opts) when is_binary(Bin) ->
open1({binary,Bin0}, read, _Raw, Opts) when is_binary(Bin0) ->
Bin = case lists:member(compressed, Opts) of
true ->
try
zlib:gunzip(Bin0)
catch
_:_ -> Bin0
end;
false ->
Bin0
end,
case file:open(Bin, [ram,binary,read]) of case file:open(Bin, [ram,binary,read]) of
{ok,File} -> {ok,File} ->
_ = [ram_file:uncompress(File) || Opts =:= [compressed]],
{ok, #reader{handle=File,access=read,func=fun file_op/2}}; {ok, #reader{handle=File,access=read,func=fun file_op/2}};
Error -> Error ->
Error Error

src/r3_hex_erl_tar.hrl → src/vendored/r3_hex_erl_tar.hrl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
% Copied from https://github.com/erlang/otp/blob/OTP-20.0.1/lib/stdlib/src/erl_tar.hrl % Copied from https://github.com/erlang/otp/blob/OTP-20.0.1/lib/stdlib/src/erl_tar.hrl

src/r3_hex_filename.erl → src/vendored/r3_hex_filename.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
% @private % @private
% Excerpt from https://github.com/erlang/otp/blob/OTP-20.0.1/lib/stdlib/src/filename.erl#L761-L788 % Excerpt from https://github.com/erlang/otp/blob/OTP-20.0.1/lib/stdlib/src/filename.erl#L761-L788

src/r3_hex_http.erl → src/vendored/r3_hex_http.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
-module(r3_hex_http). -module(r3_hex_http).
-export([request/5]). -export([request/5]).

src/r3_hex_http_httpc.erl → src/vendored/r3_hex_http_httpc.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
%% @hidden %% @hidden
@ -13,8 +13,7 @@
request(Method, URI, ReqHeaders, Body, AdapterConfig) -> request(Method, URI, ReqHeaders, Body, AdapterConfig) ->
Profile = maps:get(profile, AdapterConfig, default), Profile = maps:get(profile, AdapterConfig, default),
Request = build_request(URI, ReqHeaders, Body), Request = build_request(URI, ReqHeaders, Body),
case httpc:request(Method, Request, [{ssl, rebar_utils:ssl_opts(URI)}],
[{body_format, binary}], Profile) of
case httpc:request(Method, Request, [], [{body_format, binary}], Profile) of
{ok, {{_, StatusCode, _}, RespHeaders, RespBody}} -> {ok, {{_, StatusCode, _}, RespHeaders, RespBody}} ->
RespHeaders2 = load_headers(RespHeaders), RespHeaders2 = load_headers(RespHeaders),
{ok, {StatusCode, RespHeaders2, RespBody}}; {ok, {StatusCode, RespHeaders2, RespBody}};

src/r3_hex_pb_names.erl → src/vendored/r3_hex_pb_names.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
%% -*- coding: utf-8 -*- %% -*- coding: utf-8 -*-
%% Automatically generated, do not edit %% Automatically generated, do not edit

src/r3_hex_pb_package.erl → src/vendored/r3_hex_pb_package.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
%% -*- coding: utf-8 -*- %% -*- coding: utf-8 -*-
%% Automatically generated, do not edit %% Automatically generated, do not edit

src/r3_hex_pb_signed.erl → src/vendored/r3_hex_pb_signed.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
%% -*- coding: utf-8 -*- %% -*- coding: utf-8 -*-
%% Automatically generated, do not edit %% Automatically generated, do not edit

src/r3_hex_pb_versions.erl → src/vendored/r3_hex_pb_versions.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
%% -*- coding: utf-8 -*- %% -*- coding: utf-8 -*-
%% Automatically generated, do not edit %% Automatically generated, do not edit

src/r3_hex_registry.erl → src/vendored/r3_hex_registry.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
-module(r3_hex_registry). -module(r3_hex_registry).
-export([ -export([

src/r3_hex_repo.erl → src/vendored/r3_hex_repo.erl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
-module(r3_hex_repo). -module(r3_hex_repo).
-export([ -export([

src/r3_hex_tarball.erl → src/vendored/r3_hex_tarball.erl View File

@ -1,13 +1,12 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
-module(r3_hex_tarball). -module(r3_hex_tarball).
-export([create/2, create_docs/1, unpack/2, unpack_docs/2, format_checksum/1, format_error/1]).
-export([create/2, create/3, create_docs/1, create_docs/2, unpack/2, unpack/3,
unpack_docs/2, unpack_docs/3, format_checksum/1, format_error/1]).
-ifdef(TEST). -ifdef(TEST).
-export([do_decode_metadata/1, gzip/1, normalize_requirements/1]). -export([do_decode_metadata/1, gzip/1, normalize_requirements/1]).
-endif. -endif.
-define(VERSION, <<"3">>). -define(VERSION, <<"3">>).
-define(TARBALL_MAX_SIZE, 8 * 1024 * 1024).
-define(TARBALL_MAX_UNCOMPRESSED_SIZE, 64 * 1024 * 1024).
-define(BUILD_TOOL_FILES, [ -define(BUILD_TOOL_FILES, [
{<<"mix.exs">>, <<"mix">>}, {<<"mix.exs">>, <<"mix">>},
{<<"rebar.config">>, <<"rebar3">>}, {<<"rebar.config">>, <<"rebar3">>},
@ -45,13 +44,16 @@
%% inner_checksum => <<178,12,...>>}} %% inner_checksum => <<178,12,...>>}}
%% ''' %% '''
%% @end %% @end
-spec create(metadata(), files()) -> {ok, {tarball(), checksum()}} | {error, term()}.
create(Metadata, Files) ->
-spec create(metadata(), files(), r3_hex_core:config()) -> {ok, #{tarball => tarball(), outer_checksum => checksum(),
inner_checksum => tarball()}} | {error, term()}.
create(Metadata, Files, Config) ->
MetadataBinary = encode_metadata(Metadata), MetadataBinary = encode_metadata(Metadata),
ContentsTarball = create_memory_tarball(Files), ContentsTarball = create_memory_tarball(Files),
ContentsTarballCompressed = gzip(ContentsTarball), ContentsTarballCompressed = gzip(ContentsTarball),
InnerChecksum = inner_checksum(?VERSION, MetadataBinary, ContentsTarballCompressed), InnerChecksum = inner_checksum(?VERSION, MetadataBinary, ContentsTarballCompressed),
InnerChecksumBase16 = encode_base16(InnerChecksum), InnerChecksumBase16 = encode_base16(InnerChecksum),
TarballMaxSize = maps:get(tarball_max_size, Config),
TarballMaxUncompressedSize = maps:get(tarball_max_uncompressed_size, Config),
OuterFiles = [ OuterFiles = [
{"VERSION", ?VERSION}, {"VERSION", ?VERSION},
@ -65,14 +67,22 @@ create(Metadata, Files) ->
UncompressedSize = byte_size(ContentsTarball), UncompressedSize = byte_size(ContentsTarball),
case(byte_size(Tarball) > ?TARBALL_MAX_SIZE) or (UncompressedSize > ?TARBALL_MAX_UNCOMPRESSED_SIZE) of
true ->
{error, {tarball, too_big}};
case {(byte_size(Tarball) > TarballMaxSize), (UncompressedSize > TarballMaxUncompressedSize)} of
{_, true} ->
{error, {tarball, {too_big_uncompressed, TarballMaxUncompressedSize}}};
false ->
{true, _} ->
{error, {tarball, {too_big_compressed, TarballMaxSize}}};
{false, false} ->
{ok, #{tarball => Tarball, outer_checksum => OuterChecksum, inner_checksum => InnerChecksum}} {ok, #{tarball => Tarball, outer_checksum => OuterChecksum, inner_checksum => InnerChecksum}}
end. end.
-spec create(metadata(), files()) -> {ok, #{tarball => tarball(), outer_checksum => checksum(),
inner_checksum => tarball()}} | {error, term()}.
create(Metadata, Files) ->
create(Metadata, Files, r3_hex_core:default_config()).
%% @doc %% @doc
%% Creates a docs tarball. %% Creates a docs tarball.
%% %%
@ -84,14 +94,14 @@ create(Metadata, Files) ->
%% {ok, <<86,69,...>>} %% {ok, <<86,69,...>>}
%% ''' %% '''
%% @end %% @end
-spec create_docs(files()) -> {ok, tarball()}.
create_docs(Files) ->
-spec create_docs(files(), r3_hex_core:config()) -> {ok, tarball()} | {error, term()}.
create_docs(Files, #{tarball_max_size := TarballMaxSize, tarball_max_uncompressed_size := TarballMaxUncompressedSize}) ->
UncompressedTarball = create_memory_tarball(Files), UncompressedTarball = create_memory_tarball(Files),
UncompressedSize = byte_size(UncompressedTarball), UncompressedSize = byte_size(UncompressedTarball),
Tarball = gzip(UncompressedTarball), Tarball = gzip(UncompressedTarball),
Size = byte_size(Tarball), Size = byte_size(Tarball),
case(Size > ?TARBALL_MAX_SIZE) or (UncompressedSize > ?TARBALL_MAX_UNCOMPRESSED_SIZE) of
case(Size > TarballMaxSize) or (UncompressedSize > TarballMaxUncompressedSize) of
true -> true ->
{error, {tarball, too_big}}; {error, {tarball, too_big}};
@ -99,6 +109,10 @@ create_docs(Files) ->
{ok, Tarball} {ok, Tarball}
end. end.
-spec create_docs(files()) -> {ok, tarball()}.
create_docs(Files) ->
create_docs(Files, r3_hex_core:default_config()).
%% @doc %% @doc
%% Unpacks a package tarball. %% Unpacks a package tarball.
%% %%
@ -117,16 +131,18 @@ create_docs(Files) ->
%% {ok,#{outer_checksum => <<...>>, %% {ok,#{outer_checksum => <<...>>,
%% metadata => #{<<"name">> => <<"foo">>, ...}}} %% metadata => #{<<"name">> => <<"foo">>, ...}}}
%% ''' %% '''
-spec unpack(tarball(), memory) ->
{ok, #{checksum => checksum(), metadata => metadata(), contents => contents()}} |
-spec unpack(tarball(), memory, r3_hex_core:config()) ->
{ok, #{outer_checksum => checksum(), inner_checksum => checksum(),
metadata => metadata(), contents => contents()}} |
{error, term()}; {error, term()};
(tarball(), filename()) ->
{ok, #{checksum => checksum(), metadata => metadata()}} |
(tarball(), filename(), r3_hex_core:config()) ->
{ok, #{outer_checksum => checksum(), inner_checksum => checksum(),
metadata => metadata()}} |
{error, term()}. {error, term()}.
unpack(Tarball, _) when byte_size(Tarball) > ?TARBALL_MAX_SIZE ->
unpack(Tarball, _, #{tarball_max_size := TarballMaxSize}) when byte_size(Tarball) > TarballMaxSize ->
{error, {tarball, too_big}}; {error, {tarball, too_big}};
unpack(Tarball, Output) ->
unpack(Tarball, Output, _Config) ->
case r3_hex_erl_tar:extract({binary, Tarball}, [memory]) of case r3_hex_erl_tar:extract({binary, Tarball}, [memory]) of
{ok, []} -> {ok, []} ->
{error, {tarball, empty}}; {error, {tarball, empty}};
@ -139,6 +155,18 @@ unpack(Tarball, Output) ->
{error, {tarball, Reason}} {error, {tarball, Reason}}
end. end.
-spec unpack(tarball(), memory) ->
{ok, #{outer_checksum => checksum(), inner_checksum => checksum(),
metadata => metadata(), contents => contents()}} |
{error, term()};
(tarball(), filename()) ->
{ok, #{outer_checksum => checksum(), inner_checksum => checksum(),
metadata => metadata()}} |
{error, term()}.
unpack(Tarball, Output) ->
unpack(Tarball, Output, r3_hex_core:default_config()).
%% @doc %% @doc
%% Unpacks a documentation tarball. %% Unpacks a documentation tarball.
%% %%
@ -151,14 +179,19 @@ unpack(Tarball, Output) ->
%% > r3_hex_tarball:unpack_docs(Tarball, "path/to/unpack"). %% > r3_hex_tarball:unpack_docs(Tarball, "path/to/unpack").
%% ok %% ok
%% ''' %% '''
-spec unpack_docs(tarball(), memory) -> {ok, contents()} | {error, term()};
(tarball(), filename()) -> ok | {error, term()}.
unpack_docs(Tarball, _) when byte_size(Tarball) > ?TARBALL_MAX_SIZE ->
-spec unpack_docs(tarball(), memory, r3_hex_core:config()) -> {ok, contents()} | {error, term()};
(tarball(), filename(), r3_hex_core:config()) -> ok | {error, term()}.
unpack_docs(Tarball, _, #{tarball_max_size := TarballMaxSize}) when byte_size(Tarball) > TarballMaxSize ->
{error, {tarball, too_big}}; {error, {tarball, too_big}};
unpack_docs(Tarball, Output) ->
unpack_docs(Tarball, Output, _Config) ->
unpack_tarball(Tarball, Output). unpack_tarball(Tarball, Output).
-spec unpack_docs(tarball(), memory) -> {ok, contents()} | {error, term()};
(tarball(), filename()) -> ok | {error, term()}.
unpack_docs(Tarball, Output) ->
unpack_docs(Tarball, Output, r3_hex_core:default_config()).
%% @doc %% @doc
%% Returns base16-encoded representation of checksum. %% Returns base16-encoded representation of checksum.
-spec format_checksum(checksum()) -> binary(). -spec format_checksum(checksum()) -> binary().
@ -169,7 +202,11 @@ format_checksum(Checksum) ->
%% Converts an error reason term to a human-readable error message string. %% Converts an error reason term to a human-readable error message string.
-spec format_error(term()) -> string(). -spec format_error(term()) -> string().
format_error({tarball, empty}) -> "empty tarball"; format_error({tarball, empty}) -> "empty tarball";
format_error({tarball, too_big}) -> "tarball is too big";
format_error({tarball, {too_big_uncompressed, Size}}) ->
io_lib:format("package exceeds max uncompressed size ~w ~s", [format_byte_size(Size), "MB"]);
format_error({tarball, {too_big_compressed, Size}}) ->
io_lib:format("package exceeds max compressed size ~w ~s", [format_byte_size(Size), "MB"]);
format_error({tarball, {missing_files, Files}}) -> io_lib:format("missing files: ~p", [Files]); format_error({tarball, {missing_files, Files}}) -> io_lib:format("missing files: ~p", [Files]);
format_error({tarball, {bad_version, Vsn}}) -> io_lib:format("unsupported version: ~p", [Vsn]); format_error({tarball, {bad_version, Vsn}}) -> io_lib:format("unsupported version: ~p", [Vsn]);
format_error({tarball, invalid_checksum}) -> "invalid tarball checksum"; format_error({tarball, invalid_checksum}) -> "invalid tarball checksum";
@ -186,6 +223,9 @@ format_error({checksum_mismatch, ExpectedChecksum, ActualChecksum}) ->
"Actual (base16-encoded): ~s", "Actual (base16-encoded): ~s",
[encode_base16(ExpectedChecksum), encode_base16(ActualChecksum)]). [encode_base16(ExpectedChecksum), encode_base16(ActualChecksum)]).
format_byte_size(Size) ->
Size / 1000000.
%%==================================================================== %%====================================================================
%% Internal functions %% Internal functions
%%==================================================================== %%====================================================================
@ -225,7 +265,12 @@ finish_unpack({error, _} = Error) ->
finish_unpack(#{metadata := Metadata, files := Files, inner_checksum := InnerChecksum, outer_checksum := OuterChecksum, output := Output}) -> finish_unpack(#{metadata := Metadata, files := Files, inner_checksum := InnerChecksum, outer_checksum := OuterChecksum, output := Output}) ->
_ = maps:get("VERSION", Files), _ = maps:get("VERSION", Files),
ContentsBinary = maps:get("contents.tar.gz", Files), ContentsBinary = maps:get("contents.tar.gz", Files),
filelib:ensure_dir(filename:join(Output, "*")),
case Output of
memory -> ok;
_ -> filelib:ensure_dir(filename:join(Output, "*"))
end,
case unpack_tarball(ContentsBinary, Output) of case unpack_tarball(ContentsBinary, Output) of
ok -> ok ->
copy_metadata_config(Output, maps:get("metadata.config", Files)), copy_metadata_config(Output, maps:get("metadata.config", Files)),

src/r3_safe_erl_term.xrl → src/vendored/r3_safe_erl_term.xrl View File

@ -1,4 +1,4 @@
%% Vendored from hex_core v0.6.8, do not edit manually
%% Vendored from hex_core v0.7.0, do not edit manually
%%% Author : Robert Virding %%% Author : Robert Virding
%%% Purpose : Token definitions for Erlang. %%% Purpose : Token definitions for Erlang.

+ 1
- 1
vendor_hex_core.sh View File

@ -7,7 +7,7 @@ if [[ -z "$1" ]]; then
fi fi
source_dir=$1/src source_dir=$1/src
target_dir=src
target_dir=src/vendored
prefix=r3_ prefix=r3_
hex_core_version=`cat $source_dir/hex_core.hrl | grep HEX_CORE_VERSION | cut -d'"' -f2` hex_core_version=`cat $source_dir/hex_core.hrl | grep HEX_CORE_VERSION | cut -d'"' -f2`

Loading…
Cancel
Save