Workaround for #346: try to better detect when an asset path is a directory or a (possible) compressed file

This commit is contained in:
Javier Castro 2017-09-21 15:12:07 -03:00
parent a23a70389a
commit 18ee5b35ef

View File

@ -342,16 +342,17 @@ public class RNFSManager extends ReactContextBaseJavaModule {
String path = directory.isEmpty() ? childFile : String.format("%s/%s", directory, childFile); // don't allow / at the start when directory is "" String path = directory.isEmpty() ? childFile : String.format("%s/%s", directory, childFile); // don't allow / at the start when directory is ""
fileMap.putString("path", path); fileMap.putString("path", path);
int length = 0; int length = 0;
boolean isDirectory = false; boolean isDirectory = true;
try { try {
AssetFileDescriptor assetFileDescriptor = assetManager.openFd(path); AssetFileDescriptor assetFileDescriptor = assetManager.openFd(path);
if (assetFileDescriptor != null) { if (assetFileDescriptor != null) {
length = (int) assetFileDescriptor.getLength(); length = (int) assetFileDescriptor.getLength();
assetFileDescriptor.close(); assetFileDescriptor.close();
isDirectory = false;
} }
} catch (IOException ex) { } catch (IOException ex) {
//.. ah.. is a directory! //.. ah.. is a directory or a compressed file?
isDirectory = true; isDirectory = ex.getMessage().indexOf("compressed") == -1;
} }
fileMap.putInt("size", length); fileMap.putInt("size", length);
fileMap.putInt("type", isDirectory ? 1 : 0); // if 0, probably a folder.. fileMap.putInt("type", isDirectory ? 1 : 0); // if 0, probably a folder..