@@ -67,21 +67,21 @@ public String getName() {
6767 return "RNFSManager" ;
6868 }
6969
70- private Uri getFileUri (String filepath ) throws IORejectionException {
70+ private Uri getFileUri (String filepath , boolean isDirectoryAllowed ) throws IORejectionException {
7171 Uri uri = Uri .parse (filepath );
7272 if (uri .getScheme () == null ) {
7373 // No prefix, assuming that provided path is absolute path to file
7474 File file = new File (filepath );
75- if (file .isDirectory ()) {
75+ if (! isDirectoryAllowed && file .isDirectory ()) {
7676 throw new IORejectionException ("EISDIR" , "EISDIR: illegal operation on a directory, read '" + filepath + "'" );
7777 }
7878 uri = Uri .parse ("file://" + filepath );
7979 }
8080 return uri ;
8181 }
8282
83- private String getOriginalFilepath (String filepath ) throws IORejectionException {
84- Uri uri = getFileUri (filepath );
83+ private String getOriginalFilepath (String filepath , boolean isDirectoryAllowed ) throws IORejectionException {
84+ Uri uri = getFileUri (filepath , isDirectoryAllowed );
8585 String originalFilepath = filepath ;
8686 if (uri .getScheme ().equals ("content" )) {
8787 try {
@@ -96,7 +96,7 @@ private String getOriginalFilepath(String filepath) throws IORejectionException
9696 }
9797
9898 private InputStream getInputStream (String filepath ) throws IORejectionException {
99- Uri uri = getFileUri (filepath );
99+ Uri uri = getFileUri (filepath , false );
100100 InputStream stream ;
101101 try {
102102 stream = reactContext .getContentResolver ().openInputStream (uri );
@@ -110,7 +110,7 @@ private InputStream getInputStream(String filepath) throws IORejectionException
110110 }
111111
112112 private OutputStream getOutputStream (String filepath , boolean append ) throws IORejectionException {
113- Uri uri = getFileUri (filepath );
113+ Uri uri = getFileUri (filepath , false );
114114 OutputStream stream ;
115115 try {
116116 stream = reactContext .getContentResolver ().openOutputStream (uri , append ? "wa" : "w" );
@@ -556,7 +556,7 @@ public void setReadable(String filepath, Boolean readable, Boolean ownerOnly, Pr
556556 @ ReactMethod
557557 public void stat (String filepath , Promise promise ) {
558558 try {
559- String originalFilepath = getOriginalFilepath (filepath );
559+ String originalFilepath = getOriginalFilepath (filepath , true );
560560 File file = new File (originalFilepath );
561561
562562 if (!file .exists ()) throw new Exception ("File does not exist" );
@@ -621,8 +621,8 @@ public void mkdir(String filepath, ReadableMap options, Promise promise) {
621621
622622 private void sendEvent (ReactContext reactContext , String eventName , @ Nullable WritableMap params ) {
623623 reactContext
624- .getJSModule (RCTNativeAppEventEmitter .class )
625- .emit (eventName , params );
624+ .getJSModule (RCTNativeAppEventEmitter .class )
625+ .emit (eventName , params );
626626 }
627627
628628 @ ReactMethod
0 commit comments