HDFS-15252. HttpFS: setWorkingDirectory should not accept invalid paths. Contributed by hemanthboyina.
(cherry picked from commit 736659e0e1
)
This commit is contained in:
parent
2da3356428
commit
14fddba715
@ -47,6 +47,7 @@
|
|||||||
import org.apache.hadoop.fs.permission.FsAction;
|
import org.apache.hadoop.fs.permission.FsAction;
|
||||||
import org.apache.hadoop.fs.permission.FsPermission;
|
import org.apache.hadoop.fs.permission.FsPermission;
|
||||||
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
||||||
|
import org.apache.hadoop.hdfs.DFSUtilClient;
|
||||||
import org.apache.hadoop.hdfs.protocol.BlockStoragePolicy;
|
import org.apache.hadoop.hdfs.protocol.BlockStoragePolicy;
|
||||||
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
|
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
|
||||||
import org.apache.hadoop.hdfs.protocol.FsPermissionExtension;
|
import org.apache.hadoop.hdfs.protocol.FsPermissionExtension;
|
||||||
@ -802,6 +803,11 @@ public DirectoryEntries listStatusBatch(Path f, byte[] token) throws
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setWorkingDirectory(Path newDir) {
|
public void setWorkingDirectory(Path newDir) {
|
||||||
|
String result = newDir.toUri().getPath();
|
||||||
|
if (!DFSUtilClient.isValidName(result)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Invalid DFS directory name " + result);
|
||||||
|
}
|
||||||
workingDir = newDir;
|
workingDir = newDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@
|
|||||||
import org.apache.hadoop.security.UserGroupInformation;
|
import org.apache.hadoop.security.UserGroupInformation;
|
||||||
import org.apache.hadoop.test.HFSTestCase;
|
import org.apache.hadoop.test.HFSTestCase;
|
||||||
import org.apache.hadoop.test.HadoopUsersConfTestHelper;
|
import org.apache.hadoop.test.HadoopUsersConfTestHelper;
|
||||||
|
import org.apache.hadoop.test.LambdaTestUtils;
|
||||||
import org.apache.hadoop.test.TestDir;
|
import org.apache.hadoop.test.TestDir;
|
||||||
import org.apache.hadoop.test.TestDirHelper;
|
import org.apache.hadoop.test.TestDirHelper;
|
||||||
import org.apache.hadoop.test.TestHdfs;
|
import org.apache.hadoop.test.TestHdfs;
|
||||||
@ -557,9 +558,18 @@ private void testWorkingdirectory() throws Exception {
|
|||||||
fs = getHttpFSFileSystem();
|
fs = getHttpFSFileSystem();
|
||||||
fs.setWorkingDirectory(new Path("/tmp"));
|
fs.setWorkingDirectory(new Path("/tmp"));
|
||||||
workingDir = fs.getWorkingDirectory();
|
workingDir = fs.getWorkingDirectory();
|
||||||
fs.close();
|
|
||||||
assertEquals(workingDir.toUri().getPath(),
|
assertEquals(workingDir.toUri().getPath(),
|
||||||
new Path("/tmp").toUri().getPath());
|
new Path("/tmp").toUri().getPath());
|
||||||
|
final FileSystem httpFs = getHttpFSFileSystem();
|
||||||
|
LambdaTestUtils.intercept(IllegalArgumentException.class,
|
||||||
|
"Invalid DFS directory name /foo:bar",
|
||||||
|
() -> httpFs.setWorkingDirectory(new Path("/foo:bar")));
|
||||||
|
fs.setWorkingDirectory(new Path("/bar"));
|
||||||
|
workingDir = fs.getWorkingDirectory();
|
||||||
|
httpFs.close();
|
||||||
|
fs.close();
|
||||||
|
assertEquals(workingDir.toUri().getPath(),
|
||||||
|
new Path("/bar").toUri().getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testTrashRoot() throws Exception {
|
private void testTrashRoot() throws Exception {
|
||||||
|
Loading…
Reference in New Issue
Block a user