Skip to content

Commit 6bf4de9

Browse files
committed
fix: removed the configuration from the filesystem provider and used the one in the filesystem instead.
1 parent 4b54ddd commit 6bf4de9

File tree

2 files changed

+16
-45
lines changed

2 files changed

+16
-45
lines changed

src/main/java/software/amazon/nio/spi/s3/S3FileSystem.java

-11
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,6 @@ public class S3FileSystem extends FileSystem {
6767
configuration = (config == null) ? new S3NioSpiConfiguration() : config;
6868
bucketName = configuration.getBucketName();
6969

70-
// This is quite questionable and may be removed in future versions:
71-
provider.setConfiguration(config);
72-
// The configuration field in {@code S3FileSystemProvider} is used for certain tasks
73-
// that are implemented there.
74-
// But those tasks are in service of {@code S3FileSystem} instances.
75-
// So if there are multiple ones with different configurations, the provider will use
76-
// the one that has been set by the last created filesystem, overriding potentially
77-
// different values in older {@code S3FileSystem} instances.
78-
//
79-
// See https://github.com/awslabs/aws-java-nio-spi-for-s3/issues/597
80-
8170
logger.debug("creating FileSystem for '{}://{}'", provider.getScheme(), bucketName);
8271

8372
clientProvider = new S3ClientProvider(configuration);

src/main/java/software/amazon/nio/spi/s3/S3FileSystemProvider.java

+16-34
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,6 @@ public class S3FileSystemProvider extends FileSystemProvider {
9898
static final String SCHEME = "s3";
9999
private static final Map<String, S3FileSystem> FS_CACHE = new ConcurrentHashMap<>();
100100

101-
/**
102-
* This variable holds the configuration for the S3 NIO Service Provider Interface (SPI).
103-
* It is used to manage and handle the configuration details required for interaction
104-
* with S3 NIO services.
105-
*
106-
* @deprecated This variable is deprecated and may be removed in future versions.
107-
* Consider using updated configuration mechanisms if available.
108-
*/
109-
@Deprecated
110-
protected S3NioSpiConfiguration configuration = new S3NioSpiConfiguration();
111-
112101
private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());
113102

114103
/**
@@ -393,11 +382,12 @@ public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOExcept
393382
directoryKey = directoryKey + PATH_SEPARATOR;
394383
}
395384

396-
var timeOut = configuration.getTimeoutLow();
385+
var s3FileSystem = s3Directory.getFileSystem();
386+
var timeOut = s3FileSystem.getConfiguration().getTimeoutLow();
397387
final var unit = MINUTES;
398388

399389
try {
400-
s3Directory.getFileSystem().client().putObject(
390+
s3FileSystem.client().putObject(
401391
PutObjectRequest.builder()
402392
.bucket(s3Directory.bucketName())
403393
.key(directoryKey)
@@ -426,9 +416,10 @@ public void delete(Path path) throws IOException {
426416
final var prefix = s3Path.toRealPath(NOFOLLOW_LINKS).getKey();
427417
final var bucketName = s3Path.bucketName();
428418

429-
final var s3Client = s3Path.getFileSystem().client();
419+
final var s3FileSystem = s3Path.getFileSystem();
420+
final var s3Client = s3FileSystem.client();
430421

431-
var timeOut = configuration.getTimeoutLow();
422+
var timeOut = s3FileSystem.getConfiguration().getTimeoutLow();
432423
final var unit = MINUTES;
433424
try {
434425
var keys = s3Path.isDirectory() ?
@@ -479,10 +470,11 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep
479470
var s3SourcePath = checkPath(source);
480471
var s3TargetPath = checkPath(target);
481472

482-
final var s3Client = s3SourcePath.getFileSystem().client();
473+
final var s3FileSystem = s3SourcePath.getFileSystem();
474+
final var s3Client = s3FileSystem.client();
483475
final var sourceBucket = s3SourcePath.bucketName();
484476

485-
final var timeOut = configuration.getTimeoutHigh();
477+
final var timeOut = s3FileSystem.getConfiguration().getTimeoutHigh();
486478
final var unit = MINUTES;
487479

488480
var fileExistsAndCannotReplace = cannotReplaceAndFileExistsCheck(options, s3Client);
@@ -654,7 +646,7 @@ public void checkAccess(Path path, AccessMode... modes) throws IOException {
654646
final var s3Path = checkPath(path.toRealPath(NOFOLLOW_LINKS));
655647
final var response = getCompletableFutureForHead(s3Path);
656648

657-
var timeOut = configuration.getTimeoutLow();
649+
var timeOut = s3Path.getFileSystem().getConfiguration().getTimeoutLow();
658650
var unit = MINUTES;
659651

660652
try {
@@ -758,8 +750,9 @@ public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type
758750
var s3Path = checkPath(path);
759751

760752
if (type.equals(BasicFileAttributes.class)) {
753+
var timeoutLow = s3Path.getFileSystem().getConfiguration().getTimeoutLow();
761754
@SuppressWarnings("unchecked")
762-
var a = (A) S3BasicFileAttributes.get(s3Path, Duration.ofMinutes(configuration.getTimeoutLow()));
755+
var a = (A) S3BasicFileAttributes.get(s3Path, Duration.ofMinutes(timeoutLow));
763756
return a;
764757
} else {
765758
throw new UnsupportedOperationException("cannot read attributes of type: " + type);
@@ -795,8 +788,9 @@ public Map<String, Object> readAttributes(Path path, String attributes, LinkOpti
795788
return Collections.emptyMap();
796789
}
797790

791+
var timeoutLow = s3Path.getFileSystem().getConfiguration().getTimeoutLow();
798792
var attributesFilter = attributesFilterFor(attributes);
799-
return S3BasicFileAttributes.get(s3Path, Duration.ofMinutes(configuration.getTimeoutLow())).asMap(attributesFilter);
793+
return S3BasicFileAttributes.get(s3Path, Duration.ofMinutes(timeoutLow)).asMap(attributesFilter);
800794
}
801795

802796
/**
@@ -810,19 +804,6 @@ public void setAttribute(Path path, String attribute, Object value, LinkOption..
810804
throw new UnsupportedOperationException("s3 file attributes cannot be modified by this class");
811805
}
812806

813-
/**
814-
* Set custom configuration. This configuration is referred to for API timeouts.
815-
*
816-
* @param configuration The new configuration containing the timeout info
817-
*
818-
* @deprecated This method is deprecated and may be removed in future versions.
819-
*
820-
*/
821-
@Deprecated
822-
public void setConfiguration(S3NioSpiConfiguration configuration) {
823-
this.configuration = configuration;
824-
}
825-
826807
/**
827808
* @param path the path of the file to open or create
828809
* @param options options specifying how the file is opened
@@ -894,8 +875,9 @@ private void closeFileSystemIfOpen(FileSystem fs) throws IOException {
894875

895876
boolean exists(S3AsyncClient s3Client, S3Path path) throws InterruptedException, TimeoutException {
896877
try {
878+
var timeoutLow = path.getFileSystem().getConfiguration().getTimeoutLow();
897879
s3Client.headObject(HeadObjectRequest.builder().bucket(path.bucketName()).key(path.getKey()).build())
898-
.get(configuration.getTimeoutLow(), MINUTES);
880+
.get(timeoutLow, MINUTES);
899881
return true;
900882
} catch (ExecutionException | NoSuchKeyException e) {
901883
logger.debug("Could not retrieve object head information", e);

0 commit comments

Comments
 (0)