|
60 | 60 |
|
61 | 61 | -include_lib("common_test/include/ct.hrl"). |
62 | 62 | -include_lib("kernel/include/file.hrl"). |
| 63 | +-include_lib("stdlib/include/assert.hrl"). |
63 | 64 | -include("ssh_xfer.hrl"). |
64 | 65 | -include("ssh.hrl"). |
65 | 66 | -include("ssh_test_lib.hrl"). |
@@ -728,25 +729,33 @@ root_with_cwd(Config) when is_list(Config) -> |
728 | 729 | FileName = "root_with_cwd.txt", |
729 | 730 | FilePath = filename:join(CWD, FileName), |
730 | 731 | ok = filelib:ensure_dir(FilePath), |
731 | | - ok = file:write_file(FilePath ++ "0", <<>>), |
732 | | - ok = file:write_file(FilePath ++ "1", <<>>), |
733 | | - ok = file:write_file(FilePath ++ "2", <<>>), |
734 | 732 | {Cm, Channel} = proplists:get_value(sftp, Config), |
735 | | - ReqId0 = 0, |
736 | | - {ok, <<?SSH_FXP_HANDLE, ?UINT32(ReqId0), _Handle0/binary>>, _} = |
737 | | - open_file(FileName ++ "0", Cm, Channel, ReqId0, |
738 | | - ?ACE4_READ_DATA bor ?ACE4_READ_ATTRIBUTES, |
739 | | - ?SSH_FXF_OPEN_EXISTING), |
740 | | - ReqId1 = 1, |
741 | | - {ok, <<?SSH_FXP_HANDLE, ?UINT32(ReqId1), _Handle1/binary>>, _} = |
742 | | - open_file("./" ++ FileName ++ "1", Cm, Channel, ReqId1, |
743 | | - ?ACE4_READ_DATA bor ?ACE4_READ_ATTRIBUTES, |
744 | | - ?SSH_FXF_OPEN_EXISTING), |
745 | | - ReqId2 = 2, |
746 | | - {ok, <<?SSH_FXP_HANDLE, ?UINT32(ReqId2), _Handle2/binary>>, _} = |
747 | | - open_file("/home/" ++ FileName ++ "2", Cm, Channel, ReqId2, |
748 | | - ?ACE4_READ_DATA bor ?ACE4_READ_ATTRIBUTES, |
749 | | - ?SSH_FXF_OPEN_EXISTING). |
| 733 | + |
| 734 | + %% repeat procedure to make sure uniq file handles are generated |
| 735 | + FileHandles = |
| 736 | + [begin |
| 737 | + ReqIdStr = integer_to_list(ReqId), |
| 738 | + ok = file:write_file(FilePath ++ ReqIdStr, <<>>), |
| 739 | + {ok, <<?SSH_FXP_HANDLE, ?UINT32(ReqId), Handle/binary>>, _} = |
| 740 | + open_file(FileName ++ ReqIdStr, Cm, Channel, ReqId, |
| 741 | + ?ACE4_READ_DATA bor ?ACE4_READ_ATTRIBUTES, |
| 742 | + ?SSH_FXF_OPEN_EXISTING), |
| 743 | + Handle |
| 744 | + end || |
| 745 | + ReqId <- lists:seq(0,2)], |
| 746 | + ?assertEqual(length(FileHandles), |
| 747 | + length(lists:uniq(FileHandles))), |
| 748 | + %% create a gap in file handles |
| 749 | + [_, MiddleHandle, _] = FileHandles, |
| 750 | + close(MiddleHandle, 3, Cm, Channel), |
| 751 | + |
| 752 | + %% check that gap in file handles is is re-used |
| 753 | + GapReqId = 4, |
| 754 | + {ok, <<?SSH_FXP_HANDLE, ?UINT32(GapReqId), MiddleHandle/binary>>, _} = |
| 755 | + open_file(FileName ++ integer_to_list(1), Cm, Channel, GapReqId, |
| 756 | + ?ACE4_READ_DATA bor ?ACE4_READ_ATTRIBUTES, |
| 757 | + ?SSH_FXF_OPEN_EXISTING), |
| 758 | + ok. |
750 | 759 |
|
751 | 760 | %%-------------------------------------------------------------------- |
752 | 761 | relative_path(Config) when is_list(Config) -> |
|
0 commit comments