Skip to content

Commit cd63f32

Browse files
committed
fix: 修复 Files.move 时的 FileAlreadyExistsException
在 Android 虚拟化环境(如 Fold Craft Launcher)中,文件系统操作可能存在延迟。 虽然代码在移动前尝试删除目标文件,但 Files.move() 仍可能因文件系统缓存 而抛出 FileAlreadyExistsException。 添加 StandardCopyOption.REPLACE_EXISTING 选项作为保底方案,确保移动操作 能够正确覆盖目标文件。 修复日志中的错误: FileAlreadyExistsException: .../options.txt
1 parent 72864ca commit cd63f32

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

  • src/main/java/com/github/balloonupdate/mcpatch/client

src/main/java/com/github/balloonupdate/mcpatch/client/Work.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.nio.charset.StandardCharsets;
1717
import java.nio.file.Files;
1818
import java.nio.file.Path;
19+
import java.nio.file.StandardCopyOption;
1920
import java.nio.file.attribute.FileTime;
2021
import java.util.ArrayList;
2122
import java.util.Collections;
@@ -532,7 +533,7 @@ boolean run2(Servers server) throws IOException, McpatchBusinessException {
532533
Log.debug(" To " + to);
533534

534535
if (Files.exists(from)) {
535-
Files.move(from, to);
536+
Files.move(from, to, StandardCopyOption.REPLACE_EXISTING);
536537
}
537538
}
538539

@@ -585,7 +586,7 @@ boolean run2(Servers server) throws IOException, McpatchBusinessException {
585586
throw new McpatchBusinessException("移动临时文件时,要被移动的源文件不存在: " + from);
586587
}
587588

588-
Files.move(from, to);
589+
Files.move(from, to, StandardCopyOption.REPLACE_EXISTING);
589590
}
590591

591592
// 6.清理临时文件夹

0 commit comments

Comments
 (0)