Skip to content

Commit

Permalink
[FM] Prevent infinite loop when an inaccessible file is a symbolic link
Browse files Browse the repository at this point in the history
Signed-off-by: Muntashir Al-Islam <[email protected]>
  • Loading branch information
MuntashirAkon committed Sep 9, 2023
1 parent ec10570 commit b64d490
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private void loadFiles(@NonNull Uri uri, @Nullable String scrollToFilename) {
while (currentPath.isSymbolicLink()) {
try {
Path realPath = currentPath.getRealPath();
if (realPath == null) {
if (realPath == null || realPath.equals(currentPath)) {
// Not a symbolic link
break;
}
Expand All @@ -314,13 +314,15 @@ private void loadFiles(@NonNull Uri uri, @Nullable String scrollToFilename) {
}
// Send current URI
mUriLiveData.postValue(mCurrentUri);
long s, e;
boolean isSaf = ContentResolver.SCHEME_CONTENT.equals(mCurrentUri.getScheme());
FolderShortInfo folderShortInfo = new FolderShortInfo();
int folderCount = 0;
synchronized (mFmItems) {
mFmItems.clear();
if (isSaf) {
// SAF needs special handling to retrieve children
s = System.currentTimeMillis();
ContentResolver resolver = getApplication().getContentResolver();
Uri childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(mCurrentUri,
DocumentsContract.getDocumentId(mCurrentUri));
Expand Down Expand Up @@ -351,13 +353,19 @@ private void loadFiles(@NonNull Uri uri, @Nullable String scrollToFilename) {
return;
}
}
e = System.currentTimeMillis();
Log.e(TAG, "Time to fetch files via SAF: %d ms", e - s);
} catch (Exception ex) {
Log.w(TAG, "Failed query: %s", ex);
} finally {
IoUtils.closeQuietly(c);
}
} else {
s = System.currentTimeMillis();
Path[] children = path.listFiles();
e = System.currentTimeMillis();
Log.e(TAG, "Time to list files: %d ms", e - s);
s = System.currentTimeMillis();
for (Path child : children) {
FmItem fmItem = new FmItem(child);
mFmItems.add(fmItem);
Expand All @@ -368,6 +376,8 @@ private void loadFiles(@NonNull Uri uri, @Nullable String scrollToFilename) {
return;
}
}
e = System.currentTimeMillis();
Log.e(TAG, "Time to process file list: %d ms", e - s);
}
}
folderShortInfo.folderCount = folderCount;
Expand All @@ -380,7 +390,10 @@ private void loadFiles(@NonNull Uri uri, @Nullable String scrollToFilename) {
// Send folder info for the first time
mFolderShortInfoLiveData.postValue(folderShortInfo);
// Run filter and sorting options for fmItems
s = System.currentTimeMillis();
filterAndSort();
e = System.currentTimeMillis();
Log.e(TAG, "Time to sort files: %d ms", e - s);
synchronized (mSizeLock) {
// Calculate size and send folder info again
folderShortInfo.size = Paths.size(path);
Expand Down

0 comments on commit b64d490

Please sign in to comment.