Conversation
e6a0fc4 to
32a80a2
Compare
|
Please run |
| } | ||
|
|
||
| downloads.delete(source); | ||
| ResourceFetcherUtils.triggerHuggingFaceDownloadCounter(uri); |
There was a problem hiding this comment.
remove from here, i want those calls to be strictly inside core package so that they are mandatory.
Also there is a bug when we fire those calls even when file is already downloaded (see packages/react-native-executorch/src/utils/ResourceFetcher.ts:128
| if (dl.task) { | ||
| // iOS: background downloader cancel | ||
| dl.task.stop(); | ||
| } else if (dl.jobId !== undefined) { |
There was a problem hiding this comment.
Two things here
- why are we checking with (dl.task) and the other time with (dl.jobId !==...) instead of (!dl.jobId)
- why are we using those fields (task/jobId) as a proxy for checking what platform we are using, especially since you are then writing comments explaining the platforms
There was a problem hiding this comment.
regarding the first point, jobId can be 0 which is falsy, so it would incorrectly tread a valid job with id 0 as missing. Task is an object ref, so !downloadHandle.task is safe.
There was a problem hiding this comment.
and regarding the second point, I could do something like this instead, but I'm not sure if its much cleaner though:
if (Platform.OS === 'ios') {
if (!downloadHandle.task) {
throw new RnExecutorchError(
RnExecutorchErrorCode.ResourceFetcherDownloadFailed,
'Download task is missing. This should not happen on iOS.'
);
}
downloadHandle.task.stop();
} else if (Platform.OS === 'android') {
if (downloadHandle.jobId === undefined) {
throw new RnExecutorchError(
RnExecutorchErrorCode.ResourceFetcherDownloadFailed,
'Download job ID is missing. This should not happen on Android.'
);
}
RNFS.stopDownload(downloadHandle.jobId);
if (await ResourceFetcherUtils.checkFileExists(downloadHandle.cacheFileUri)) {
await RNFS.unlink(downloadHandle.cacheFileUri);
}
}
Description
implementations
Note: this PR still uses the legacy FS as the support for background / resumable downloads is WIP.
Introduces a breaking change?
Type of change
Tested on
Testing instructions
Screenshots
Related issues
Checklist
Additional notes