Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.google.common.collect.AbstractSequentialIterator;
import com.google.common.collect.Iterators;
import com.google.common.io.Closer;
import com.google.common.net.MediaType;
import io.airlift.units.DataSize;
import io.airlift.units.Duration;
import org.apache.hadoop.conf.Configurable;
Expand Down Expand Up @@ -155,8 +156,6 @@
public class PrestoS3FileSystem
extends ExtendedFileSystem
{
static final String S3_DIRECTORY_OBJECT_CONTENT_TYPE = "application/x-directory";

private static final Logger log = Logger.get(PrestoS3FileSystem.class);
private static final PrestoS3FileSystemStats STATS = new PrestoS3FileSystemStats();
private static final PrestoS3FileSystemMetricCollector METRIC_COLLECTOR = new PrestoS3FileSystemMetricCollector(STATS);
Expand All @@ -166,6 +165,7 @@ public class PrestoS3FileSystem
private static final String PATH_SEPARATOR = "/";
private static final Duration BACKOFF_MIN_SLEEP = new Duration(1, SECONDS);
private static final int HTTP_RANGE_NOT_SATISFIABLE = 416;
private static final MediaType DIRECTORY_MEDIA_TYPE = MediaType.create("application", "x-directory");

private URI uri;
private Path workingDirectory;
Expand Down Expand Up @@ -359,7 +359,8 @@ public FileStatus getFileStatus(Path path)

return new FileStatus(
getObjectSize(path, metadata),
S3_DIRECTORY_OBJECT_CONTENT_TYPE.equals(metadata.getContentType()),
// Some directories (e.g. uploaded through S3 GUI) return a charset in the Content-Type header
MediaType.parse(metadata.getContentType()).is(DIRECTORY_MEDIA_TYPE),
1,
BLOCK_SIZE.toBytes(),
lastModifiedTime(metadata),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import java.util.concurrent.atomic.AtomicInteger;

import static com.facebook.airlift.testing.Assertions.assertInstanceOf;
import static com.facebook.presto.hive.s3.PrestoS3FileSystem.S3_DIRECTORY_OBJECT_CONTENT_TYPE;
import static com.facebook.presto.hive.s3.S3ConfigurationUpdater.S3_ACCESS_KEY;
import static com.facebook.presto.hive.s3.S3ConfigurationUpdater.S3_ACL_TYPE;
import static com.facebook.presto.hive.s3.S3ConfigurationUpdater.S3_CREDENTIALS_PROVIDER;
Expand Down Expand Up @@ -635,8 +634,7 @@ public void testFullBucketOwnerControlAcl()
}
}

@Test
public void testEmptyDirectory()
private void testEmptyDirectoryWithContentType(String s3ObjectContentType)
throws Exception
{
try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) {
Expand All @@ -647,7 +645,7 @@ public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetada
{
if (getObjectMetadataRequest.getKey().equals("empty-dir/")) {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentType(S3_DIRECTORY_OBJECT_CONTENT_TYPE);
objectMetadata.setContentType(s3ObjectContentType);
return objectMetadata;
}
return super.getObjectMetadata(getObjectMetadataRequest);
Expand All @@ -661,6 +659,14 @@ public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetada
}
}

@Test
public void testEmptyDirectory()
throws Exception
{
testEmptyDirectoryWithContentType("application/x-directory");
testEmptyDirectoryWithContentType("application/x-directory; charset=UTF-8");
}

@Test
public void testPrestoS3InputStreamEOS() throws Exception
{
Expand Down