Skip to content

Commit 0f4e69e

Browse files
authored
Fix the problem of stopping local attachment deletion (#196)
Fixes halo-dev/halo#7610 ```release-note 修复无法删除本地物理文件的问题 ```
1 parent 42e27da commit 0f4e69e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/main/java/run/halo/s3os/S3OsAttachmentHandler.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,19 @@ public Mono<Attachment> upload(UploadContext uploadContext) {
7777

7878
@Override
7979
public Mono<Attachment> delete(DeleteContext deleteContext) {
80-
return Mono.just(deleteContext).filter(context -> this.shouldHandle(context.policy()))
80+
return Mono.just(deleteContext)
81+
.filter(context -> this.shouldHandle(context.policy()))
8182
.flatMap(context -> {
8283
var objectKey = getObjectKey(context.attachment());
8384
if (objectKey == null) {
8485
log.warn(
8586
"Cannot obtain object key from attachment {}, skip deleting object from S3.",
8687
context.attachment().getMetadata().getName());
87-
return Mono.just(context);
88+
return Mono.just(context.attachment());
8889
} else if (MetadataUtil.nullSafeAnnotations(context.attachment())
8990
.containsKey(SKIP_REMOTE_DELETION_ANNO)) {
9091
log.info("Skip deleting object {} from S3.", objectKey);
91-
return Mono.just(context);
92+
return Mono.just(context.attachment());
9293
}
9394
var properties = S3OsProperties.convertFrom(deleteContext.configMap());
9495
return Mono.using(
@@ -106,12 +107,11 @@ public Mono<Attachment> delete(DeleteContext deleteContext) {
106107
log.info("Delete object {} from bucket {} successfully",
107108
objectKey, properties.getBucket());
108109
})
109-
.thenReturn(context);
110-
})
111-
// ignore when the object does not exist
112-
.onErrorComplete(NoSuchKeyException.class::isInstance)
113-
.onErrorMap(S3ExceptionHandler::map)
114-
.thenReturn(deleteContext.attachment());
110+
// ignore when the object does not exist
111+
.onErrorComplete(NoSuchKeyException.class::isInstance)
112+
.onErrorMap(S3ExceptionHandler::map)
113+
.thenReturn(context.attachment());
114+
});
115115
}
116116

117117
@Override

0 commit comments

Comments
 (0)