From 736ceab2f58fb9ab5907c5b5110bd44384038e6b Mon Sep 17 00:00:00 2001 From: Arpit Agarwal Date: Sun, 20 Aug 2017 23:41:06 -0700 Subject: [PATCH] HDFS-12325. SFTPFileSystem operations should restore cwd. Contributed by Chen Liang. --- .../main/java/org/apache/hadoop/fs/sftp/SFTPFileSystem.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 421769d632a..43eb7833390 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 @@ private boolean mkdirs(ChannelSftp client, Path file, FsPermission permission) 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 @@ private boolean rename(ChannelSftp channel, Path src, Path dst) } 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 FSDataOutputStream create(Path f, FsPermission permission, } 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); }