|
@@ -39,20 +39,26 @@ class Mkdir extends FsCommand {
|
|
|
}
|
|
|
|
|
|
public static final String NAME = "mkdir";
|
|
|
- public static final String USAGE = "<path> ...";
|
|
|
+ public static final String USAGE = "[-p] <path> ...";
|
|
|
public static final String DESCRIPTION =
|
|
|
- "Create a directory in specified location.";
|
|
|
+ "Create a directory in specified location.\n" +
|
|
|
+ " -p Do not fail if the directory already exists";
|
|
|
|
|
|
+ private boolean createParents;
|
|
|
+
|
|
|
@Override
|
|
|
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);
|
|
|
+ createParents = cf.getOpt("p");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void processPath(PathData item) throws IOException {
|
|
|
if (item.stat.isDirectory()) {
|
|
|
- throw new PathExistsException(item.toString());
|
|
|
+ if (!createParents) {
|
|
|
+ throw new PathExistsException(item.toString());
|
|
|
+ }
|
|
|
} else {
|
|
|
throw new PathIsNotDirectoryException(item.toString());
|
|
|
}
|
|
@@ -60,6 +66,7 @@ class Mkdir extends FsCommand {
|
|
|
|
|
|
@Override
|
|
|
protected void processNonexistentPath(PathData item) throws IOException {
|
|
|
+ // TODO: should use createParents to control intermediate dir creation
|
|
|
if (!item.fs.mkdirs(item.path)) {
|
|
|
throw new PathIOException(item.toString());
|
|
|
}
|