fix(setup): validate keystore output path in perry setup android#1291
Merged
Conversation
…d re-prompt instead of crashing `perry setup android` invokes `keytool -genkeypair` with whatever path the user typed at the "Output path" prompt. A typo like `~/../release-key.keystore` expands to `/Users/<you>/../release-key.keystore` = `/Users/release-key.keystore`, which the user almost certainly cannot write to. keytool then exits non-zero, the wizard bails, and the user loses their alias + password entries. Add a `prompt_output_path` helper that: - expands `~/` (existing behavior), - canonicalizes the *parent* directory (collapsing `..` segments so the error message names the directory the OS will actually refuse), - probes write access with a `.perry-write-test-<pid>` create/remove round-trip — `permissions().readonly()` lies about effective-uid permission on Unix, so a real probe is the only honest check, - on failure prints a red ✗ + the resolved-parent + errno kind and re-prompts. Wire it into android.rs's keystore-generation branch in place of the prior `Input::interact_text` + `expand_tilde` pair. The other inputs (alias, password) come after the path now succeeds, so a slip on the path no longer wastes the user's password retype. Reuse target later: the same helper fits the other wizards' "where do I save this generated cert/key" prompts, but no behavior change there yet — staying scoped to the bug Ralph hit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
perry setup androidcrashes the whole wizard when the user mistypes the keystore path. Concrete repro: typing~/../release-key.keystoreexpands to/Users/<you>/../release-key.keystore=/Users/release-key.keystore, whichkeytoolcan't write to. The wizardbail!s after the user has already entered an alias + password.prompt_output_pathhelper that expands~/, canonicalizes the parent through any.., probes write-access by creating + deleting a tiny.perry-write-test-<pid>file (becausepermissions().readonly()doesn't honor effective-uid on Unix), and re-prompts on failure instead of bailing.android.rs— alias + password prompts now only run once the path is known good.Why a probe instead of a permission check
On Unix,
metadata.permissions().readonly()only reflects whether the owner-write bit is set on the file, not whether the current process can actually create entries in that directory. Trying to create a probe file is the only check that matches whatkeytool(or any subsequent open(O_CREAT) call) will hit.Test plan
cargo build --release -p perry— greencargo fmt --all -- --check— cleanperry setup androidwith~/../release-key.keystore: now prints✗ Cannot write to /Users (permission denied)and re-prompts instead of crashing. Typing~/release-key.keystoresucceeds and proceeds to alias/password.lint,cargo-test,api-docs-drift,security-auditOut of scope
The same helper would also fit
tvos.rs/visionos.rs/watchos.rs/macos.rs"save this generated cert" prompts, but I kept the change scoped to the path that actually broke. Happy to roll those into a follow-up if it's worth it.