HDFS-12325. SFTPFileSystem operations should restore cwd. Contributed by Chen Liang.
This commit is contained in:
parent
913760cb4f
commit
736ceab2f5
@ -326,8 +326,10 @@ public class SFTPFileSystem extends FileSystem {
|
|||||||
String parentDir = parent.toUri().getPath();
|
String parentDir = parent.toUri().getPath();
|
||||||
boolean succeeded = true;
|
boolean succeeded = true;
|
||||||
try {
|
try {
|
||||||
|
final String previousCwd = client.pwd();
|
||||||
client.cd(parentDir);
|
client.cd(parentDir);
|
||||||
client.mkdir(pathName);
|
client.mkdir(pathName);
|
||||||
|
client.cd(previousCwd);
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
throw new IOException(String.format(E_MAKE_DIR_FORPATH, pathName,
|
throw new IOException(String.format(E_MAKE_DIR_FORPATH, pathName,
|
||||||
parentDir));
|
parentDir));
|
||||||
@ -474,8 +476,10 @@ public class SFTPFileSystem extends FileSystem {
|
|||||||
}
|
}
|
||||||
boolean renamed = true;
|
boolean renamed = true;
|
||||||
try {
|
try {
|
||||||
|
final String previousCwd = channel.pwd();
|
||||||
channel.cd("/");
|
channel.cd("/");
|
||||||
channel.rename(src.toUri().getPath(), dst.toUri().getPath());
|
channel.rename(src.toUri().getPath(), dst.toUri().getPath());
|
||||||
|
channel.cd(previousCwd);
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
renamed = false;
|
renamed = false;
|
||||||
}
|
}
|
||||||
@ -558,8 +562,10 @@ public class SFTPFileSystem extends FileSystem {
|
|||||||
}
|
}
|
||||||
OutputStream os;
|
OutputStream os;
|
||||||
try {
|
try {
|
||||||
|
final String previousCwd = client.pwd();
|
||||||
client.cd(parent.toUri().getPath());
|
client.cd(parent.toUri().getPath());
|
||||||
os = client.put(f.getName());
|
os = client.put(f.getName());
|
||||||
|
client.cd(previousCwd);
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user