oxide_cli/addons/steps/
move_step.rs1use std::path::Path;
2
3use anyhow::{anyhow, Result};
4
5use crate::addons::manifest::MoveStep;
6
7use super::Rollback;
8
9pub fn execute_move(step: &MoveStep, project_root: &Path) -> Result<Vec<Rollback>> {
10 let from = super::safe_join(project_root, &step.from, "move source")?;
11 let to = super::safe_join(project_root, &step.to, "move destination")?;
12
13 if !from.exists() {
14 return Err(anyhow!("{} does not exist", from.display()));
15 }
16 if to.exists() {
17 return Err(anyhow!("{} already exists", to.display()));
18 }
19
20 if let Some(parent) = to.parent() {
21 std::fs::create_dir_all(parent)?;
22 }
23 std::fs::rename(&from, &to)?;
24
25 Ok(vec![Rollback::RenameFile { from: to, to: from }])
26}
27