修复分块下载文件有时偏大的问题

pull/330/head
laoyuyu 6 years ago
parent d47ac22dfa
commit 1ca3ff900d
  1. 4
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  2. 8
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  3. 17
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  4. 2
      DEV_LOG.md
  5. 13
      README.md
  6. 2
      build.gradle

@ -392,10 +392,10 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
mCompleteThreadNum++; mCompleteThreadNum++;
} else { } else {
tr.isComplete = false; tr.isComplete = false;
if (realLocation < tr.startLocation) { if (realLocation != tr.startLocation) {
ALog.i(TAG, String.format("修正分块【%s】的进度记录为:%s", temp.getPath(), realLocation)); ALog.i(TAG, String.format("修正分块【%s】的进度记录为:%s", temp.getPath(), realLocation));
tr.startLocation = realLocation; tr.startLocation = realLocation;
} else if (realLocation > tr.endLocation) { }else if (realLocation > tr.endLocation) {
ALog.i(TAG, String.format("分块【%s】错误,将重新开始该分块", temp.getPath())); ALog.i(TAG, String.format("分块【%s】错误,将重新开始该分块", temp.getPath()));
temp.delete(); temp.delete();
tr.startLocation = i * blockLen; tr.startLocation = i * blockLen;

@ -18,11 +18,11 @@ package com.arialyy.aria.core.download;
import android.support.annotation.CheckResult; import android.support.annotation.CheckResult;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.delegate.HttpHeaderDelegate; import com.arialyy.aria.core.delegate.HttpHeaderDelegate;
import com.arialyy.aria.core.inf.IHttpHeaderTarget; import com.arialyy.aria.core.inf.IHttpHeaderTarget;
import com.arialyy.aria.core.manager.TEManager; import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.io.File; import java.io.File;
@ -67,7 +67,6 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
private void init() { private void init() {
mGroupName = CommonUtil.getMd5Code(mUrls); mGroupName = CommonUtil.getMd5Code(mUrls);
mTaskEntity = TEManager.getInstance().getGTEntity(DownloadGroupTaskEntity.class, mUrls); mTaskEntity = TEManager.getInstance().getGTEntity(DownloadGroupTaskEntity.class, mUrls);
//ALog.d(TAG, "gHash=" + mEntity.getSubEntities().get(0).hashCode() + "; subHash="+mEntity.getT)
mEntity = mTaskEntity.getEntity(); mEntity = mTaskEntity.getEntity();
if (mEntity != null) { if (mEntity != null) {
mDirPathTemp = mEntity.getDirPath(); mDirPathTemp = mEntity.getDirPath();
@ -239,6 +238,11 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> im
if (oldFile.exists()) { if (oldFile.exists()) {
oldFile.renameTo(new File(newPath)); oldFile.renameTo(new File(newPath));
} }
if (DbEntity.checkDataExist(DownloadEntity.class, "downloadPath=?", newPath)) {
ALog.w(TAG, String.format("更新文件名失败,路径【%s】已存在", newPath));
return;
}
CommonUtil.modifyTaskRecord(oldFile.getPath(), newPath); CommonUtil.modifyTaskRecord(oldFile.getPath(), newPath);
entity.setDownloadPath(newPath); entity.setDownloadPath(newPath);
taskEntity.setKey(newPath); taskEntity.setKey(newPath);

@ -21,10 +21,13 @@ import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.ICmd; import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.command.normal.CancelCmd; import com.arialyy.aria.core.command.normal.CancelCmd;
import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.common.TaskRecord;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.manager.TEManager; import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList; import java.util.ArrayList;
@ -35,7 +38,7 @@ import java.util.List;
*/ */
public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity> public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity>
implements ITarget<TARGET> { implements ITarget<TARGET> {
protected String TAG ; protected String TAG;
protected ENTITY mEntity; protected ENTITY mEntity;
protected TASK_ENTITY mTaskEntity; protected TASK_ENTITY mTaskEntity;
protected String mTargetName; protected String mTargetName;
@ -64,7 +67,17 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
ALog.d("AbsTarget", "任务正在下载,即将删除任务"); ALog.d("AbsTarget", "任务正在下载,即将删除任务");
cancel(); cancel();
} else { } else {
mEntity.deleteData(); if (mEntity instanceof AbsNormalEntity) {
TaskRecord record =
DbEntity.findFirst(TaskRecord.class, "TaskRecord.filePath=?", mTaskEntity.getKey());
if (record != null) {
CommonUtil.delTaskRecord(record, mTaskEntity.isRemoveFile(), (AbsNormalEntity) mEntity);
} else {
mEntity.deleteData();
}
} else if (mEntity instanceof DownloadGroupEntity) {
CommonUtil.delGroupTaskRecord(mTaskEntity.isRemoveFile(), ((DownloadGroupEntity) mEntity));
}
TEManager.getInstance().removeTEntity(mEntity.getKey()); TEManager.getInstance().removeTEntity(mEntity.getKey());
} }
} }

@ -1,4 +1,6 @@
## 开发日志 ## 开发日志
+ v_3.4.7
- 修复分块任务异常操作导致的问题
+ v_3.4.6 + v_3.4.6
- 修复android 4.4.4 版本多dex下无法进行回调的问题 - 修复android 4.4.4 版本多dex下无法进行回调的问题
- 新增`updateUrl(newUrl)`用于修改任务的url,[see](https://aria.laoyuyu.me/aria_doc/api/task_handle.html#%E6%9B%B4%E6%96%B0%E4%BB%BB%E5%8A%A1url) - 新增`updateUrl(newUrl)`用于修改任务的url,[see](https://aria.laoyuyu.me/aria_doc/api/task_handle.html#%E6%9B%B4%E6%96%B0%E4%BB%BB%E5%8A%A1url)

@ -31,8 +31,8 @@ Aria有以下特点:
[![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion)
[![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion)
```java ```java
compile 'com.arialyy.aria:aria-core:3.4.6' compile 'com.arialyy.aria:aria-core:3.4.7'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.4.6' annotationProcessor 'com.arialyy.aria:aria-compiler:3.4.7'
``` ```
如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:<last-version>'`替换为 如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:<last-version>'`替换为
``` ```
@ -100,13 +100,8 @@ protected void onCreate(Bundle savedInstanceState) {
### 版本日志 ### 版本日志
+ v_3.4.6 + v_3.4.7
- 修复android 4.4.4 版本多dex下无法进行回调的问题 - 修复分块任务异常操作导致的问题
- 新增`updateUrl(newUrl)`用于修改任务的url,[see](https://aria.laoyuyu.me/aria_doc/api/task_handle.html#%E6%9B%B4%E6%96%B0%E4%BB%BB%E5%8A%A1url)
- 优化分块下载
- 修复了字符串中有特殊字符导致的路径冲突问题;修复ftp分块下载失败问题
- 修复连接中有`+`导致的地址呗使用问题。
- 修复表重复创建导致的崩溃问题 https://github.com/AriaLyy/Aria/issues/264
[更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md)

@ -39,7 +39,7 @@ task clean(type: Delete) {
ext { ext {
userOrg = 'arialyy' userOrg = 'arialyy'
groupId = 'com.arialyy.aria' groupId = 'com.arialyy.aria'
publishVersion = '3.4.6' publishVersion = '3.4.7'
// publishVersion = '1.0.3' //FTP插件 // publishVersion = '1.0.3' //FTP插件
repoName='maven' repoName='maven'
desc = 'android 下载框架' desc = 'android 下载框架'

Loading…
Cancel
Save