From 104f9abe67d1e35816129003413d46d5df1222f2 Mon Sep 17 00:00:00 2001
From: Thomas White <tomwhite@apache.org>
Date: Thu, 28 May 2009 16:43:30 +0000
Subject: [PATCH] HADOOP-5805. problem using top level s3 buckets as input/output directories. Contributed by Ian Nowland.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@779656 13f79535-47bb-0310-9956-ffa450edef68
---
 .../hadoop/fs/s3native/NativeS3FileSystem.java     |    5 +++++
 .../NativeS3FileSystemContractBaseTest.java        |    3 +++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/core/org/apache/hadoop/fs/s3native/NativeS3FileSystem.java b/src/core/org/apache/hadoop/fs/s3native/NativeS3FileSystem.java
index 96191ba..d58e61a 100644
--- a/src/core/org/apache/hadoop/fs/s3native/NativeS3FileSystem.java
+++ b/src/core/org/apache/hadoop/fs/s3native/NativeS3FileSystem.java
@@ -249,6 +249,11 @@ public class NativeS3FileSystem extends FileSystem {
   }
   
   private static String pathToKey(Path path) {
+    if (path.toUri().getScheme() != null && "".equals(path.toUri().getPath())) {
+      // allow uris without trailing slash after bucket to refer to root,
+      // like s3n://mybucket
+      return "";
+    }
     if (!path.isAbsolute()) {
       throw new IllegalArgumentException("Path must be absolute: " + path);
     }
diff --git a/src/test/org/apache/hadoop/fs/s3native/NativeS3FileSystemContractBaseTest.java b/src/test/org/apache/hadoop/fs/s3native/NativeS3FileSystemContractBaseTest.java
index bf2e3c3..be39fd0 100644
--- a/src/test/org/apache/hadoop/fs/s3native/NativeS3FileSystemContractBaseTest.java
+++ b/src/test/org/apache/hadoop/fs/s3native/NativeS3FileSystemContractBaseTest.java
@@ -56,4 +56,7 @@ public abstract class NativeS3FileSystemContractBaseTest
     assertEquals(path("/test"), paths[0].getPath());
   }
   
+  public void testNoTrailingBackslashOnBucket() throws Exception {
+    assertTrue(fs.getFileStatus(new Path(fs.getUri().toString())).isDir());
+  }
 }
-- 
1.6.0.4

