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

Commit 2224a46

Browse files
committed
Fix android stat and lstat method
1 parent e3daba1 commit 2224a46

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void removeSession(ReadableArray paths, Callback callback) {
116116

117117
@ReactMethod
118118
public void lstat(String path, Callback callback) {
119-
RNFetchBlobFS.ls(path, callback);
119+
RNFetchBlobFS.lstat(path, callback);
120120
}
121121

122122
@ReactMethod

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ protected Integer doInBackground(String ...args) {
376376
if(src.isDirectory()) {
377377
String [] files = src.list();
378378
for(String p : files) {
379-
res.pushMap(statFile ( src.getPath() + p));
379+
res.pushMap(statFile ( src.getPath() + "/" + p));
380380
}
381381
}
382382
else {
@@ -394,18 +394,23 @@ protected Integer doInBackground(String ...args) {
394394
* @param callback
395395
*/
396396
static void stat(String path, Callback callback) {
397-
File target = new File(path);
398-
if(!target.exists()) {
399-
callback.invoke("stat error: file "+path+" does not exists");
400-
return;
397+
try {
398+
File target = new File(path);
399+
if (!target.exists()) {
400+
callback.invoke("stat error: file " + path + " does not exists");
401+
return;
402+
}
403+
WritableMap stat = Arguments.createMap();
404+
stat.putString("filename", target.getName());
405+
stat.putString("path", target.getPath());
406+
stat.putString("type", target.isDirectory() ? "directory" : "file");
407+
stat.putString("size", String.valueOf(target.length()));
408+
String lastModified = String.valueOf(target.lastModified());
409+
stat.putString("lastModified", lastModified);
410+
callback.invoke(null, stat);
411+
} catch(Exception err) {
412+
callback.invoke(err.getLocalizedMessage());
401413
}
402-
WritableMap stat = Arguments.createMap();
403-
stat.putString("filename", target.getName());
404-
stat.putString("path", target.getPath());
405-
stat.putString("type", target.isDirectory() ? "directory" : "file");
406-
stat.putInt("size", (int)target.length());
407-
stat.putInt("lastModified", (int)target.lastModified());
408-
callback.invoke(null, stat);
409414
}
410415

411416
void scanFile(String [] path, String[] mimes, final Callback callback) {
@@ -453,6 +458,10 @@ static void createFile(String path, String data, String encoding, Callback callb
453458
static void createFileASCII(String path, ReadableArray data, Callback callback) {
454459
try {
455460
File dest = new File(path);
461+
if(dest.exists()) {
462+
callback.invoke("create file error: failed to create file at path `" + path + "`, file already exists.");
463+
return;
464+
}
456465
boolean created = dest.createNewFile();
457466
if(!created) {
458467
callback.invoke("create file error: failed to create file at path `" + path + "` for its parent path may not exists");

0 commit comments

Comments
 (0)