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

Directory detection always returns true. #3

Closed
timo-drick opened this issue Dec 6, 2022 · 4 comments
Closed

Directory detection always returns true. #3

timo-drick opened this issue Dec 6, 2022 · 4 comments

Comments

@timo-drick
Copy link

Hey great work with this alternative to DocumentFile. For my current project i can not use the original one because it is way too slow.
I found one bug. The function ResolverCompat.isTreeUri() (in file ResolverCompat.kt:101) does not work anymore. It always returns true. So all files declared as directory. For me it works fine when i only use the mime type to decide if it is a directory.

    // Returns True if the Uri is a Tree Uri, false otherwise.
    internal fun isTreeUri(): Boolean {
        val paths = uri.pathSegments
        return paths.size >= 2 && "tree" == paths[0]
    }
@ItzNotABug
Copy link
Owner

Hey,
Thanks for filing an issue for this.

I just tested this behaviour via the sample app & I don't see files being marked as directory.
Could you share a sample to reproduce this along with a bunch of files on which this behaviour is reproducible or maybe share any other relevant info. which can be helpful.

@timo-drick
Copy link
Author

timo-drick commented Dec 7, 2022

I do see this on a Pixel 5 device with Android 13. I am using the ActivityResultContracts.OpenDocumentTree() to open the directory picker. The returned uris for a directory looking as follows:

Query uri: content://com.android.externalstorage.documents/tree/primary%3AMovies/document/primary%3AMovies/children
content://com.android.externalstorage.documents/tree/primary%3AMovies/document/primary%3AMovies%2F.thumbnails
content://com.android.externalstorage.documents/tree/primary%3AMovies/document/primary%3AMovies%2Ffonts
content://com.android.externalstorage.documents/tree/primary%3AMovies/document/primary%3AMovies%2FDJIG0012.srt
content://com.android.externalstorage.documents/tree/primary%3AMovies/document/primary%3AMovies%2FDJIG0013.mp4
content://com.android.externalstorage.documents/tree/primary%3AMovies/document/primary%3AMovies%2FDJIG0013.osd

Only the first and second uri are folders. But all uris do start with tree in the path.

I tried your code in my open source app: https://gitlab.com/compose1/WTFOsd/-/blob/master/app/src/main/java/de/appsonair/wtf/osdplayer/ui/folder_tree_model.kt
But i already moved to some custom code to read the directory. I hope this helps. If you want i could create a branch where i use your library to read the directories. Please just let me know.

@ItzNotABug
Copy link
Owner

I can confirm this bug returning files as directory due to isTreeUri() call which shouldn't have been there.
Looks like I added it by mistake while checking some other logic in DocumentsContract api.

Will push a fix to address this issue.

@ItzNotABug
Copy link
Owner

The latest version 0.91 should address this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants