Explorar el Código

HADOOP-18826. [ABFS] Fix for GetFileStatus("/") failure. (#5909)

Contributed by Anmol Asrani
Anuj Modi hace 1 año
padre
commit
ba32ea70fd

+ 6 - 1
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystemStore.java

@@ -1661,7 +1661,12 @@ public class AzureBlobFileSystemStore implements Closeable, ListingSupport {
 
   private String getRelativePath(final Path path) {
     Preconditions.checkNotNull(path, "path");
-    return path.toUri().getPath();
+    String relPath = path.toUri().getPath();
+    if (relPath.isEmpty()) {
+      // This means that path passed by user is absolute path of root without "/" at end.
+      relPath = ROOT_PATH;
+    }
+    return relPath;
   }
 
   private long parseContentLength(final String contentLength) {

+ 22 - 0
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemFileStatus.java

@@ -18,7 +18,9 @@
 
 package org.apache.hadoop.fs.azurebfs;
 
+import java.io.File;
 import java.io.IOException;
+import java.io.OutputStream;
 
 import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.junit.Test;
@@ -83,9 +85,11 @@ public class ITestAzureBlobFileSystemFileStatus extends
       if (isDir) {
         assertEquals(errorInStatus + ": permission",
                 new FsPermission(DEFAULT_DIR_PERMISSION_VALUE), fileStatus.getPermission());
+        assertTrue(errorInStatus + "not a directory", fileStatus.isDirectory());
       } else {
         assertEquals(errorInStatus + ": permission",
                 new FsPermission(DEFAULT_FILE_PERMISSION_VALUE), fileStatus.getPermission());
+        assertTrue(errorInStatus + "not a file", fileStatus.isFile());
       }
     }
 
@@ -144,4 +148,22 @@ public class ITestAzureBlobFileSystemFileStatus extends
     assertTrue("lastModifiedTime should be before createEndTime",
         createEndTime > lastModifiedTime);
   }
+
+  @Test
+  public void testFileStatusOnRoot() throws IOException {
+    AzureBlobFileSystem fs = getFileSystem();
+
+    // Assert that passing relative root path works
+    Path testPath = new Path("/");
+    validateStatus(fs, testPath, true);
+
+    // Assert that passing absolute root path works
+    String testPathStr = makeQualified(testPath).toString();
+    validateStatus(fs, new Path(testPathStr), true);
+
+    // Assert that passing absolute root path without "/" works
+    testPathStr = testPathStr.substring(0, testPathStr.length() - 1);
+    validateStatus(fs, new Path(testPathStr), true);
+
+  }
 }