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

Method move_file

atomic-repository/src/repository/tracking.rs:424–452  ·  view source on GitHub ↗

Move or rename a tracked file. This updates the tracking to reflect a file move/rename. The file's history is preserved because the inode stays the same. Note: This does NOT move the actual file on disk. You should move the file first, then call this method. # Arguments `from` - Current path of the file `to` - New path for the file # Example ```rust,ignore // First move the actual file std::

(
        &self,
        from: P,
        to: Q,
    )

Source from the content-addressed store, hash-verified

422 /// repo.move_file("old_name.rs", "new_name.rs")?;
423 /// ```
424 pub fn move_file<P: AsRef<Path>, Q: AsRef<Path>>(
425 &self,
426 from: P,
427 to: Q,
428 ) -> Result<Inode, RepositoryError> {
429 let from_normalized = normalize_path(from.as_ref());
430 let to_normalized = normalize_path(to.as_ref());
431
432 let mut txn = self
433 .pristine
434 .write_txn()
435 .map_err(|e| RepositoryError::Database(e.to_string()))?;
436
437 let inode =
438 move_tracked(&mut txn, &from_normalized, &to_normalized).map_err(|e| match e {
439 TrackingError::NotTracked { path } => RepositoryError::FileNotTracked {
440 path: PathBuf::from(path),
441 },
442 TrackingError::DestinationExists { path } => RepositoryError::FileAlreadyTracked {
443 path: PathBuf::from(path),
444 },
445 other => RepositoryError::Database(other.to_string()),
446 })?;
447
448 txn.commit()
449 .map_err(|e| RepositoryError::Database(e.to_string()))?;
450
451 Ok(inode)
452 }
453
454 /// Check if a file is tracked.
455 ///

Callers 1

test_repo_move_fileFunction · 0.45

Calls 5

move_trackedFunction · 0.85
as_refMethod · 0.80
write_txnMethod · 0.80
commitMethod · 0.80
normalize_pathFunction · 0.50

Tested by 1

test_repo_move_fileFunction · 0.36