HDFS-13622. mkdir should print the parent directory in the error message when parent directories do not exist. Contributed by Shweta.
This commit is contained in:
parent
a19229594e
commit
be150a17b1
@ -68,11 +68,14 @@ protected void processPath(PathData item) throws IOException {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void processNonexistentPath(PathData item) throws IOException {
|
protected void processNonexistentPath(PathData item) throws IOException {
|
||||||
// check if parent exists. this is complicated because getParent(a/b/c/) returns a/b/c, but
|
if (!createParents) {
|
||||||
// we want a/b
|
// check if parent exists. this is complicated because getParent(a/b/c/) returns a/b/c, but
|
||||||
if (!createParents &&
|
// we want a/b
|
||||||
!item.fs.exists(new Path(item.path.toString()).getParent())) {
|
final Path itemPath = new Path(item.path.toString());
|
||||||
throw new PathNotFoundException(item.toString());
|
final Path itemParentPath = itemPath.getParent();
|
||||||
|
if (!item.fs.exists(itemParentPath)) {
|
||||||
|
throw new PathNotFoundException(itemParentPath.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!item.fs.mkdirs(item.path)) {
|
if (!item.fs.mkdirs(item.path)) {
|
||||||
throw new PathIOException(item.toString());
|
throw new PathIOException(item.toString());
|
||||||
|
@ -721,6 +721,14 @@ public void testErrOutPut() throws Exception {
|
|||||||
assertTrue(" -mkdir returned this is a file ",
|
assertTrue(" -mkdir returned this is a file ",
|
||||||
(returned.lastIndexOf("not a directory") != -1));
|
(returned.lastIndexOf("not a directory") != -1));
|
||||||
out.reset();
|
out.reset();
|
||||||
|
argv[0] = "-mkdir";
|
||||||
|
argv[1] = "/testParent/testChild";
|
||||||
|
ret = ToolRunner.run(shell, argv);
|
||||||
|
returned = out.toString();
|
||||||
|
assertEquals(" -mkdir returned 1", 1, ret);
|
||||||
|
assertTrue(" -mkdir returned there is No file or directory but has testChild in the path",
|
||||||
|
(returned.lastIndexOf("testChild") == -1));
|
||||||
|
out.reset();
|
||||||
argv = new String[3];
|
argv = new String[3];
|
||||||
argv[0] = "-mv";
|
argv[0] = "-mv";
|
||||||
argv[1] = "/testfile";
|
argv[1] = "/testfile";
|
||||||
|
@ -6183,11 +6183,11 @@
|
|||||||
<comparators>
|
<comparators>
|
||||||
<comparator>
|
<comparator>
|
||||||
<type>RegexpComparator</type>
|
<type>RegexpComparator</type>
|
||||||
<expected-output>mkdir: `dir0/dir1': No such file or directory</expected-output>
|
<expected-output>.*mkdir:.*dir0': No such file or directory$</expected-output>
|
||||||
</comparator>
|
</comparator>
|
||||||
</comparators>
|
</comparators>
|
||||||
</test>
|
</test>
|
||||||
|
|
||||||
<test> <!-- TESTED -->
|
<test> <!-- TESTED -->
|
||||||
<description>mkdir: Test recreate of existing directory fails</description>
|
<description>mkdir: Test recreate of existing directory fails</description>
|
||||||
<test-commands>
|
<test-commands>
|
||||||
|
Loading…
Reference in New Issue
Block a user