askpass: Fix cli path when executed in a remote server (#39475)
Closes #39469 Closes #39438 Closes #39458 I'm not able to test it, i would appreciate if somebody could do it. I think this bug was present also for SSH remote projects Release Notes: - Fixed an issue where zed bin was not found in remote servers for askpass --------- Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
This commit is contained in:
+11
-30
@@ -18,7 +18,9 @@ pub mod time;
|
||||
use anyhow::{Context as _, Result};
|
||||
use futures::Future;
|
||||
use itertools::Either;
|
||||
use paths::PathExt;
|
||||
use regex::Regex;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{LazyLock, OnceLock};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
@@ -288,27 +290,19 @@ fn load_shell_from_passwd() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
/// Returns a shell escaped path for the current zed executable
|
||||
pub fn get_shell_safe_zed_path() -> anyhow::Result<String> {
|
||||
let zed_path = std::env::current_exe()
|
||||
.context("Failed to determine current zed executable path.")?
|
||||
.to_string_lossy()
|
||||
.trim_end_matches(" (deleted)") // see https://github.com/rust-lang/rust/issues/69343
|
||||
.to_string();
|
||||
let zed_path =
|
||||
std::env::current_exe().context("Failed to determine current zed executable path.")?;
|
||||
|
||||
// As of writing, this can only be fail if the path contains a null byte, which shouldn't be possible
|
||||
// but shlex has annotated the error as #[non_exhaustive] so we can't make it a compile error if other
|
||||
// errors are introduced in the future :(
|
||||
let zed_path_escaped =
|
||||
shlex::try_quote(&zed_path).context("Failed to shell-escape Zed executable path.")?;
|
||||
|
||||
Ok(zed_path_escaped.to_string())
|
||||
zed_path
|
||||
.try_shell_safe()
|
||||
.context("Failed to shell-escape Zed executable path.")
|
||||
}
|
||||
|
||||
/// Returns a shell escaped path for the zed cli executable, this function
|
||||
/// Returns a path for the zed cli executable, this function
|
||||
/// should be called from the zed executable, not zed-cli.
|
||||
pub fn get_shell_safe_zed_cli_path() -> Result<String> {
|
||||
pub fn get_zed_cli_path() -> Result<PathBuf> {
|
||||
let zed_path =
|
||||
std::env::current_exe().context("Failed to determine current zed executable path.")?;
|
||||
let parent = zed_path
|
||||
@@ -329,7 +323,7 @@ pub fn get_shell_safe_zed_cli_path() -> Result<String> {
|
||||
anyhow::bail!("unsupported platform for determining zed-cli path");
|
||||
};
|
||||
|
||||
let zed_cli_path = possible_locations
|
||||
possible_locations
|
||||
.iter()
|
||||
.find_map(|p| {
|
||||
parent
|
||||
@@ -343,20 +337,7 @@ pub fn get_shell_safe_zed_cli_path() -> Result<String> {
|
||||
"could not find zed-cli from any of: {}",
|
||||
possible_locations.join(", ")
|
||||
)
|
||||
})?
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
Ok(zed_cli_path)
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
Ok(shlex::try_quote(&zed_cli_path)
|
||||
.context("Failed to shell-escape Zed executable path.")?
|
||||
.to_string())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
|
||||
Reference in New Issue
Block a user