Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EISDIR on stat directory #585

Merged
merged 1 commit into from
Dec 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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