From e59bdf4ac0b66ce683be1bbc36852bfce6f70a63 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sun, 4 Oct 2020 13:43:15 +0800 Subject: Pump up --- .../operation/backup/BackupMethod.java | 5 +-- .../operation/backup/PrimitiveBackupMehtod.java | 42 ---------------------- .../operation/backup/PrimitiveBackupMethod.java | 42 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 44 deletions(-) delete mode 100644 src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMehtod.java create mode 100644 src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMethod.java (limited to 'src/main/java/com/keuin/kbackupfabric/operation/backup') diff --git a/src/main/java/com/keuin/kbackupfabric/operation/backup/BackupMethod.java b/src/main/java/com/keuin/kbackupfabric/operation/backup/BackupMethod.java index 97c609d..b0b77cb 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/backup/BackupMethod.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/backup/BackupMethod.java @@ -10,10 +10,11 @@ public interface BackupMethod { /** * Perform a backup with given method. The backup will be saved as the given name. - * Note: real file name is depended by the backup type. + * Note: real file name depends on the backup type. * @param backupName the backup name. + * @return if the backup operation succeed. */ - void backup(@NotNull String backupName, @NotNull String levelPath, @NotNull String backupSaveDirectory) throws IOException; + boolean backup(@NotNull String backupName, @NotNull String levelPath, @NotNull String backupSaveDirectory) throws IOException; BackupFileNameBuilder getBackupFileNameBuilder(); diff --git a/src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMehtod.java b/src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMehtod.java deleted file mode 100644 index 3c2a608..0000000 --- a/src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMehtod.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.keuin.kbackupfabric.operation.backup; - -import com.keuin.kbackupfabric.exception.ZipUtilException; -import com.keuin.kbackupfabric.metadata.BackupMetadata; -import com.keuin.kbackupfabric.util.PrintUtil; -import com.keuin.kbackupfabric.util.ZipUtil; -import com.keuin.kbackupfabric.util.backup.builder.BackupFileNameBuilder; -import com.keuin.kbackupfabric.util.backup.formatter.BackupFileNameFormatter; - -import java.io.File; -import java.io.IOException; -import java.time.LocalDate; -import java.time.LocalDateTime; - -public class PrimitiveBackupMehtod implements BackupMethod { - @Override - public boolean backup(String backupName, String levelPath, String backupSaveDirectory) throws IOException { - try { - String backupFileName = BackupFileNameBuilder.primitiveZipBackup().build(LocalDateTime.now(),backupName); - BackupMetadata backupMetadata = new BackupMetadata(System.currentTimeMillis(), backupName); - - PrintUtil.info(String.format("zip(srcPath=%s, destPath=%s)", levelPath, backupSaveDirectory)); - PrintUtil.info("Compressing level ..."); - ZipUtil.makeBackupZip(levelPath, backupSaveDirectory, backupFileName, backupMetadata); - - } catch (ZipUtilException exception) { - PrintUtil.info("Infinite recursive of directory tree detected, backup was aborted."); - return false; - } - return true; - } - - @Override - public BackupFileNameBuilder getBackupFileNameBuilder() { - return BackupFileNameBuilder.primitiveZipBackup(); - } - - @Override - public BackupFileNameFormatter getBackupFileNameFormatter() { - return BFNF; - } -} diff --git a/src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMethod.java b/src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMethod.java new file mode 100644 index 0000000..bb1c8cb --- /dev/null +++ b/src/main/java/com/keuin/kbackupfabric/operation/backup/PrimitiveBackupMethod.java @@ -0,0 +1,42 @@ +package com.keuin.kbackupfabric.operation.backup; + +import com.keuin.kbackupfabric.exception.ZipUtilException; +import com.keuin.kbackupfabric.metadata.BackupMetadata; +import com.keuin.kbackupfabric.util.PrintUtil; +import com.keuin.kbackupfabric.util.ZipUtil; +import com.keuin.kbackupfabric.util.backup.builder.BackupFileNameBuilder; +import com.keuin.kbackupfabric.util.backup.formatter.BackupFileNameFormatter; + +import java.io.File; +import java.io.IOException; +import java.time.LocalDate; +import java.time.LocalDateTime; + +public class PrimitiveBackupMethod implements BackupMethod { + @Override + public boolean backup(String backupName, String levelPath, String backupSaveDirectory) throws IOException { + try { + String backupFileName = BackupFileNameBuilder.primitiveZipBackup().build(LocalDateTime.now(),backupName); + BackupMetadata backupMetadata = new BackupMetadata(System.currentTimeMillis(), backupName); + + PrintUtil.info(String.format("zip(srcPath=%s, destPath=%s)", levelPath, backupSaveDirectory)); + PrintUtil.info("Compressing level ..."); + ZipUtil.makeBackupZip(levelPath, backupSaveDirectory, backupFileName, backupMetadata); + + } catch (ZipUtilException exception) { + PrintUtil.info("Infinite recursive of directory tree detected, backup was aborted."); + return false; + } + return true; + } + + @Override + public BackupFileNameBuilder getBackupFileNameBuilder() { + return BackupFileNameBuilder.primitiveZipBackup(); + } + + @Override + public BackupFileNameFormatter getBackupFileNameFormatter() { + return BFNF; + } +} -- cgit v1.2.3