(
socket: &Path,
repository: libatomic::atomic::RepositoryRef,
target: libatomic::atomic::ViewRef,
prefix: Option<String>,
sandbox: &Path,
)
| 451 | /// a tonic channel is bound to the runtime that created it. |
| 452 | #[cfg(unix)] |
| 453 | fn atomic_sandbox( |
| 454 | socket: &Path, |
| 455 | repository: libatomic::atomic::RepositoryRef, |
| 456 | target: libatomic::atomic::ViewRef, |
| 457 | prefix: Option<String>, |
| 458 | sandbox: &Path, |
| 459 | ) -> Result<(BTreeMap<String, u128>, usize)> { |
| 460 | use libatomic::daemon::sandbox_wire; |
| 461 | |
| 462 | let mut phases = BTreeMap::new(); |
| 463 | let sandbox = sandbox.to_path_buf(); |
| 464 | let socket = socket.to_path_buf(); |
| 465 | let (written, inner) = |
| 466 | std::thread::spawn(move || -> Result<(usize, BTreeMap<String, u128>)> { |
| 467 | let runtime = tokio::runtime::Builder::new_current_thread() |
| 468 | .enable_all() |
| 469 | .build() |
| 470 | .map_err(anyhow::Error::msg)?; |
| 471 | runtime.block_on(async move { |
| 472 | use tokio_stream::StreamExt; |
| 473 | let mut phases = BTreeMap::new(); |
| 474 | let started = Instant::now(); |
| 475 | let mut client = connect(&socket).await?; |
| 476 | phases.insert("connect".into(), started.elapsed().as_nanos()); |
| 477 | let started = Instant::now(); |
| 478 | let mut stream = client |
| 479 | .materialize(MaterializeRequest { |
| 480 | repository: Some(repository), |
| 481 | target: Some(target), |
| 482 | path_prefix: prefix, |
| 483 | }) |
| 484 | .await? |
| 485 | .into_inner(); |
| 486 | phases.insert("request".into(), started.elapsed().as_nanos()); |
| 487 | let started = Instant::now(); |
| 488 | let mut written = 0usize; |
| 489 | loop { |
| 490 | let frame = stream |
| 491 | .next() |
| 492 | .await |
| 493 | .ok_or_else(|| anyhow::anyhow!("materialize ended without its summary"))? |
| 494 | .map_err(anyhow::Error::msg)?; |
| 495 | match frame.frame { |
| 496 | Some(libatomic::atomic::materialize_frame::Frame::Entry(entry)) => { |
| 497 | atomic_repository::write_sandbox_entry( |
| 498 | &sandbox, |
| 499 | &entry.path, |
| 500 | sandbox_wire::tree_entry_kind(&entry) |
| 501 | .map_err(anyhow::Error::msg)?, |
| 502 | entry.mode.unwrap_or(0o644), |
| 503 | entry.inline.as_deref().unwrap_or_default(), |
| 504 | )?; |
| 505 | written += 1; |
| 506 | } |
| 507 | Some(libatomic::atomic::materialize_frame::Frame::Done(done)) => { |
| 508 | ensure!( |
| 509 | done.entries as usize == written, |
| 510 | "the server sent {written} entries but said {}", |
no test coverage detected