libblobd_direct/op/
inspect_object.rs1use super::OpError;
2use super::OpResult;
3use crate::ctx::Ctx;
4use chrono::DateTime;
5use chrono::Utc;
6use std::sync::atomic::Ordering::Relaxed;
7use std::sync::Arc;
8use tinybuf::TinyBuf;
9
10pub struct OpInspectObjectInput {
11 pub key: TinyBuf,
12 pub id: Option<u64>,
14}
15
16pub struct OpInspectObjectOutput {
17 pub id: u64,
18 pub size: u64,
19 pub created: DateTime<Utc>,
20}
21
22pub(crate) async fn op_inspect_object(
23 ctx: Arc<Ctx>,
24 req: OpInspectObjectInput,
25) -> OpResult<OpInspectObjectOutput> {
26 let Some(obj) = ctx.committed_objects.get(&req.key).filter(|o| req.id.is_none() || Some(o.id()) == req.id).map(|e| e.value().clone()) else {
27 return Err(OpError::ObjectNotFound);
28 };
29 ctx.metrics.0.inspect_op_count.fetch_add(1, Relaxed);
30 Ok(OpInspectObjectOutput {
31 id: obj.id(),
32 size: obj.size,
33 created: obj.created,
34 })
35}