Skip to content

Commit

Permalink
PMP-5747 Fix EISDIR on stat directory
Browse files Browse the repository at this point in the history
  • Loading branch information
pmobileghub committed Nov 16, 2018
1 parent f1e4235 commit d115cde
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions android/src/main/java/com/rnfs/RNFSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ 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);
}
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 {
Expand All @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d115cde

Please sign in to comment.