Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite(S3FileSystemProvider): instantiate S3FileAttributes once #288

Merged
merged 1 commit into from
Nov 9, 2023
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 @@ -191,14 +191,6 @@ private HeadObjectResponse getObjectMetadata(String forOperation) {
}
}

/**
* Construct a <code>Map</code> representation of this object
* @return a map
*/
protected Map<String, Object> asMap(){
return asMap(x -> true);
}

/**
* Construct a <code>Map</code> representation of this object with properties filtered
* @param attributeFilter a filter to include properties in the resulting Map
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/software/amazon/nio/spi/s3/S3FileSystemProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static java.nio.file.LinkOption.NOFOLLOW_LINKS;
Expand Down Expand Up @@ -680,14 +681,16 @@ public Map<String, Object> readAttributes(Path path, String attributes, LinkOpti
if (s3Path.isDirectory() || attributes.trim().isEmpty())
return Collections.emptyMap();

if (attributes.equals("*") || attributes.equals("s3"))
return new S3BasicFileAttributes(s3Path, Duration.ofMinutes(TimeOutUtils.TIMEOUT_TIME_LENGTH_1)).asMap();

final var attrSet = Arrays.stream(attributes.split(","))
.map(attr -> attr.replaceAll("^s3:", ""))
.collect(Collectors.toSet());
return ((S3BasicFileAttributes)readAttributes(path, BasicFileAttributes.class, options))
.asMap(attrSet::contains);
Predicate<String> attributesFilter;
if (attributes.equals("*") || attributes.equals("s3")) {
attributesFilter = x -> true;
} else {
final var attrSet = Arrays.stream(attributes.split(","))
.map(attr -> attr.replaceAll("^s3:", ""))
.collect(Collectors.toSet());
attributesFilter = attrSet::contains;
}
return new S3BasicFileAttributes(s3Path, Duration.ofMinutes(TimeOutUtils.TIMEOUT_TIME_LENGTH_1)).asMap(attributesFilter);
}

/**
Expand Down