From 8785bb28756f24584a6b59519548b6171407a056 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Thu, 27 Aug 2020 20:43:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B7=AF=E5=BE=84=E4=B8=8D?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=86=99=E7=9A=84=E5=88=A4=E6=96=AD=EF=BC=8C?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=97=B6=EF=BC=8C=E5=A6=82=E6=9E=9C=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E4=B8=8D=E5=8F=AF=E5=86=99=EF=BC=8C=E5=B0=86=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=A4=B1=E8=B4=A5=E5=9B=9E=E8=B0=83=20https://github.?= =?UTF-8?q?com/AriaLyy/Aria/issues/750?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aria/core/download/CheckDEntityUtil.java | 7 ++++- .../aria/core/download/CheckDGEntityUtil.java | 26 ++++++++++++------- .../core/download/CheckFtpDirEntityUtil.java | 20 +++++++------- DEV_LOG.md | 3 +++ .../java/com/arialyy/aria/util/FileUtil.java | 2 +- README.md | 1 + 6 files changed, 39 insertions(+), 20 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java index 22e024e8..17a5e193 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java @@ -110,7 +110,12 @@ public class CheckDEntityUtil implements ICheckEntityUtil { if (TextUtils.isEmpty(filePath)) { ALog.e(TAG, "下载失败,文件保存路径为null"); return false; - } else if (!filePath.startsWith("/")) { + } + if (!FileUtil.canWrite(filePath)){ + ALog.e(TAG, String.format("路径【%s】不可写", filePath)); + return false; + } + if (!filePath.startsWith("/")) { ALog.e(TAG, String.format("下载失败,文件保存路径【%s】错误", filePath)); return false; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/CheckDGEntityUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/CheckDGEntityUtil.java index f540e770..5370f800 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/CheckDGEntityUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/CheckDGEntityUtil.java @@ -23,6 +23,7 @@ import com.arialyy.aria.core.inf.IOptionConstant; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CheckUtil; +import com.arialyy.aria.util.FileUtil; import com.arialyy.aria.util.RecordUtil; import java.io.File; import java.util.ArrayList; @@ -62,33 +63,40 @@ public class CheckDGEntityUtil implements ICheckEntityUtil { * @return {@code true} 合法 */ private boolean checkDirPath() { - if (TextUtils.isEmpty(mWrapper.getDirPathTemp())) { + String dirPath = mWrapper.getDirPathTemp(); + + if (TextUtils.isEmpty(dirPath)) { ALog.e(TAG, "文件夹路径不能为null"); return false; - } else if (!mWrapper.getDirPathTemp().startsWith("/")) { - ALog.e(TAG, String.format("文件夹路径【%s】错误", mWrapper.getDirPathTemp())); + } + if (!FileUtil.canWrite(dirPath)){ + ALog.e(TAG, String.format("路径【%s】不可写", dirPath)); + return false; + } + if (!dirPath.startsWith("/")) { + ALog.e(TAG, String.format("文件夹路径【%s】错误", dirPath)); return false; } - File file = new File(mWrapper.getDirPathTemp()); + File file = new File(dirPath); if (file.isFile()) { - ALog.e(TAG, String.format("路径【%s】是文件,请设置文件夹路径", mWrapper.getDirPathTemp())); + ALog.e(TAG, String.format("路径【%s】是文件,请设置文件夹路径", dirPath)); return false; } // 检查路径冲突 if (mWrapper.isNewTask() && !CheckUtil.checkDGPathConflicts(mWrapper.isIgnoreFilePathOccupy(), - mWrapper.getDirPathTemp())) { + dirPath)) { return false; } if (TextUtils.isEmpty(mEntity.getDirPath()) || !mEntity.getDirPath() - .equals(mWrapper.getDirPathTemp())) { + .equals(dirPath)) { if (!file.exists()) { file.mkdirs(); } needModifyPath = true; - mEntity.setDirPath(mWrapper.getDirPathTemp()); - ALog.i(TAG, String.format("文件夹路径改变,将更新文件夹路径为:%s", mWrapper.getDirPathTemp())); + mEntity.setDirPath(dirPath); + ALog.i(TAG, String.format("文件夹路径改变,将更新文件夹路径为:%s", dirPath)); } return true; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/CheckFtpDirEntityUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/CheckFtpDirEntityUtil.java index 3373ccd4..9e479fea 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/CheckFtpDirEntityUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/CheckFtpDirEntityUtil.java @@ -45,32 +45,34 @@ public class CheckFtpDirEntityUtil implements ICheckEntityUtil { * @return {@code true} 合法 */ private boolean checkDirPath() { - if (TextUtils.isEmpty(mWrapper.getDirPathTemp())) { + String dirPath = mWrapper.getDirPathTemp(); + if (TextUtils.isEmpty(dirPath)) { ALog.e(TAG, "文件夹路径不能为null"); return false; - } else if (!mWrapper.getDirPathTemp().startsWith("/")) { - ALog.e(TAG, String.format("文件夹路径【%s】错误", mWrapper.getDirPathTemp())); + } + if (!dirPath.startsWith("/")) { + ALog.e(TAG, String.format("文件夹路径【%s】错误", dirPath)); return false; } - File file = new File(mWrapper.getDirPathTemp()); + File file = new File(dirPath); if (file.isFile()) { - ALog.e(TAG, String.format("路径【%s】是文件,请设置文件夹路径", mWrapper.getDirPathTemp())); + ALog.e(TAG, String.format("路径【%s】是文件,请设置文件夹路径", dirPath)); return false; } // 检查路径冲突 if (mWrapper.isNewTask() && !CheckUtil.checkDGPathConflicts(mWrapper.isIgnoreFilePathOccupy(), - mWrapper.getDirPathTemp())) { + dirPath)) { return false; } if (TextUtils.isEmpty(mEntity.getDirPath()) || !mEntity.getDirPath() - .equals(mWrapper.getDirPathTemp())) { + .equals(dirPath)) { if (!file.exists()) { file.mkdirs(); } - mEntity.setDirPath(mWrapper.getDirPathTemp()); - ALog.i(TAG, String.format("文件夹路径改变,将更新文件夹路径为:%s", mWrapper.getDirPathTemp())); + mEntity.setDirPath(dirPath); + ALog.i(TAG, String.format("文件夹路径改变,将更新文件夹路径为:%s", dirPath)); } return true; } diff --git a/DEV_LOG.md b/DEV_LOG.md index 3326794e..a4d2ecc6 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,4 +1,7 @@ ## 开发日志 + + v_3.8.13 + - 修复spi机制的兼容问题,https://github.com/AriaLyy/Aria/issues/743 + - 增加路径不可以写的判断,下载时,如果路径不可写,将执行失败回调 https://github.com/AriaLyy/Aria/issues/750 + v_3.8.12 (2020/8/15) - 修复一个正则表达式导致的文件名保存号异常问题 https://github.com/AriaLyy/Aria/issues/715 - 修复一个匿名内部类中的内存溢出的问题 https://github.com/AriaLyy/Aria/issues/705 diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java b/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java index 0fbc8ead..d75410f3 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java @@ -691,7 +691,7 @@ public class FileUtil { return list; } - private static boolean canWrite(String dirPath) { + public static boolean canWrite(String dirPath) { File dir = new File(dirPath); if (dir.canWrite()) { return true; diff --git a/README.md b/README.md index 2c050b68..3edcd28c 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,7 @@ protected void onCreate(Bundle savedInstanceState) { ## 其他 有任何问题,可以在[issues](https://github.com/AriaLyy/Aria/issues)给我留言反馈。
在提交问题前,希望你已经查看过[wiki](https://aria.laoyuyu.me/aria_doc/)或搜索过[issues](https://github.com/AriaLyy/Aria/issues)。
+ [我的博客](https://www.laoyuyu.me) ## 捐赠 Aria是作业利用业余时间开发的一个项目,如果你喜欢我写的软件,可以考虑给我捐赠以支持我的工作