fix del bug

This commit is contained in:
Looly 2021-08-02 12:08:57 +08:00
parent e4848d5fe7
commit 69b981e8c0
3 changed files with 22 additions and 11 deletions

View File

@ -3,7 +3,7 @@
-------------------------------------------------------------------------------------------------------------
# 5.7.7 (2021-08-01)
# 5.7.7 (2021-08-02)
### 🐣新特性
* 【core 】 增加LookupFactory和MethodHandleUtilissue#I42TVY@Gitee
@ -18,6 +18,7 @@
* 【jwt 】 修复JWTUtil中几个方法非static的问题issue#1735@Github
* 【core 】 修复SpringUtil无法处理autowired问题pr#388@Gitee
* 【core 】 修复AbsCollValueMap中常量拼写错误pr#1736@Github
* 【core 】 修复FileUtil.del在文件只读情况下无法删除的问题pr#389@Gitee
-------------------------------------------------------------------------------------------------------------

View File

@ -710,10 +710,7 @@ public class FileUtil extends PathUtil {
// 删除文件或清空后的目录
try {
Files.delete(file.toPath());
} catch (AccessDeniedException access) {
// 可能遇到只读文件无法删除.使用 file 方法删除
return file.delete();
delFile(file.toPath());
} catch (IOException e) {
throw new IORuntimeException(e);
}

View File

@ -135,12 +135,7 @@ public class PathUtil {
if (isDirectory(path)) {
Files.walkFileTree(path, DelVisitor.INSTANCE);
} else {
try {
Files.delete(path);
} catch (AccessDeniedException access) {
// 可能遇到只读文件无法删除.使用 file 方法删除
return path.toFile().delete();
}
delFile(path);
}
} catch (IOException e) {
throw new IORuntimeException(e);
@ -596,4 +591,22 @@ public class PathUtil {
public static Path mkParentDirs(Path path) {
return mkdir(path.getParent());
}
/**
* 删除文件不追踪软链
*
* @param path 文件对象
* @throws IORuntimeException IO异常
* @since 5.7.7
*/
protected static void delFile(Path path) throws IOException {
try {
Files.delete(path);
}catch (AccessDeniedException e) {
// 可能遇到只读文件无法删除.使用 file 方法删除
if(false == path.toFile().delete()) {
throw e;
}
}
}
}