diff options
author | Keuin <[email protected]> | 2020-04-27 17:42:07 +0800 |
---|---|---|
committer | keuin <[email protected]> | 2020-04-27 17:42:07 +0800 |
commit | 7444c2b1f281b5b147717ba2a2ed6798c66a057b (patch) | |
tree | 8d8952b2f3aaf1e497e8667b80fc59b91536c822 /src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java | |
parent | 33857f4bc061d8dc01a6d9d10e108da7cd7c6d18 (diff) |
Refactored code for a better implementation of async and blocking task.
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java')
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java index be7734d..ee1a57e 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java @@ -1,5 +1,7 @@ package com.keuin.kbackupfabric.operation; +import com.keuin.kbackupfabric.operation.abstracts.InvokableAsyncBlockingOperation; +import com.keuin.kbackupfabric.util.BackupNameSuggestionProvider; import com.keuin.kbackupfabric.util.PrintUtil; import com.mojang.brigadier.context.CommandContext; import net.minecraft.server.MinecraftServer; @@ -14,19 +16,30 @@ import static com.keuin.kbackupfabric.util.PrintUtil.msgErr; import static com.keuin.kbackupfabric.util.PrintUtil.msgInfo; import static org.apache.commons.io.FileUtils.forceDelete; -class DeleteOperation extends AbstractConfirmableOperation { +public class DeleteOperation extends InvokableAsyncBlockingOperation { //private static final Logger LOGGER = LogManager.getLogger(); private final String backupName; private final CommandContext<ServerCommandSource> context; - DeleteOperation(CommandContext<ServerCommandSource> context, String backupName) { + public DeleteOperation(CommandContext<ServerCommandSource> context, String backupName) { + super("BackupDeletingWorker"); this.backupName = backupName; this.context = context; } @Override - public boolean confirm() { + public String toString() { + return String.format("deletion of %s", backupName); + } + + @Override + protected void async() { + delete(); + BackupNameSuggestionProvider.updateCandidateList(); + } + + private void delete() { MinecraftServer server = context.getSource().getMinecraftServer(); String backupFileName = getBackupFileName(backupName); PrintUtil.info("Deleting backup " + backupName); @@ -37,7 +50,7 @@ class DeleteOperation extends AbstractConfirmableOperation { String msg = "Failed to delete file " + backupFileName; PrintUtil.error(msg); msgErr(context, msg); - return false; + return; } try { if (!backupFile.delete()) @@ -48,11 +61,5 @@ class DeleteOperation extends AbstractConfirmableOperation { } while (backupFile.exists()); PrintUtil.info("Deleted backup " + backupName); msgInfo(context, "Deleted backup " + backupName); - return true; - } - - @Override - public String toString() { - return String.format("deletion of %s", backupName); } } |