Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 56 additions & 5 deletions engine/src/network/ssh_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl SshSession {
.await
.map_err(NetworkError::from)?;

let mut remote_stderr = String::new();
let mut protocol = UploadPackProtocol::with_haves(haves);
let mut protocol_completed = false;

Expand All @@ -94,13 +95,25 @@ impl SshSession {
if verbose {
println!("Remote command exited with status: {exit_status}");
}

if exit_status != 0 {
if !remote_stderr.is_empty() {
let clean_msg = remote_stderr.trim().to_string();
return Err(NetworkError::RemoteError { message: clean_msg }.into());
}

return Err(NetworkError::RemoteCommand {
status: exit_status,
}
.into());
}
}
ChannelMsg::ExtendedData { data, ext } => {
if ext == 1 {
let text = String::from_utf8_lossy(&data);
remote_stderr.push_str(&text);
}
}
_ => {}
}
}
Expand Down Expand Up @@ -144,6 +157,7 @@ impl SshSession {
.await
.map_err(NetworkError::from)?;

let mut remote_stderr = String::new();
let mut protocol = ReceivePackProtocol::new(updates.to_vec());
let mut protocol_completed = false;

Expand All @@ -168,12 +182,23 @@ impl SshSession {
println!("Remote command exited with status: {exit_status}");
}
if exit_status != 0 {
if !remote_stderr.is_empty() {
let clean_msg = remote_stderr.trim().to_string();
return Err(NetworkError::RemoteError { message: clean_msg }.into());
}

return Err(NetworkError::RemoteCommand {
status: exit_status,
}
.into());
}
}
ChannelMsg::ExtendedData { data, ext } => {
if ext == 1 {
let text = String::from_utf8_lossy(&data);
remote_stderr.push_str(&text);
}
}
_ => {}
}
}
Expand Down Expand Up @@ -213,16 +238,42 @@ impl SshSession {
.await
.map_err(NetworkError::from)?;

let mut remote_stderr = String::new();
let mut protocol = UploadPackProtocol::discovery_only();
let mut protocol_completed = false;

while let Some(msg) = channel.wait().await {
if let ChannelMsg::Data { data } = msg {
let is_complete = protocol.process_data(&data, &mut channel, verbose).await?;
if is_complete {
protocol_completed = true;
channel.close().await.map_err(NetworkError::from)?;
match msg {
ChannelMsg::Data { data } => {
let is_complete = protocol.process_data(&data, &mut channel, verbose).await?;
if is_complete {
protocol_completed = true;
channel.close().await.map_err(NetworkError::from)?;
}
}
ChannelMsg::ExitStatus { exit_status } => {
if verbose {
println!("Remote command exited with status: {exit_status}");
}
if exit_status != 0 {
if !remote_stderr.is_empty() {
let clean_msg = remote_stderr.trim().to_string();
return Err(NetworkError::RemoteError { message: clean_msg }.into());
}

return Err(NetworkError::RemoteCommand {
status: exit_status,
}
.into());
}
}
ChannelMsg::ExtendedData { data, ext } => {
if ext == 1 {
let text = String::from_utf8_lossy(&data);
remote_stderr.push_str(&text);
}
}
_ => {}
}
}

Expand Down
5 changes: 3 additions & 2 deletions server/src/server_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,12 @@ impl Handler for ServerHandler {
session: &mut Session,
) -> Result<(), Self::Error> {
let command_str = std::str::from_utf8(data)?;

let mut reject = |msg: &str| -> Result<(), Self::Error> {
error!("Executing command on channel {channel:?}: {msg}");
session.data(

session.extended_data(
channel,
1,
CryptoVec::from_slice(format!("{msg}\n").as_bytes()),
);
session.exit_status_request(channel, 1);
Expand Down