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

Function write_checkpoint

atomic-cli/src/commands/git/checkpoint.rs:265–294  ·  view source on GitHub ↗

Atomically write a version-2 checkpoint.

(
    root: &Path,
    checkpoint: &ShimCheckpoint,
)

Source from the content-addressed store, hash-verified

263
264/// Atomically write a version-2 checkpoint.
265pub(crate) fn write_checkpoint(
266 root: &Path,
267 checkpoint: &ShimCheckpoint,
268) -> Result<(), CheckpointError> {
269 let directory = root.join(".atomic/bridge");
270 fs::create_dir_all(&directory).map_err(CheckpointError::Write)?;
271 let destination = checkpoint_path(root);
272 let temporary = directory.join(format!(".workspace.json.{}.tmp", std::process::id()));
273
274 let mut persisted = checkpoint.clone();
275 persisted.version = CHECKPOINT_VERSION;
276 let bytes = serde_json::to_vec_pretty(&persisted).map_err(CheckpointError::Encode)?;
277
278 let result = (|| -> std::io::Result<()> {
279 let mut file = OpenOptions::new()
280 .write(true)
281 .create_new(true)
282 .open(&temporary)?;
283 file.write_all(&bytes)?;
284 file.write_all(b"\n")?;
285 file.sync_all()?;
286 fs::rename(&temporary, &destination)?;
287 Ok(())
288 })();
289 if let Err(error) = result {
290 let _ = fs::remove_file(&temporary);
291 return Err(CheckpointError::Write(error));
292 }
293 Ok(())
294}
295
296/// Observe the current Atomic view using graph-derived bytes only.
297///

Calls 4

checkpoint_pathFunction · 0.85
cloneMethod · 0.45
openMethod · 0.45
writeMethod · 0.45

Tested by 1