From a2120c3a4233e7759a72c7f8859801267a86c49e Mon Sep 17 00:00:00 2001 From: John Niang Date: Fri, 4 Jul 2025 12:00:08 +0800 Subject: [PATCH] Fix the problem of stopping local attachment deletion --- .../run/halo/s3os/S3OsAttachmentHandler.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java b/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java index 7e62ae4..d983352 100644 --- a/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java +++ b/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java @@ -77,18 +77,19 @@ public Mono upload(UploadContext uploadContext) { @Override public Mono delete(DeleteContext deleteContext) { - return Mono.just(deleteContext).filter(context -> this.shouldHandle(context.policy())) + return Mono.just(deleteContext) + .filter(context -> this.shouldHandle(context.policy())) .flatMap(context -> { var objectKey = getObjectKey(context.attachment()); if (objectKey == null) { log.warn( "Cannot obtain object key from attachment {}, skip deleting object from S3.", context.attachment().getMetadata().getName()); - return Mono.just(context); + return Mono.just(context.attachment()); } else if (MetadataUtil.nullSafeAnnotations(context.attachment()) .containsKey(SKIP_REMOTE_DELETION_ANNO)) { log.info("Skip deleting object {} from S3.", objectKey); - return Mono.just(context); + return Mono.just(context.attachment()); } var properties = S3OsProperties.convertFrom(deleteContext.configMap()); return Mono.using( @@ -106,12 +107,11 @@ public Mono delete(DeleteContext deleteContext) { log.info("Delete object {} from bucket {} successfully", objectKey, properties.getBucket()); }) - .thenReturn(context); - }) - // ignore when the object does not exist - .onErrorComplete(NoSuchKeyException.class::isInstance) - .onErrorMap(S3ExceptionHandler::map) - .thenReturn(deleteContext.attachment()); + // ignore when the object does not exist + .onErrorComplete(NoSuchKeyException.class::isInstance) + .onErrorMap(S3ExceptionHandler::map) + .thenReturn(context.attachment()); + }); } @Override