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,
)
| 387 | /// * `from` - The current path |
| 388 | /// * `to` - The new path |
| 389 | pub 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 | /// |