diff options
author | Hans Nilsson <[email protected]> | 2017-02-17 11:40:36 +0100 |
---|---|---|
committer | Hans Nilsson <[email protected]> | 2017-02-17 11:40:36 +0100 |
commit | af4855549d2a7b1cf414b0e6c0568c0e151e1319 (patch) | |
tree | 8f97c2687e4c1a568ab2efca5d35186ea1ec333e /lib/ssh/src | |
parent | adbcc111926afe5dc43ceaf322bfa007d9f5d00a (diff) | |
parent | 859ac82433da2dcd11685b8c8beb972336cf70cf (diff) | |
download | otp-af4855549d2a7b1cf414b0e6c0568c0e151e1319.tar.gz otp-af4855549d2a7b1cf414b0e6c0568c0e151e1319.tar.bz2 otp-af4855549d2a7b1cf414b0e6c0568c0e151e1319.zip |
Merge branch 'ssh_sftpd_cwd_with_root' into hans/ssh/sftpd_fixes/OTP-14225
Conflicts:
lib/ssh/test/ssh_sftpd_SUITE.erl
Diffstat (limited to 'lib/ssh/src')
-rw-r--r-- | lib/ssh/src/ssh_sftpd.erl | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/lib/ssh/src/ssh_sftpd.erl b/lib/ssh/src/ssh_sftpd.erl index b739955836..bc30b7fb7d 100644 --- a/lib/ssh/src/ssh_sftpd.erl +++ b/lib/ssh/src/ssh_sftpd.erl @@ -742,6 +742,10 @@ resolve_symlinks_2([], State, _LinkCnt, AccPath) -> {{ok, AccPath}, State}. +%% The File argument is always in a user visible file system, i.e. +%% is under Root and is relative to CWD or Root, if starts with "/". +%% The result of the function is always an absolute path in a +%% "backend" file system. relate_file_name(File, State) -> relate_file_name(File, State, _Canonicalize=true). @@ -749,19 +753,20 @@ relate_file_name(File, State, Canonicalize) when is_binary(File) -> relate_file_name(unicode:characters_to_list(File), State, Canonicalize); relate_file_name(File, #state{cwd = CWD, root = ""}, Canonicalize) -> relate_filename_to_path(File, CWD, Canonicalize); -relate_file_name(File, #state{root = Root}, Canonicalize) -> - case is_within_root(Root, File) of - true -> - File; - false -> - RelFile = make_relative_filename(File), - NewFile = relate_filename_to_path(RelFile, Root, Canonicalize), - case is_within_root(Root, NewFile) of - true -> - NewFile; - false -> - Root - end +relate_file_name(File, #state{cwd = CWD, root = Root}, Canonicalize) -> + CWD1 = case is_within_root(Root, CWD) of + true -> CWD; + false -> Root + end, + AbsFile = case make_relative_filename(File) of + File -> + relate_filename_to_path(File, CWD1, Canonicalize); + RelFile -> + relate_filename_to_path(RelFile, Root, Canonicalize) + end, + case is_within_root(Root, AbsFile) of + true -> AbsFile; + false -> Root end. is_within_root(Root, File) -> |