diff --git a/crates/askpass/src/askpass.rs b/crates/askpass/src/askpass.rs index baa67a7c5525cbb8f04a2e9d127fbf2b90eb5e4d..917b0efc1599112e44d23199cd832d75c4ba30b1 100644 --- a/crates/askpass/src/askpass.rs +++ b/crates/askpass/src/askpass.rs @@ -73,17 +73,18 @@ impl AskPassDelegate { pub struct AskPassSession { #[cfg(target_os = "windows")] - secret: std::sync::Arc>, + secret: std::sync::Arc>>, askpass_task: PasswordProxy, askpass_opened_rx: Option>, askpass_kill_master_rx: Option>, executor: BackgroundExecutor, } -#[cfg(not(target_os = "windows"))] -const ASKPASS_SCRIPT_NAME: &str = "askpass.sh"; -#[cfg(target_os = "windows")] -const ASKPASS_SCRIPT_NAME: &str = "askpass.ps1"; +const ASKPASS_SCRIPT_NAME: &str = if cfg!(target_os = "windows") { + "askpass.ps1" +} else { + "askpass.sh" +}; impl AskPassSession { /// This will create a new AskPassSession. @@ -91,7 +92,8 @@ impl AskPassSession { #[must_use] pub async fn new(executor: BackgroundExecutor, mut delegate: AskPassDelegate) -> Result { #[cfg(target_os = "windows")] - let secret = std::sync::Arc::new(OnceLock::new()); + let secret = std::sync::Arc::new(std::sync::Mutex::new(None)); + let (askpass_opened_tx, askpass_opened_rx) = oneshot::channel::<()>(); let askpass_opened_tx = Arc::new(Mutex::new(Some(askpass_opened_tx))); @@ -99,11 +101,11 @@ impl AskPassSession { let (askpass_kill_master_tx, askpass_kill_master_rx) = oneshot::channel::<()>(); let kill_tx = Arc::new(Mutex::new(Some(askpass_kill_master_tx))); - #[cfg(target_os = "windows")] - let askpass_secret = secret.clone(); let get_password = { let executor = executor.clone(); + #[cfg(target_os = "windows")] + let askpass_secret = secret.clone(); move |prompt| { let prompt = delegate.ask_password(prompt); let kill_tx = kill_tx.clone(); @@ -117,7 +119,7 @@ impl AskPassSession { if let Some(password) = prompt.await { #[cfg(target_os = "windows")] { - _ = askpass_secret.set(password.clone()); + askpass_secret.lock().unwrap().replace(password.clone()); } ControlFlow::Continue(Ok(password)) } else { @@ -172,7 +174,7 @@ impl AskPassSession { /// This will return the password that was last set by the askpass script. #[cfg(target_os = "windows")] pub fn get_password(&self) -> Option { - self.secret.get().cloned() + self.secret.lock().ok()?.clone() } pub fn script_path(&self) -> impl AsRef {