Skip to content

Commit

Permalink
fix: removed the configuration from the filesystem provider and used …
Browse files Browse the repository at this point in the history
…the one in the filesystem instead.
  • Loading branch information
sielenk-yara committed Jan 16, 2025
1 parent 2048127 commit 913db0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
2 changes: 0 additions & 2 deletions src/main/java/software/amazon/nio/spi/s3/S3FileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public class S3FileSystem extends FileSystem {
configuration = (config == null) ? new S3NioSpiConfiguration() : config;
bucketName = configuration.getBucketName();

provider.setConfiguration(config);

logger.debug("creating FileSystem for '{}://{}'", provider.getScheme(), bucketName);

clientProvider = new S3ClientProvider(configuration);
Expand Down
37 changes: 16 additions & 21 deletions src/main/java/software/amazon/nio/spi/s3/S3FileSystemProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ public class S3FileSystemProvider extends FileSystemProvider {
static final String SCHEME = "s3";
private static final Map<String, S3FileSystem> FS_CACHE = new ConcurrentHashMap<>();

protected S3NioSpiConfiguration configuration = new S3NioSpiConfiguration();

private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());

/**
Expand Down Expand Up @@ -384,11 +382,12 @@ public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOExcept
directoryKey = directoryKey + PATH_SEPARATOR;
}

var timeOut = configuration.getTimeoutLow();
var s3FileSystem = s3Directory.getFileSystem();
var timeOut = s3FileSystem.configuration().getTimeoutLow();
final var unit = MINUTES;

try {
s3Directory.getFileSystem().client().putObject(
s3FileSystem.client().putObject(
PutObjectRequest.builder()
.bucket(s3Directory.bucketName())
.key(directoryKey)
Expand Down Expand Up @@ -417,9 +416,10 @@ public void delete(Path path) throws IOException {
final var prefix = s3Path.toRealPath(NOFOLLOW_LINKS).getKey();
final var bucketName = s3Path.bucketName();

final var s3Client = s3Path.getFileSystem().client();
final var s3FileSystem = s3Path.getFileSystem();
final var s3Client = s3FileSystem.client();

var timeOut = configuration.getTimeoutLow();
var timeOut = s3FileSystem.configuration().getTimeoutLow();
final var unit = MINUTES;
try {
var keys = s3Path.isDirectory() ?
Expand Down Expand Up @@ -470,10 +470,11 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep
var s3SourcePath = checkPath(source);
var s3TargetPath = checkPath(target);

final var s3Client = s3SourcePath.getFileSystem().client();
final var s3FileSystem = s3SourcePath.getFileSystem();
final var s3Client = s3FileSystem.client();
final var sourceBucket = s3SourcePath.bucketName();

final var timeOut = configuration.getTimeoutHigh();
final var timeOut = s3FileSystem.configuration().getTimeoutHigh();
final var unit = MINUTES;

var fileExistsAndCannotReplace = cannotReplaceAndFileExistsCheck(options, s3Client);
Expand Down Expand Up @@ -645,7 +646,7 @@ public void checkAccess(Path path, AccessMode... modes) throws IOException {
final var s3Path = checkPath(path.toRealPath(NOFOLLOW_LINKS));
final var response = getCompletableFutureForHead(s3Path);

var timeOut = configuration.getTimeoutLow();
var timeOut = s3Path.getFileSystem().configuration().getTimeoutLow();
var unit = MINUTES;

try {
Expand Down Expand Up @@ -749,8 +750,9 @@ public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type
var s3Path = checkPath(path);

if (type.equals(BasicFileAttributes.class)) {
var timeoutLow = s3Path.getFileSystem().configuration().getTimeoutLow();
@SuppressWarnings("unchecked")
var a = (A) S3BasicFileAttributes.get(s3Path, Duration.ofMinutes(configuration.getTimeoutLow()));
var a = (A) S3BasicFileAttributes.get(s3Path, Duration.ofMinutes(timeoutLow));
return a;
} else {
throw new UnsupportedOperationException("cannot read attributes of type: " + type);
Expand Down Expand Up @@ -786,8 +788,9 @@ public Map<String, Object> readAttributes(Path path, String attributes, LinkOpti
return Collections.emptyMap();
}

var timeoutLow = s3Path.getFileSystem().configuration().getTimeoutLow();
var attributesFilter = attributesFilterFor(attributes);
return S3BasicFileAttributes.get(s3Path, Duration.ofMinutes(configuration.getTimeoutLow())).asMap(attributesFilter);
return S3BasicFileAttributes.get(s3Path, Duration.ofMinutes(timeoutLow)).asMap(attributesFilter);
}

/**
Expand All @@ -801,15 +804,6 @@ public void setAttribute(Path path, String attribute, Object value, LinkOption..
throw new UnsupportedOperationException("s3 file attributes cannot be modified by this class");
}

/**
* Set custom configuration. This configuration is referred to for API timeouts
*
* @param configuration The new configuration containing the timeout info
*/
public void setConfiguration(S3NioSpiConfiguration configuration) {
this.configuration = configuration;
}

/**
* @param path the path of the file to open or create
* @param options options specifying how the file is opened
Expand Down Expand Up @@ -881,8 +875,9 @@ private void closeFileSystemIfOpen(FileSystem fs) throws IOException {

boolean exists(S3AsyncClient s3Client, S3Path path) throws InterruptedException, TimeoutException {
try {
var timeoutLow = path.getFileSystem().configuration().getTimeoutLow();
s3Client.headObject(HeadObjectRequest.builder().bucket(path.bucketName()).key(path.getKey()).build())
.get(configuration.getTimeoutLow(), MINUTES);
.get(timeoutLow, MINUTES);
return true;
} catch (ExecutionException | NoSuchKeyException e) {
logger.debug("Could not retrieve object head information", e);
Expand Down

0 comments on commit 913db0b

Please sign in to comment.