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

Function move_tracked

atomic-repository/src/tracking/tree_ops.rs:389–422  ·  view source on GitHub ↗

Move/rename a tracked file. This updates the path → inode mapping while preserving the inode, so the file's history is maintained. # Arguments `txn` - A mutable transaction `from` - The current path `to` - The new path

(
    txn: &mut T,
    from: &str,
    to: &str,
)

Source from the content-addressed store, hash-verified

387/// * `from` - The current path
388/// * `to` - The new path
389pub fn move_tracked<T: MutTxnT + TreeTxnT>(
390 txn: &mut T,
391 from: &str,
392 to: &str,
393) -> TrackingResult<Inode> {
394 // Get the inode for the source
395 let inode = txn
396 .get_inode(from)
397 .map_err(|e| TrackingError::Database(e.to_string()))?
398 .ok_or_else(|| TrackingError::NotTracked {
399 path: from.to_string(),
400 })?;
401
402 // Check destination doesn't exist
403 if txn
404 .get_inode(to)
405 .map_err(|e| TrackingError::Database(e.to_string()))?
406 .is_some()
407 {
408 return Err(TrackingError::DestinationExists {
409 path: to.to_string(),
410 });
411 }
412
413 // Remove old mapping
414 txn.del_tree(from)
415 .map_err(|e| TrackingError::Database(e.to_string()))?;
416
417 // Add new mapping with same inode
418 txn.put_tree(to, inode)
419 .map_err(|e| TrackingError::Database(e.to_string()))?;
420
421 Ok(inode)
422}
423
424/// Get all tracked paths under a directory prefix.
425///

Callers 4

move_fileMethod · 0.85
test_move_tracked_fileFunction · 0.85

Calls 3

del_treeMethod · 0.80
put_treeMethod · 0.80
get_inodeMethod · 0.45

Tested by 3

test_move_tracked_fileFunction · 0.68