This commit is contained in:
Looly 2023-02-15 17:39:08 +08:00
parent ec3a1b2519
commit e2266f593f
2 changed files with 11 additions and 1 deletions

View File

@ -511,7 +511,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;
}

View File

@ -78,4 +78,13 @@ public class PathUtilTest {
final 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);
}
}