1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

fix(runtime): fix Windows permission prompt (#23212)

Followup to https://github.com/denoland/deno/pull/23184
This commit is contained in:
Matt Mastracci 2024-04-04 09:44:43 -06:00 committed by GitHub
parent e01bc09573
commit 945eb5eba6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -335,7 +335,8 @@ impl PermissionPrompter for TtyPrompter {
let value = loop { let value = loop {
// Clear stdin each time we loop around in case the user accidentally pasted // Clear stdin each time we loop around in case the user accidentally pasted
// multiple lines or otherwise did something silly to generate a torrent of // multiple lines or otherwise did something silly to generate a torrent of
// input. // input. This doesn't work on Windows because `clear_stdin` has other side-effects.
#[cfg(unix)]
if let Err(err) = clear_stdin(&mut stdin_lock, &mut stderr_lock) { if let Err(err) = clear_stdin(&mut stdin_lock, &mut stderr_lock) {
eprintln!("Error clearing stdin for permission prompt. {err:#}"); eprintln!("Error clearing stdin for permission prompt. {err:#}");
return PromptResponse::Deny; // don't grant permission if this fails return PromptResponse::Deny; // don't grant permission if this fails
@ -343,14 +344,11 @@ impl PermissionPrompter for TtyPrompter {
let mut input = String::new(); let mut input = String::new();
let result = stdin_lock.read_line(&mut input); let result = stdin_lock.read_line(&mut input);
if result.is_err() || input.len() > 2 { let input = input.trim_end_matches(|c| c == '\r' || c == '\n');
if result.is_err() || input.len() != 1 {
break PromptResponse::Deny; break PromptResponse::Deny;
}; };
let ch = match input.chars().next() { match input.as_bytes()[0] as char {
None => break PromptResponse::Deny,
Some(v) => v,
};
match ch {
'y' | 'Y' => { 'y' | 'Y' => {
clear_n_lines( clear_n_lines(
&mut stderr_lock, &mut stderr_lock,