Skip to content

Commit

Permalink
Merge pull request #585 from ProductiveMobile/master
Browse files Browse the repository at this point in the history
Fix EISDIR on stat directory
  • Loading branch information
itinance authored Dec 19, 2018
2 parents 8c121e8 + d115cde commit a93f36e
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 @@ -67,21 +67,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 @@ -96,7 +96,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 @@ -110,7 +110,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 @@ -556,7 +556,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 @@ -621,8 +621,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 a93f36e

Please sign in to comment.