fix FileUtil.move

This commit is contained in:
winlans 2023-02-10 18:15:45 +08:00
parent d0a2b90c55
commit 2d311a6b90
2 changed files with 12 additions and 1 deletions

View File

@ -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;
}

View File

@ -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);
}
}