From 17a97013490c9ce7cc55e55a99bbfb3fafce9e45 Mon Sep 17 00:00:00 2001 From: Looly Date: Tue, 5 Mar 2024 11:41:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DPathMover=E5=AF=B9=E7=9B=AE?= =?UTF-8?q?=E6=A0=87=E5=B7=B2=E5=AD=98=E5=9C=A8=E4=B8=94=E5=8F=AA=E8=AF=BB?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=8A=A5=E9=94=99=E9=94=99=E8=AF=AF=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 ++- .../src/main/java/cn/hutool/core/io/file/PathMover.java | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd07095ad..244faf230 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ # 🚀Changelog ------------------------------------------------------------------------------------------------------------- -# 5.8.27(2024-02-26) +# 5.8.27(2024-03-05) ### 🐣新特性 * 【extra 】 FreemarkerEngine修改默认版本参数 @@ -10,6 +10,7 @@ * 【core 】 HexUtil#format方法增加prefix参数(issue#I93PU9@Gitee) ### 🐞Bug修复 +* 【core 】 修复PathMover对目标已存在且只读文件报错错误问题(issue#I95CLT@Gitee) ------------------------------------------------------------------------------------------------------------- # 5.8.26(2024-02-10) diff --git a/hutool-core/src/main/java/cn/hutool/core/io/file/PathMover.java b/hutool-core/src/main/java/cn/hutool/core/io/file/PathMover.java index 926237426..9c0c0c037 100755 --- a/hutool-core/src/main/java/cn/hutool/core/io/file/PathMover.java +++ b/hutool-core/src/main/java/cn/hutool/core/io/file/PathMover.java @@ -101,9 +101,10 @@ public class PathMover { try { return Files.move(src, target, options); } catch (final IOException e) { - if (e instanceof FileAlreadyExistsException) { - // 目标文件已存在,直接抛出异常 - // issue#I4QV0L@Gitee + if (e instanceof FileAlreadyExistsException || e instanceof AccessDeniedException) { + // issue#I4QV0L@Gitee issue#I95CLT@Gitee + // FileAlreadyExistsException 目标已存在 + // AccessDeniedException 目标已存在且只读 throw new IORuntimeException(e); } // 移动失败,可能是跨分区移动导致的,采用递归移动方式