HADOOP-8175. FsShell: Add -p option to mkdir. Contributed by Daryn Sharp

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1301273 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2012-03-15 23:42:38 +00:00
parent dffd37926d
commit 889a863da1
2 changed files with 13 additions and 4 deletions

View File

@ -305,7 +305,10 @@ Release 0.23.2 - UNRELEASED
HADOOP-8137. Added links to CLI manuals to the site. (tgraves via HADOOP-8137. Added links to CLI manuals to the site. (tgraves via
acmurthy) acmurthy)
HADOOP-8175. FsShell: Add -p option to mkdir. (Daryn Sharp via szetszwo)
OPTIMIZATIONS OPTIMIZATIONS
HADOOP-8071. Avoid an extra packet in client code when nagling is HADOOP-8071. Avoid an extra packet in client code when nagling is
disabled. (todd) disabled. (todd)

View File

@ -43,16 +43,21 @@ class Mkdir extends FsCommand {
public static final String DESCRIPTION = public static final String DESCRIPTION =
"Create a directory in specified location."; "Create a directory in specified location.";
private boolean createParents;
@Override @Override
protected void processOptions(LinkedList<String> args) { protected void processOptions(LinkedList<String> args) {
CommandFormat cf = new CommandFormat(1, Integer.MAX_VALUE); CommandFormat cf = new CommandFormat(1, Integer.MAX_VALUE, "p");
cf.parse(args); cf.parse(args);
createParents = cf.getOpt("p");
} }
@Override @Override
protected void processPath(PathData item) throws IOException { protected void processPath(PathData item) throws IOException {
if (item.stat.isDirectory()) { if (item.stat.isDirectory()) {
if (!createParents) {
throw new PathExistsException(item.toString()); throw new PathExistsException(item.toString());
}
} else { } else {
throw new PathIsNotDirectoryException(item.toString()); throw new PathIsNotDirectoryException(item.toString());
} }
@ -60,6 +65,7 @@ class Mkdir extends FsCommand {
@Override @Override
protected void processNonexistentPath(PathData item) throws IOException { protected void processNonexistentPath(PathData item) throws IOException {
// TODO: should use createParents to control intermediate dir creation
if (!item.fs.mkdirs(item.path)) { if (!item.fs.mkdirs(item.path)) {
throw new PathIOException(item.toString()); throw new PathIOException(item.toString());
} }