Skip to content

Commit 800dc6d

Browse files
committed
fix: removed the configuration from the filesystem provider and used the one in the filesystem instead.
1 parent 7be8498 commit 800dc6d

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

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

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

70-
provider.setConfiguration(config);
71-
7270
logger.debug("creating FileSystem for '{}://{}'", provider.getScheme(), bucketName);
7371

7472
clientProvider = new S3ClientProvider(configuration);

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

+16-21
Original file line numberDiff line numberDiff line change
@@ -98,8 +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-
protected S3NioSpiConfiguration configuration = new S3NioSpiConfiguration();
102-
103101
private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());
104102

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

387-
var timeOut = configuration.getTimeoutLow();
385+
var s3FileSystem = s3Directory.getFileSystem();
386+
var timeOut = s3FileSystem.configuration().getTimeoutLow();
388387
final var unit = MINUTES;
389388

390389
try {
391-
s3Directory.getFileSystem().client().putObject(
390+
s3FileSystem.client().putObject(
392391
PutObjectRequest.builder()
393392
.bucket(s3Directory.bucketName())
394393
.key(directoryKey)
@@ -417,9 +416,10 @@ public void delete(Path path) throws IOException {
417416
final var prefix = s3Path.toRealPath(NOFOLLOW_LINKS).getKey();
418417
final var bucketName = s3Path.bucketName();
419418

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

422-
var timeOut = configuration.getTimeoutLow();
422+
var timeOut = s3FileSystem.configuration().getTimeoutLow();
423423
final var unit = MINUTES;
424424
try {
425425
var keys = s3Path.isDirectory() ?
@@ -470,10 +470,11 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep
470470
var s3SourcePath = checkPath(source);
471471
var s3TargetPath = checkPath(target);
472472

473-
final var s3Client = s3SourcePath.getFileSystem().client();
473+
final var s3FileSystem = s3SourcePath.getFileSystem();
474+
final var s3Client = s3FileSystem.client();
474475
final var sourceBucket = s3SourcePath.bucketName();
475476

476-
final var timeOut = configuration.getTimeoutHigh();
477+
final var timeOut = s3FileSystem.configuration().getTimeoutHigh();
477478
final var unit = MINUTES;
478479

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

648-
var timeOut = configuration.getTimeoutLow();
649+
var timeOut = s3Path.getFileSystem().configuration().getTimeoutLow();
649650
var unit = MINUTES;
650651

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

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

791+
var timeoutLow = s3Path.getFileSystem().configuration().getTimeoutLow();
789792
var attributesFilter = attributesFilterFor(attributes);
790-
return S3BasicFileAttributes.get(s3Path, Duration.ofMinutes(configuration.getTimeoutLow())).asMap(attributesFilter);
793+
return S3BasicFileAttributes.get(s3Path, Duration.ofMinutes(timeoutLow)).asMap(attributesFilter);
791794
}
792795

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

804-
/**
805-
* Set custom configuration. This configuration is referred to for API timeouts
806-
*
807-
* @param configuration The new configuration containing the timeout info
808-
*/
809-
public void setConfiguration(S3NioSpiConfiguration configuration) {
810-
this.configuration = configuration;
811-
}
812-
813807
/**
814808
* @param path the path of the file to open or create
815809
* @param options options specifying how the file is opened
@@ -881,8 +875,9 @@ private void closeFileSystemIfOpen(FileSystem fs) throws IOException {
881875

882876
boolean exists(S3AsyncClient s3Client, S3Path path) throws InterruptedException, TimeoutException {
883877
try {
878+
var timeoutLow = path.getFileSystem().configuration().getTimeoutLow();
884879
s3Client.headObject(HeadObjectRequest.builder().bucket(path.bucketName()).key(path.getKey()).build())
885-
.get(configuration.getTimeoutLow(), MINUTES);
880+
.get(timeoutLow, MINUTES);
886881
return true;
887882
} catch (ExecutionException | NoSuchKeyException e) {
888883
logger.debug("Could not retrieve object head information", e);

0 commit comments

Comments
 (0)