MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / put_working_copy

Method put_working_copy

atomic-core/src/pristine/txn/write/working_copy.rs:62–100  ·  view source on GitHub ↗
(&mut self, record: &WorkingCopyRecord)

Source from the content-addressed store, hash-verified

60
61impl WorkingCopyMutTxnT for WriteTxn<'_> {
62 fn put_working_copy(&mut self, record: &WorkingCopyRecord) -> PristineResult<()> {
63 let encoded = encode_working_copy_record(record)?;
64
65 if ViewTxnT::get_view_by_id(self, record.desired_view)?.is_none() {
66 return Err(PristineError::ViewNotFound {
67 name: format!("desired view id={}", record.desired_view),
68 });
69 }
70
71 if let Some(existing) = WorkingCopyTxnT::get_working_copy(self, record.id)? {
72 if existing.location_fingerprint != record.location_fingerprint {
73 return Err(PristineError::WorkingCopyIdentityConflict {
74 requested_id: record.id.to_string(),
75 existing_id: existing.id.to_string(),
76 });
77 }
78 }
79
80 if let Some(existing) =
81 WorkingCopyTxnT::find_working_copy_by_location(self, &record.location_fingerprint)?
82 {
83 if existing.id != record.id {
84 return Err(PristineError::WorkingCopyIdentityConflict {
85 requested_id: record.id.to_string(),
86 existing_id: existing.id.to_string(),
87 });
88 }
89 }
90
91 let mut table = match self.txn.open_table(WORKING_COPIES) {
92 Ok(table) => table,
93 Err(redb::TableError::TableDoesNotExist(_)) => {
94 return Err(PristineError::WorkingCopySchemaUnavailable);
95 }
96 Err(error) => return Err(error.into()),
97 };
98 table.insert(record.id.as_bytes(), encoded.as_slice())?;
99 Ok(())
100 }
101}
102
103#[cfg(test)]

Calls 5

is_noneMethod · 0.80
insertMethod · 0.45
as_bytesMethod · 0.45
as_sliceMethod · 0.45