HDFS-12325. SFTPFileSystem operations should restore cwd. Contributed by Chen Liang.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/736ceab2 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/736ceab2 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/736ceab2 Branch: refs/heads/HDFS-7240 Commit: 736ceab2f58fb9ab5907c5b5110bd44384038e6b Parents: 913760c Author: Arpit Agarwal <a...@apache.org> Authored: Sun Aug 20 23:41:06 2017 -0700 Committer: Arpit Agarwal <a...@apache.org> Committed: Mon Aug 21 11:48:51 2017 -0700 ---------------------------------------------------------------------- .../main/java/org/apache/hadoop/fs/sftp/SFTPFileSystem.java | 6 ++++++ 1 file changed, 6 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/736ceab2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/sftp/SFTPFileSystem.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/sftp/SFTPFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/sftp/SFTPFileSystem.java index 421769d..43eb783 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/sftp/SFTPFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/sftp/SFTPFileSystem.java @@ -326,8 +326,10 @@ public class SFTPFileSystem extends FileSystem { String parentDir = parent.toUri().getPath(); boolean succeeded = true; try { + final String previousCwd = client.pwd(); client.cd(parentDir); client.mkdir(pathName); + client.cd(previousCwd); } catch (SftpException e) { throw new IOException(String.format(E_MAKE_DIR_FORPATH, pathName, parentDir)); @@ -474,8 +476,10 @@ public class SFTPFileSystem extends FileSystem { } boolean renamed = true; try { + final String previousCwd = channel.pwd(); channel.cd("/"); channel.rename(src.toUri().getPath(), dst.toUri().getPath()); + channel.cd(previousCwd); } catch (SftpException e) { renamed = false; } @@ -558,8 +562,10 @@ public class SFTPFileSystem extends FileSystem { } OutputStream os; try { + final String previousCwd = client.pwd(); client.cd(parent.toUri().getPath()); os = client.put(f.getName()); + client.cd(previousCwd); } catch (SftpException e) { throw new IOException(e); } --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org