mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
修复ZipUtil.zip压缩到本目录时可能造成的死循环问题
This commit is contained in:
parent
146fb20881
commit
82a7417a9d
@ -59,6 +59,7 @@ public class ZipWriter implements Closeable {
|
||||
return new ZipWriter(out, charset);
|
||||
}
|
||||
|
||||
private File zipFile;
|
||||
private final ZipOutputStream out;
|
||||
|
||||
/**
|
||||
@ -75,6 +76,7 @@ public class ZipWriter implements Closeable {
|
||||
*/
|
||||
public ZipWriter(final File zipFile, final Charset charset) {
|
||||
this(getZipOutputStream(zipFile, charset));
|
||||
this.zipFile = zipFile;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -296,6 +298,11 @@ public class ZipWriter implements Closeable {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// issue#IAGYDG 检查加入的文件是否为压缩结果文件本身,避免死循环
|
||||
if (FileUtil.equals(file, zipFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果是文件或其它符号,则直接压缩该文件
|
||||
putEntry(subPath, FileUtil.getInputStream(file));
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2024. looly(loolly@aliyun.com)
|
||||
* Hutool is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* https://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
package org.dromara.hutool.core.compress;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* https://gitee.com/dromara/hutool/issues/IAGYDG
|
||||
*/
|
||||
public class IssueIAGYDGTest {
|
||||
@Test
|
||||
@Disabled
|
||||
void zipTest() {
|
||||
// 第一次压缩后,IssueIAGYDG.zip也会作为文件压缩到IssueIAGYDG.zip中,导致死循环
|
||||
final File filea = new File("d:/test/");
|
||||
final File fileb = new File("d:/test/IssueIAGYDG.zip");
|
||||
ZipUtil.zip(fileb, false, filea.listFiles());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user