HADOOP-16840. AliyunOSS: getFileStatus throws FileNotFoundException in versioning bucket. Contributed by wujinhu.
(cherry picked from commit 6dfe00c71e
)
This commit is contained in:
parent
def9a04087
commit
a55f96c053
|
@ -273,12 +273,18 @@ public class AliyunOSSFileSystem extends FileSystem {
|
||||||
}
|
}
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
ObjectListing listing = store.listObjects(key, 1, null, false);
|
ObjectListing listing = store.listObjects(key, 1, null, false);
|
||||||
if (CollectionUtils.isNotEmpty(listing.getObjectSummaries()) ||
|
do {
|
||||||
CollectionUtils.isNotEmpty(listing.getCommonPrefixes())) {
|
if (CollectionUtils.isNotEmpty(listing.getObjectSummaries()) ||
|
||||||
return new OSSFileStatus(0, true, 1, 0, 0, qualifiedPath, username);
|
CollectionUtils.isNotEmpty(listing.getCommonPrefixes())) {
|
||||||
} else {
|
return new OSSFileStatus(0, true, 1, 0, 0, qualifiedPath, username);
|
||||||
throw new FileNotFoundException(path + ": No such file or directory!");
|
} else if (listing.isTruncated()) {
|
||||||
}
|
listing = store.listObjects(key, 1000, listing.getNextMarker(),
|
||||||
|
false);
|
||||||
|
} else {
|
||||||
|
throw new FileNotFoundException(
|
||||||
|
path + ": No such file or directory!");
|
||||||
|
}
|
||||||
|
} while (true);
|
||||||
} else if (objectRepresentsDirectory(key, meta.getContentLength())) {
|
} else if (objectRepresentsDirectory(key, meta.getContentLength())) {
|
||||||
return new OSSFileStatus(0, true, 1, 0, meta.getLastModified().getTime(),
|
return new OSSFileStatus(0, true, 1, 0, meta.getLastModified().getTime(),
|
||||||
qualifiedPath, username);
|
qualifiedPath, username);
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
@ -96,6 +97,28 @@ public class TestAliyunOSSFileSystemContract
|
||||||
UserGroupInformation.getCurrentUser().getShortUserName());
|
UserGroupInformation.getCurrentUser().getShortUserName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetFileStatusInVersioningBucket() throws Exception {
|
||||||
|
Path file = this.path("/test/hadoop/file");
|
||||||
|
for (int i = 1; i <= 30; ++i) {
|
||||||
|
this.createFile(new Path(file, "sub" + i));
|
||||||
|
}
|
||||||
|
assertTrue("File exists", this.fs.exists(file));
|
||||||
|
FileStatus fs = this.fs.getFileStatus(file);
|
||||||
|
assertEquals(fs.getOwner(),
|
||||||
|
UserGroupInformation.getCurrentUser().getShortUserName());
|
||||||
|
assertEquals(fs.getGroup(),
|
||||||
|
UserGroupInformation.getCurrentUser().getShortUserName());
|
||||||
|
|
||||||
|
AliyunOSSFileSystemStore store = ((AliyunOSSFileSystem)this.fs).getStore();
|
||||||
|
for (int i = 0; i < 29; ++i) {
|
||||||
|
store.deleteObjects(Arrays.asList("test/hadoop/file/sub" + i));
|
||||||
|
}
|
||||||
|
|
||||||
|
// HADOOP-16840, will throw FileNotFoundException without this fix
|
||||||
|
this.fs.getFileStatus(file);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteSubdir() throws IOException {
|
public void testDeleteSubdir() throws IOException {
|
||||||
Path parentDir = this.path("/test/hadoop");
|
Path parentDir = this.path("/test/hadoop");
|
||||||
|
|
Loading…
Reference in New Issue