chore(psk): return line number rather than the content of line

This commit is contained in:
zhouzb 2021-09-27 22:06:28 +08:00
parent 74c9a38e9f
commit 2cc2cd2831
1 changed files with 6 additions and 4 deletions

View File

@ -162,7 +162,7 @@ import_psks(SrcFile) ->
reason => Reason}), reason => Reason}),
{error, Reason}; {error, Reason};
{ok, Io} -> {ok, Io} ->
try import_psks(Io, get_config(separator), get_config(chunk_size)) of try import_psks(Io, get_config(separator), get_config(chunk_size), 0) of
ok -> ok; ok -> ok;
{error, Reason} -> {error, Reason} ->
?SLOG(error, #{msg => "failed_to_import_psk_file", ?SLOG(error, #{msg => "failed_to_import_psk_file",
@ -182,14 +182,16 @@ import_psks(SrcFile) ->
end end
end. end.
import_psks(Io, Delimiter, ChunkSize) -> import_psks(Io, Delimiter, ChunkSize, NChunk) ->
case get_psks(Io, Delimiter, ChunkSize) of case get_psks(Io, Delimiter, ChunkSize) of
{ok, Entries} -> {ok, Entries} ->
_ = trans(fun insert_psks/1, [Entries]), _ = trans(fun insert_psks/1, [Entries]),
import_psks(Io, Delimiter, ChunkSize); import_psks(Io, Delimiter, ChunkSize, NChunk + 1);
{eof, Entries} -> {eof, Entries} ->
_ = trans(fun insert_psks/1, [Entries]), _ = trans(fun insert_psks/1, [Entries]),
ok; ok;
{error, {bad_format, {line, N}}} ->
{error, {bad_format, {line, NChunk * ChunkSize + N}}};
{error, Reaosn} -> {error, Reaosn} ->
{error, Reaosn} {error, Reaosn}
end. end.
@ -207,7 +209,7 @@ get_psks(Io, Delimiter, Remaining, Acc) ->
NSharedSecret = trim_crlf(SharedSecret), NSharedSecret = trim_crlf(SharedSecret),
get_psks(Io, Delimiter, Remaining - 1, [{PSKIdentity, NSharedSecret} | Acc]); get_psks(Io, Delimiter, Remaining - 1, [{PSKIdentity, NSharedSecret} | Acc]);
_ -> _ ->
{error, {bad_format, Line}} {error, {bad_format, {line, length(Acc) + 1}}}
end; end;
eof -> eof ->
{eof, Acc}; {eof, Acc};