@@ -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