summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/util/backup/name
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/util/backup/name')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/backup/name/BackupFileNameEncoder.java8
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/backup/name/IncrementalBackupFileNameEncoder.java2
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/backup/name/PrimitiveBackupFileNameEncoder.java2
3 files changed, 9 insertions, 3 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/name/BackupFileNameEncoder.java b/src/main/java/com/keuin/kbackupfabric/util/backup/name/BackupFileNameEncoder.java
index 972403b..8ebc7ff 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/backup/name/BackupFileNameEncoder.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/backup/name/BackupFileNameEncoder.java
@@ -18,13 +18,19 @@ public interface BackupFileNameEncoder {
/**
* Extract custom and backup time from backup file name.
+ *
* @param fileName the backup file name.
* @return the information. If the given file name is invalid, return null.
*/
BackupBasicInformation decode(String fileName);
+ default boolean isValidFileName(String fileName) {
+ return decode(fileName) != null;
+ }
+
/**
* Check if the given string is a valid custom backup name.
+ *
* @param customName the custom backup name.
* @return if the name is valid.
*/
@@ -45,7 +51,7 @@ public interface BackupFileNameEncoder {
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm.ss");
- BackupBasicInformation(String customName, LocalDateTime time) {
+ protected BackupBasicInformation(String customName, LocalDateTime time) {
this.customName = customName;
this.time = time;
}
diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/name/IncrementalBackupFileNameEncoder.java b/src/main/java/com/keuin/kbackupfabric/util/backup/name/IncrementalBackupFileNameEncoder.java
index 3c35201..926f47c 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/backup/name/IncrementalBackupFileNameEncoder.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/backup/name/IncrementalBackupFileNameEncoder.java
@@ -24,7 +24,7 @@ public class IncrementalBackupFileNameEncoder implements BackupFileNameEncoder {
@Override
public BackupFileNameEncoder.BackupBasicInformation decode(String fileName) {
Pattern pattern = Pattern.compile(
- backupFileNamePrefix + "-" + "([0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2})_(.+)\\.kbi"
+ "^" + backupFileNamePrefix + "-" + "([0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2})_(.+)\\.kbi" + "$"
);
Matcher matcher = pattern.matcher(fileName);
if (matcher.find()) {
diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/name/PrimitiveBackupFileNameEncoder.java b/src/main/java/com/keuin/kbackupfabric/util/backup/name/PrimitiveBackupFileNameEncoder.java
index bcba114..ef15ae7 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/backup/name/PrimitiveBackupFileNameEncoder.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/backup/name/PrimitiveBackupFileNameEncoder.java
@@ -20,7 +20,7 @@ public class PrimitiveBackupFileNameEncoder implements BackupFileNameEncoder {
@Override
public BackupBasicInformation decode(String fileName) {
Pattern pattern = Pattern.compile(
- backupFileNamePrefix + "-" + "([0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2})_(.+)\\.zip"
+ "^" + backupFileNamePrefix + "-" + "([0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2})_(.+)\\.zip" + "$"
);
Matcher matcher = pattern.matcher(fileName);
if (matcher.find()) {