mirror of
https://github.com/status-im/react-native-fs.git
synced 2025-03-01 07:20:33 +00:00
Workaround for #346: try to better detect when an asset path is a directory or a (possible) compressed file
This commit is contained in:
parent
a23a70389a
commit
18ee5b35ef
@ -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..
|
||||||
|
Loading…
x
Reference in New Issue
Block a user