remote: More nushell fixes (#42608) (cherry-pick to stable) (#42609)

zed-zippy[bot] and Lukas Wirth created

Cherry-pick of #42608 to stable

----
Closes https://github.com/zed-industries/zed/issues/42594

Release Notes:

- Fixed remote server installation failing with nutshell

Co-authored-by: Lukas Wirth <lukas@zed.dev>

Change summary

crates/remote/src/transport/ssh.rs | 13 +++++++------
crates/remote/src/transport/wsl.rs | 12 +++++++++---
2 files changed, 16 insertions(+), 9 deletions(-)

Detailed changes

crates/remote/src/transport/ssh.rs 🔗

@@ -487,7 +487,9 @@ impl SshRemoteConnection {
         drop(askpass);
 
         let ssh_shell = socket.shell().await;
+        log::info!("Remote shell discovered: {}", ssh_shell);
         let ssh_platform = socket.platform(ShellKind::new(&ssh_shell, false)).await?;
+        log::info!("Remote platform discovered: {}", ssh_shell);
         let ssh_path_style = match ssh_platform.os {
             "windows" => PathStyle::Windows,
             _ => PathStyle::Posix,
@@ -622,7 +624,7 @@ impl SshRemoteConnection {
                 }
                 Err(e) => {
                     log::error!(
-                        "Failed to download binary on server, attempting to upload server: {e:#}",
+                        "Failed to download binary on server, attempting to download locally and then upload it the server: {e:#}",
                     )
                 }
             }
@@ -688,6 +690,7 @@ impl SshRemoteConnection {
                     return Err(e);
                 }
 
+                log::info!("curl is not available, trying wget");
                 match self
                     .socket
                     .run_command(
@@ -973,13 +976,11 @@ impl SshSocket {
         args: &[impl AsRef<str>],
         allow_pseudo_tty: bool,
     ) -> Result<String> {
-        let output = self
-            .ssh_command(shell_kind, program, args, allow_pseudo_tty)
-            .output()
-            .await?;
+        let mut command = self.ssh_command(shell_kind, program, args, allow_pseudo_tty);
+        let output = command.output().await?;
         anyhow::ensure!(
             output.status.success(),
-            "failed to run command: {}",
+            "failed to run command {command:?}: {}",
             String::from_utf8_lossy(&output.stderr)
         );
         Ok(String::from_utf8_lossy(&output.stdout).to_string())

crates/remote/src/transport/wsl.rs 🔗

@@ -84,12 +84,15 @@ impl WslRemoteConnection {
             .detect_shell()
             .await
             .context("failed detecting shell")?;
+        log::info!("Remote shell discovered: {}", this.shell);
         this.shell_kind = ShellKind::new(&this.shell, false);
         this.can_exec = this.detect_can_exec().await;
+        log::info!("Remote can exec: {}", this.can_exec);
         this.platform = this
             .detect_platform()
             .await
             .context("failed detecting platform")?;
+        log::info!("Remote platform discovered: {}", this.shell);
         this.remote_binary_path = Some(
             this.ensure_server_binary(&delegate, release_channel, version, commit, cx)
                 .await
@@ -178,7 +181,8 @@ impl WslRemoteConnection {
 
         if let Some(parent) = dst_path.parent() {
             let parent = parent.display(PathStyle::Posix);
-            self.run_wsl_command("mkdir", &["-p", &parent])
+            let mkdir = self.shell_kind.prepend_command_prefix("mkdir");
+            self.run_wsl_command(&mkdir, &["-p", &parent])
                 .await
                 .map_err(|e| anyhow!("Failed to create directory: {}", e))?;
         }
@@ -244,7 +248,8 @@ impl WslRemoteConnection {
 
         if let Some(parent) = dst_path.parent() {
             let parent = parent.display(PathStyle::Posix);
-            self.run_wsl_command("mkdir", &["-p", &parent])
+            let mkdir = self.shell_kind.prepend_command_prefix("mkdir");
+            self.run_wsl_command(&mkdir, &["-p", &parent])
                 .await
                 .map_err(|e| anyhow!("Failed to create directory when uploading file: {}", e))?;
         }
@@ -259,8 +264,9 @@ impl WslRemoteConnection {
         );
 
         let src_path_in_wsl = self.windows_path_to_wsl_path(src_path).await?;
+        let cp = self.shell_kind.prepend_command_prefix("cp");
         self.run_wsl_command(
-            "cp",
+            &cp,
             &["-f", &src_path_in_wsl, &dst_path.display(PathStyle::Posix)],
         )
         .await