You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow extern getFd() to get file descriptors from Java for Kiwix Android #852
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).
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.
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).
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.
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[/+]on Mar 23, 2024
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.
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.
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)
AI-assisted comment. Left by agent driven by @soloturn via GDD.
@mgautierfr — status update on the PRs open against this.
What's there
fix: open fd-backed archive parts via dup() instead of reopening by path #1119 (this repo, open): dup() the fd we already have instead of reopening by path. Directly answers your 2024-05-13 concern above ("we cannot assume we can open by path, even /dev/fd/xxx") - dup() never opens by path at all, so there's no path-assumption left to make. Covers FilePart/getDbFromAccessInfo(), i.e. the Xapian index case this issue opened with.
Only verified on-device on arm64-v8a (real emulator repro, not this repo's own test suite - see the PR's verification section). x86/x86_64 - the architectures also named in the original kiwix-android#3636 report - not independently confirmed, since the Apple Silicon host used can't run an x86_64 Android emulator.
Activity
kelson42 commentedon Mar 9, 2024
@mgautierfr Any feedback here?
kelson42 commentedon Mar 23, 2024
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).
I answer here under the control of @mgautierfr, but "yes" you can open many fd from the same file. Each
fileInputStreamwill have its own fd, but you can open manyfileInputStreamfor 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, inkiwix/java-libkiwixandkiwix/kiwix-android.[-]Can we open the `SuggestionSearcher` and `Archive` with existing FileDescriptor[/-][+]Allow extern `getFd()` to get file descriptors from Java for Kiwix Android[/+]mgautierfr commentedon 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.
veloman-yunkan commentedon May 13, 2024
@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 oflibzim- let the users do that conversion themselves (libzimmay simply provide a utility) and the public API will only accept paths.mgautierfr commentedon May 13, 2024
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)soloturn commentedon Aug 30, 2026
@mgautierfr — status update on the PRs open against this.
What's there
dup()the fd we already have instead of reopening by path. Directly answers your 2024-05-13 concern above ("we cannot assume we can open by path, even/dev/fd/xxx") -dup()never opens by path at all, so there's no path-assumption left to make. CoversFilePart/getDbFromAccessInfo(), i.e. the Xapian index case this issue opened with.fdthrough JNI forItem::getDirectAccessInformation(), so large media items get the samedup()treatment, not just the Xapian db.ZimFileReaderuses the JNI-provided fd instead of reopening by path for direct-access reads.FileUtils.ktwas also reopening by path (citing kiwix-android#3636 in its own comment) before ever reaching libkiwix. Fixed the same way, doesn't depend on fix: open fd-backed archive parts via dup() instead of reopening by path #1119.What's still missing
getFd()... for Kiwix Android") - closing it for real probably wants the JNI+Android layer (Delete "subprojects" directory / GoogleTest source code from the git repo #151/#5056) landed too, not just the libzim-side fix.fix: address review comments on the fd-based-xapian-open PR
feat: add Item::getDirectAccessFd(), a new ABI-safe public API for th…
feat: expose a direct-access fd for items across JNI