diff --git a/android/src/main/java/com/rnfs/RNFSManager.java b/android/src/main/java/com/rnfs/RNFSManager.java index 87c7a947..d64341d1 100755 --- a/android/src/main/java/com/rnfs/RNFSManager.java +++ b/android/src/main/java/com/rnfs/RNFSManager.java @@ -66,12 +66,12 @@ public String getName() { return "RNFSManager"; } - private Uri getFileUri(String filepath) throws IORejectionException { + private Uri getFileUri(String filepath, boolean isDirectoryAllowed) throws IORejectionException { Uri uri = Uri.parse(filepath); if (uri.getScheme() == null) { // No prefix, assuming that provided path is absolute path to file File file = new File(filepath); - if (file.isDirectory()) { + if (!isDirectoryAllowed && file.isDirectory()) { throw new IORejectionException("EISDIR", "EISDIR: illegal operation on a directory, read '" + filepath + "'"); } uri = Uri.parse("file://" + filepath); @@ -79,8 +79,8 @@ private Uri getFileUri(String filepath) throws IORejectionException { return uri; } - private String getOriginalFilepath(String filepath) throws IORejectionException { - Uri uri = getFileUri(filepath); + private String getOriginalFilepath(String filepath, boolean isDirectoryAllowed) throws IORejectionException { + Uri uri = getFileUri(filepath, isDirectoryAllowed); String originalFilepath = filepath; if (uri.getScheme().equals("content")) { try { @@ -95,7 +95,7 @@ private String getOriginalFilepath(String filepath) throws IORejectionException } private InputStream getInputStream(String filepath) throws IORejectionException { - Uri uri = getFileUri(filepath); + Uri uri = getFileUri(filepath, false); InputStream stream; try { stream = reactContext.getContentResolver().openInputStream(uri); @@ -109,7 +109,7 @@ private InputStream getInputStream(String filepath) throws IORejectionException } private OutputStream getOutputStream(String filepath, boolean append) throws IORejectionException { - Uri uri = getFileUri(filepath); + Uri uri = getFileUri(filepath, false); OutputStream stream; try { stream = reactContext.getContentResolver().openOutputStream(uri, append ? "wa" : "w"); @@ -532,7 +532,7 @@ public void setReadable(String filepath, Boolean readable, Boolean ownerOnly, Pr @ReactMethod public void stat(String filepath, Promise promise) { try { - String originalFilepath = getOriginalFilepath(filepath); + String originalFilepath = getOriginalFilepath(filepath, true); File file = new File(originalFilepath); if (!file.exists()) throw new Exception("File does not exist"); @@ -597,8 +597,8 @@ public void mkdir(String filepath, ReadableMap options, Promise promise) { private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) { reactContext - .getJSModule(RCTNativeAppEventEmitter.class) - .emit(eventName, params); + .getJSModule(RCTNativeAppEventEmitter.class) + .emit(eventName, params); } @ReactMethod