From 8a28062d34e5f0c0b83a9577dc9d818bab58c269 Mon Sep 17 00:00:00 2001 From: Adrian Petrescu Date: Wed, 15 Jun 2016 10:15:21 -0400 Subject: [PATCH] No need to check parent path components when creating a directory. Given S3 semantics, there's actually no problem with having a/b/c be a prefix even if a/b or a is already a file. So there's no need to check for it - it wastes API calls and can lead to problems with access control if the caller only has permissions starting at some prefix. --- .../apache/hadoop/fs/s3a/S3AFileSystem.java | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java index 9af0a99376f38..1bfe7952efad1 100644 --- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java +++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java @@ -1328,22 +1328,16 @@ private boolean innerMkdirs(Path f, FsPermission permission) } } catch (FileNotFoundException e) { Path fPart = f; - do { - try { - FileStatus fileStatus = getFileStatus(fPart); - if (fileStatus.isDirectory()) { - break; - } - if (fileStatus.isFile()) { - throw new FileAlreadyExistsException(String.format( - "Can't make directory for path '%s' since it is a file.", - fPart)); - } - } catch (FileNotFoundException fnfe) { - instrumentation.errorIgnored(); + try { + FileStatus fileStatus = getFileStatus(fPart); + if (fileStatus.isFile()) { + throw new FileAlreadyExistsException(String.format( + "Can't make directory for path '%s' since it is a file.", + fPart)); } - fPart = fPart.getParent(); - } while (fPart != null); + } catch (FileNotFoundException fnfe) { + instrumentation.errorIgnored(); + } String key = pathToKey(f); createFakeDirectory(key);