From 27ab5f7385c70f16fd593edc336c573c69f19331 Mon Sep 17 00:00:00 2001 From: Steve Loughran Date: Tue, 22 Aug 2017 11:55:48 +0100 Subject: [PATCH] HADOOP-14787. AliyunOSS: Implement the `createNonRecursive` operator. Contributed by Genmao Yu --- .../fs/aliyun/oss/AliyunOSSFileSystem.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java b/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java index 0491087d02..3561b0241e 100644 --- a/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java +++ b/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java @@ -22,11 +22,13 @@ import java.io.IOException; import java.net.URI; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.CreateFlag; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileAlreadyExistsException; @@ -103,6 +105,31 @@ public FSDataOutputStream create(Path path, FsPermission permission, store, key, progress, statistics), (Statistics)(null)); } + /** + * {@inheritDoc} + * @throws FileNotFoundException if the parent directory is not present -or + * is not a directory. + */ + @Override + public FSDataOutputStream createNonRecursive(Path path, + FsPermission permission, + EnumSet flags, + int bufferSize, + short replication, + long blockSize, + Progressable progress) throws IOException { + Path parent = path.getParent(); + if (parent != null) { + // expect this to raise an exception if there is no parent + if (!getFileStatus(parent).isDirectory()) { + throw new FileAlreadyExistsException("Not a directory: " + parent); + } + } + return create(path, permission, + flags.contains(CreateFlag.OVERWRITE), bufferSize, + replication, blockSize, progress); + } + @Override public boolean delete(Path path, boolean recursive) throws IOException { try {