Stream a tar archive from the sandbox and extract it into a fresh destination directory. The source is always wrapped on the sandbox side so the host can pick a basename when needed.
(
session: &SshSessionConfig,
tar_cmd: String,
extract_into: &Path,
)
| 1157 | /// destination directory. The source is always wrapped on the sandbox side so |
| 1158 | /// the host can pick a basename when needed. |
| 1159 | async fn stream_sandbox_tar( |
| 1160 | session: &SshSessionConfig, |
| 1161 | tar_cmd: String, |
| 1162 | extract_into: &Path, |
| 1163 | ) -> Result<()> { |
| 1164 | let mut ssh = ssh_base_command(&session.proxy_command); |
| 1165 | ssh.arg("-T") |
| 1166 | .arg("-o") |
| 1167 | .arg("RequestTTY=no") |
| 1168 | .arg("sandbox") |
| 1169 | .arg(tar_cmd) |
| 1170 | .stdin(Stdio::null()) |
| 1171 | .stdout(Stdio::piped()) |
| 1172 | .stderr(Stdio::inherit()); |
| 1173 | |
| 1174 | let mut child = ssh.spawn().into_diagnostic()?; |
| 1175 | let stdout = child |
| 1176 | .stdout |
| 1177 | .take() |
| 1178 | .ok_or_else(|| miette::miette!("failed to open stdout for ssh process"))?; |
| 1179 | |
| 1180 | let extract_into = extract_into.to_path_buf(); |
| 1181 | tokio::task::spawn_blocking(move || -> Result<()> { |
| 1182 | let mut archive = tar::Archive::new(stdout); |
| 1183 | archive |
| 1184 | .unpack(&extract_into) |
| 1185 | .into_diagnostic() |
| 1186 | .wrap_err("failed to extract tar archive from sandbox")?; |
| 1187 | Ok(()) |
| 1188 | }) |
| 1189 | .await |
| 1190 | .into_diagnostic()??; |
| 1191 | |
| 1192 | let status = tokio::task::spawn_blocking(move || child.wait()) |
| 1193 | .await |
| 1194 | .into_diagnostic()? |
| 1195 | .into_diagnostic()?; |
| 1196 | |
| 1197 | if !status.success() { |
| 1198 | return Err(miette::miette!( |
| 1199 | "ssh tar create exited with status {status}" |
| 1200 | )); |
| 1201 | } |
| 1202 | Ok(()) |
| 1203 | } |
| 1204 | |
| 1205 | /// Build the `tar cf - -C <parent> -- <basename>` command used to wrap a |
| 1206 | /// single sandbox-side file for download. |
no test coverage detected