aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2014-12-01 11:04:25 +0100
committerHans Nilsson <[email protected]>2014-12-01 11:04:25 +0100
commita3c6ca9a4732984c5530fe9c03c6fe45ac1369f2 (patch)
tree208365f222f11a30f3209d390f68323c720f005e /lib/stdlib
parent6c87be5952439f66513e3bf72fb0e48ee93c24d3 (diff)
parentc5a526735109a27d919b340148db6a5a99f9ad09 (diff)
downloadotp-a3c6ca9a4732984c5530fe9c03c6fe45ac1369f2.tar.gz
otp-a3c6ca9a4732984c5530fe9c03c6fe45ac1369f2.tar.bz2
otp-a3c6ca9a4732984c5530fe9c03c6fe45ac1369f2.zip
Merge branch 'hans/ssh/tar_read_and_crypto/OTP-12312' into maint
* hans/ssh/tar_read_and_crypto/OTP-12312: ssh: Implements and tests erl_tar read from remote host. ssh: crypto framework for ssh_sftp:open_tar added
Diffstat (limited to 'lib/stdlib')
-rw-r--r--lib/stdlib/src/erl_tar.erl43
1 files changed, 26 insertions, 17 deletions
diff --git a/lib/stdlib/src/erl_tar.erl b/lib/stdlib/src/erl_tar.erl
index ab6223c0fe..caa3276d09 100644
--- a/lib/stdlib/src/erl_tar.erl
+++ b/lib/stdlib/src/erl_tar.erl
@@ -36,7 +36,7 @@
%% Opens a tar archive.
init(UsrHandle, AccessMode, Fun) when is_function(Fun,2) ->
- {ok, {AccessMode,{UsrHandle,Fun}}}.
+ {ok, {AccessMode,{tar_descriptor,UsrHandle,Fun}}}.
%%%================================================================
%%% The open function with friends is to keep the file and binary api of this module
@@ -532,27 +532,36 @@ read_opts([_|Rest], Opts) ->
read_opts([], Opts) ->
Opts.
+foldl_read({AccessMode,TD={tar_descriptor,_UsrHandle,_AccessFun}}, Fun, Accu, Opts) ->
+ case AccessMode of
+ read ->
+ foldl_read0(TD, Fun, Accu, Opts);
+ _ ->
+ {error,{read_mode_expected,AccessMode}}
+ end;
foldl_read(TarName, Fun, Accu, Opts) ->
case open(TarName, [read|Opts#read_opts.open_mode]) of
{ok, {read, File}} ->
- Result =
- case catch foldl_read1(Fun, Accu, File, Opts) of
- {'EXIT', Reason} ->
- exit(Reason);
- {error, {Reason, Format, Args}} ->
- read_verbose(Opts, Format, Args),
- {error, Reason};
- {error, Reason} ->
- {error, Reason};
- Ok ->
- Ok
- end,
+ Result = foldl_read0(File, Fun, Accu, Opts),
ok = do_close(File),
Result;
Error ->
Error
end.
+foldl_read0(File, Fun, Accu, Opts) ->
+ case catch foldl_read1(Fun, Accu, File, Opts) of
+ {'EXIT', Reason} ->
+ exit(Reason);
+ {error, {Reason, Format, Args}} ->
+ read_verbose(Opts, Format, Args),
+ {error, Reason};
+ {error, Reason} ->
+ {error, Reason};
+ Ok ->
+ Ok
+ end.
+
foldl_read1(Fun, Accu0, File, Opts) ->
case get_header(File) of
eof ->
@@ -1014,10 +1023,10 @@ open_mode(_, _, _, _) ->
{error, einval}.
%%%================================================================
-do_write({UsrHandle,Fun}, Data) -> Fun(write,{UsrHandle,Data}).
+do_write({tar_descriptor,UsrHandle,Fun}, Data) -> Fun(write,{UsrHandle,Data}).
-do_position({UsrHandle,Fun}, Pos) -> Fun(position,{UsrHandle,Pos}).
+do_position({tar_descriptor,UsrHandle,Fun}, Pos) -> Fun(position,{UsrHandle,Pos}).
-do_read({UsrHandle,Fun}, Len) -> Fun(read2,{UsrHandle,Len}).
+do_read({tar_descriptor,UsrHandle,Fun}, Len) -> Fun(read2,{UsrHandle,Len}).
-do_close({UsrHandle,Fun}) -> Fun(close,UsrHandle).
+do_close({tar_descriptor,UsrHandle,Fun}) -> Fun(close,UsrHandle).