增加路径不可以写的判断,下载时,如果路径不可写,将执行失败回调 https://github.com/AriaLyy/Aria/issues/750
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
File file = new File(mWrapper.getDirPathTemp());
|
||||
if (!dirPath.startsWith("/")) {
|
||||
ALog.e(TAG, String.format("文件夹路径【%s】错误", dirPath));
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -181,6 +181,7 @@ protected void onCreate(Bundle savedInstanceState) {
|
||||
## 其他
|
||||
有任何问题,可以在[issues](https://github.com/AriaLyy/Aria/issues)给我留言反馈。</br>
|
||||
在提交问题前,希望你已经查看过[wiki](https://aria.laoyuyu.me/aria_doc/)或搜索过[issues](https://github.com/AriaLyy/Aria/issues)。</br>
|
||||
[我的博客](https://www.laoyuyu.me)
|
||||
|
||||
## 捐赠
|
||||
Aria是作业利用业余时间开发的一个项目,如果你喜欢我写的软件,可以考虑给我捐赠以支持我的工作</br>
|
||||
|
||||
Reference in New Issue
Block a user