Browse Source

set explicit encoding when reading and writing hex config

fixes tsloughter/rebar3_hex#184
pull/2405/head
Willy Blandin 4 years ago
parent
commit
f903eea713
2 changed files with 10 additions and 3 deletions
  1. +3
    -2
      src/rebar_hex_repos.erl
  2. +7
    -1
      test/rebar_pkg_repos_SUITE.erl

+ 3
- 2
src/rebar_hex_repos.erl View File

@ -163,5 +163,6 @@ update_auth_config(Updates, State) ->
Config = auth_config(State),
AuthConfigFile = auth_config_file(State),
ok = filelib:ensure_dir(AuthConfigFile),
NewConfig = iolist_to_binary([io_lib:print(maps:merge(Config, Updates)) | ".\n"]),
ok = file:write_file(AuthConfigFile, NewConfig).
NewConfig = iolist_to_binary(["%% coding: utf-8", io_lib:nl(),
io_lib:print(maps:merge(Config, Updates)), ".", io_lib:nl()]),
ok = file:write_file(AuthConfigFile, NewConfig, [{encoding, utf8}]).

+ 7
- 1
test/rebar_pkg_repos_SUITE.erl View File

@ -9,7 +9,8 @@
all() ->
[default_repo, repo_merging, repo_replacing,
auth_merging, auth_config_errors, organization_merging, {group, resolve_version}].
auth_read_write_read, auth_merging, auth_config_errors, organization_merging,
{group, resolve_version}].
groups() ->
[{resolve_version, [use_first_repo_match, use_exact_with_hash, fail_repo_update,
@ -271,6 +272,11 @@ auth_config_errors(_Config) ->
?assertEqual(undefined, maps:get(write_key, DefaultRepo, undefined)),
ok.
auth_read_write_read(_Config) ->
State = rebar_state:new([]),
rebar_hex_repos:update_auth_config(#{"foo" => <<200>>}, State),
rebar_hex_repos:update_auth_config(#{"foo" => <<200>>}, State).
organization_merging(_Config) ->
Repo1 = #{name => <<"hexpm:repo-1">>,
api_url => <<"repo-1/api">>},

Loading…
Cancel
Save