修复单线程下载时,文件已经完成,重复下载回调下载失败的问题

修复一个重新下载文件时,同名路径文件没有被被删除的问题
pull/907/head
laoyuyu 4 years ago
parent 840facd1cc
commit d7d081ffb1
  1. 3
      DEV_LOG.md
  2. 5
      HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDTTBuilderAdapter.java
  3. 10
      PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java
  4. 15
      PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalThreadStateManager.java
  5. 2
      PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java
  6. 2
      PublicComponent/src/main/java/com/arialyy/aria/util/FileUtil.java
  7. 2
      app/src/main/assets/aria_config.xml
  8. 7
      app/src/main/java/com/arialyy/simple/core/download/HttpDownloadModule.java
  9. 2
      app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java

@ -1,4 +1,7 @@
## 开发日志
+ v_3.8.16
- 修复单线程下载时,文件已经完成,重复下载回调下载失败的问题
- 修复一个重新下载文件时,同名路径文件没有被被删除的问题
+ v_3.8.15 (2020/11/9)
- 修复不支持断点的连接下载失败问题,https://github.com/AriaLyy/Aria/issues/771
- 修复iv不存在时,索引文件异常的问题,https://github.com/AriaLyy/Aria/issues/780

@ -35,10 +35,13 @@ final class HttpDTTBuilderAdapter extends AbsNormalTTBuilderAdapter {
BufferedRandomAccessFile file = null;
try {
if (totalThreadNum > 1 && !record.isBlock) {
file = new BufferedRandomAccessFile(new File(getTempFile().getPath()), "rwd", 8192);
file = new BufferedRandomAccessFile(getTempFile().getPath(), "rwd", 8192);
//设置文件长度
file.setLength(getEntity().getFileSize());
}
if (getTempFile().exists()) {
FileUtil.deleteFile(getTempFile());
}
return true;
} catch (IOException e) {
e.printStackTrace();

@ -76,7 +76,7 @@ public class RecordHelper {
tr.endLocation = endL;
}
}
mWrapper.setNewTask(false);
//mWrapper.setNewTask(false);
}
/**
@ -125,8 +125,8 @@ public class RecordHelper {
continue;
}
long realLocation =
tr.threadId * normalRectLen + blockFileLen; //正常情况下,该线程的startLocation的位置
//正常情况下,该线程的startLocation的位置
long realLocation = tr.threadId * normalRectLen + blockFileLen;
/*
* 检查记录文件
*/
@ -147,7 +147,7 @@ public class RecordHelper {
}
}
}
mWrapper.setNewTask(false);
//mWrapper.setNewTask(false);
}
/**
@ -190,7 +190,7 @@ public class RecordHelper {
tr.isComplete = false;
}
}
mWrapper.setNewTask(false);
//mWrapper.setNewTask(false);
}
/**

@ -105,16 +105,16 @@ public class NormalThreadStateManager implements IThreadStateManager {
// mergerSFtp();
// mListener.onComplete();
//} else
if (mTaskRecord.isBlock) {
if (mTaskRecord.isBlock || mTaskRecord.threadNum == 1) {
if (mergeFile()) {
mListener.onComplete();
} else {
mListener.onFail(false, null);
}
} else {
mListener.onComplete();
quitLooper();
break;
}
mListener.onComplete();
quitLooper();
}
break;
@ -248,8 +248,13 @@ public class NormalThreadStateManager implements IThreadStateManager {
*/
private boolean mergeFile() {
if (mTaskRecord.threadNum == 1) {
File targetFile = new File(mTaskRecord.filePath);
if (targetFile.exists() && targetFile.length() == mTaskRecord.fileLength){
return true;
}
FileUtil.deleteFile(targetFile);
File partFile = new File(String.format(IRecordHandler.SUB_PATH, mTaskRecord.filePath, 0));
return partFile.renameTo(new File(mTaskRecord.filePath));
return partFile.renameTo(targetFile);
}
List<String> partPath = new ArrayList<>();

@ -310,7 +310,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
}
@Override public synchronized void updateCompleteState() {
ALog.i(TAG, String.format("任务【%s】线程__%s__完成", getTaskWrapper().getKey(), mRecord.threadId));
ALog.i(TAG, String.format("任务【%s】线程__%s__完成, blockSize = %s", getTaskWrapper().getKey(), mRecord.threadId, mConfig.tempFile.length()));
writeConfig(true, mRecord.endLocation);
// 进度发送不是实时的,发送完成任务前,需要更新一次进度
sendRunningState();

@ -25,6 +25,7 @@ import android.os.StatFs;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.AriaConfig;
import java.io.BufferedReader;
import java.io.File;
@ -322,6 +323,7 @@ public class FileUtil {
* @return {@code true} 合并成功{@code false}合并失败
*/
public static boolean mergeFile(String targetPath, List<String> subPaths) {
Log.d(TAG, "开始合并文件");
File file = new File(targetPath);
FileOutputStream fos = null;
FileChannel foc = null;

@ -44,7 +44,7 @@
3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间;
对于采用多线程的任务或旧任务,依然采用原来的文件空间占用方式;
-->
<threadNum value="3"/>
<threadNum value="1"/>
<!--设置下载队列最大任务数, 默认为2-->
<maxTaskNum value="1"/>

@ -51,10 +51,11 @@ public class HttpDownloadModule extends BaseViewModule {
//String url = AppUtil.getConfigValue(context, HTTP_URL_KEY, defUrl);
//String url = "http://fdfs.speedata.cn:9989/group1/M00/00/05/rBGFrl3fdAKAVJwfMtSa9R18wLU139.zip";
//String url = "http://9.9.9.28:8088/files/update.zip";
//String url = "https://y.qq.com/download/import/QQMusic-import-1.2.1.zip";
String url = "https://gitee.com/huang-junhua/iptv/raw/master/guonei.m3u8";
String url = "https://y.qq.com/download/import/QQMusic-import-1.2.1.zip";
//String url = "https://gitee.com/huang-junhua/iptv/raw/master/guonei.m3u8";
//String url = "http://v.kjjl100.com/kz/zx/cj/2020cjswxdb/1.mp4";
//String url = "https://static.runoob.com/images/demo/demo2.jpg";
String filePath = "/mnt/sdcard/xxx.m3u8";
String filePath = "/mnt/sdcard/qq.zip";
singDownloadInfo = Aria.download(context).getFirstDownloadEntity(url);
if (singDownloadInfo == null) {

@ -266,7 +266,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
if (task.getKey().equals(mUrl)) {
Toast.makeText(SingleTaskActivity.this, getString(R.string.download_success),
Toast.LENGTH_SHORT).show();
//ALog.d(TAG, "文件md5: 9886e90f014d462b560dcec9c327bdb7");
ALog.d(TAG, "文件md5: e088677570afe2e9f847cc8159b932dd");
ALog.d(TAG, "下载完成的文件md5: " + CommonUtil.getFileMD5(new File(task.getFilePath())));
getBinding().pl.setInfo(task.getEntity());
getBinding().pl.setProgress(100);

Loading…
Cancel
Save