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

Allow extern getFd() to get file descriptors from Java for Kiwix Android #852

Open
MohitMaliFtechiz opened this issue Jan 15, 2024 · 5 comments
Assignees
Labels
Milestone

Comments

@MohitMaliFtechiz
Copy link

MohitMaliFtechiz commented Jan 15, 2024

We have an issue in Android directly accessing the fd via file path on Android 11 and above without MANAGE_EXTERNAL_PERMISSION(Which is special permission in Android and Play Store does not allow us to take this permission).

Archive and SuggestionSearcher need the file path to work properly with the Xapian index as per conversation with @mgautierfr in kiwix/kiwix-android#3636. See kiwix/kiwix-android#3636 (comment) for more details.

So to solve this issue can we open a new fd from the existing fd via fileInputStream API and use it for Xapian without affecting the existing one? Somehow this is possible at the libzim level. Or if you think of any better suggestion that can achieve this with existing fd would be welcome.

@kelson42
Copy link
Contributor

kelson42 commented Mar 9, 2024

@mgautierfr Any feedback here?

@kelson42 kelson42 assigned kelson42 and unassigned mgautierfr Mar 23, 2024
@kelson42
Copy link
Contributor

We have an issue in Android directly accessing the fd via file path on Android 11 and above without MANAGE_EXTERNAL_PERMISSION(Which is special permission in Android and Play Store does not allow us to take this permission).

Phrasing seems incorrect. Correct phrasing is: Issues on Android to fully (suggestions/ft search) use ZIM files when open via fd only (so without a - ZIM - file path). In such a case Xapian indexes can not be open (as they do require a dedicated fd, which can only be properly retrieved in "Java world" from the ZIM file path).

Archive and SuggestionSearcher need the file path to work properly with the Xapian index as per conversation with @mgautierfr in kiwix/kiwix-android#3636. See kiwix/kiwix-android#3636 (comment) for more details.

So to solve this issue can we open a new fd from the existing fd via fileInputStream API and use it for Xapian without affecting the existing one? Somehow this is possible at the libzim level. Or if you think of any better suggestion that can achieve this with existing fd would be welcome.

I answer here under the control of @mgautierfr, but "yes" you can open many fd from the same file. Each fileInputStream will have its own fd, but you can open many fileInputStream for the same file and then you should have many fds.

So. here I see only one solution: the libzim should be modified to allow an "external" getFD() method which would be able to call java code to get one. This is a feature request which implies modifications here, in kiwix/java-libkiwix and kiwix/kiwix-android.

@kelson42 kelson42 changed the title Can we open the SuggestionSearcher and Archive with existing FileDescriptor Allow extern getFd() to get file descriptors from Java for Kiwix Android Mar 23, 2024
@kelson42 kelson42 modified the milestones: 9.2.0, 9.3.0 Mar 23, 2024
@mgautierfr
Copy link
Collaborator

This comment kiwix/libkiwix#1015 (comment) is interesting and must not be forgotten, and here an answer:

Opening an archive with a list of (file-path, offset, size) would be interesting/needed in itself but not enough.
We may have system (android, flatpak,...) where we cannot have full access to filesystem. In those cases, file is opened by an external tool and we only get a fd.

@veloman-yunkan
Copy link
Collaborator

veloman-yunkan commented May 13, 2024

This comment kiwix/libkiwix#1015 (comment) is interesting and must not be forgotten, and here an answer:

Opening an archive with a list of (file-path, offset, size) would be interesting/needed in itself but not enough. We may have system (android, flatpak,...) where we cannot have full access to filesystem. In those cases, file is opened by an external tool and we only get a fd.

@mgautierfr As I noted in the said comment, we convert a file descriptor to a file path (of the form /dev/fd/XXX) and actually open the file by path. What I had proposed was to move that trick out of libzim - let the users do that conversion themselves (libzim may simply provide a utility) and the public API will only accept paths.

@mgautierfr
Copy link
Collaborator

The problem is that the trick may be not possible at all. Moving it to the user side move the problem outside of libzim but the root issue is still there: We cannot assume we can open by path (even /dev/fd/xxx)

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

No branches or pull requests

4 participants