Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

下载超过2G多大文件时,杀进程后,再次下载无法断点续传。 #491

Open
weiwdev opened this issue Oct 13, 2022 · 2 comments

Comments

@weiwdev
Copy link

weiwdev commented Oct 13, 2022

OkDownload Version

v1.0.7

Problem Describe

使用OKdownload下载一个大文件(如2.4G,超出int范围,为long型), 下载一部分后,退出app,并杀掉该进程;重新进入app下载,此时下载进度从0开始。
小文件下载,断点续传正常,没有该问题。

###Cause
第二次重新进入app下载时,新建BreakpointStoreOnSQLite时,会判断BlockInfoRow的startOffset, contentLength, currentOffset等字段,如果小于0,则抛出异常,无法使用SQLite里的断点信息。
大文件下载时,contentLength字段会被写入long型的数据(超出int范围),第二次下载读取BlockInfoRow的contentLength时,仍然是按int型读取,导致读取到负值,加载BreakpointStoreOnSQLite、断点信息失败。

相关代码如下:startOffset、contentLength、currentOffset是long型,确按int读取。
public class BlockInfoRow {
private final int breakpointId;

private final long startOffset;
private final long contentLength;
private final long currentOffset;

public BlockInfoRow(Cursor cursor) {
    this.breakpointId = cursor.getInt(cursor.getColumnIndex(HOST_ID));
    this.startOffset = cursor.getInt(cursor.getColumnIndex(START_OFFSET));
    this.contentLength = cursor.getInt(cursor.getColumnIndex(CONTENT_LENGTH));
    this.currentOffset = cursor.getInt(cursor.getColumnIndex(CURRENT_OFFSET));
}

Log

在okdownload-breakpoint-sqlite增加部分调试log,打印如下:
--------- beginning of main
--------- beginning of system
10-11 17:41:28.911 3160 3160 E debug : ##return BreakpointStoreOnSQLite##
10-11 17:41:29.745 3332 3332 E debug : ##return BreakpointStoreOnSQLite##
10-11 17:41:29.989 3238 3238 E debug : ##return BreakpointStoreOnSQLite##
10-11 17:41:31.607 3613 3613 E debug : ##return BreakpointStoreOnSQLite##
10-11 17:41:37.620 3160 3877 E debug : ##get BreakpointInfo,task:1
10-11 17:41:37.627 3160 3877 E debug : ##get BreakpointInfo,task:1
10-11 17:41:37.627 3160 3877 E debug : ##get BreakpointInfo,task:1
10-11 17:41:37.628 3160 3881 E debug : ##get BreakpointInfo,task:1
10-11 17:41:39.130 3160 3287 E debug : ##get BreakpointInfo,task:1
10-11 17:41:39.134 3160 3287 E debug : insert blockCount success:1current_offset=4096 start_offset=0 content_length=2568924379 breakpoint_id=1 block_index=0
10-11 17:41:39.957 3160 3887 E debug : BreakpointStoreOnSQLite onSyncToFilesystemSuccess, blockIndex:0, increaseLength:756868
10-11 17:41:41.985 3160 3887 E debug : BreakpointStoreOnSQLite onSyncToFilesystemSuccess, blockIndex:0, increaseLength:1794048
10-11 17:41:44.004 3160 3887 E debug : BreakpointStoreOnSQLite onSyncToFilesystemSuccess, blockIndex:0, increaseLength:1773568
10-11 17:41:44.889 3160 3160 E debug : ##get BreakpointInfo,task:1
10-11 17:41:46.035 3160 3887 E debug : BreakpointStoreOnSQLite onSyncToFilesystemSuccess, blockIndex:0, increaseLength:2158592
10-11 17:41:48.073 3160 3887 E debug : BreakpointStoreOnSQLite onSyncToFilesystemSuccess, blockIndex:0, increaseLength:2568192
10-11 17:41:50.117 3160 3887 E debug : BreakpointStoreOnSQLite onSyncToFilesystemSuccess, blockIndex:0, increaseLength:2977792
10-11 17:41:52.166 3160 3887 E debug : BreakpointStoreOnSQLite onSyncToFilesystemSuccess, blockIndex:0, increaseLength:3387392
10-11 17:41:53.477 3160 3160 E debug : ##get BreakpointInfo,task:1
10-11 17:41:54.196 3160 3887 E debug : BreakpointStoreOnSQLite onSyncToFilesystemSuccess, blockIndex:0, increaseLength:3795208
10-11 17:41:56.241 3160 3887 E debug : BreakpointStoreOnSQLite onSyncToFilesystemSuccess, blockIndex:0, increaseLength:3899392
10-11 17:41:57.049 3160 3160 E debug : ##get BreakpointInfo,task:1
10-11 17:41:57.077 3160 3887 E debug : BreakpointStoreOnSQLite onSyncToFilesystemSuccess, blockIndex:0, increaseLength:1949696

杀进程后,重新启动下载:
10-11 17:42:07.654 4868 4868 E debug : ##return BreakpointStoreOnSQLite##
10-11 17:42:07.657 4868 4868 E debug : ###BlockInfoRow startOffset, contentLength, currentOffset###0,-1726042917,25064844
10-11 17:42:07.659 4868 4868 E debug : ##create BreakpointStoreOnSQLite fail InvocationTargetException##java.lang.reflect.InvocationTargetException
10-11 17:42:07.659 4868 4868 E debug : ##return BreakpointStoreOnCache##
10-11 17:42:08.380 5007 5007 E debug : ##return BreakpointStoreOnSQLite##
10-11 17:42:08.390 5007 5007 E debug : ###BlockInfoRow startOffset, contentLength, currentOffset###0,-1726042917,25064844
10-11 17:42:08.392 5007 5007 E debug : ##create BreakpointStoreOnSQLite fail InvocationTargetException##java.lang.reflect.InvocationTargetException
10-11 17:42:08.392 5007 5007 E debug : ##return BreakpointStoreOnCache##

@tianshaokai
Copy link

@weiwdev 可以发一下下载文件链接吗

@wjzabc
Copy link

wjzabc commented May 4, 2023

遇到同样的大文件杀进程无法续传问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants