- 修复组任务,其中一个子任务在获取文件长度失败后,重新恢复组合任务,组合任务状态变为完成的问题 https://github.com/AriaLyy/Aria/issues/628

This commit is contained in:
laoyuyu
2020-03-03 21:03:37 +08:00
parent 54cbdb7ee0
commit 669ac6b09c
15 changed files with 131 additions and 99 deletions

View File

@@ -30,6 +30,7 @@ import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 组合任务文件信息,用于获取长度未知时,组合任务的长度
@@ -41,8 +42,8 @@ public final class HttpDGInfoTask implements IInfoTask {
private final Object LOCK = new Object();
private ExecutorService mPool = null;
private boolean getLenComplete = false;
private int count;
private int failCount;
private AtomicInteger count = new AtomicInteger();
private AtomicInteger failCount = new AtomicInteger();
private DownloadGroupListener listener;
/**
@@ -50,18 +51,18 @@ public final class HttpDGInfoTask implements IInfoTask {
*/
private Callback subCallback = new Callback() {
@Override public void onSucceed(String url, CompleteInfo info) {
count++;
checkGetSizeComplete(count, failCount);
count.getAndIncrement();
checkGetSizeComplete(count.get(), failCount.get());
ALog.d(TAG, "获取子任务信息完成");
}
@Override public void onFail(AbsEntity entity, AriaException e, boolean needRetry) {
ALog.e(TAG, String.format("获取文件信息失败url%s", ((DownloadEntity) entity).getUrl()));
count++;
failCount++;
count.getAndIncrement();
failCount.getAndIncrement();
listener.onSubFail((DownloadEntity) entity, new AriaHTTPException(TAG,
String.format("子任务获取文件长度失败url%s", ((DownloadEntity) entity).getUrl())));
checkGetSizeComplete(count, failCount);
checkGetSizeComplete(count.get(), failCount.get());
}
};
@@ -79,7 +80,7 @@ public final class HttpDGInfoTask implements IInfoTask {
return;
}
// 处理组合任务大小未知的情况
if (wrapper.isUnknownSize() && wrapper.getEntity().getFileSize() < 1) {
if (wrapper.isUnknownSize()) {
mPool = Executors.newCachedThreadPool();
getGroupSize();
try {
@@ -89,7 +90,7 @@ public final class HttpDGInfoTask implements IInfoTask {
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!mPool.isShutdown()){
if (!mPool.isShutdown()) {
mPool.shutdown();
}
} else {
@@ -107,6 +108,10 @@ public final class HttpDGInfoTask implements IInfoTask {
new Thread(new Runnable() {
@Override public void run() {
for (DTaskWrapper dTaskWrapper : wrapper.getSubTaskWrapper()) {
if (dTaskWrapper.getEntity().getFileSize() > 0) {
count.getAndIncrement();
continue;
}
cloneHeader(dTaskWrapper);
HttpDFileInfoTask infoTask = new HttpDFileInfoTask(dTaskWrapper);
infoTask.setCallback(subCallback);
@@ -158,7 +163,6 @@ public final class HttpDGInfoTask implements IInfoTask {
subOption.setFileNameAdapter(groupOption.getFileNameAdapter());
subOption.setUseServerFileName(groupOption.isUseServerFileName());
subOption.setFileNameAdapter(groupOption.getFileNameAdapter());
subOption.setRequestEnum(groupOption.getRequestEnum());
subOption.setHeaders(groupOption.getHeaders());

View File

@@ -26,6 +26,7 @@ import com.arialyy.aria.core.listener.DownloadGroupListener;
import com.arialyy.aria.core.loader.IInfoTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.exception.AriaException;
import java.io.File;
/**
* http 组合任务加载器
@@ -53,6 +54,12 @@ final class HttpDGLoader extends AbsGroupLoader {
}
onPostStart();
for (DTaskWrapper wrapper : getWrapper().getSubTaskWrapper()) {
File subFile = new File(wrapper.getEntity().getFilePath());
if (wrapper.getEntity().getFileSize() > 0
&& subFile.exists()
&& subFile.length() == wrapper.getEntity().getFileSize()) {
continue;
}
DownloadEntity dEntity = wrapper.getEntity();
startSubLoader(createSubLoader(wrapper, dEntity.getFileSize() < 0));
}