S3 storage: fix issues from code review

This commit is contained in:
Skye 2024-02-23 18:30:38 +09:00
parent 09473e7b72
commit 43adac0dbf
No known key found for this signature in database
GPG Key ID: 0104BC05F41B77B8
2 changed files with 32 additions and 41 deletions

View File

@ -8,15 +8,14 @@
import java.util.Optional;
@SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"})
@DebugDump
@ConfigSerializable
public class S3Config extends StorageConfig implements S3StorageSettings {
private String endpoint = null;
private String region = "";
private String accessKey = "";
@DebugDump private String endpoint = null;
@DebugDump private String region = "";
@DebugDump private String accessKey = "";
private String secretKey = "";
private String bucket = "";
private Compression compression = Compression.GZIP;
@DebugDump private String bucket = "";
@DebugDump private Compression compression = Compression.GZIP;
@Override
public Optional<String> getEndpoint() {

View File

@ -5,6 +5,7 @@
import de.bluecolored.bluemap.core.util.OnCloseOutputStream;
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.core.exception.SdkException;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
@ -62,10 +63,9 @@ public Optional<CompressedInputStream> readMapTile(String mapId, int lod, Vector
.build()
);
return Optional.of(new CompressedInputStream(is, compression));
} catch (Exception e) {
if (e instanceof NoSuchKeyException) {
return Optional.empty();
}
} catch (NoSuchKeyException e) {
return Optional.empty();
} catch (SdkException e) {
throw new IOException(e);
}
}
@ -104,10 +104,9 @@ public long getLastModified() {
return info.lastModified().getEpochSecond();
}
});
} catch (Exception e) {
if (e instanceof NoSuchKeyException) {
return Optional.empty();
}
} catch (NoSuchKeyException e) {
return Optional.empty();
} catch (SdkException e) {
throw new IOException(e);
}
}
@ -123,10 +122,8 @@ public void deleteMapTile(String mapId, int lod, Vector2i tile) throws IOExcepti
.key(path)
.build()
);
} catch (Exception e) {
if (e instanceof NoSuchKeyException) {
return;
}
} catch (NoSuchKeyException ignored) {
} catch (SdkException e) {
throw new IOException(e);
}
}
@ -166,10 +163,9 @@ public Optional<InputStream> readMeta(String mapId, String name) throws IOExcept
.build()
);
return Optional.of(is);
} catch (Exception e) {
if (e instanceof NoSuchKeyException) {
return Optional.empty();
}
} catch (NoSuchKeyException e) {
return Optional.empty();
} catch (SdkException e) {
throw new IOException(e);
}
}
@ -197,10 +193,9 @@ public long getSize() {
return info.contentLength();
}
});
} catch (Exception e) {
if (e instanceof NoSuchKeyException) {
return Optional.empty();
}
} catch (NoSuchKeyException e) {
return Optional.empty();
} catch (SdkException e) {
throw new IOException(e);
}
}
@ -216,10 +211,8 @@ public void deleteMeta(String mapId, String name) throws IOException {
.key(path)
.build()
);
} catch (Exception e) {
if (e instanceof NoSuchKeyException) {
return;
}
} catch (NoSuchKeyException ignored) {
} catch (SdkException e) {
throw new IOException(e);
}
}
@ -238,22 +231,21 @@ public void purgeMap(String mapId, Function<ProgressInfo, Boolean> onProgress) t
var filesList = files.contents().stream().collect(Collectors.toList());
for (int i = 0; i < filesList.size(); i++) {
var file = filesList.get(i);
client.deleteObject(
DeleteObjectRequest
.builder()
.bucket(bucket)
.key(file.key())
.build()
);
try {
client.deleteObject(
DeleteObjectRequest
.builder()
.bucket(bucket)
.key(file.key())
.build()
);
} catch (NoSuchKeyException ignored) {}
if (!onProgress.apply(
new ProgressInfo((double) (i + 1) / filesList.size())
)) return;
}
} catch (Exception e) {
if (e instanceof NoSuchKeyException) {
return;
}
} catch (SdkException e) {
throw new IOException(e);
}
}