summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gradle.properties2
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java20
-rw-r--r--src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java4
3 files changed, 16 insertions, 10 deletions
diff --git a/gradle.properties b/gradle.properties
index 4d7ec6c..ccc429a 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -6,7 +6,7 @@ minecraft_version=1.14.4
yarn_mappings=1.14.4+build.18
loader_version=0.11.0
# Mod Properties
-mod_version=1.4.0
+mod_version=1.4.1
maven_group=com.keuin.kbackupfabric
archives_base_name=kbackup-fabric
# Dependencies
diff --git a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java
index c670cf1..0fa9d77 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java
@@ -4,7 +4,10 @@ import com.keuin.kbackupfabric.exception.ZipUtilException;
import com.keuin.kbackupfabric.metadata.BackupMetadata;
import java.io.*;
+import java.util.Collections;
import java.util.Enumeration;
+import java.util.Optional;
+import java.util.Set;
import java.util.zip.*;
public final class ZipUtil {
@@ -15,9 +18,10 @@ public final class ZipUtil {
* @param srcRootDir 压缩文件夹根目录的子路径
* @param file 当前递归压缩的文件或目录对象
* @param zipOutputStream 压缩文件存储对象
+ * @param filesSkipping 被忽略的文件
* @throws IOException IO Error
*/
- private static void zip(String srcRootDir, File file, ZipOutputStream zipOutputStream) throws IOException {
+ private static void zip(String srcRootDir, File file, ZipOutputStream zipOutputStream, Set<String> filesSkipping) throws IOException {
if (file == null) {
return;
}
@@ -26,7 +30,8 @@ public final class ZipUtil {
return; // Reject
// 如果是文件,则直接压缩该文件
- if (file.isFile()) {
+ boolean skipping = Optional.ofNullable(filesSkipping).orElse(Collections.emptySet()).contains(file.getName());
+ if (file.isFile() && !skipping) {
int count, bufferLen = 1024;
byte[] data = new byte[bufferLen];
@@ -36,6 +41,8 @@ public final class ZipUtil {
if (index != -1) {
subPath = subPath.substring(srcRootDir.length() + File.separator.length());
}
+
+ // 写入压缩包
ZipEntry entry = new ZipEntry(subPath);
zipOutputStream.putNextEntry(entry);
BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file));
@@ -44,14 +51,13 @@ public final class ZipUtil {
}
inputStream.close();
zipOutputStream.closeEntry();
- }
- // 如果是目录,则压缩整个目录
- else {
+ } else {
+ // 如果是目录,则压缩整个目录
// 压缩目录中的文件或子目录
File[] childFileList = file.listFiles();
if (childFileList != null) {
for (File value : childFileList)
- zip(srcRootDir, value, zipOutputStream);
+ zip(srcRootDir, value, zipOutputStream, filesSkipping);
}
}
}
@@ -127,7 +133,7 @@ public final class ZipUtil {
}
}
//调用递归压缩方法进行目录或文件压缩
- zip(srcRootDir, srcFile, zipOutputStream);
+ zip(srcRootDir, srcFile, zipOutputStream, Collections.singleton("session.lock"));
zipOutputStream.flush();
} finally {
try {
diff --git a/src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java b/src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java
index 58e1711..30f2d44 100644
--- a/src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java
+++ b/src/test/java/com/keuin/kbackupfabric/operation/backup/method/ConfiguredIncrementalBackupMethodTest.java
@@ -15,12 +15,12 @@ import static org.junit.Assert.*;
public class ConfiguredIncrementalBackupMethodTest {
- private final String testTempPath = "R:\\";
+ private final String testTempPath = (new File("R:\\").isDirectory()) ? "R:\\" : ".\\testfile\\ConfiguredIncrementalBackupMethodTest";
private final String sourceDirectoryName = "source";
private final String destDirectoryName = "destination";
private final String indexFileName = "index";
- private final double directoryFactor = 0.03;
+ private final double directoryFactor = 0.02;
private final double fileFactor = 0.05;
private final int maxRandomFileSizeBytes = 1024 * 1024 * 16;
private final Function<Integer, Integer> scaleDecayFunc = (x) -> x - 1;