Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 5413016

Browse files
committed
Fix session dispose bug on android
1 parent f46ecf8 commit 5413016

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -494,15 +494,20 @@ static void createFileASCII(String path, ReadableArray data, Callback callback)
494494
* @param paths An array of file paths.
495495
* @param callback JS contest callback
496496
*/
497-
static void removeSession(ReadableArray paths, Callback callback) {
497+
static void removeSession(ReadableArray paths, final Callback callback) {
498498

499499
AsyncTask<ReadableArray, Integer, Integer> task = new AsyncTask<ReadableArray, Integer, Integer>() {
500500
@Override
501501
protected Integer doInBackground(ReadableArray ...paths) {
502-
for(int i =0; i< paths[0].size(); i++) {
503-
File f = new File(paths[0].getString(i));
504-
if(f.exists())
505-
f.delete();
502+
try {
503+
for (int i = 0; i < paths[0].size(); i++) {
504+
File f = new File(paths[0].getString(i));
505+
if (f.exists())
506+
f.delete();
507+
}
508+
callback.invoke(null, true);
509+
} catch(Exception err) {
510+
callback.invoke(err.getLocalizedMessage());
506511
}
507512
return paths[0].size();
508513
}

src/class/RNFetchBlobSession.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
const RNFetchBlob = NativeModules.RNFetchBlob
1313
const emitter = DeviceEventEmitter
1414

15+
let sessions = {}
16+
1517
export default class RNFetchBlobSession {
1618

1719
add : (path:string) => RNFetchBlobSession;
@@ -20,6 +22,18 @@ export default class RNFetchBlobSession {
2022
list : () => Array<string>;
2123
name : string;
2224

25+
static getSession(name:string):any {
26+
return sessions[name]
27+
}
28+
29+
static setSession(name:string, val:any) {
30+
sessions[name] = val
31+
}
32+
33+
static removeSession(name:string) {
34+
delete sessions[name]
35+
}
36+
2337
constructor(name:string, list:Array<string>) {
2438
this.name = name
2539
if(!sessions[name]) {

src/fs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ function getSystemDirs() {
6868
* @return {RNFetchBlobSession}
6969
*/
7070
function session(name:string):RNFetchBlobSession {
71-
let s = sessions[name]
71+
let s = RNFetchBlobSession.getSession(name)
7272
if(s)
7373
return new RNFetchBlobSession(name)
7474
else {
75-
sessions[name] = []
75+
RNFetchBlobSession.setSession(name, [])
7676
return new RNFetchBlobSession(name, [])
7777
}
7878
}

0 commit comments

Comments
 (0)