-
Notifications
You must be signed in to change notification settings - Fork 11
feat: export a compact version of the database #1740
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks plausible, pending green CI. I had to double-check the docs, but I agree that using VACUUM INTO on an encrypted database produces encrypted output.
Getting CI green might take a few more iterations, but just doing cargo +nightly fmt and avoiding re-adding the close method should handle the currently-most-obvious failures.
|
@marcoconti83 what is the motivation for this? |
fde8fe3 to
6fb466b
Compare
32bbb08 to
c543575
Compare
c543575 to
0ca5dd7
Compare
| pub async fn export_database_copy(database: &Database, destination_path: &str) -> CoreCryptoResult<()> { | ||
| #[cfg(target_family = "wasm")] | ||
| { | ||
| let _ = (database, destination_path); // Suppress unused warnings | ||
| Err(CoreCryptoError::ad_hoc( | ||
| "export_database_copy is not supported on WASM. This function requires filesystem operations and SQLCipher, which are only available on native platforms (iOS, Android, JVM).", | ||
| )) | ||
| } | ||
|
|
||
| #[cfg(not(target_family = "wasm"))] | ||
| { | ||
| database | ||
| .0 | ||
| .export_copy(destination_path) | ||
| .await | ||
| .map_err(CoreCryptoError::generic()) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we feature-gated this entire function instead:
#[cfg(not(feature = "wasm"))]
we could prevent this function to be generated for typescript entirely. Or was there a particular reason why you wanted to expose this function for TypeScript?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to feature-gate the entire function. I then spent hours trying to get the WASM tests to run - they would fail, because even if the tests were not using this function, there was a step in the test setup that checks that all functions part of the FFI are defined, and it would fail. I didn't dig deeper into why this happens, but removing this check seems like a big architectural change that is beyond the scope of this PR.
Auto-generating stubs for WASM did not work because the function just does not exists when using the WASM target. So I tried manually generating stubs, but either we hardcode the stubs (and we need to keep them in sync with the code as the code changes), or we would have a script that looks for functions that don't exists and generates stubs for them (which feels very hacky).
I decided to just throw an error when running this in WASM, and this makes the tests happy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this function will only ever be called by Android anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that you annotated the function with exactly the attribute I'm mentioning above?
It's unintuitive at first that if we want to hide a part of the API for typescript, we cannot compile conditionnally by target family, but have to use that feature-gate. It's due to how uniffi-bindgen-for-react-native (ubrn) generates the bindings. They are generated from a binary that is compiled for the host platform. So if you'd compile conditionally by target family, the function would still appear in the binary the bindings are generated from, which would then try to bind to a function that doesn't exist on the target.
I did an experiment in 96307cc where I feature-gate the function. Typescript tests are passing there for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO building on Simon's work is the way to go here. Possibly that will also solve the interop test issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interop test issue will probably be fixed with a rebase on main: on main, we're creating android emulators freshly for each android test (including interop), and this branch assumes emulators are reused across test runs.
What's new in this PR
Added a function to flush and export the database. This allows for a compact export without the WAL file.
This only works with SQLite DBs. It won't work on WASM.