From 67a101efeb1050de4479aeaf69e27616d5ca1fee Mon Sep 17 00:00:00 2001 From: John Niang Date: Wed, 23 Aug 2023 12:16:13 +0800 Subject: [PATCH] Fix the problem that it is always in deleting phase after deleting backups (#4462) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /area core /milestone 2.9.x #### What this PR does / why we need it: Before this, if we deleted a backup without filename, the BackupReconciler would get stuck infinitely. And no further backups would be reconciled. This PR fixes the problem that it is always in deleting phase after deleting backups. #### Does this PR introduce a user-facing change? ```release-note 修复因备份数据状态不正常导致无法正常删除备份的问题。 ``` --- .../halo/app/migration/impl/MigrationServiceImpl.java | 4 +++- .../app/migration/impl/MigrationServiceImplTest.java | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/run/halo/app/migration/impl/MigrationServiceImpl.java b/application/src/main/java/run/halo/app/migration/impl/MigrationServiceImpl.java index 27bb87214..9e3a668ba 100644 --- a/application/src/main/java/run/halo/app/migration/impl/MigrationServiceImpl.java +++ b/application/src/main/java/run/halo/app/migration/impl/MigrationServiceImpl.java @@ -26,6 +26,7 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; import org.springframework.web.server.ServerWebInputException; import reactor.core.Exceptions; import reactor.core.publisher.Flux; @@ -145,7 +146,8 @@ public class MigrationServiceImpl implements MigrationService { public Mono cleanup(Backup backup) { return Mono.create(sink -> { var status = backup.getStatus(); - if (status == null || status.getFilename() == null) { + if (status == null || !StringUtils.hasText(status.getFilename())) { + sink.success(); return; } var filename = status.getFilename(); diff --git a/application/src/test/java/run/halo/app/migration/impl/MigrationServiceImplTest.java b/application/src/test/java/run/halo/app/migration/impl/MigrationServiceImplTest.java index 1bbac7df3..808ae0c65 100644 --- a/application/src/test/java/run/halo/app/migration/impl/MigrationServiceImplTest.java +++ b/application/src/test/java/run/halo/app/migration/impl/MigrationServiceImplTest.java @@ -153,6 +153,15 @@ class MigrationServiceImplTest { assertTrue(Files.notExists(backupFile)); } + @Test + void cleanupBackupWithNoFilename() { + var backup = createSucceededBackup("fake-backup", null); + StepVerifier.create(migrationService.cleanup(backup)) + .verifyComplete(); + verify(haloProperties, never()).getWorkDir(); + verify(backupRoot, never()).get(); + } + @Test void downloadBackupTest() throws IOException { var backupFile = tempDir.resolve("workdir").resolve("backups").resolve("backup.zip");