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