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

Fixes NPE on HybridFile#isDirectory #3940

Merged
merged 2 commits into from
Oct 29, 2023
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
57 changes: 23 additions & 34 deletions app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ public boolean isDirectory() {
}

public boolean isDirectory(Context context) {
boolean isDirectory;
switch (mode) {
case SFTP:
final Boolean returnValue =
Expand All @@ -634,56 +633,46 @@ public Boolean execute(@NonNull SFTPClient client) {

if (returnValue == null) {
LOG.error("Error obtaining if path is directory over SFTP");
return false;
}

//noinspection SimplifiableConditionalExpression
return returnValue == null ? false : returnValue;
return returnValue;
case SMB:
try {
isDirectory =
Single.fromCallable(() -> getSmbFile().isDirectory())
.subscribeOn(Schedulers.io())
.blockingGet();
return Single.fromCallable(() -> getSmbFile().isDirectory())
.subscribeOn(Schedulers.io())
.blockingGet();
} catch (Exception e) {
isDirectory = false;
LOG.warn("failed to get isDirectory with context for smb file", e);
return false;
}
break;
case FTP:
FTPFile ftpFile = getFtpFile();
isDirectory = ftpFile != null && ftpFile.isDirectory();
break;
case FILE:
isDirectory = getFile().isDirectory();
break;
return ftpFile != null && ftpFile.isDirectory();
case ROOT:
isDirectory = NativeOperations.isDirectory(path);
break;
return NativeOperations.isDirectory(path);
case DOCUMENT_FILE:
isDirectory = getDocumentFile(false).isDirectory();
break;
DocumentFile documentFile = getDocumentFile(false);
return documentFile != null && documentFile.isDirectory();
case OTG:
isDirectory = OTGUtil.getDocumentFile(path, context, false).isDirectory();
break;
DocumentFile otgFile = OTGUtil.getDocumentFile(path, context, false);
return otgFile != null && otgFile.isDirectory();
case DROPBOX:
case BOX:
case GDRIVE:
case ONEDRIVE:
isDirectory =
Single.fromCallable(
() ->
dataUtils
.getAccount(mode)
.getMetadata(CloudUtil.stripPath(mode, path))
.getFolder())
.subscribeOn(Schedulers.io())
.blockingGet();
break;
default:
isDirectory = getFile().isDirectory();
break;
return Single.fromCallable(
() ->
dataUtils
.getAccount(mode)
.getMetadata(CloudUtil.stripPath(mode, path))
.getFolder())
.subscribeOn(Schedulers.io())
.blockingGet();
default: // also handles the case `FILE`
File file = getFile();
return file != null && file.isDirectory();
}
return isDirectory;
}

/**
Expand Down