From 85c0cb00750fddae1a230974d001908cb70b101b Mon Sep 17 00:00:00 2001 From: cnauroth Date: Fri, 25 Sep 2015 22:33:53 -0700 Subject: [PATCH] HADOOP-11918. Listing an empty s3a root directory throws FileNotFound. Contributed by Lei (Eddy) Xu. (cherry picked from commit 7fe521b1dd49f81ae325f78cf531cfff15be6641) --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../AbstractContractRootDirectoryTest.java | 14 ++++++++++++++ .../org/apache/hadoop/fs/s3a/S3AFileSystem.java | 3 +++ 3 files changed, 20 insertions(+) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 513d377835c..36418825a5a 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -582,6 +582,9 @@ Release 2.8.0 - UNRELEASED HADOOP-12252. LocalDirAllocator should not throw NPE with empty string configuration. (Zhihai Xu) + HADOOP-11918. Listing an empty s3a root directory throws FileNotFound. + (Lei (Eddy) Xu via cnauroth) + OPTIMIZATIONS HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString() diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractRootDirectoryTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractRootDirectoryTest.java index 83d9143e77d..fb1455e618f 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractRootDirectoryTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractRootDirectoryTest.java @@ -25,6 +25,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; +import org.apache.hadoop.fs.FileStatus; import static org.apache.hadoop.fs.contract.ContractTestUtils.createFile; import static org.apache.hadoop.fs.contract.ContractTestUtils.dataset; @@ -120,4 +121,17 @@ public abstract class AbstractContractRootDirectoryTest extends AbstractFSContra assertIsDirectory(root); } + @Test + public void testListEmptyRootDirectory() throws IOException { + //extra sanity checks here to avoid support calls about complete loss of data + skipIfUnsupported(TEST_ROOT_TESTS_ENABLED); + FileSystem fs = getFileSystem(); + Path root = new Path("/"); + FileStatus[] statuses = fs.listStatus(root); + for (FileStatus status : statuses) { + ContractTestUtils.assertDeleted(fs, status.getPath(), true); + } + assertEquals("listStatus on empty root-directory returned a non-empty list", + 0, fs.listStatus(root).length); + } } 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 f9e937f8f4d..83be18423fe 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 @@ -983,6 +983,9 @@ public class S3AFileSystem extends FileSystem { return new S3AFileStatus(true, false, f.makeQualified(uri, workingDir)); + } else if (key.isEmpty()) { + LOG.debug("Found root directory"); + return new S3AFileStatus(true, true, f.makeQualified(uri, workingDir)); } } catch (AmazonServiceException e) { if (e.getStatusCode() != 404) {