Function hyper_scripter::util::mv
source · Examples found in repository?
src/util/main_util.rs (line 40)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
pub async fn mv(
entry: &mut RepoEntry<'_>,
new_name: Option<ScriptName>,
ty: Option<ScriptType>,
tags: Option<TagSelector>,
) -> Result {
if ty.is_some() || new_name.is_some() {
let og_path = path::open_script(&entry.name, &entry.ty, Some(true))?;
let new_name = new_name.as_ref().unwrap_or(&entry.name);
let new_ty = ty.as_ref().unwrap_or(&entry.ty);
let new_path = path::open_script(new_name, new_ty, None)?; // NOTE: 不判斷存在性,因為接下來要對新舊腳本同路徑的狀況做特殊處理
if new_path != og_path {
log::debug!("改動腳本檔案:{:?} -> {:?}", og_path, new_path);
if new_path.exists() {
return Err(Error::PathExist(new_path).context("移動成既存腳本"));
}
super::mv(&og_path, &new_path)?;
} else {
log::debug!("相同的腳本檔案:{:?},不做檔案處理", og_path);
}
}
entry
.update(|info| {
if let Some(ty) = ty {
info.ty = ty;
}
if let Some(name) = new_name {
info.name = name.clone();
}
if let Some(tags) = tags {
info.append_tags(tags);
}
info.write();
})
.await?;
Ok(())
}