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

Method save_change

atomic-repository/src/changestore/mod.rs:304–335  ·  view source on GitHub ↗

Save a change to disk. The change is serialized, written to a temporary file, and then atomically renamed to its final path. The change is also added to the cache. # Arguments `change` - The change to save # Returns The hash of the saved change. # Errors Returns an error if: - The directory cannot be created - The file cannot be written - Serialization fails # Example ```rust,ignore let c

(&self, change: &Change)

Source from the content-addressed store, hash-verified

302 /// println!("Saved change: {}", hash.to_base32());
303 /// ```
304 pub fn save_change(&self, change: &Change) -> ChangeStoreResult<Hash> {
305 // Create a temporary file in the changes directory
306 let temp_file = tempfile::NamedTempFile::new_in(&self.changes_dir)?;
307
308 // Serialize the change and get its hash
309 let hash = {
310 let mut writer = BufWriter::new(&temp_file);
311 change.serialize(&mut writer)?
312 };
313
314 // Ensure the target directory exists
315 let target_path = self.change_path(&hash);
316 if let Some(parent) = target_path.parent() {
317 fs::create_dir_all(parent)?;
318 }
319
320 // Atomically move to the final location
321 temp_file.persist(&target_path)?;
322
323 // Add to cache
324 if let Ok(mut cache) = self.cache.write() {
325 cache.insert(hash, change.clone());
326 }
327
328 log::debug!(
329 "Saved change {} to {}",
330 hash.to_base32(),
331 target_path.display()
332 );
333
334 Ok(hash)
335 }
336
337 /// Load a change from disk.
338 ///

Callers 15

execute_rewordMethod · 0.45
save_downloaded_changeFunction · 0.45
save_reasoning_to_changeFunction · 0.45
save_downloaded_changeFunction · 0.45
record_turnFunction · 0.45
store_semantic_sectionsFunction · 0.45
test_save_changeFunction · 0.45
test_load_changeFunction · 0.45
test_save_load_roundtripFunction · 0.45

Calls 6

parentMethod · 0.80
serializeMethod · 0.45
change_pathMethod · 0.45
writeMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45