From 18ee5b35ef950e84550c17a56eca86e76ea739f4 Mon Sep 17 00:00:00 2001 From: Javier Castro Date: Thu, 21 Sep 2017 15:12:07 -0300 Subject: [PATCH] Workaround for #346: try to better detect when an asset path is a directory or a (possible) compressed file --- android/src/main/java/com/rnfs/RNFSManager.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/rnfs/RNFSManager.java b/android/src/main/java/com/rnfs/RNFSManager.java index 8b550781..298c1106 100755 --- a/android/src/main/java/com/rnfs/RNFSManager.java +++ b/android/src/main/java/com/rnfs/RNFSManager.java @@ -342,16 +342,17 @@ public void readDirAssets(String directory, Promise promise) { String path = directory.isEmpty() ? childFile : String.format("%s/%s", directory, childFile); // don't allow / at the start when directory is "" fileMap.putString("path", path); int length = 0; - boolean isDirectory = false; + boolean isDirectory = true; try { AssetFileDescriptor assetFileDescriptor = assetManager.openFd(path); if (assetFileDescriptor != null) { length = (int) assetFileDescriptor.getLength(); assetFileDescriptor.close(); + isDirectory = false; } } catch (IOException ex) { - //.. ah.. is a directory! - isDirectory = true; + //.. ah.. is a directory or a compressed file? + isDirectory = ex.getMessage().indexOf("compressed") == -1; } fileMap.putInt("size", length); fileMap.putInt("type", isDirectory ? 1 : 0); // if 0, probably a folder..