mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix bug
This commit is contained in:
parent
09441650de
commit
d6ac2ef4bc
@ -4,6 +4,7 @@ import cn.hutool.core.text.StrUtil;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.CopyOption;
|
import java.nio.file.CopyOption;
|
||||||
|
import java.nio.file.DirectoryNotEmptyException;
|
||||||
import java.nio.file.FileAlreadyExistsException;
|
import java.nio.file.FileAlreadyExistsException;
|
||||||
import java.nio.file.FileSystem;
|
import java.nio.file.FileSystem;
|
||||||
import java.nio.file.FileVisitResult;
|
import java.nio.file.FileVisitResult;
|
||||||
@ -44,14 +45,17 @@ public class ZipCopyVisitor extends SimpleFileVisitor<Path> {
|
|||||||
@Override
|
@Override
|
||||||
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException {
|
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException {
|
||||||
final Path targetDir = resolveTarget(dir);
|
final Path targetDir = resolveTarget(dir);
|
||||||
if(StrUtil.isNotEmpty(targetDir.toString())){
|
if (StrUtil.isNotEmpty(targetDir.toString())) {
|
||||||
// 在目标的Zip文件中的相对位置创建目录
|
// 在目标的Zip文件中的相对位置创建目录
|
||||||
try {
|
try {
|
||||||
Files.copy(dir, targetDir, copyOptions);
|
Files.copy(dir, targetDir, copyOptions);
|
||||||
|
} catch (final DirectoryNotEmptyException ignore) {
|
||||||
|
// 目录已经存在,则跳过
|
||||||
} catch (final FileAlreadyExistsException e) {
|
} catch (final FileAlreadyExistsException e) {
|
||||||
if (false == Files.isDirectory(targetDir)) {
|
if (false == Files.isDirectory(targetDir)) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
// 目录非空情况下,跳过创建目录
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package cn.hutool.core.compress;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
|
public class IssueI5DRU0Test {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void appendTest(){
|
||||||
|
// https://gitee.com/dromara/hutool/issues/I5DRU0
|
||||||
|
// 向zip中添加文件的时候,如果添加的文件的父目录已经存在,会报错。实际中目录存在忽略即可。
|
||||||
|
ZipUtil.append(Paths.get("d:/test/zipTest.zip"), Paths.get("d:/test/zipTest"), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user