Skip to content

Commit d91cf92

Browse files
committed
fix: 修复空文件下载时 FileAlreadyExistsException 和 WebdavProtocol 调试代码遗留问题
问题1: FileAlreadyExistsException - 位置: Work.java:438-444 - 原因: 下载空文件时,如果临时文件已存在(上次更新中断残留),Files.createFile() 会抛出异常导致程序崩溃 - 修复: 创建前先检查文件是否存在,存在则删除再创建 问题2: WebdavProtocol 调试代码遗留 - 位置: WebdavProtocol.java:137-141 - 原因: 代码中遗留了调试代码,条件 desc.length() > -999 永远为 true,导致 Webdav 协议下载文件时必定抛出异常,完全无法使用 - 修复: 删除遗留的调试代码
1 parent 3bcfd6c commit d91cf92

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ boolean run2(Servers server) throws IOException, McpatchBusinessException {
436436

437437
// 空文件不需要下载
438438
if (f.length == 0) {
439+
// 如果临时文件已存在(上次更新中断),先删除再创建
440+
if (Files.exists(f.tempPath)) {
441+
Files.delete(f.tempPath);
442+
}
439443
Files.createFile(f.tempPath);
440444
continue;
441445
}

src/main/java/com/github/balloonupdate/mcpatch/client/network/impl/WebdavProtocol.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,6 @@ public void downloadFile(String path, Range range, String desc, Path writeTo, On
134134
try (ContentLengthInputStream input = response.stream) {
135135
long contentLength = input.getLength();
136136

137-
if (desc.length() > -999)
138-
// throw new IOException("hahahaha");
139-
throw new McpatchBusinessException("bbbbbbbbbb");
140-
// throw new McpatchBusinessException("qqqqqqqqqqq", new IOException("hahahaha"));
141-
142137
try (OutputStream output = Files.newOutputStream(writeTo)) {
143138
byte[] buf = new byte[BytesUtils.chooseBufferSize(contentLength)];
144139

0 commit comments

Comments
 (0)