This is an automated email from the ASF dual-hosted git repository. stevel pushed a commit to branch branch-3.3 in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.3 by this push: new 6f8257b16b1 HADOOP-18826. [ABFS] Fix for GetFileStatus("/") failure. (#5909) 6f8257b16b1 is described below commit 6f8257b16b15e5a03fd4b5459ad3fe3523f76073 Author: Anuj Modi <128447756+anujmodi2...@users.noreply.github.com> AuthorDate: Tue Aug 8 11:00:02 2023 -0700 HADOOP-18826. [ABFS] Fix for GetFileStatus("/") failure. (#5909) Contributed by Anmol Asrani --- .../fs/azurebfs/AzureBlobFileSystemStore.java | 7 ++++++- .../ITestAzureBlobFileSystemFileStatus.java | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystemStore.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystemStore.java index 995654d5247..2ffd354dc0b 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystemStore.java +++ b/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) { diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemFileStatus.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemFileStatus.java index 4fa7a0fca68..dfaf203c590 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemFileStatus.java +++ b/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); + + } } --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org