Move a single file extracted by `stream_sandbox_tar` into its final position on the host. `staging_dir` must contain a single regular-file entry named `source_basename` (the wrapper produced by `tar cf - -C `). The entry is renamed onto `final_path`, atomically when `staging_dir` is on the same filesystem. Refuses to overwrite an existing directory at `final_path` to match `cp` beh
(
staging_dir: &Path,
source_basename: &str,
final_path: &Path,
)
| 1262 | /// on the same filesystem. Refuses to overwrite an existing directory at |
| 1263 | /// `final_path` to match `cp` behaviour. |
| 1264 | fn place_downloaded_file( |
| 1265 | staging_dir: &Path, |
| 1266 | source_basename: &str, |
| 1267 | final_path: &Path, |
| 1268 | ) -> Result<()> { |
| 1269 | let staged_file = staging_dir.join(source_basename); |
| 1270 | let staged_meta = fs::symlink_metadata(&staged_file) |
| 1271 | .into_diagnostic() |
| 1272 | .wrap_err("downloaded archive did not contain the expected entry")?; |
| 1273 | if !staged_meta.is_file() { |
| 1274 | return Err(miette::miette!( |
| 1275 | "downloaded entry '{source_basename}' is not a regular file" |
| 1276 | )); |
| 1277 | } |
| 1278 | |
| 1279 | if let Ok(existing) = fs::symlink_metadata(final_path) |
| 1280 | && existing.is_dir() |
| 1281 | { |
| 1282 | return Err(miette::miette!( |
| 1283 | "cannot overwrite directory '{}' with downloaded file", |
| 1284 | final_path.display() |
| 1285 | )); |
| 1286 | } |
| 1287 | |
| 1288 | fs::rename(&staged_file, final_path) |
| 1289 | .into_diagnostic() |
| 1290 | .wrap_err_with(|| format!("failed to rename into '{}'", final_path.display()))?; |
| 1291 | Ok(()) |
| 1292 | } |
| 1293 | |
| 1294 | async fn sandbox_sync_down_directory( |
| 1295 | session: &SshSessionConfig, |
no outgoing calls