MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / scan_sandboxes

Function scan_sandboxes

crates/openshell-server/src/grpc/provider.rs:319–348  ·  view source on GitHub ↗

Iterate over every `Sandbox` in the store and collect items produced by `f`. `f` receives each decoded sandbox; returning `Some(T)` includes the value in the output, `None` skips it. This is the shared pagination kernel used by all sandbox-scan helpers.

(store: &Store, mut f: F)

Source from the content-addressed store, hash-verified

317///
318/// This is the shared pagination kernel used by all sandbox-scan helpers.
319async fn scan_sandboxes<T, F>(store: &Store, mut f: F) -> Result<Vec<T>, Status>
320where
321 F: FnMut(Sandbox) -> Option<T>,
322{
323 let mut out = Vec::new();
324 let mut offset = 0u32;
325 loop {
326 let records = store
327 .list(Sandbox::object_type(), 1000, offset)
328 .await
329 .map_err(|e| Status::internal(format!("list sandboxes failed: {e}")))?;
330 if records.is_empty() {
331 break;
332 }
333 offset = offset
334 .checked_add(
335 u32::try_from(records.len())
336 .map_err(|_| Status::internal("sandbox page size exceeded u32"))?,
337 )
338 .ok_or_else(|| Status::internal("sandbox pagination offset overflow"))?;
339 for record in records {
340 let sandbox = Sandbox::decode(record.payload.as_slice())
341 .map_err(|e| Status::internal(format!("decode sandbox failed: {e}")))?;
342 if let Some(item) = f(sandbox) {
343 out.push(item);
344 }
345 }
346 }
347 Ok(out)
348}
349
350async fn sandboxes_using_provider(
351 store: &Store,

Calls 5

lenMethod · 0.80
as_sliceMethod · 0.80
pushMethod · 0.80
listMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected