Skip to content

Commit

Permalink
fix(core): no longer using deleteByPrefix to delete a single entry to…
Browse files Browse the repository at this point in the history
… prevent side effects
  • Loading branch information
brian-mulier-p committed Nov 28, 2023
1 parent 46e2a19 commit f34460d
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/main/java/io/kestra/storage/s3/S3Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,26 @@ public URI put(String tenantId, URI uri, InputStream data) throws IOException {

@Override
public boolean delete(String tenantId, URI uri) throws IOException {
return !deleteByPrefix(tenantId, uri).isEmpty();
FileAttributes fileAttributes;
try {
fileAttributes = getAttributes(tenantId, uri);
} catch (FileNotFoundException e) {
return false;
}
if(fileAttributes.getType() == FileAttributes.FileType.Directory) {
deleteByPrefix(tenantId, uri.getPath().endsWith("/") ? uri : URI.create(uri + "/"));
}

return deleteSingleObject(getPath(tenantId, uri));
}

private boolean deleteSingleObject(String path) {
DeleteObjectRequest deleteRequest = DeleteObjectRequest.builder()
.bucket(s3Config.getBucket())
.key(path)
.build();

return s3Client.deleteObject(deleteRequest).sdkHttpResponse().isSuccessful();
}

@Override
Expand Down Expand Up @@ -289,11 +308,7 @@ private void move(String oldKey, String newKey) {
.build();
s3Client.copyObject(copyRequest);

DeleteObjectRequest deleteRequest = DeleteObjectRequest.builder()
.bucket(s3Config.getBucket())
.key(oldKey)
.build();
s3Client.deleteObject(deleteRequest);
deleteSingleObject(oldKey);
}

@Override
Expand Down

0 comments on commit f34460d

Please sign in to comment.