mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-06 21:58:03 +08:00
commit
66949c9b4b
@ -488,7 +488,8 @@ public class PathUtil {
|
||||
Assert.notNull(src, "Src path must be not null !");
|
||||
Assert.notNull(target, "Target path must be not null !");
|
||||
|
||||
if(equals(src, target)){
|
||||
// issue#2893 target 不存在导致NoSuchFileException
|
||||
if (Files.exists(target) && equals(src, target)) {
|
||||
// issue#2845,当用户传入目标路径与源路径一致时,直接返回,否则会导致删除风险。
|
||||
return target;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
@ -78,4 +79,13 @@ public class PathUtilTest {
|
||||
String contentType = FileUtil.getMimeType("a001.7z");
|
||||
Assert.assertEquals("application/x-7z-compressed", contentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* issue#2893 target不存在空导致异常
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
public void moveTest2(){
|
||||
PathUtil.move(Paths.get("D:\\project\\test1.txt"), Paths.get("D:\\project\\test2.txt"), false);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user