diff options
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/operation')
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java | 6 | ||||
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java | 15 | ||||
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/BackupFeedback.java | 1 | ||||
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/IncrementalBackupFeedback.java | 28 | ||||
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/PrimitiveBackupFeedback.java | 3 | ||||
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/operation/backup/method/BackupMethod.java (renamed from src/main/java/com/keuin/kbackupfabric/operation/backup/BackupMethod.java) | 6 | ||||
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/operation/backup/method/IncrementalBackupMethod.java | 17 | ||||
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/operation/backup/method/PrimitiveBackupMethod.java (renamed from src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMethod.java) | 2 |
8 files changed, 64 insertions, 14 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java index f8736c8..3183cf0 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java @@ -1,8 +1,8 @@ package com.keuin.kbackupfabric.operation; import com.keuin.kbackupfabric.operation.abstracts.InvokableAsyncBlockingOperation; -import com.keuin.kbackupfabric.operation.backup.BackupMethod; -import com.keuin.kbackupfabric.operation.backup.feedback.PrimitiveBackupFeedback; +import com.keuin.kbackupfabric.operation.backup.feedback.BackupFeedback; +import com.keuin.kbackupfabric.operation.backup.method.BackupMethod; import com.keuin.kbackupfabric.util.PrintUtil; import com.mojang.brigadier.context.CommandContext; import net.minecraft.server.MinecraftServer; @@ -52,7 +52,7 @@ public class BackupOperation extends InvokableAsyncBlockingOperation { String levelPath = getLevelPath(server); String backupFileName = getBackupFileName(customBackupName); - PrimitiveBackupFeedback result = backupMethod.backup(customBackupName,levelPath,backupSaveDirectory); + BackupFeedback result = backupMethod.backup(customBackupName,levelPath,backupSaveDirectory); if(result.isSuccess()) { // Restore old auto-save switch stat server.getWorlds().forEach(world -> world.savingDisabled = oldWorldsSavingDisabled.getOrDefault(world, true)); diff --git a/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java index b95c767..02b76f1 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java @@ -1,8 +1,8 @@ package com.keuin.kbackupfabric.operation; import com.keuin.kbackupfabric.operation.abstracts.InvokableBlockingOperation; -import com.keuin.kbackupfabric.operation.backup.BackupMethod; -import com.keuin.kbackupfabric.operation.backup.PrimitiveBackupMethod; +import com.keuin.kbackupfabric.operation.backup.method.BackupMethod; +import com.keuin.kbackupfabric.operation.backup.method.PrimitiveBackupMethod; import com.keuin.kbackupfabric.util.PrintUtil; import com.mojang.brigadier.context.CommandContext; import net.minecraft.server.MinecraftServer; @@ -94,10 +94,12 @@ public class RestoreOperation extends InvokableBlockingOperation { }while(--cnt > 0); //////////////////// - backupMethod.restore(backupFileName, levelPath, backupSavePath); - - //ServerRestartUtil.forkAndRestart(); - System.exit(111); + if (backupMethod.restore(backupFileName, levelPath, backupSavePath)) { + //ServerRestartUtil.forkAndRestart(); + System.exit(111); + } else { + PrintUtil.error("Failed to restore! server will not restart automatically."); + } } catch (SecurityException e) { PrintUtil.error("An exception occurred while restoring: " + e.getMessage()); @@ -105,6 +107,7 @@ public class RestoreOperation extends InvokableBlockingOperation { PrintUtil.error(e.toString()); PrintUtil.error("Failed to restore."); } + System.exit(0); // all failed restoration will eventually go here } } } diff --git a/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/BackupFeedback.java b/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/BackupFeedback.java index 92a9f39..0fe0766 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/BackupFeedback.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/BackupFeedback.java @@ -2,4 +2,5 @@ package com.keuin.kbackupfabric.operation.backup.feedback; public interface BackupFeedback { String getFeedback(); + boolean isSuccess(); } diff --git a/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/IncrementalBackupFeedback.java b/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/IncrementalBackupFeedback.java new file mode 100644 index 0000000..f39fde6 --- /dev/null +++ b/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/IncrementalBackupFeedback.java @@ -0,0 +1,28 @@ +package com.keuin.kbackupfabric.operation.backup.feedback; + +public class IncrementalBackupFeedback implements BackupFeedback { + private final boolean success; + private final int newFilesAdded; + + public IncrementalBackupFeedback(boolean success, int newFilesAdded) { + this.success = success; + this.newFilesAdded = newFilesAdded; + } + + @Override + public boolean isSuccess() { + return success; + } + + public long getNewFilesAdded() { + return newFilesAdded; + } + + @Override + public String getFeedback() { + if (success && newFilesAdded >= 0) + return String.format("File(s) added: %d.", newFilesAdded); + else + return ""; + } +} diff --git a/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/PrimitiveBackupFeedback.java b/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/PrimitiveBackupFeedback.java index 6d7a15b..3bcd012 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/PrimitiveBackupFeedback.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/PrimitiveBackupFeedback.java @@ -11,6 +11,7 @@ public class PrimitiveBackupFeedback implements BackupFeedback { this.backupSizeBytes = backupSizeBytes; } + @Override public boolean isSuccess() { return success; } @@ -22,7 +23,7 @@ public class PrimitiveBackupFeedback implements BackupFeedback { @Override public String getFeedback() { if (success && backupSizeBytes >= 0) - return String.format(" File size: %s.", getFriendlyFileSizeString(backupSizeBytes)); + return String.format("File size: %s.", getFriendlyFileSizeString(backupSizeBytes)); else return ""; } diff --git a/src/main/java/com/keuin/kbackupfabric/operation/backup/BackupMethod.java b/src/main/java/com/keuin/kbackupfabric/operation/backup/method/BackupMethod.java index b65a076..25a5952 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/backup/BackupMethod.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/backup/method/BackupMethod.java @@ -1,6 +1,6 @@ -package com.keuin.kbackupfabric.operation.backup; +package com.keuin.kbackupfabric.operation.backup.method; -import com.keuin.kbackupfabric.operation.backup.feedback.PrimitiveBackupFeedback; +import com.keuin.kbackupfabric.operation.backup.feedback.BackupFeedback; import java.io.IOException; @@ -15,7 +15,7 @@ public interface BackupMethod { * @param backupName the backup name. * @return if the backup operation succeed. */ - PrimitiveBackupFeedback backup(String backupName, String levelPath, String backupSaveDirectory) throws IOException; + BackupFeedback backup(String backupName, String levelPath, String backupSaveDirectory) throws IOException; boolean restore(String backupName, String levelPath, String backupSaveDirectory) throws IOException; diff --git a/src/main/java/com/keuin/kbackupfabric/operation/backup/method/IncrementalBackupMethod.java b/src/main/java/com/keuin/kbackupfabric/operation/backup/method/IncrementalBackupMethod.java new file mode 100644 index 0000000..1dacc44 --- /dev/null +++ b/src/main/java/com/keuin/kbackupfabric/operation/backup/method/IncrementalBackupMethod.java @@ -0,0 +1,17 @@ +package com.keuin.kbackupfabric.operation.backup.method; + +import com.keuin.kbackupfabric.operation.backup.feedback.IncrementalBackupFeedback; + +import java.io.IOException; + +public class IncrementalBackupMethod implements BackupMethod { + @Override + public IncrementalBackupFeedback backup(String backupName, String levelPath, String backupSaveDirectory) throws IOException { + return null; + } + + @Override + public boolean restore(String backupName, String levelPath, String backupSaveDirectory) throws IOException { + return false; + } +} diff --git a/src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMethod.java b/src/main/java/com/keuin/kbackupfabric/operation/backup/method/PrimitiveBackupMethod.java index 9c065a6..1f15346 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMethod.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/backup/method/PrimitiveBackupMethod.java @@ -1,4 +1,4 @@ -package com.keuin.kbackupfabric.operation.backup; +package com.keuin.kbackupfabric.operation.backup.method; import com.keuin.kbackupfabric.exception.ZipUtilException; import com.keuin.kbackupfabric.metadata.BackupMetadata; |