Merge pull request #2894 from winlans/v5-dev

fix FileUtil.move
This commit is contained in:
Golden Looly 2023-02-15 17:39:37 +08:00 committed by GitHub
commit 66949c9b4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
}
}