Skip to content

Commit

Permalink
Merge pull request #3940 from TeamAmaze/issue/3816
Browse files Browse the repository at this point in the history
Fixes NPE on `HybridFile#isDirectory`
  • Loading branch information
VishalNehra committed Oct 29, 2023
2 parents 593d19c + 53f963a commit 727c036
Showing 1 changed file with 23 additions and 34 deletions.
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 @@ -616,7 +616,6 @@ public boolean isDirectory() {
}

public boolean isDirectory(Context context) {
boolean isDirectory;
switch (mode) {
case SFTP:
final Boolean returnValue =
Expand All @@ -638,56 +637,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

0 comments on commit 727c036

Please sign in to comment.