HADOOP-18826. [ABFS] Fix for GetFileStatus("/") failure. (#5909)
Contributed by Anmol Asrani
This commit is contained in:
parent
b1ed23654c
commit
ba32ea70fd
@ -1661,7 +1661,12 @@ private String getOctalNotation(FsPermission fsPermission) {
|
||||
|
||||
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) {
|
||||
|
@ -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 @@ private FileStatus validateStatus(final AzureBlobFileSystem fs, final Path name,
|
||||
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 void testLastModifiedTime() throws IOException {
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user