From 57b10ac094637a228d470352c708fdfecfb93acd Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 23 Aug 2022 09:55:45 -0700 Subject: [PATCH] Avoid full path canonicalization when resolving cwd It can have some surprising effects, so leave it at the basic logical composition of cwd + relative rather than physical. refs: https://github.com/wez/wezterm/issues/2449 --- docs/changelog.md | 1 + wezterm/src/main.rs | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 2722180cf..f6f20793a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -36,6 +36,7 @@ As features stabilize some brief notes about them will accumulate here. * `x` and `+` buttons in the fancy tab bar are now always square [#2399](https://github.com/wez/wezterm/issues/2399) * middle clicking a tab to close it will now confirm closing using the same rules as [CloseCurrentTab](config/lua/keyassignment/CloseCurrentTab.md) [#2350](https://github.com/wez/wezterm/issues/2350) * Emitting the tmux-style `ESC k TITLE ST` sequence via ConPTY breaks output for the pane [#2442](https://github.com/wez/wezterm/issues/2442) +* Avoid using full path canonicalization for `--cwd` options [#2449](https://github.com/wez/wezterm/issues/2449) ### 20220807-113146-c2fee766 diff --git a/wezterm/src/main.rs b/wezterm/src/main.rs index 5ca7ae40a..1fa168045 100644 --- a/wezterm/src/main.rs +++ b/wezterm/src/main.rs @@ -442,10 +442,10 @@ struct SetCwdCommand { impl SetCwdCommand { fn run(&self) -> anyhow::Result<()> { - let cwd: std::path::PathBuf = match self.cwd.as_ref() { - Some(d) => std::fs::canonicalize(d)?, - None => std::env::current_dir()?, - }; + let mut cwd = std::env::current_dir()?; + if let Some(dir) = &self.cwd { + cwd.push(dir); + } let mut url = url::Url::from_directory_path(&cwd) .map_err(|_| anyhow::anyhow!("cwd {} is not an absolute path", cwd.display()))?; @@ -462,11 +462,12 @@ impl SetCwdCommand { } } -fn canon_cwd(cwd: Option) -> anyhow::Result> { +fn resolve_relative_cwd(cwd: Option) -> anyhow::Result> { match cwd { None => Ok(None), Some(cwd) => Ok(Some( - std::fs::canonicalize(cwd)? + std::env::current_dir()? + .join(cwd) .to_str() .ok_or_else(|| anyhow!("path is not representable as String"))? .to_string(), @@ -1003,7 +1004,7 @@ async fn run_cli_async(config: config::ConfigHandle, cli: CliCommand) -> anyhow: let builder = CommandBuilder::from_argv(prog); Some(builder) }, - command_dir: canon_cwd(cwd)?, + command_dir: resolve_relative_cwd(cwd)?, move_pane_id, }) .await?; @@ -1098,7 +1099,7 @@ async fn run_cli_async(config: config::ConfigHandle, cli: CliCommand) -> anyhow: let builder = CommandBuilder::from_argv(prog); Some(builder) }, - command_dir: canon_cwd(cwd)?, + command_dir: resolve_relative_cwd(cwd)?, size, workspace, })