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
|
||||
protected void processNonexistentPath(PathData item) throws IOException {
|
||||
// check if parent exists. this is complicated because getParent(a/b/c/) returns a/b/c, but
|
||||
// we want a/b
|
||||
if (!createParents &&
|
||||
!item.fs.exists(new Path(item.path.toString()).getParent())) {
|
||||
throw new PathNotFoundException(item.toString());
|
||||
if (!createParents) {
|
||||
// check if parent exists. this is complicated because getParent(a/b/c/) returns a/b/c, but
|
||||
// we want a/b
|
||||
final Path itemPath = new Path(item.path.toString());
|
||||
final Path itemParentPath = itemPath.getParent();
|
||||
if (!item.fs.exists(itemParentPath)) {
|
||||
throw new PathNotFoundException(itemParentPath.toString());
|
||||
}
|
||||
}
|
||||
if (!item.fs.mkdirs(item.path)) {
|
||||
throw new PathIOException(item.toString());
|
||||
|
@ -721,6 +721,14 @@ public void testErrOutPut() throws Exception {
|
||||
assertTrue(" -mkdir returned this is a file ",
|
||||
(returned.lastIndexOf("not a directory") != -1));
|
||||
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[0] = "-mv";
|
||||
argv[1] = "/testfile";
|
||||
|
@ -6183,7 +6183,7 @@
|
||||
<comparators>
|
||||
<comparator>
|
||||
<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>
|
||||
</comparators>
|
||||
</test>
|
||||
|
Loading…
Reference in New Issue
Block a user