From 368a5e4d1c3ab25319a0c15b6d637d748ca18903 Mon Sep 17 00:00:00 2001 From: Looly Date: Thu, 23 Apr 2020 12:01:53 +0800 Subject: [PATCH] fix FileUtil.remove bug --- CHANGELOG.md | 2 ++ hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java | 5 ++++- hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e616c389d..fc495b155 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * 【core 】 增加ThreadUtil.sleep和safeSleep的重载 * 【core 】 Sftp类增加toString方法(issue#I1F2T4@Gitee) * 【core 】 修改FileUtil.size逻辑,不存在的文件返回0 +* 【extra 】 Sftp.ls遇到文件不存在返回空集合,而非抛异常(issue#844@Github) ### Bug修复 * 【db 】 修复PageResult.isLast计算问题 @@ -17,6 +18,7 @@ * 【db 】 修复Page.addOrder无效问题(issue#I1F9MZ@Gitee) * 【json 】 修复JSONConvert转换日期空指针问题(issue#I1F8M2@Gitee) * 【core 】 修复XML中带注释Xpath解析导致空指针问题(issue#I1F2WI@Gitee) +* 【core 】 修复FileUtil.rename原文件无扩展名多点的问题(issue#839@Github) ------------------------------------------------------------------------------------------------------------- ## 5.3.1 (2020-04-17) diff --git a/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java b/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java index 3cd5d63ea..b798a8f4b 100644 --- a/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java @@ -1175,7 +1175,10 @@ public class FileUtil { */ public static File rename(File file, String newName, boolean isRetainExt, boolean isOverride) { if (isRetainExt) { - newName = newName.concat(".").concat(FileUtil.extName(file)); + final String extName = FileUtil.extName(file); + if(StrUtil.isNotBlank(extName)){ + newName = newName.concat(".").concat(extName); + } } final Path path = file.toPath(); final CopyOption[] options = isOverride ? new CopyOption[]{StandardCopyOption.REPLACE_EXISTING} : new CopyOption[]{}; diff --git a/hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java b/hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java index 2bc4d19c9..c16cfeb21 100644 --- a/hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java +++ b/hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java @@ -238,7 +238,10 @@ public class Sftp extends AbstractFtp { return LsEntrySelector.CONTINUE; }); } catch (SftpException e) { - throw new JschRuntimeException(e); + if(false == StrUtil.startWithIgnoreCase(e.getMessage(), "No such file")){ + throw new JschRuntimeException(e); + } + // 文件不存在忽略 } return fileNames; }