mirror of
https://github.com/zed-industries/zed.git
synced 2026-05-24 21:59:04 +00:00
terminal_view: Prevent local path resolution for remote terminals (#50268)
When opening a terminal in a remote project, skip local-only path operations (home dir fallback, shell expansion, is_dir checks) so the remote shell opens in the remote user’s home directory by default. Closes #49613. Before you mark this PR as ready for review, make sure that you have: - [ ] Added a solid test coverage and/or screenshots from doing manual testing - [x] Done a self-review taking into account security and performance aspects - [x] Aligned any UI changes with the [UI checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) Release Notes: - Prevent local path resolution for remote terminals
This commit is contained in:
parent
0ae6b4c61a
commit
8f684fcb95
1 changed files with 11 additions and 6 deletions
|
|
@ -1979,9 +1979,13 @@ impl SearchableItem for TerminalView {
|
|||
}
|
||||
|
||||
/// Gets the working directory for the given workspace, respecting the user's settings.
|
||||
/// Falls back to the local home directory only for local workspaces.
|
||||
/// Falls back to home directory when no project directory is available.
|
||||
///
|
||||
/// For remote projects, local-only resolution (home dir fallback, shell expansion,
|
||||
/// local `is_dir` checks) is skipped -- returning `None` lets the remote shell
|
||||
/// open in the remote user's home directory by default.
|
||||
pub(crate) fn default_working_directory(workspace: &Workspace, cx: &App) -> Option<PathBuf> {
|
||||
let should_fallback_to_local_home = workspace.project().read(cx).is_local();
|
||||
let is_remote = workspace.project().read(cx).is_remote();
|
||||
let directory = match &TerminalSettings::get_global(cx).working_directory {
|
||||
WorkingDirectory::CurrentFileDirectory => workspace
|
||||
.project()
|
||||
|
|
@ -1991,16 +1995,17 @@ pub(crate) fn default_working_directory(workspace: &Workspace, cx: &App) -> Opti
|
|||
WorkingDirectory::CurrentProjectDirectory => current_project_directory(workspace, cx),
|
||||
WorkingDirectory::FirstProjectDirectory => first_project_directory(workspace, cx),
|
||||
WorkingDirectory::AlwaysHome => None,
|
||||
WorkingDirectory::Always { directory } => shellexpand::full(directory)
|
||||
WorkingDirectory::Always { directory } if !is_remote => shellexpand::full(directory)
|
||||
.ok()
|
||||
.map(|dir| Path::new(&dir.to_string()).to_path_buf())
|
||||
.filter(|dir| dir.is_dir()),
|
||||
WorkingDirectory::Always { .. } => None,
|
||||
};
|
||||
|
||||
if should_fallback_to_local_home {
|
||||
directory.or_else(dirs::home_dir)
|
||||
} else {
|
||||
if is_remote {
|
||||
directory
|
||||
} else {
|
||||
directory.or_else(dirs::home_dir)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue